mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-16 04:54:28 +02:00
bridge-port-to-default -> global-functions.d/bridge-port-to
This commit is contained in:
parent
b6215ba958
commit
f484e45b6a
10 changed files with 79 additions and 107 deletions
54
global-functions.d/bridge-port-to
Normal file
54
global-functions.d/bridge-port-to
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: global-functions.d/bridge-port-to
|
||||
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
#
|
||||
# reset bridge ports to default bridge
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/global-functions.d/bridge-port-to.md
|
||||
|
||||
:global BridgePortTo;
|
||||
|
||||
:set BridgePortTo do={
|
||||
:local BridgePortTo [ :tostr $1 ];
|
||||
|
||||
:global IfThenElse;
|
||||
:global LogPrintExit2;
|
||||
: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={
|
||||
:local DHCPClient [ / ip dhcp-client find where interface=$BridgePortVal->"interface" comment="toggle with bridge port" ];
|
||||
|
||||
:if ($BridgeDefault = "dhcp-client") do={
|
||||
:if ([ :len $DHCPClient ] != 1) do={
|
||||
$LogPrintExit2 warning $0 ([ $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={
|
||||
$LogPrintExit2 info $0 ("Disabling bridge port for interface " . $BridgePortVal->"interface" . ", enabling dhcp client.") false;
|
||||
/ interface bridge port disable $BridgePort;
|
||||
:delay 200ms;
|
||||
/ ip dhcp-client enable $DHCPClient;
|
||||
}
|
||||
} else={
|
||||
:if ($BridgePortVal->"disabled" = true || $BridgeDefault != $BridgePortVal->"bridge") do={
|
||||
$LogPrintExit2 info $0 ("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={
|
||||
$LogPrintExit2 debug $0 ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . \
|
||||
" bridge " . $BridgeDefault . ".") false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue