iplink: bridge: add stp_mode support
Subsystems (3)
PATCH 1/1 iplink: bridge: add stp_mode support
Add support for the IFLA_BR_STP_MODE bridge attribute that allows userspace to explicitly select the STP mode:
- auto (0): default, try /sbin/bridge-stp helper in init_net
- user (1): directly enable userspace STP without the helper, works in any network namespace
- kernel (2): directly enable kernel STP without the helper
Both string ("auto", "user", "kernel") and numeric values are accepted when setting the attribute. Display uses string names for known values with numeric fallback for future extensions.
Example usage:
ip link set br0 type bridge stp_mode user
ip link set br0 type bridge stp_state 1
--- ip/iplink_bridge.c | 30 ++++++++++++++++++++++++++++++ man/man8/ip-link.8.in | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)
ip/iplink_bridge.c +30 -0
@@ -31,6 +31,7 @@ static void print_explain(FILE *f)" [ max_age MAX_AGE ]\n" " [ ageing_time AGEING_TIME ]\n" " [ stp_state STP_STATE ]\n" +" [ stp_mode STP_MODE ]\n" " [ mst_enabled MST_ENABLED ]\n" " [ priority PRIORITY ]\n" " [ group_fwd_mask MASK ]\n"
@@ -67,6 +68,7 @@ static void print_explain(FILE *f)" [ mdb_offload_fail_notification MDB_OFFLOAD_FAIL_NOTIFICATION ]\n" "\n" "Where: VLAN_PROTOCOL := { 802.1Q | 802.1ad }\n" +" STP_MODE := { auto | user | kernel }\n" ); }
@@ -120,6 +122,20 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,invarg ("invalid stp_state" , *argv);addattr32 (n,1024 ,IFLA_BR_STP_STATE , val); + }else if (strcmp (*argv,"stp_mode" ) ==0 ) { +__u32 stp_mode; + +NEXT_ARG (); +if (strcmp (*argv,"auto" ) ==0 ) + stp_mode =BR_STP_MODE_AUTO ; +else if (strcmp (*argv,"user" ) ==0 ) + stp_mode =BR_STP_MODE_USER ; +else if (strcmp (*argv,"kernel" ) ==0 ) + stp_mode =BR_STP_MODE_KERNEL ; +else if (get_u32 (&stp_mode, *argv,0 )) +invarg ("invalid stp_mode" , *argv); + +addattr32 (n,1024 ,IFLA_BR_STP_MODE , stp_mode); }else if (matches (*argv,"priority" ) ==0 ) {__u16 prio;
@@ -512,6 +528,20 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])"stp_state %u " , rta_getattr_u32(tb[IFLA_BR_STP_STATE])); +if (tb[IFLA_BR_STP_MODE ]) { +static const char *stp_modes[] = { +"auto" ,"user" ,"kernel" + }; +__u32 mode =rta_getattr_u32 (tb[IFLA_BR_STP_MODE ]); + +if (mode <ARRAY_SIZE (stp_modes)) +print_string (PRINT_ANY ,"stp_mode" , +"stp_mode %s " , stp_modes[mode]); +else +print_uint (PRINT_ANY ,"stp_mode" , +"stp_mode %u " , mode); + } +if (tb[IFLA_BR_PRIORITY ]) print_uint(PRINT_ANY, "priority",
man/man8/ip-link.8.in +32 -0
@@ -1719,6 +1719,8 @@ the following additional arguments are supported: ] [ .BI stp_state " STP_STATE " ] [ +.BI stp_mode " STP_MODE " +] [ .BI mst_enabled " MST_ENABLED " ] [ .BI priority " PRIORITY "
@@ -1828,6 +1830,36 @@ or off .RI ( STP_STATE " == 0). " for this bridge. +.BI stp_mode " STP_MODE " +- set the STP mode for this bridge. This controls how the bridge +selects between userspace and kernel STP when STP is enabled via +.BR stp_state . +.I STP_MODE +can be one of: +.in +8 +.sp +.B auto +(default) - invoke the +.B /sbin/bridge-stp +helper to hand the bridge to a userspace STP daemon. Only attempted in +the initial network namespace; in other namespaces this falls back to +kernel STP. + +.B user +- directly enable userspace STP without invoking the helper. Works in +any network namespace. The caller is responsible for registering the +bridge with the userspace STP daemon. + +.B kernel +- directly enable kernel STP without invoking the helper. +.in -8 + +Can only be changed while STP is disabled. Both +.B stp_mode +and +.B stp_state +can be set in a single command. + .BI mst_enabled " MST_ENABLED " - turn multiple spanning tree (MST) support on .RI ( MST_ENABLED " > 0) "
Signature · 1 line
2.43.0
Quoted 4 lines · On Mon, 18 May 2026 09:36:47 -0700 Andy Roulin <[email protected]> wrote:
ip/iplink_bridge.c +4
-0+ }else if (strcmp (*argv,"stp_mode" ) ==0 ) { +__u32 stp_mode; + +NEXT_ARG ();
ip/iplink_bridge.c static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, · line 138
Quoted 10 lines
ip/iplink_bridge.c +10
-0+if (strcmp (*argv,"auto" ) ==0 ) + stp_mode =BR_STP_MODE_AUTO ; +else if (strcmp (*argv,"user" ) ==0 ) + stp_mode =BR_STP_MODE_USER ; +else if (strcmp (*argv,"kernel" ) ==0 ) + stp_mode =BR_STP_MODE_KERNEL ; +else if (get_u32 (&stp_mode, *argv,0 )) +invarg ("invalid stp_mode" , *argv); + +addattr32 (n,1024 ,IFLA_BR_STP_MODE , stp_mode);
Not your fault but yet another case where matches() was bad idea because if you pass "stp" it matches only stp_state.
Really should fix all of iproute2 to use a table approach and not allow conflicting matches, but that is a lot of work, and will break peoples scripts.
Quoted 26 lines · Andy Roulin
ip/iplink_bridge.c +14
-0@@ -120,6 +122,20 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,invarg ("invalid stp_state" , *argv);addattr32 (n,1024 ,IFLA_BR_STP_STATE , val); + }else if (strcmp (*argv,"stp_mode" ) ==0 ) { +__u32 stp_mode; + +NEXT_ARG (); +if (strcmp (*argv,"auto" ) ==0 ) + stp_mode =BR_STP_MODE_AUTO ; +else if (strcmp (*argv,"user" ) ==0 ) + stp_mode =BR_STP_MODE_USER ; +else if (strcmp (*argv,"kernel" ) ==0 ) + stp_mode =BR_STP_MODE_KERNEL ; +else if (get_u32 (&stp_mode, *argv,0 )) +invarg ("invalid stp_mode" , *argv); + +addattr32 (n,1024 ,IFLA_BR_STP_MODE , stp_mode); }else if (matches (*argv,"priority" ) ==0 ) {__u16 prio;
ip/iplink_bridge.c static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) · line 534
Quoted 7 lines
ip/iplink_bridge.c +4
-0@@ -512,6 +528,20 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])"stp_state %u " , rta_getattr_u32(tb[IFLA_BR_STP_STATE])); +if (tb[IFLA_BR_STP_MODE ]) { +static const char *stp_modes[] = { +"auto" ,"user" ,"kernel" + };
Make this a single table used for both set and show.
Quoted 13 lines
ip/iplink_bridge.c +10
-0+__u32 mode =rta_getattr_u32 (tb[IFLA_BR_STP_MODE ]); + +if (mode <ARRAY_SIZE (stp_modes)) +print_string (PRINT_ANY ,"stp_mode" , +"stp_mode %s " , stp_modes[mode]); +else +print_uint (PRINT_ANY ,"stp_mode" , +"stp_mode %u " , mode); + } +if (tb[IFLA_BR_PRIORITY ]) print_uint(PRINT_ANY, "priority",