From 7e3b89a4d4c0b55a9b2376b88cbe72a1edc5cd82 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Tue, 14 Mar 2017 21:36:38 +0100 Subject: [PATCH] system-linux: parse gre specific settings as nested json data object Parse gre specific settings ikey, okey, icsum, ocsum, iseqno and oseqno as nested json data object Signed-off-by: Hans Dedecker --- system-linux.c | 48 +++++++++++++++++++++++++++++------------------- system.c | 14 ++++++++++++++ system.h | 11 +++++++++++ 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/system-linux.c b/system-linux.c index 8888047..b7297fd 100644 --- a/system-linux.c +++ b/system-linux.c @@ -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) { diff --git a/system.c b/system.c index 52172c3..f899c7b 100644 --- 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 diff --git a/system.h b/system.h index 6501d15..14b1e53 100644 --- 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 */ -- 2.11.0