set the igmp snooping option for bridges
authorFelix Fietkau <nbd@openwrt.org>
Tue, 18 Oct 2011 23:00:32 +0000 (01:00 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 18 Oct 2011 23:00:32 +0000 (01:00 +0200)
bridge.c
system-linux.c
system.h

index fe4b477365168dbd4400f7abaa814d29e9191715..1adabb9f3ceafc2dfe75439bde629a369f5b4461 100644 (file)
--- a/bridge.c
+++ b/bridge.c
@@ -13,6 +13,7 @@ enum {
        BRIDGE_ATTR_IFNAME,
        BRIDGE_ATTR_STP,
        BRIDGE_ATTR_FORWARD_DELAY,
+       BRIDGE_ATTR_IGMP_SNOOP,
        BRIDGE_ATTR_AGEING_TIME,
        BRIDGE_ATTR_HELLO_TIME,
        BRIDGE_ATTR_MAX_AGE,
@@ -26,6 +27,7 @@ static const struct blobmsg_policy bridge_attrs[__BRIDGE_ATTR_MAX] = {
        [BRIDGE_ATTR_AGEING_TIME] = { "ageing_time", BLOBMSG_TYPE_INT32 },
        [BRIDGE_ATTR_HELLO_TIME] = { "hello_time", BLOBMSG_TYPE_INT32 },
        [BRIDGE_ATTR_MAX_AGE] = { "max_age", BLOBMSG_TYPE_INT32 },
+       [BRIDGE_ATTR_IGMP_SNOOP] = { "igmp_snooping", BLOBMSG_TYPE_BOOL },
 };
 
 static const union config_param_info bridge_attr_info[__BRIDGE_ATTR_MAX] = {
@@ -340,6 +342,7 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
        /* defaults */
        cfg->stp = true;
        cfg->forward_delay = 1;
+       cfg->igmp_snoop = true;
 
        if ((cur = tb[BRIDGE_ATTR_STP]))
                cfg->stp = blobmsg_get_bool(cur);
@@ -347,6 +350,9 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
        if ((cur = tb[BRIDGE_ATTR_FORWARD_DELAY]))
                cfg->forward_delay = blobmsg_get_u32(cur);
 
+       if ((cur = tb[BRIDGE_ATTR_IGMP_SNOOP]))
+               cfg->igmp_snoop = blobmsg_get_bool(cur);
+
        if ((cur = tb[BRIDGE_ATTR_AGEING_TIME])) {
                cfg->ageing_time = blobmsg_get_u32(cur);
                cfg->flags |= BRIDGE_OPT_AGEING_TIME;
index 24254451308b1ad5c069bc06968b938d45f12d32..3d6230d841830a7cf1723dd5453d8d8d62169513 100644 (file)
@@ -99,12 +99,17 @@ static void system_set_sysctl(const char *path, const char *val)
        close(fd);
 }
 
-static void system_set_disable_ipv6(struct device *dev, const char *val)
+static void system_set_dev_sysctl(const char *path, const char *device, const char *val)
 {
        char buf[256];
 
-       snprintf(buf, sizeof(buf), "/proc/sys/net/ipv6/conf/%s/disable_ipv6", dev->ifname);
-       system_set_sysctl(buf, "0");
+       snprintf(buf, sizeof(buf), path, val);
+       system_set_sysctl(buf, val);
+}
+
+static void system_set_disable_ipv6(struct device *dev, const char *val)
+{
+       system_set_dev_sysctl("/proc/sys/net/ipv6/conf/%s/disable_ipv6", dev->ifname, val);
 }
 
 // Evaluate netlink messages
@@ -411,6 +416,9 @@ int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
        args[1] = sec_to_jiffies(cfg->forward_delay);
        system_bridge_if(bridge->ifname, NULL, SIOCDEVPRIVATE, &args);
 
+       system_set_dev_sysctl("/sys/devices/virtual/net/%s/bridge/multicast_snooping",
+               bridge->ifname, cfg->igmp_snoop ? "1" : "0");
+
        if (cfg->flags & BRIDGE_OPT_AGEING_TIME) {
                args[0] = BRCTL_SET_AGEING_TIME;
                args[1] = sec_to_jiffies(cfg->ageing_time);
index cfe7c9f3fa1d277a2f2b8da6540a0439260a7ca6..dee7137555767b031a5dd8f6dec22a6010b21830 100644 (file)
--- a/system.h
+++ b/system.h
@@ -16,6 +16,7 @@ enum bridge_opt {
 struct bridge_config {
        enum bridge_opt flags;
        bool stp;
+       bool igmp_snoop;
        int forward_delay;
 
        int ageing_time;