bridge: tune default stp parameters
authorFelix Fietkau <nbd@nbd.name>
Tue, 24 Aug 2021 15:16:05 +0000 (17:16 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 24 Aug 2021 15:16:06 +0000 (17:16 +0200)
The default forwarding delay 2 is broken and makes STP non-functional by
default. The kernel's default of 15 is rather long.
This commit changes makes the timer settings more aggressive than the
kernel's default while still being consistent and allowing proper
convergence for a network diameter up to 4

Signed-off-by: Felix Fietkau <nbd@nbd.name>
bridge.c
system-linux.c
system.h

index 15e09dd1c26dc31d382617653d88e1d67025822b..2ce5c2b11b49fd23c14b7c707e9af0c4463e13a8 100644 (file)
--- a/bridge.c
+++ b/bridge.c
@@ -339,10 +339,8 @@ static void bridge_stp_notify(struct bridge_state *bst)
        if (cfg->stp_proto)
                blobmsg_add_string(&b, "proto", cfg->stp_proto);
        blobmsg_add_u32(&b, "forward_delay", cfg->forward_delay);
-       if (cfg->flags & BRIDGE_OPT_HELLO_TIME)
-               blobmsg_add_u32(&b, "hello_time", cfg->hello_time);
-       if (cfg->flags & BRIDGE_OPT_MAX_AGE)
-               blobmsg_add_u32(&b, "max_age", cfg->max_age);
+       blobmsg_add_u32(&b, "hello_time", cfg->hello_time);
+       blobmsg_add_u32(&b, "max_age", cfg->max_age);
        if (cfg->flags & BRIDGE_OPT_AGEING_TIME)
                blobmsg_add_u32(&b, "ageing_time", cfg->ageing_time);
        netifd_ubus_device_notify("stp_init", b.head, 1000);
@@ -1045,7 +1043,6 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
        memset(cfg, 0, sizeof(*cfg));
        cfg->stp = false;
        cfg->stp_kernel = false;
-       cfg->forward_delay = 2;
        cfg->robustness = 2;
        cfg->igmp_snoop = false;
        cfg->multicast_querier = false;
@@ -1057,6 +1054,10 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
        cfg->priority = 0x7FFF;
        cfg->vlan_filtering = false;
 
+       cfg->forward_delay = 8;
+       cfg->max_age = 10;
+       cfg->hello_time = 1;
+
        if ((cur = tb[BRIDGE_ATTR_STP]))
                cfg->stp = blobmsg_get_bool(cur);
 
@@ -1106,15 +1107,11 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
                cfg->flags |= BRIDGE_OPT_AGEING_TIME;
        }
 
-       if ((cur = tb[BRIDGE_ATTR_HELLO_TIME])) {
+       if ((cur = tb[BRIDGE_ATTR_HELLO_TIME]))
                cfg->hello_time = blobmsg_get_u32(cur);
-               cfg->flags |= BRIDGE_OPT_HELLO_TIME;
-       }
 
-       if ((cur = tb[BRIDGE_ATTR_MAX_AGE])) {
+       if ((cur = tb[BRIDGE_ATTR_MAX_AGE]))
                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);
index e9a19f7e437ee9ec31de81df1500431995c6feca..85942a546d3e75e88fe66a5bc9e7fc21e9b8ae81 100644 (file)
@@ -1276,21 +1276,17 @@ int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
        snprintf(buf, sizeof(buf), "%d", cfg->priority);
        system_bridge_set_priority(bridge, buf);
 
+       snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->hello_time));
+       system_bridge_set_hello_time(bridge, buf);
+
+       snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->max_age));
+       system_bridge_set_max_age(bridge, buf);
+
        if (cfg->flags & BRIDGE_OPT_AGEING_TIME) {
                snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->ageing_time));
                system_bridge_set_ageing_time(bridge, buf);
        }
 
-       if (cfg->flags & BRIDGE_OPT_HELLO_TIME) {
-               snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->hello_time));
-               system_bridge_set_hello_time(bridge, buf);
-       }
-
-       if (cfg->flags & BRIDGE_OPT_MAX_AGE) {
-               snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->max_age));
-               system_bridge_set_max_age(bridge, buf);
-       }
-
        return 0;
 }
 
index c5c4f23591036715fe82d50caaf0d2793f7980e4..b6eda7ea11496bf077f82d7556700c8ba67b6d95 100644 (file)
--- a/system.h
+++ b/system.h
@@ -108,14 +108,12 @@ extern const struct uci_blob_param_list ipip6_data_attr_list;
 extern const struct uci_blob_param_list fmr_data_attr_list;
 
 enum bridge_opt {
-       /* stp and forward delay always set */
+       /* stp, forward delay, max age and hello time are always set */
        BRIDGE_OPT_AGEING_TIME              = (1 << 0),
-       BRIDGE_OPT_HELLO_TIME               = (1 << 1),
-       BRIDGE_OPT_MAX_AGE                  = (1 << 2),
-       BRIDGE_OPT_ROBUSTNESS               = (1 << 3),
-       BRIDGE_OPT_QUERY_INTERVAL           = (1 << 4),
-       BRIDGE_OPT_QUERY_RESPONSE_INTERVAL  = (1 << 5),
-       BRIDGE_OPT_LAST_MEMBER_INTERVAL     = (1 << 6),
+       BRIDGE_OPT_ROBUSTNESS               = (1 << 1),
+       BRIDGE_OPT_QUERY_INTERVAL           = (1 << 2),
+       BRIDGE_OPT_QUERY_RESPONSE_INTERVAL  = (1 << 3),
+       BRIDGE_OPT_LAST_MEMBER_INTERVAL     = (1 << 4),
 };
 
 struct bridge_config {