Skip to content

net: bridge: add stp_mode attribute for STP mode selection

Andy Roulin bridge linux-doc linux-kselftest lkml netdev 4 versions – Applied

Status from this message: This series was applied to netdev/net-next.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 0 repliesApplied 3/3
  2. v33 patches 1 replySuperseded
  3. v23 patches 1 replySuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches4 repliesSuperseded

Changes in v4 from the cover letter

Patch #1:
* Use u8 for stp_mode struct field.
* Add stp_helper_active bool to track whether the usermode helper was invoked during start.
* Allow mode change when STP is being disabled in the same netlink message.
Patch #3:
* Add disable+mode-change simultaneous test.

Patches in v4 All 3 applied

#Subject and filesSizeRepliesApplied
1/3net: bridge: add stp_mode attribute for STP mode selectionDocumentation/netlink/specs/rt-link.yaml include/uapi/linux/if_link.h net/bridge/br_device.c +3 more+89 -80 repliesApplied
2/3docs: net: bridge: document stp_mode attributeDocumentation/networking/bridge.rst+22 -00 repliesApplied
3/3selftests: net: add bridge STP mode selection testtools/testing/selftests/net/Makefile tools/testing/selftests/net/bridge_stp_mode.sh+289 -00 repliesApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchIdo SchimmelNikolay Aleksandrov
1/3R-b A-b
2/3R-b A-b
3/3R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH net-next v4 0/3] net: bridge: add stp_mode attribute for STP mode selection

The bridge-stp usermode helper is currently restricted to the initial network namespace, preventing userspace STP daemons like mstpd from operating on bridges in other namespaces. Since commit ff62198553e4 ("bridge: Only call /sbin/bridge-stp for the initial network namespace"), bridges in non-init namespaces silently fall back to kernel STP with no way to request userspace STP.

This series adds a new IFLA_BR_STP_MODE bridge attribute that allows explicit per-bridge control over STP mode selection. Three modes are supported:

- auto (default): existing behavior, try /sbin/bridge-stp in init_net, fall back to kernel STP otherwise
- user: directly enable BR_USER_STP without invoking the helper, works in any network namespace
- kernel: directly enable BR_KERNEL_STP without invoking the helper

The user and kernel modes bypass call_usermodehelper() entirely, addressing the security concerns discussed at [1]. Userspace is responsible for ensuring an STP daemon manages the bridge, rather than relying on the kernel to invoke /sbin/bridge-stp.

Patch 1 adds the kernel support. The mode can only be changed while STP is disabled and is processed before IFLA_BR_STP_STATE in br_changelink() so both can be set atomically in a single netlink message.

Patch 2 adds documentation for the new attribute in the bridge docs.

Patch 3 adds a selftest with 9 test cases. The test requires iproute2 with IFLA_BR_STP_MODE support and can be run with virtme-ng:

  vng --run arch/x86/boot/bzImage --skip-modules \
      --overlay-rwdir /sbin --overlay-rwdir /tmp --overlay-rwdir /bin \
      --exec 'cp /path/to/iproute2-next/ip/ip /bin/ip && \
              cd tools/testing/selftests/net && \
              bash bridge_stp_mode.sh'

iproute2 support can be found here [2].

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://github.com/aroulin/iproute2-next/tree/bridge-stp-mode

v4:
Patch #1:
* Use u8 for stp_mode struct field.
* Add stp_helper_active bool to track whether the usermode helper was invoked during start.
* Allow mode change when STP is being disabled in the same netlink message.
Patch #3:
* Add disable+mode-change simultaneous test.
v3:
Patch #1:
* Name enum br_stp_mode for YNL codegen.
* Add enum-name to rt-link.yaml spec.
v2:
Patch #1:
* Add rt-link.yaml netlink spec update.
* Allow idempotent stp_mode set while STP is active.
* Move stp_mode next to root_port to fill a struct hole.
* Rephrase BR_STP_MODE_USER doc.
Patch #3:
* Fix shellcheck CI: add SC2329 suppression.
* Add idempotent stp_mode test.

Andy Roulin (3):
net: bridge: add stp_mode attribute for STP mode selection
docs: net: bridge: document stp_mode attribute
selftests: net: add bridge STP mode selection test

 Documentation/netlink/specs/rt-link.yaml      |  12 +
 Documentation/networking/bridge.rst           |  22 ++
 include/uapi/linux/if_link.h                  |  39 +++
 net/bridge/br_device.c                        |   1 +
 net/bridge/br_netlink.c                       |  24 +-
 net/bridge/br_private.h                       |   2 +
 net/bridge/br_stp_if.c                        |  19 +-
 tools/testing/selftests/net/Makefile          |   1 +
 .../testing/selftests/net/bridge_stp_mode.sh  | 288 ++++++++++++++++++
 9 files changed, 400 insertions(+), 8 deletions(-)
 create mode 100755 tools/testing/selftests/net/bridge_stp_mode.sh

--
2.43.0