diff options
author | Christian Hesse <mail@eworm.de> | 2020-10-23 15:25:01 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2020-10-23 15:27:17 +0200 |
commit | cbb1e624b24c6c6b2a5c55eb4bc8b3ca2ec9febe (patch) | |
tree | e5909f05cce808ed21e1b55956c638d1cd59c1ad /bridge-port-to-default | |
parent | ae5570325b8509ad8c637e8e6ebc81f1d8528cd0 (diff) |
bridge-port-to-default: be more robust
This was unreliable with inconsistent configuration...
Diffstat (limited to 'bridge-port-to-default')
-rw-r--r-- | bridge-port-to-default | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/bridge-port-to-default b/bridge-port-to-default index 4db04e8..e4d4947 100644 --- a/bridge-port-to-default +++ b/bridge-port-to-default @@ -8,6 +8,7 @@ :global BridgePortTo; +:global IfThenElse; :global LogPrintExit; :global ParseKeyValueStore; @@ -15,23 +16,32 @@ :local BridgePortVal [ / interface bridge port get $BridgePort ]; :foreach Config,BridgeDefault in=[ $ParseKeyValueStore ($BridgePortVal->"comment") ] do={ :if ($Config = $BridgePortTo) do={ + :local DHCPClient [ / ip dhcp-client find where interface=$BridgePortVal->"interface" comment="toggle with bridge port" ]; + :if ($BridgeDefault = "dhcp-client") do={ - :if ($BridgePortVal->"disabled" = false) do={ + :if ([ :len $DHCPClient ] != 1) do={ + $LogPrintExit warning ([ $IfThenElse ([ :len $DHCPClient ] = 0) "Missing" "Duplicate" ] . \ + " dhcp client configuration for interface " . $BridgePortVal->"interface" . "!") true; + } + :local DHCPClientDisabled [ / ip dhcp-client get $DHCPClient disabled ]; + + :if ($BridgePortVal->"disabled" = false || $DHCPClientDisabled = true) do={ $LogPrintExit info ("Disabling bridge port for interface " . $BridgePortVal->"interface" . ", enabling dhcp client.") false; / interface bridge port disable $BridgePort; - / ip dhcp-client enable [ find where interface=$BridgePortVal->"interface" comment="toggle with bridge port" disabled=yes ]; + / ip dhcp-client enable $DHCPClient; } } else={ - :if ($BridgePortVal->"disabled" = true) do={ - $LogPrintExit info ("Enabling bridge port for interface " . $BridgePortVal->"interface" . ", disabling dhcp client.") false; - / ip dhcp-client disable [ find where interface=$BridgePortVal->"interface" comment="toggle with bridge port" disabled=no ]; - / interface bridge port enable $BridgePort; - } - :if ($BridgeDefault != $BridgePortVal->"bridge") do={ - $LogPrintExit info ("Changing interface " . $BridgePortVal->"interface" . " to " . $BridgePortTo . " bridge " . $BridgeDefault) false; - / interface bridge port set bridge=$BridgeDefault $BridgePort; + :if ($BridgePortVal->"disabled" = true || $BridgeDefault != $BridgePortVal->"bridge") do={ + $LogPrintExit info ("Enabling bridge port for interface " . $BridgePortVal->"interface" . ", changing to " . $BridgePortTo . \ + " bridge " . $BridgeDefault . ", disabling dhcp client.") false; + :if ([ :len $DHCPClient ] = 1) do={ + / ip dhcp-client disable $DHCPClient; + :delay 200ms; + } + / interface bridge port set disabled=no bridge=$BridgeDefault $BridgePort; } else={ - $LogPrintExit debug ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . " bridge " . $BridgeDefault) false; + $LogPrintExit debug ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . \ + " bridge " . $BridgeDefault . ".") false; } } } |