Config support to set the IGMP host version on device level; possible values 
are :
    1 : IGMPv1
    2 : IGMPv2
    3 : IGMPv3

Signed-off-by: Hans Dedecker <dedec...@gmail.com>
---
 device.c       | 11 +++++++++++
 device.h       |  3 +++
 system-dummy.c |  6 ++++++
 system-linux.c | 34 ++++++++++++++++++++++++++++++++++
 system.h       |  1 +
 5 files changed, 55 insertions(+)

diff --git a/device.c b/device.c
index aa5818f..6cdfb49 100644
--- a/device.c
+++ b/device.c
@@ -41,6 +41,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] 
= {
        [DEV_ATTR_PROMISC] = { .name = "promisc", .type = BLOBMSG_TYPE_BOOL },
        [DEV_ATTR_RPFILTER] = { .name = "rpfilter", .type = BLOBMSG_TYPE_STRING 
},
        [DEV_ATTR_ACCEPTLOCAL] = { .name = "acceptlocal", .type = 
BLOBMSG_TYPE_BOOL },
+       [DEV_ATTR_IGMPVERSION] = { .name = "igmpversion", .type = 
BLOBMSG_TYPE_INT32 },
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -158,6 +159,7 @@ device_merge_settings(struct device *dev, struct 
device_settings *n)
        n->promisc = s->flags & DEV_OPT_PROMISC ? s->promisc : os->promisc;
        n->rpfilter = s->flags & DEV_OPT_RPFILTER ? s->rpfilter : os->rpfilter;
        n->acceptlocal = s->flags & DEV_OPT_ACCEPTLOCAL ? s->acceptlocal : 
os->acceptlocal;
+       n->igmpversion = s->flags & DEV_OPT_IGMPVERSION ? s->igmpversion : 
os->igmpversion;
        n->flags = s->flags | os->flags;
 }
 
@@ -213,6 +215,13 @@ device_init_settings(struct device *dev, struct blob_attr 
**tb)
                s->flags |= DEV_OPT_ACCEPTLOCAL;
        }
 
+       if ((cur = tb[DEV_ATTR_IGMPVERSION])) {
+               if (system_resolve_igmpversion(blobmsg_get_u32(cur), 
&s->igmpversion))
+                       s->flags |= DEV_OPT_IGMPVERSION;
+               else
+                       DPRINTF("Failed to resolve igmpversion: %d\n", 
blobmsg_get_u32(cur));
+       }
+
        device_set_disabled(dev, disabled);
 }
 
@@ -754,6 +763,8 @@ device_dump_status(struct blob_buf *b, struct device *dev)
                        blobmsg_add_u32(b, "rpfilter", st.rpfilter);
                if (st.flags & DEV_OPT_ACCEPTLOCAL)
                        blobmsg_add_u8(b, "acceptlocal", st.acceptlocal);
+               if (st.flags & DEV_OPT_IGMPVERSION)
+                       blobmsg_add_u32(b, "igmpversion", st.igmpversion);
        }
 
        s = blobmsg_open_table(b, "statistics");
diff --git a/device.h b/device.h
index 8569be7..a83cac8 100644
--- a/device.h
+++ b/device.h
@@ -35,6 +35,7 @@ enum {
        DEV_ATTR_PROMISC,
        DEV_ATTR_RPFILTER,
        DEV_ATTR_ACCEPTLOCAL,
+       DEV_ATTR_IGMPVERSION,
        __DEV_ATTR_MAX,
 };
 
@@ -70,6 +71,7 @@ enum {
        DEV_OPT_PROMISC         = (1 << 4),
        DEV_OPT_RPFILTER        = (1 << 5),
        DEV_OPT_ACCEPTLOCAL     = (1 << 6),
+       DEV_OPT_IGMPVERSION     = (1 << 7),
 };
 
 /* events broadcasted to all users of a device */
