bridge: add bridge_empty option which allows creation of empty bridges
authorLuka Perkov <luka@openwrt.org>
Thu, 11 Jul 2013 22:20:59 +0000 (00:20 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 13 Jul 2013 10:26:02 +0000 (12:26 +0200)
Signed-off-by: Luka Perkov <luka@openwrt.org>
bridge.c
system.h

index 9aa26f232c6205620ccd03eaf10fcbc0ed4c0387..05f2ad69133b8f73d38ef355e165fb6aadfe712c 100644 (file)
--- a/bridge.c
+++ b/bridge.c
@@ -31,6 +31,7 @@ enum {
        BRIDGE_ATTR_AGEING_TIME,
        BRIDGE_ATTR_HELLO_TIME,
        BRIDGE_ATTR_MAX_AGE,
+       BRIDGE_ATTR_BRIDGE_EMPTY,
        __BRIDGE_ATTR_MAX
 };
 
@@ -43,6 +44,7 @@ static const struct blobmsg_policy bridge_attrs[__BRIDGE_ATTR_MAX] = {
        [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 },
+       [BRIDGE_ATTR_BRIDGE_EMPTY] = { "bridge_empty", BLOBMSG_TYPE_BOOL },
 };
 
 static const struct uci_blob_param_info bridge_attr_info[__BRIDGE_ATTR_MAX] = {
@@ -185,6 +187,9 @@ bridge_remove_member(struct bridge_member *bm)
        bm->present = false;
        bm->bst->n_present--;
 
+       if (bst->config.bridge_empty)
+               return;
+
        bst->force_active = false;
        if (bst->n_present == 0)
                device_set_present(&bst->dev, false);
@@ -444,6 +449,11 @@ bridge_config_init(struct device *dev)
 
        bst = container_of(dev, struct bridge_state, dev);
 
+       if (bst->config.bridge_empty) {
+               bst->force_active = true;
+               device_set_present(&bst->dev, true);
+       }
+
        if (!bst->ifnames)
                return;
 
@@ -464,6 +474,7 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
        cfg->stp = false;
        cfg->forward_delay = 2;
        cfg->igmp_snoop = false;
+       cfg->bridge_empty = false;
        cfg->priority = 0x7FFF;
 
        if ((cur = tb[BRIDGE_ATTR_STP]))
@@ -492,6 +503,9 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
                cfg->max_age = blobmsg_get_u32(cur);
                cfg->flags |= BRIDGE_OPT_MAX_AGE;
        }
+
+       if ((cur = tb[BRIDGE_ATTR_BRIDGE_EMPTY]))
+               cfg->bridge_empty = blobmsg_get_bool(cur);
 }
 
 enum dev_change_type
index f1f32cb1582078155756697437339116da53baf3..e50201a87cb35a8db949dbb5ba6f85680fbc6418 100644 (file)
--- a/system.h
+++ b/system.h
@@ -47,6 +47,7 @@ struct bridge_config {
        bool igmp_snoop;
        unsigned short priority;
        int forward_delay;
+       bool bridge_empty;
 
        int ageing_time;
        int hello_time;