summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-08-27 21:48:28 +0200
committerHans Dedecker <dedeckeh@gmail.com>2017-08-29 21:02:30 +0200
commit7d94ede3c38dd7b8e08c8a2fd8ae5ede71a2059b (patch)
treee9510cd11a343f4afaf4726e77ea58334b14bddf
parentb5731bfbabaf7aab0fc47143bd6ad0b12cc3df0a (diff)
downloadnetifd-7d94ede3c38dd7b8e08c8a2fd8ae5ede71a2059b.tar.gz
system-linux: parse map-e fmrs parameters as nested data json object
Parse map-e fmrs parameters IPv6 prefix, IPv4 prefix, ealen and offset as array elements nested in a data json object. At the same time remove the now obsolete TUNNEL_ATTR_FMRS tunnel attribute. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--system-linux.c81
-rw-r--r--system.c13
-rw-r--r--system.h10
3 files changed, 73 insertions, 31 deletions
diff --git a/system-linux.c b/system-linux.c
index 0bf071e..6d97a02 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -2328,45 +2328,68 @@ static int system_add_ip6_tunnel(const char *name, const unsigned int link,
}
#ifdef IFLA_IPTUN_FMR_MAX
- if ((cur = tb[TUNNEL_ATTR_FMRS])) {
+ if ((cur = tb[TUNNEL_ATTR_DATA])) {
struct nlattr *fmrs = nla_nest_start(nlm, IFLA_IPTUN_FMRS);
+ struct blob_attr *dcur;
+ unsigned drem, fmrcnt = 0;
- struct blob_attr *fmr;
- unsigned rem, fmrcnt = 0;
- blobmsg_for_each_attr(fmr, cur, rem) {
- if (blobmsg_type(fmr) != BLOBMSG_TYPE_STRING)
+ blobmsg_for_each_attr(dcur, cur, drem) {
+ if (blobmsg_type(dcur) != BLOBMSG_TYPE_ARRAY ||
+ strcmp(blobmsg_name(dcur), "fmrs") ||
+ blobmsg_check_array(dcur, BLOBMSG_TYPE_UNSPEC) <= 0)
continue;
- unsigned ip4len, ip6len, ealen, offset = 6;
- char ip6buf[48];
- char ip4buf[16];
+ struct blob_attr *rcur;
+ unsigned rrem;
+ blobmsg_for_each_attr(rcur, dcur, rrem) {
+ struct blob_attr *tb_fmr[__FMR_DATA_ATTR_MAX], *tb_cur;
+ struct in6_addr ip6prefix;
+ struct in_addr ip4prefix;
+ unsigned ip4len, ip6len, ealen, offset;
+
+ blobmsg_parse(fmr_data_attr_list.params, __FMR_DATA_ATTR_MAX, tb_fmr,
+ blobmsg_data(rcur), blobmsg_len(rcur));
+
+ if (!(tb_cur = tb_fmr[FMR_DATA_PREFIX6]) ||
+ !parse_ip_and_netmask(AF_INET6,
+ blobmsg_data(tb_cur), &ip6prefix,
+ &ip6len)) {
+ ret = -EINVAL;
+ goto failure;
+ }
- if (sscanf(blobmsg_get_string(fmr), "%47[^/]/%u,%15[^/]/%u,%u,%u",
- ip6buf, &ip6len, ip4buf, &ip4len, &ealen, &offset) < 5) {
- ret = -EINVAL;
- goto failure;
- }
+ if (!(tb_cur = tb_fmr[FMR_DATA_PREFIX4]) ||
+ !parse_ip_and_netmask(AF_INET,
+ blobmsg_data(tb_cur), &ip4prefix,
+ &ip4len)) {
+ ret = -EINVAL;
+ goto failure;
+ }
- struct in6_addr ip6prefix;
- struct in_addr ip4prefix;
- if (inet_pton(AF_INET6, ip6buf, &ip6prefix) != 1 ||
- inet_pton(AF_INET, ip4buf, &ip4prefix) != 1) {
- ret = -EINVAL;
- goto failure;
- }
+ if (!(tb_cur = tb_fmr[FMR_DATA_EALEN])) {
+ ret = -EINVAL;
+ goto failure;
+ }
+ ealen = blobmsg_get_u32(tb_cur);
- struct nlattr *rule = nla_nest_start(nlm, ++fmrcnt);
+ if (!(tb_cur = tb_fmr[FMR_DATA_OFFSET])) {
+ ret = -EINVAL;
+ goto failure;
+ }
+ offset = blobmsg_get_u32(tb_cur);
- nla_put(nlm, IFLA_IPTUN_FMR_IP6_PREFIX, sizeof(ip6prefix), &ip6prefix);
- nla_put(nlm, IFLA_IPTUN_FMR_IP4_PREFIX, sizeof(ip4prefix), &ip4prefix);
- nla_put_u8(nlm, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, ip6len);
- nla_put_u8(nlm, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, ip4len);
- nla_put_u8(nlm, IFLA_IPTUN_FMR_EA_LEN, ealen);
- nla_put_u8(nlm, IFLA_IPTUN_FMR_OFFSET, offset);
+ struct nlattr *rule = nla_nest_start(nlm, ++fmrcnt);
- nla_nest_end(nlm, rule);
- }
+ nla_put(nlm, IFLA_IPTUN_FMR_IP6_PREFIX, sizeof(ip6prefix), &ip6prefix);
+ nla_put(nlm, IFLA_IPTUN_FMR_IP4_PREFIX, sizeof(ip4prefix), &ip4prefix);
+ nla_put_u8(nlm, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, ip6len);
+ nla_put_u8(nlm, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, ip4len);
+ nla_put_u8(nlm, IFLA_IPTUN_FMR_EA_LEN, ealen);
+ nla_put_u8(nlm, IFLA_IPTUN_FMR_OFFSET, offset);
+ nla_nest_end(nlm, rule);
+ }
+ }
nla_nest_end(nlm, fmrs);
}
#endif
diff --git a/system.c b/system.c
index bf3fd77..5555272 100644
--- a/system.c
+++ b/system.c
@@ -24,7 +24,6 @@ static const struct blobmsg_policy tunnel_attrs[__TUNNEL_ATTR_MAX] = {
[TUNNEL_ATTR_TTL] = { .name = "ttl", .type = BLOBMSG_TYPE_INT32 },
[TUNNEL_ATTR_TOS] = { .name = "tos", .type = BLOBMSG_TYPE_STRING },
[TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
- [TUNNEL_ATTR_FMRS] = { .name = "fmrs", .type = BLOBMSG_TYPE_ARRAY },
[TUNNEL_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
};
@@ -78,6 +77,18 @@ const struct uci_blob_param_list sixrd_data_attr_list = {
.params = sixrd_data_attrs,
};
+static const struct blobmsg_policy fmr_data_attrs[__FMR_DATA_ATTR_MAX] = {
+ [FMR_DATA_PREFIX6] = { .name = "prefix6", .type = BLOBMSG_TYPE_STRING },
+ [FMR_DATA_PREFIX4] = { .name = "prefix4", .type = BLOBMSG_TYPE_STRING },
+ [FMR_DATA_EALEN] = { .name = "ealen", .type = BLOBMSG_TYPE_INT32 },
+ [FMR_DATA_OFFSET] = { .name = "offset", .type = BLOBMSG_TYPE_INT32 },
+};
+
+const struct uci_blob_param_list fmr_data_attr_list = {
+ .n_params = __FMR_DATA_ATTR_MAX,
+ .params = fmr_data_attrs,
+};
+
void system_fd_set_cloexec(int fd)
{
#ifdef FD_CLOEXEC
diff --git a/system.h b/system.h
index a5817ca..61c72c2 100644
--- a/system.h
+++ b/system.h
@@ -31,7 +31,6 @@ enum tunnel_param {
TUNNEL_ATTR_TTL,
TUNNEL_ATTR_TOS,
TUNNEL_ATTR_LINK,
- TUNNEL_ATTR_FMRS,
TUNNEL_ATTR_DATA,
__TUNNEL_ATTR_MAX
};
@@ -67,10 +66,19 @@ enum sixrd_data {
__SIXRD_DATA_ATTR_MAX
};
+enum fmr_data {
+ FMR_DATA_PREFIX6,
+ FMR_DATA_PREFIX4,
+ FMR_DATA_EALEN,
+ FMR_DATA_OFFSET,
+ __FMR_DATA_ATTR_MAX
+};
+
extern const struct uci_blob_param_list vxlan_data_attr_list;
extern const struct uci_blob_param_list gre_data_attr_list;
extern const struct uci_blob_param_list vti_data_attr_list;
extern const struct uci_blob_param_list sixrd_data_attr_list;
+extern const struct uci_blob_param_list fmr_data_attr_list;
enum bridge_opt {
/* stp and forward delay always set */