aboutsummaryrefslogtreecommitdiffstats
path: root/bridge-port-to-default
diff options
context:
space:
mode:
Diffstat (limited to 'bridge-port-to-default')
-rw-r--r--bridge-port-to-default32
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;
}
}
}