fix the exit status for the proto-shell task, use WEXITSTATUS
[project/netifd.git] / bridge.c
index fe4b477..70ea0f0 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] = {
@@ -75,6 +77,8 @@ struct bridge_member {
        bool present;
 };
 
+static void bridge_free_member(struct bridge_member *bm);
+
 static int
 bridge_disable_member(struct bridge_member *bm)
 {
@@ -145,6 +149,8 @@ bridge_member_cb(struct device_user *dev, enum device_event ev)
                if (bst->n_present == 0)
                        device_set_present(&bst->dev, false);
 
+               if (dev->hotplug)
+                       bridge_free_member(bm);
                break;
        default:
                return;
@@ -211,19 +217,17 @@ bridge_set_state(struct device *dev, bool up)
 }
 
 static struct bridge_member *
-bridge_create_member(struct bridge_state *bst, struct device *dev)
+bridge_create_member(struct bridge_state *bst, struct device *dev, bool hotplug)
 {
        struct bridge_member *bm;
 
        bm = calloc(1, sizeof(*bm));
        bm->bst = bst;
        bm->dev.cb = bridge_member_cb;
-       device_add_user(&bm->dev, dev);
-
+       bm->dev.hotplug = hotplug;
        list_add_tail(&bm->list, &bst->members);
 
-       if (bst->dev.active)
-               bridge_enable_member(bm);
+       device_add_user(&bm->dev, dev);
 
        return bm;
 }
@@ -252,7 +256,7 @@ bridge_add_member(struct bridge_state *bst, const char *name)
        if (!dev)
                return;
 
-       bridge_create_member(bst, dev);
+       bridge_create_member(bst, dev, false);
 }
 
 static int
@@ -260,7 +264,7 @@ bridge_hotplug_add(struct device *dev, struct device *member)
 {
        struct bridge_state *bst = container_of(dev, struct bridge_state, dev);
 
-       bridge_create_member(bst, member);
+       bridge_create_member(bst, member, true);
 
        return 0;
 }
@@ -340,6 +344,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 +352,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;