system-linux: parse vti specific settings as nested json data object
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 14 Mar 2017 20:36:39 +0000 (21:36 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Tue, 21 Mar 2017 21:40:54 +0000 (22:40 +0100)
Parse vti specific settings ikey and okey as nested json data object.
At the same time remove the now obsolete TUNNEL_ATTR_INFO attribute.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
system-linux.c
system.c
system.h

index b7297fd6a6d8cfc08a63321a3d2a4deb8b24ea56..471efffcd2876d5da733c44981240e67cd8527d0 100644 (file)
@@ -2462,7 +2462,6 @@ static int system_add_vti_tunnel(const char *name, const char *kind,
        struct nl_msg *nlm;
        struct ifinfomsg ifi = { .ifi_family = AF_UNSPEC, };
        struct blob_attr *cur;
        struct nl_msg *nlm;
        struct ifinfomsg ifi = { .ifi_family = AF_UNSPEC, };
        struct blob_attr *cur;
-       uint32_t ikey = 0, okey = 0;
        int ret = 0;
 
        nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE);
        int ret = 0;
 
        nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE);
@@ -2488,14 +2487,6 @@ static int system_add_vti_tunnel(const char *name, const char *kind,
        if (link)
                nla_put_u32(nlm, IFLA_VTI_LINK, link);
 
        if (link)
                nla_put_u32(nlm, IFLA_VTI_LINK, link);
 
-       if ((cur = tb[TUNNEL_ATTR_INFO]) && (blobmsg_type(cur) == BLOBMSG_TYPE_STRING)) {
-               if (sscanf(blobmsg_get_string(cur), "%u,%u",
-                       &ikey, &okey) < 2) {
-                       ret = -EINVAL;
-                       goto failure;
-               }
-       }
-
        if (v6) {
                struct in6_addr in6buf;
                if ((cur = tb[TUNNEL_ATTR_LOCAL])) {
        if (v6) {
                struct in6_addr in6buf;
                if ((cur = tb[TUNNEL_ATTR_LOCAL])) {
@@ -2535,11 +2526,23 @@ static int system_add_vti_tunnel(const char *name, const char *kind,
 
        }
 
 
        }
 
-       if (okey)
-               nla_put_u32(nlm, IFLA_VTI_OKEY, htonl(okey));
+       if ((cur = tb[TUNNEL_ATTR_DATA])) {
+               struct blob_attr *tb_data[__VTI_DATA_ATTR_MAX];
+               uint32_t ikey = 0, okey = 0;
 
 
-       if (ikey)
-               nla_put_u32(nlm, IFLA_VTI_IKEY, htonl(ikey));
+               blobmsg_parse(vti_data_attr_list.params, __VTI_DATA_ATTR_MAX, tb_data,
+                       blobmsg_data(cur), blobmsg_len(cur));
+
+               if ((cur = tb_data[VTI_DATA_IKEY])) {
+                       if ((ikey = blobmsg_get_u32(cur)))
+                               nla_put_u32(nlm, IFLA_VTI_IKEY, htonl(ikey));
+               }
+
+               if ((cur = tb_data[VTI_DATA_OKEY])) {
+                       if ((okey = blobmsg_get_u32(cur)))
+                               nla_put_u32(nlm, IFLA_VTI_OKEY, htonl(okey));
+               }
+       }
 
        nla_nest_end(nlm, infodata);
        nla_nest_end(nlm, linkinfo);
 
        nla_nest_end(nlm, infodata);
        nla_nest_end(nlm, linkinfo);
index f899c7b6dd39fdf4e8fb2f18429f5430a9f76d02..3d4a979c6372fd77f0733c9cb923bc9d4e0e56e4 100644 (file)
--- a/system.c
+++ b/system.c
@@ -27,7 +27,6 @@ static const struct blobmsg_policy tunnel_attrs[__TUNNEL_ATTR_MAX] = {
        [TUNNEL_ATTR_6RD_RELAY_PREFIX] = { .name = "6rd-relay-prefix", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_FMRS] = { .name = "fmrs", .type = BLOBMSG_TYPE_ARRAY },
        [TUNNEL_ATTR_6RD_RELAY_PREFIX] = { .name = "6rd-relay-prefix", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_FMRS] = { .name = "fmrs", .type = BLOBMSG_TYPE_ARRAY },
-       [TUNNEL_ATTR_INFO] = { .name = "info", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
 };
 
        [TUNNEL_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
 };
 
@@ -61,6 +60,16 @@ const struct uci_blob_param_list gre_data_attr_list = {
        .params = gre_data_attrs,
 };
 
        .params = gre_data_attrs,
 };
 
+static const struct blobmsg_policy vti_data_attrs[__VTI_DATA_ATTR_MAX] = {
+       [VTI_DATA_IKEY] = { .name = "ikey", .type = BLOBMSG_TYPE_INT32 },
+       [VTI_DATA_OKEY] = { .name = "okey", .type = BLOBMSG_TYPE_INT32 },
+};
+
+const struct uci_blob_param_list vti_data_attr_list = {
+       .n_params = __VTI_DATA_ATTR_MAX,
+       .params = vti_data_attrs,
+};
+
 void system_fd_set_cloexec(int fd)
 {
 #ifdef FD_CLOEXEC
 void system_fd_set_cloexec(int fd)
 {
 #ifdef FD_CLOEXEC
index 14b1e53dbe7a79e6e125c7d56eab3d1e15861998..9995fa94094bf325f03048248bb9c760956d86ce 100644 (file)
--- a/system.h
+++ b/system.h
@@ -34,7 +34,6 @@ enum tunnel_param {
        TUNNEL_ATTR_6RD_RELAY_PREFIX,
        TUNNEL_ATTR_LINK,
        TUNNEL_ATTR_FMRS,
        TUNNEL_ATTR_6RD_RELAY_PREFIX,
        TUNNEL_ATTR_LINK,
        TUNNEL_ATTR_FMRS,
-       TUNNEL_ATTR_INFO,
        TUNNEL_ATTR_DATA,
        __TUNNEL_ATTR_MAX
 };
        TUNNEL_ATTR_DATA,
        __TUNNEL_ATTR_MAX
 };
@@ -58,8 +57,15 @@ enum gre_data {
        __GRE_DATA_ATTR_MAX
 };
 
        __GRE_DATA_ATTR_MAX
 };
 
+enum vti_data {
+       VTI_DATA_IKEY,
+       VTI_DATA_OKEY,
+       __VTI_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 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;
 
 enum bridge_opt {
        /* stp and forward delay always set */
 
 enum bridge_opt {
        /* stp and forward delay always set */