system-linux: parse 6rd specific settings as nested json data object
[project/netifd.git] / system.c
1 /*
2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 #include "netifd.h"
15 #include "system.h"
16 #include <fcntl.h>
17
18 static const struct blobmsg_policy tunnel_attrs[__TUNNEL_ATTR_MAX] = {
19 [TUNNEL_ATTR_TYPE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
20 [TUNNEL_ATTR_LOCAL] = { .name = "local", .type = BLOBMSG_TYPE_STRING },
21 [TUNNEL_ATTR_REMOTE] = { .name = "remote", .type = BLOBMSG_TYPE_STRING },
22 [TUNNEL_ATTR_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
23 [TUNNEL_ATTR_DF] = { .name = "df", .type = BLOBMSG_TYPE_BOOL },
24 [TUNNEL_ATTR_TTL] = { .name = "ttl", .type = BLOBMSG_TYPE_INT32 },
25 [TUNNEL_ATTR_TOS] = { .name = "tos", .type = BLOBMSG_TYPE_STRING },
26 [TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
27 [TUNNEL_ATTR_FMRS] = { .name = "fmrs", .type = BLOBMSG_TYPE_ARRAY },
28 [TUNNEL_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
29 };
30
31 const struct uci_blob_param_list tunnel_attr_list = {
32 .n_params = __TUNNEL_ATTR_MAX,
33 .params = tunnel_attrs,
34 };
35
36 static const struct blobmsg_policy vxlan_data_attrs[__VXLAN_DATA_ATTR_MAX] = {
37 [VXLAN_DATA_ATTR_ID] = { .name = "id", .type = BLOBMSG_TYPE_INT32 },
38 [VXLAN_DATA_ATTR_PORT] = { .name = "port", .type = BLOBMSG_TYPE_INT32 },
39 [VXLAN_DATA_ATTR_MACADDR] = { .name = "macaddr", .type = BLOBMSG_TYPE_STRING },
40 };
41
42 const struct uci_blob_param_list vxlan_data_attr_list = {
43 .n_params = __VXLAN_DATA_ATTR_MAX,
44 .params = vxlan_data_attrs,
45 };
46
47 static const struct blobmsg_policy gre_data_attrs[__GRE_DATA_ATTR_MAX] = {
48 [GRE_DATA_IKEY] = { .name = "ikey", .type = BLOBMSG_TYPE_INT32 },
49 [GRE_DATA_OKEY] = { .name = "okey", .type = BLOBMSG_TYPE_INT32 },
50 [GRE_DATA_ICSUM] = { .name = "icsum", .type = BLOBMSG_TYPE_BOOL },
51 [GRE_DATA_OCSUM] = { .name = "ocsum", .type = BLOBMSG_TYPE_BOOL },
52 [GRE_DATA_ISEQNO] = { .name = "iseqno", .type = BLOBMSG_TYPE_BOOL },
53 [GRE_DATA_OSEQNO] = { .name = "oseqno", .type = BLOBMSG_TYPE_BOOL },
54 };
55
56 const struct uci_blob_param_list gre_data_attr_list = {
57 .n_params = __GRE_DATA_ATTR_MAX,
58 .params = gre_data_attrs,
59 };
60
61 static const struct blobmsg_policy vti_data_attrs[__VTI_DATA_ATTR_MAX] = {
62 [VTI_DATA_IKEY] = { .name = "ikey", .type = BLOBMSG_TYPE_INT32 },
63 [VTI_DATA_OKEY] = { .name = "okey", .type = BLOBMSG_TYPE_INT32 },
64 };
65
66 const struct uci_blob_param_list vti_data_attr_list = {
67 .n_params = __VTI_DATA_ATTR_MAX,
68 .params = vti_data_attrs,
69 };
70
71 static const struct blobmsg_policy sixrd_data_attrs[__SIXRD_DATA_ATTR_MAX] = {
72 [SIXRD_DATA_PREFIX] = { .name = "prefix", .type = BLOBMSG_TYPE_STRING },
73 [SIXRD_DATA_RELAY_PREFIX] = { .name = "relay-prefix", .type = BLOBMSG_TYPE_STRING },
74 };
75
76 const struct uci_blob_param_list sixrd_data_attr_list = {
77 .n_params = __SIXRD_DATA_ATTR_MAX,
78 .params = sixrd_data_attrs,
79 };
80
81 void system_fd_set_cloexec(int fd)
82 {
83 #ifdef FD_CLOEXEC
84 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
85 #endif
86 }