system-linux: parse gre specific settings as nested json data object
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 14 Mar 2017 20:36:38 +0000 (21:36 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Tue, 21 Mar 2017 21:39:14 +0000 (22:39 +0100)
Parse gre specific settings ikey, okey, icsum, ocsum, iseqno and oseqno
as nested json data object

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

index 8888047..b7297fd 100644 (file)
@@ -2316,31 +2316,41 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
                }
        }
 
-       if ((cur = tb[TUNNEL_ATTR_INFO]) && (blobmsg_type(cur) == BLOBMSG_TYPE_STRING)) {
-               uint8_t icsum, ocsum, iseqno, oseqno;
-               if (sscanf(blobmsg_get_string(cur), "%u,%u,%hhu,%hhu,%hhu,%hhu",
-                       &ikey, &okey, &icsum, &ocsum, &iseqno, &oseqno) < 6) {
-                       ret = -EINVAL;
-                       goto failure;
-               }
+       if ((cur = tb[TUNNEL_ATTR_DATA])) {
+               struct blob_attr *tb_data[__GRE_DATA_ATTR_MAX];
+
+               blobmsg_parse(gre_data_attr_list.params, __GRE_DATA_ATTR_MAX, tb_data,
+                       blobmsg_data(cur), blobmsg_len(cur));
 
-               if (ikey)
-                       iflags |= GRE_KEY;
+               if ((cur = tb_data[GRE_DATA_IKEY])) {
+                       if ((ikey = blobmsg_get_u32(cur)))
+                               iflags |= GRE_KEY;
+               }
 
-               if (okey)
-                       oflags |= GRE_KEY;
+               if ((cur = tb_data[GRE_DATA_OKEY])) {
+                       if ((okey = blobmsg_get_u32(cur)))
+                               oflags |= GRE_KEY;
+               }
 
-               if (icsum)
-                       iflags |= GRE_CSUM;
+               if ((cur = tb_data[GRE_DATA_ICSUM])) {
+                       if (blobmsg_get_bool(cur))
+                               iflags |= GRE_CSUM;
+               }
 
-               if (ocsum)
-                       oflags |= GRE_CSUM;
+               if ((cur = tb_data[GRE_DATA_OCSUM])) {
+                       if (blobmsg_get_bool(cur))
+                               oflags |= GRE_CSUM;
+               }
 
-               if (iseqno)
-                       iflags |= GRE_SEQ;
+               if ((cur = tb_data[GRE_DATA_ISEQNO])) {
+                       if (blobmsg_get_bool(cur))
+                               iflags |= GRE_SEQ;
+               }
 
-               if (oseqno)
-                       oflags |= GRE_SEQ;
+               if ((cur = tb[GRE_DATA_OSEQNO])) {
+                       if (blobmsg_get_bool(cur))
+                               oflags |= GRE_SEQ;
+               }
        }
 
        if (v6) {
index 52172c3..f899c7b 100644 (file)
--- a/system.c
+++ b/system.c
@@ -47,6 +47,20 @@ const struct uci_blob_param_list vxlan_data_attr_list = {
        .params = vxlan_data_attrs,
 };
 
+static const struct blobmsg_policy gre_data_attrs[__GRE_DATA_ATTR_MAX] = {
+       [GRE_DATA_IKEY] = { .name = "ikey", .type = BLOBMSG_TYPE_INT32 },
+       [GRE_DATA_OKEY] = { .name = "okey", .type = BLOBMSG_TYPE_INT32 },
+       [GRE_DATA_ICSUM] = { .name = "icsum", .type = BLOBMSG_TYPE_BOOL },
+       [GRE_DATA_OCSUM] = { .name = "ocsum", .type = BLOBMSG_TYPE_BOOL },
+       [GRE_DATA_ISEQNO] = { .name = "iseqno", .type = BLOBMSG_TYPE_BOOL },
+       [GRE_DATA_OSEQNO] = { .name = "oseqno", .type = BLOBMSG_TYPE_BOOL },
+};
+
+const struct uci_blob_param_list gre_data_attr_list = {
+       .n_params = __GRE_DATA_ATTR_MAX,
+       .params = gre_data_attrs,
+};
+
 void system_fd_set_cloexec(int fd)
 {
 #ifdef FD_CLOEXEC
index 6501d15..14b1e53 100644 (file)
--- a/system.h
+++ b/system.h
@@ -48,7 +48,18 @@ enum vxlan_data {
        __VXLAN_DATA_ATTR_MAX
 };
 
+enum gre_data {
+       GRE_DATA_IKEY,
+       GRE_DATA_OKEY,
+       GRE_DATA_ICSUM,
+       GRE_DATA_OCSUM,
+       GRE_DATA_ISEQNO,
+       GRE_DATA_OSEQNO,
+       __GRE_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;
 
 enum bridge_opt {
        /* stp and forward delay always set */