[LEDE-DEV,netifd,1/2] system-linux: parse gre specific settings as nested json data object

Submitted by Hans Dedecker on March 14, 2017, 8:36 p.m.

Details

Message ID 20170314203639.4236-1-dedeckeh@gmail.com
State Accepted
Headers show

Commit Message

Hans Dedecker March 14, 2017, 8:36 p.m.
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 | 48 +++++++++++++++++++++++++++++-------------------
 system.c       | 14 ++++++++++++++
 system.h       | 11 +++++++++++
 3 files changed, 54 insertions(+), 19 deletions(-)

Comments

Felix Fietkau March 14, 2017, 10:32 p.m.
On 2017-03-14 21:36, Hans Dedecker wrote:
> Parse gre specific settings ikey, okey, icsum, ocsum, iseqno and oseqno
> as nested json data object
> 
> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Are you sure this works? If I remember correctly, uci_to_blob will only
add options for which it has a policy.

- Felix
Hans Dedecker March 15, 2017, 7:49 a.m.
On Tue, Mar 14, 2017 at 11:32 PM, Felix Fietkau <nbd@nbd.name> wrote:
> On 2017-03-14 21:36, Hans Dedecker wrote:
>> Parse gre specific settings ikey, okey, icsum, ocsum, iseqno and oseqno
>> as nested json data object
>>
>> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
> Are you sure this works? If I remember correctly, uci_to_blob will only
> add options for which it has a policy.
The nested json data object is created by the proto shell handler
script in this case the gre.sh script. I tested this successfully with
the following gre.sh patch
(https://git.lede-project.org/?p=lede/dedeckeh/staging.git;a=commitdiff;h=8d7ee5c816e7c8792cab565e00a96ae884ea766d)
currently in my staging tree . A similar patch is available for the
vti.sh script.


Hans
>
> - Felix
>

Patch hide | download patch | download mbox

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 */