device: add support for setting the isolate options for bridge ports
authorFelix Fietkau <nbd@nbd.name>
Tue, 13 Mar 2018 11:52:43 +0000 (12:52 +0100)
committerFelix Fietkau <nbd@nbd.name>
Tue, 13 Mar 2018 11:57:40 +0000 (12:57 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
device.c
device.h
system-linux.c

index ad470c929793b0ca4a8f3215cc85fdd2f014b53b..09998f4d529bb8fb17c4ad32432d69a4483a4db0 100644 (file)
--- a/device.c
+++ b/device.c
@@ -57,6 +57,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
        [DEV_ATTR_UNICAST_FLOOD] = { .name ="unicast_flood", .type = BLOBMSG_TYPE_BOOL },
        [DEV_ATTR_SENDREDIRECTS] = { .name = "sendredirects", .type = BLOBMSG_TYPE_BOOL },
        [DEV_ATTR_NEIGHLOCKTIME] = { .name = "neighlocktime", .type = BLOBMSG_TYPE_INT32 },
+       [DEV_ATTR_ISOLATE] = { .name = "isolate", .type = BLOBMSG_TYPE_BOOL },
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -362,6 +363,11 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
                s->flags |= DEV_OPT_SENDREDIRECTS;
        }
 
+       if ((cur = tb[DEV_ATTR_ISOLATE])) {
+               s->isolate = blobmsg_get_bool(cur);
+               s->flags |= DEV_OPT_ISOLATE;
+       }
+
        device_set_disabled(dev, disabled);
 }
 
index dc45967eb95db2a85654e6e9781ec602fdf887f6..84acf52ba00bde10dcec01448008ef7d4c1c1369 100644 (file)
--- a/device.h
+++ b/device.h
@@ -50,6 +50,7 @@ enum {
        DEV_ATTR_NEIGHGCSTALETIME,
        DEV_ATTR_SENDREDIRECTS,
        DEV_ATTR_NEIGHLOCKTIME,
+       DEV_ATTR_ISOLATE,
        __DEV_ATTR_MAX,
 };
 
@@ -102,6 +103,7 @@ enum {
        DEV_OPT_MULTICAST_FAST_LEAVE    = (1 << 20),
        DEV_OPT_SENDREDIRECTS           = (1 << 21),
        DEV_OPT_NEIGHLOCKTIME           = (1 << 22),
+       DEV_OPT_ISOLATE                 = (1 << 23),
 };
 
 /* events broadcasted to all users of a device */
@@ -168,6 +170,7 @@ struct device_settings {
        bool learning;
        bool unicast_flood;
        bool sendredirects;
+       bool isolate;
 };
 
 /*
index 4f3b9b06c2f1feca20792c9bbc63f201a8fc0499..0ca525602d9ea63ac5b845b2be9c6c7bdec7c26c 100644 (file)
@@ -346,6 +346,11 @@ static void system_bridge_set_hairpin_mode(struct device *dev, const char *val)
        system_set_dev_sysctl("/sys/class/net/%s/brport/hairpin_mode", dev->ifname, val);
 }
 
+static void system_bridge_set_isolate_mode(struct device *dev, const char *val)
+{
+       system_set_dev_sysctl("/sys/class/net/%s/brport/isolate_mode", dev->ifname, val);
+}
+
 static void system_bridge_set_multicast_router(struct device *dev, const char *val, bool bridge)
 {
        system_set_dev_sysctl(bridge ? "/sys/class/net/%s/bridge/multicast_router" :
@@ -748,6 +753,10 @@ int system_bridge_addif(struct device *bridge, struct device *dev)
            !dev->settings.unicast_flood)
                system_bridge_set_unicast_flood(dev, "0");
 
+       if (dev->settings.flags & DEV_OPT_ISOLATE &&
+           dev->settings.isolate)
+               system_bridge_set_isolate_mode(dev, "1");
+
        return ret;
 }