@@ -119,6 +121,7 @@ struct device_settings {
        bool promisc;
        unsigned int rpfilter;
        bool acceptlocal;
+       unsigned int igmpversion;
 };
 
 /*
diff --git a/system-dummy.c b/system-dummy.c
index 76c6ffa..9542d3c 100644
--- a/system-dummy.c
+++ b/system-dummy.c
@@ -215,6 +215,12 @@ bool system_resolve_rpfilter(const char *filter, unsigned 
int *id)
        return true;
 }
 
+bool system_resolve_igmpversion(const unsigned int version, unsigned int *id)
+{
+       *id = 0;
+       return true;
+}
+
 int system_add_iprule(struct iprule *rule)
 {
        return 0;
diff --git a/system-linux.c b/system-linux.c
index 4662bf8..7beae09 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -275,6 +275,11 @@ static void system_set_acceptlocal(struct device *dev, 
const char *val)
        system_set_dev_sysctl("/proc/sys/net/ipv4/conf/%s/accept_local", 
dev->ifname, val);
 }
 
+static void system_set_igmpversion(struct device *dev, const char *val)
+{
+       system_set_dev_sysctl("/proc/sys/net/ipv4/conf/%s/force_igmp_version", 
dev->ifname, val);
+}
+
 static int system_get_sysctl(const char *path, char *buf, const size_t buf_sz)
 {
        int fd = -1, ret = -1;
@@ -321,6 +326,12 @@ static int system_get_acceptlocal(struct device *dev, char 
*buf, const size_t bu
                        dev->ifname, buf, buf_sz);
 }
 
+static int system_get_igmpversion(struct device *dev, char *buf, const size_t 
buf_sz)
+{
+       return 
system_get_dev_sysctl("/proc/sys/net/ipv4/conf/%s/force_igmp_version",
+                       dev->ifname, buf, buf_sz);
+}
+
 // Evaluate netlink messages
 static int cb_rtnl_event(struct nl_msg *msg, void *arg)
 {
@@ -985,6 +996,11 @@ system_if_get_settings(struct device *dev, struct 
device_settings *s)
                s->acceptlocal = strtoul(buf, NULL, 0);
                s->flags |= DEV_OPT_ACCEPTLOCAL;
        }
+
+       if (!system_get_igmpversion(dev, buf, sizeof(buf))) {
+               s->igmpversion = strtoul(buf, NULL, 0);
+               s->flags |= DEV_OPT_IGMPVERSION;
+       }
 }
 
 void
@@ -1028,6 +1044,12 @@ system_if_apply_settings(struct device *dev, struct 
device_settings *s, unsigned
        }
        if (s->flags & DEV_OPT_ACCEPTLOCAL & apply_mask)
                system_set_acceptlocal(dev, s->acceptlocal ? "1" : "0");
+       if (s->flags & DEV_OPT_IGMPVERSION & apply_mask) {
+               char buf[2];
+
+               snprintf(buf, sizeof(buf), "%d", s->igmpversion);
+               system_set_igmpversion(dev, buf);
+       }
 }
 
 int system_if_up(struct device *dev)
@@ -1575,6 +1597,18 @@ bool system_resolve_rpfilter(const char *filter, 
unsigned int *id)
        return true;
 }
 
+bool system_resolve_igmpversion(const unsigned int version, unsigned int *id)
+{
+       if (!version || version > 3)
+               return false;
+
+       *id = version;
+       if (*id == 3)
+               *id = 0;
+
+       return true;
+}
+
 static int system_iprule(struct iprule *rule, int cmd)
 {
        int alen = ((rule->flags & IPRULE_FAMILY) == IPRULE_INET4) ? 4 : 16;
diff --git a/system.h b/system.h
index 9a2326b..8c9e994 100644
--- a/system.h
+++ b/system.h
@@ -136,6 +136,7 @@ bool system_resolve_rt_type(const char *type, unsigned int 
*id);
 bool system_resolve_rt_table(const char *name, unsigned int *id);
 bool system_is_default_rt_table(unsigned int id);
 bool system_resolve_rpfilter(const char *filter, unsigned int *id);
+bool system_resolve_igmpversion(const unsigned int version, unsigned int *id);
 
 int system_del_ip_tunnel(const char *name, struct blob_attr *attr);
 int system_add_ip_tunnel(const char *name, struct blob_attr *attr);
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to