From: Rafał Miłecki <[email protected]>

Many protocol handlers support "zone" option independently and they pass
it in the "data". Then it's read e.g. by a firewall[34].

Add support for "zone" directly to the netifd so:
1. It works for all protocols
2. Handlers don't have to duplicate code

Signed-off-by: Rafał Miłecki <[email protected]>
---
 interface.c | 6 ++++++
 interface.h | 1 +
 ubus.c      | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/interface.c b/interface.c
index b3bb601..255ce84 100644
--- a/interface.c
+++ b/interface.c
@@ -34,6 +34,7 @@ enum {
        IFACE_ATTR_IFNAME, /* Backward compatibility */
        IFACE_ATTR_PROTO,
        IFACE_ATTR_AUTO,
+       IFACE_ATTR_ZONE,
        IFACE_ATTR_JAIL,
        IFACE_ATTR_JAIL_DEVICE,
        IFACE_ATTR_JAIL_IFNAME,
@@ -62,6 +63,7 @@ static const struct blobmsg_policy 
iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_AUTO] = { .name = "auto", .type = BLOBMSG_TYPE_BOOL },
+       [IFACE_ATTR_ZONE] = { .name = "zone", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_JAIL] = { .name = "jail", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_JAIL_DEVICE] = { .name = "jail_device", .type = 
BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_JAIL_IFNAME] = { .name = "jail_ifname", .type = 
BLOBMSG_TYPE_STRING },
@@ -832,6 +834,10 @@ interface_alloc(const char *name, struct blob_attr 
*config, bool dynamic)
        blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
                      blob_data(config), blob_len(config));
 
+       iface->zone = NULL;
+       if ((cur = tb[IFACE_ATTR_ZONE]))
+               iface->zone = strdup(blobmsg_get_string(cur));
+
        if ((cur = tb[IFACE_ATTR_PROTO]))
                proto_name = blobmsg_data(cur);
 
diff --git a/interface.h b/interface.h
index 73a9070..9343ade 100644
--- a/interface.h
+++ b/interface.h
@@ -108,6 +108,7 @@ struct interface {
 
        const char *name;
        const char *device;
+       const char *zone;
        char *jail;
        char *jail_device;
        char *host_device;
diff --git a/ubus.c b/ubus.c
index 2876e7d..7f4821d 100644
--- a/ubus.c
+++ b/ubus.c
@@ -918,6 +918,9 @@ netifd_dump_status(struct interface *iface)
        }
 
        a = blobmsg_open_table(&b, "data");
+
+       if (iface->zone)
+               blobmsg_add_string(&b, "zone", iface->zone);
        avl_for_each_element(&iface->data, data, node)
                blobmsg_add_blob(&b, data->data);
 
-- 
2.34.1


_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to