我正在尝试改变 Linux brigde 系统上网桥从属设备的状态,但它的行为非常奇怪,总是将端口状态更改为转发。
IE:
创建一个具有虚拟接口的桥作为从属接口(它与其他类型的接口一起出现)
$ ip link add dev midummy type dummy
$ ip link add dev br type bridge
$ ip link set dev midummy master br
$ ip link set dev br up
$ ip link set dev midummy up
检查网桥从站的状态:
$ brctl showstp br
...
midummy (1)
port id 8001 state forwarding
...
尝试切换到阻塞状态
$ ip link set dev midummy type bridge_slave state 4
...
midummy (1)
port id 8001 state forwarding
...
$dmesg
[ 2414.108892] br: port 1(midummy) entered blocking state
[ 2414.108898] br: port 1(midummy) entered forwarding state
为什么内核要将网桥从属状态更改为转发?是否有任何网桥标志可以配置此行为?
提前致谢
答案1
简而言之,即使 stp 完全禁用,这种行为也是由 stp 和计时器定期检查桥接端口状态造成的。您可以调查源代码以找出发生这种情况的原因。我找到了实现您的愿望的解决方法。Linux 内核支持用户空间 stp 守护程序,您可以编写它或将其链接到 /dev/true 以手动管理 stp 状态。
简短演示:
# create the fake stp daemon and disable in-kernel stp handling.
# should return success exit code
ln -s /bin/true /sbin/bridge-stp
# start the fake stp daemon
brctl stp br on
# bring up the interface to the blocking state
ip link set dev midummy type bridge_slave state 4
# check the interface state again and again. state aren't changing
# except the transactions between disabled and blocking state,
# that depends on bridge port status (UP or DOWN)
# use 'bridge monitor' to realtime monitoring of state changes
# !!! stop the fake stp before removing the symlink /bin/bridge-stp !!!
brctl stp br off
# and then remove the symbolic link to prevent future effects
rm /sbin/bridge-stp