tunneldigger-broker: add option to isolate bridge ports
authorPerry Melange <isprotejesvalkata@gmail.com>
Sat, 29 Jul 2023 19:50:28 +0000 (21:50 +0200)
committerNick Hainke <vincent@systemli.org>
Wed, 23 Aug 2023 11:46:32 +0000 (13:46 +0200)
Add new option to a config bridge section to indicate
if a bridge port added to the bridge should be isolated
or not.  The default is 0 (no isolation).

example

config bridge
     option interface 'br-mybridge1446'
     option mtu '1446'
     option isolate '1' # default '0'

Signed-off-by: Perry Melange <isprotejesvalkata@gmail.com>
(cherry picked from commit 49cdf15da458c384d6c0cd19b228e2d84ba205f4)

net/tunneldigger-broker/files/hook-mtu-changed
net/tunneldigger-broker/files/hook-setup
net/tunneldigger-broker/files/tunneldigger.sh

index 3cfc59a14e82374c7046121f9860e59470bbbd05..9be884d66a625a27bdca666f6d14a519d36b0178 100755 (executable)
@@ -21,10 +21,14 @@ if [ -z "$new_bridge" ]; then
   exit 1
 fi
 
+# Get the isolation option for this bridge
+tunneldigger_get_bridge_isolate isolate "${NEW_MTU}"
+
 # Remove interface from old bridge.
 ip link set dev ${INTERFACE} nomaster
 ip link set dev ${old_bridge} mtu ${OLD_MTU}
 
 # Change interface bridge and MTU.
 ip link set dev ${INTERFACE} master ${new_bridge} mtu ${NEW_MTU}
+echo $isolate > /sys/class/net/${INTERFACE}/brport/isolated
 ip link set dev ${new_bridge} mtu ${NEW_MTU}
index ed809ad6dc74e0ef6177ece99bd07831a20a69de..08fd177547202361d1a9377ecf03f2d5e8bec41a 100755 (executable)
@@ -13,9 +13,14 @@ if [ -z "$bridge" ]; then
   exit 1
 fi
 
+# Get the isolation option for this bridge
+tunneldigger_get_bridge_isolate isolate "${MTU}"
+
 # Disable IPv6 on this interface as it will be bridged.
 echo 1 > /proc/sys/net/ipv6/conf/${INTERFACE}/disable_ipv6
 # Add the interface to the proper bridge and bring it up.
 ip link set dev ${INTERFACE} master ${bridge} mtu ${MTU} up
+# Isolate the bridge port, if so configured
+echo $isolate > /sys/class/net/${INTERFACE}/brport/isolated
 # Ensure bridge MTU.
 ip link set dev ${bridge} mtu ${MTU}
index 3c7b8fff84f5e2ab0ec907fa83b1eac9fc1fc295..5b492d699b7330f60eb279b2e62abcc7aa7d8025 100644 (file)
@@ -34,3 +34,37 @@ tunneldigger_get_bridge() {
        export ${NO_EXPORT:+-n} "$1=$variable"
 }
 
+# Get the isolation option for this bridge
+tunneldigger_get_bridge_isolate() {
+       local variable="$1"
+       local mtr="$2"
+
+        # Overwrite the destination variable.
+        unset $variable
+
+        # Discover the configured bridge.
+        unset _isolate_bridge
+        _isolate_bridge=""
+        handle_bridge() {
+                local cfg="$1"
+
+                config_get cfg_mtu "$cfg" mtu
+                config_get isolate "$cfg" isolate 0
+
+                if [ "$cfg_mtu" != "$mtu" ]; then
+                        return
+                fi
+
+                _isolate_bridge="$isolate"
+        }
+
+        config_load tunneldigger-broker
+        config_foreach handle_bridge bridge $mtu
+        if [ -z "$_isolate_bridge" ]; then
+                return
+        fi
+
+        variable="$_isolate_bridge"
+        export ${NO_EXPORT:+-n} "$1=$variable"
+
+}