Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2-next v2] iplink: bridge: add stp_mode support
@ 2026-06-03 17:33 Andy Roulin
  2026-06-03 17:41 ` Nikolay Aleksandrov
  2026-06-04 15:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Roulin @ 2026-06-03 17:33 UTC (permalink / raw)
  To: netdev; +Cc: stephen, bridge, razor, nikolay, idosch, petrm, danieller,
	dsahern

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

A shared file-scope stp_modes[] table indexed by BR_STP_MODE_* drives
both directions: parsing uses parse_one_of(), printing goes through a
stp_mode_to_str() helper that returns "(unknown)" for modes not yet
known to iproute2, keeping the JSON type of stp_mode consistently a
string.

Example usage:
  ip link set br0 type bridge stp_mode user
  ip link set br0 type bridge stp_state 1

Link: https://lore.kernel.org/netdev/20260405205224.3163000-1-aroulin@nvidia.com/
Assisted-by: Claude:claude-opus-4-7
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Andy Roulin <aroulin@nvidia.com>
---

Notes:
    v2:
            * Use a single file-scope stp_modes[] table indexed by
              BR_STP_MODE_* for both parse and show, instead of an ad-hoc
              strcmp ladder in parse and a separate local table in show
              (David Ahern).
            * Switch parsing to the shared parse_one_of() helper. Drop the
              fallback that accepted numeric values on the parse side.
            * Print path always returns a string: keep the JSON type of
              stp_mode stable and fall back to "(unknown)" for unrecognized
              values via a stp_mode_to_str() helper matching the style of
              validate_to_str() in ip/ipmacsec.c (Ido Schimmel).
    
    v1: https://lore.kernel.org/netdev/20260518163647.1935156-1-aroulin@nvidia.com/

 ip/iplink_bridge.c    | 33 +++++++++++++++++++++++++++++++++
 man/man8/ip-link.8.in | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index df3264c3..1ae0501a 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -19,6 +19,20 @@
 #include "utils.h"
 #include "ip_common.h"
 
+static const char * const stp_modes[] = {
+	[BR_STP_MODE_AUTO]	= "auto",
+	[BR_STP_MODE_USER]	= "user",
+	[BR_STP_MODE_KERNEL]	= "kernel",
+};
+
+static const char *stp_mode_to_str(__u32 mode)
+{
+	if (mode >= ARRAY_SIZE(stp_modes) || !stp_modes[mode])
+		return "(unknown)";
+
+	return stp_modes[mode];
+}
+
 static unsigned int xstats_print_attr;
 static int filter_index;
 
@@ -31,6 +45,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 +82,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 +136,16 @@ 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;
+			int err;
+
+			NEXT_ARG();
+			stp_mode = parse_one_of("stp_mode", *argv, stp_modes,
+						ARRAY_SIZE(stp_modes), &err);
+			if (err)
+				return err;
+			addattr32(n, 1024, IFLA_BR_STP_MODE, stp_mode);
 		} else if (matches(*argv, "priority") == 0) {
 			__u16 prio;
 
@@ -512,6 +538,13 @@ 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]) {
+		__u32 mode = rta_getattr_u32(tb[IFLA_BR_STP_MODE]);
+
+		print_string(PRINT_ANY, "stp_mode", "stp_mode %s ",
+			     stp_mode_to_str(mode));
+	}
+
 	if (tb[IFLA_BR_PRIORITY])
 		print_uint(PRINT_ANY,
 			   "priority",
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index e89b2db3..b2661bdc 100644
--- a/man/man8/ip-link.8.in
+++ b/man/man8/ip-link.8.in
@@ -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) "
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2-next v2] iplink: bridge: add stp_mode support
  2026-06-03 17:33 [PATCH iproute2-next v2] iplink: bridge: add stp_mode support Andy Roulin
@ 2026-06-03 17:41 ` Nikolay Aleksandrov
  2026-06-04 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Aleksandrov @ 2026-06-03 17:41 UTC (permalink / raw)
  To: Andy Roulin, netdev
  Cc: stephen, bridge, razor, idosch, petrm, danieller, dsahern

On 03/06/2026 20:33, Andy Roulin wrote:
> 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
> 
> A shared file-scope stp_modes[] table indexed by BR_STP_MODE_* drives
> both directions: parsing uses parse_one_of(), printing goes through a
> stp_mode_to_str() helper that returns "(unknown)" for modes not yet
> known to iproute2, keeping the JSON type of stp_mode consistently a
> string.
> 
> Example usage:
>    ip link set br0 type bridge stp_mode user
>    ip link set br0 type bridge stp_state 1
> 
> Link: https://lore.kernel.org/netdev/20260405205224.3163000-1-aroulin@nvidia.com/
> Assisted-by: Claude:claude-opus-4-7
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Signed-off-by: Andy Roulin <aroulin@nvidia.com>
> ---
> 
> Notes:
>      v2:
>              * Use a single file-scope stp_modes[] table indexed by
>                BR_STP_MODE_* for both parse and show, instead of an ad-hoc
>                strcmp ladder in parse and a separate local table in show
>                (David Ahern).
>              * Switch parsing to the shared parse_one_of() helper. Drop the
>                fallback that accepted numeric values on the parse side.
>              * Print path always returns a string: keep the JSON type of
>                stp_mode stable and fall back to "(unknown)" for unrecognized
>                values via a stp_mode_to_str() helper matching the style of
>                validate_to_str() in ip/ipmacsec.c (Ido Schimmel).
>      
>      v1: https://lore.kernel.org/netdev/20260518163647.1935156-1-aroulin@nvidia.com/
> 
>   ip/iplink_bridge.c    | 33 +++++++++++++++++++++++++++++++++
>   man/man8/ip-link.8.in | 32 ++++++++++++++++++++++++++++++++
>   2 files changed, 65 insertions(+)
> 

Reviewed-by: Nikolay Aleksandrov <nikolay@nvidia.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2-next v2] iplink: bridge: add stp_mode support
  2026-06-03 17:33 [PATCH iproute2-next v2] iplink: bridge: add stp_mode support Andy Roulin
  2026-06-03 17:41 ` Nikolay Aleksandrov
@ 2026-06-04 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-04 15:30 UTC (permalink / raw)
  To: Andy Roulin
  Cc: netdev, stephen, bridge, razor, nikolay, idosch, petrm, danieller,
	dsahern

Hello:

This patch was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Wed,  3 Jun 2026 10:33:04 -0700 you wrote:
> 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
> 
> [...]

Here is the summary with links:
  - [iproute2-next,v2] iplink: bridge: add stp_mode support
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=2d84aef19e96

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-04 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 17:33 [PATCH iproute2-next v2] iplink: bridge: add stp_mode support Andy Roulin
2026-06-03 17:41 ` Nikolay Aleksandrov
2026-06-04 15:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox