routeros-scripts/bridge-port-to-default
Christian Hesse 628ae1bd70 bridge-port-to-default: use $ParseKeyValueStore...
... and unbreak last commit removing delay (69352c90).
This requires a change in configuration syntax. Change this...

    comment="default:br-local, alt:br-guest"

to...

    comment="default=br-local, alt=br-guest"
2020-03-03 13:32:00 +01:00

37 lines
1.8 KiB
Text

#!rsc
# RouterOS script: bridge-port-to-default
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
#
# reset bridge ports to default bridge
:global BridgePortTo;
:global LogPrintExit;
:global ParseKeyValueStore;
:foreach BridgePort in=[ / interface bridge port find where comment~"." ] do={
:local BridgePortVal [ / interface bridge port get $BridgePort ];
:foreach Config,BridgeDefault in=[ $ParseKeyValueStore ($BridgePortVal->"comment") ] do={
:if ($Config = $BridgePortTo) do={
:if ($BridgeDefault = "dhcp-client") do={
:if ($BridgePortVal->"disabled" = false) 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 ];
}
} 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;
} else={
:log debug ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . " bridge " . $BridgeDefault);
}
}
}
}
}