aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-11-12 14:10:13 +0100
committerGravatar Christian Hesse <mail@eworm.de>2021-11-15 22:18:10 +0100
commitf484e45b6a1fe5284462da19c90219d0716d916a (patch)
tree5fae733f782467e6dd912dd1b40efeeafe9d6c88
parentb6215ba95899328bd13fabbf6488b602763b9352 (diff)
bridge-port-to-default -> global-functions.d/bridge-port-tochange-66
-rw-r--r--README.md2
-rw-r--r--bridge-port-to-default53
-rw-r--r--bridge-port-toggle21
-rw-r--r--doc/global-functions.d/bridge-port-to.md (renamed from doc/bridge-port.md)39
-rw-r--r--doc/global-functions.d/bridge-port-vlan.md2
-rw-r--r--global-config9
-rw-r--r--global-config-overlay2
-rw-r--r--global-config.changes2
-rw-r--r--global-functions2
-rw-r--r--global-functions.d/bridge-port-to54
10 files changed, 79 insertions, 107 deletions
diff --git a/README.md b/README.md
index 1787ab5..7eb646d 100644
--- a/README.md
+++ b/README.md
@@ -159,7 +159,6 @@ Available Scripts
-----------------
* [Find and remove access list duplicates](doc/accesslist-duplicates.md)
-* [Manage ports in bridge](doc/bridge-port.md)
* [Download packages for CAP upgrade from CAPsMAN](doc/capsman-download-packages.md)
* [Run rolling CAP upgrades from CAPsMAN](doc/capsman-rolling-upgrade.md)
* [Renew locally issued certificates](doc/certificate-renew-issued.md)
@@ -204,6 +203,7 @@ Available Scripts
Available modules
-----------------
+* [Manage ports in bridge](doc/global-functions.d/bridge-port-to.md)
* [Manage VLANs on bridge ports](doc/global-functions.d/bridge-port-vlan.md)
Contact
diff --git a/bridge-port-to-default b/bridge-port-to-default
deleted file mode 100644
index b8503df..0000000
--- a/bridge-port-to-default
+++ /dev/null
@@ -1,53 +0,0 @@
-#!rsc by RouterOS
-# RouterOS script: bridge-port-to-default
-# 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/bridge-port.md
-
-:local 0 "bridge-port-to-default";
-:global GlobalFunctionsReady;
-:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-
-:global BridgePortTo;
-
-: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;
- / 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;
- }
- }
- }
- }
-}
diff --git a/bridge-port-toggle b/bridge-port-toggle
deleted file mode 100644
index 9eeab35..0000000
--- a/bridge-port-toggle
+++ /dev/null
@@ -1,21 +0,0 @@
-#!rsc by RouterOS
-# RouterOS script: bridge-port-toggle
-# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
-# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
-#
-# toggle bridge ports between default and alt bridge
-# https://git.eworm.de/cgit/routeros-scripts/about/doc/bridge-port.md
-
-:local 0 "bridge-port-toggle";
-:global GlobalFunctionsReady;
-:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-
-:global BridgePortTo;
-
-:if ($BridgePortTo != "default") do={
- :set BridgePortTo "default";
-} else={
- :set BridgePortTo "alt";
-}
-
-/ system script run bridge-port-to-default;
diff --git a/doc/bridge-port.md b/doc/global-functions.d/bridge-port-to.md
index 924bd6a..e0eba1e 100644
--- a/doc/bridge-port.md
+++ b/doc/global-functions.d/bridge-port-to.md
@@ -3,21 +3,21 @@ Manage ports in bridge
[◀ Go back to main README](../README.md)
-🛈 This script can not be used on its own but requires the base installation.
+🛈 This module can not be used on its own but requires the base installation.
See [main README](../README.md) for details.
Description
-----------
-These scripts are supposed to handle interfaces and switching them from
-one bridge to another.
+This module and its functio are are supposed to handle interfaces and
+switching them from one bridge to another.
Requirements and installation
-----------------------------
-Just install the scripts:
+Just install the module:
- $ScriptInstallUpdate bridge-port-to-default,bridge-port-toggle;
+ $ScriptInstallUpdate global-functions.d/bridge-port-to;
Configuration
-------------
@@ -32,23 +32,19 @@ Also dhcp client can be handled:
/ ip dhcp-client add comment="toggle with bridge port" disabled=no interface=en1;
-There is also global configuration:
-
-* `BridgePortTo`: specify the configuration to be applied by default
-
Add a scheduler to start with default setup on system startup:
- / system scheduler add name=bridge-port-to-default on-event="/ system script run bridge-port-to-default;" start-time=startup;
+ / system scheduler add name=bridge-port-to on-event=":global GlobalFunctionsReady; :while (\$GlobalFunctionsReady != true) do={ :delay 500ms; }; :global BridgePortTo; \$BridgePortTo default;" start-time=startup;
Usage and invocation
--------------------
The usage examples show what happens with the configuration from above.
-Running the script `bridge-port-to-default` applies all configuration given
-with `default=`:
+Running the function `$BridgePortTo` with parameter `default` applies all
+configuration given with `default=`:
- / system script run bridge-port-to-default;
+ $BridgePortTo default;
For the three interfaces we get this configuration:
@@ -56,22 +52,19 @@ For the three interfaces we get this configuration:
* Interface `en2` is put in bridge `br-intern`.
* Interface `en3` is put in bridge `br-guest`.
-Running the script `bridge-port-toggle` toggles to configuration given
-with `alt=`:
+Running the function `$BridgePortTo` with parameter `alt` applies all
+configuration given with `alt=`:
- / system script run bridge-port-toggle;
+ $BridgePortTo alt;
* Interface `en1` is put in bridge `br-guest`, dhcp client for the interface is disabled.
* Interface `en2` is put in bridge `br-guest`.
* Interface `en3` is unchanged, stays in bridge `br-guest`.
-Running the script `bridge-port-toggle` again toggles back to configuration
-given with `default=`.
-
-More configuration can be loaded by setting `BridgePortTo`:
+Running the function `$BridgePortTo` with parameter `extra` applies another
+configuration:
- :set BridgePortTo "extra";
- / system script run bridge-port-to-default;
+ $BridgePortTo extra;
* Interfaces `en1` and `en2` are unchanged.
* Interface `en3` is put in bridge `br-intern`.
@@ -79,7 +72,7 @@ More configuration can be loaded by setting `BridgePortTo`:
See also
--------
-* [Manage VLANs on bridge ports](global-functions.d/bridge-port-vlan.md)
+* [Manage VLANs on bridge ports](bridge-port-vlan.md)
---
[◀ Go back to main README](../README.md)
diff --git a/doc/global-functions.d/bridge-port-vlan.md b/doc/global-functions.d/bridge-port-vlan.md
index f59cb83..9df46b0 100644
--- a/doc/global-functions.d/bridge-port-vlan.md
+++ b/doc/global-functions.d/bridge-port-vlan.md
@@ -76,7 +76,7 @@ configuration:
See also
--------
-* [Manage ports in bridge](../bridge-port.md)
+* [Manage ports in bridge](bridge-port-to.md)
---
[◀ Go back to main README](../../README.md)
diff --git a/global-config b/global-config
index 5dc9a20..3905c8e 100644
--- a/global-config
+++ b/global-config
@@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
-:global GlobalConfigVersion 65;
+:global GlobalConfigVersion 66;
# This is used for DNS and backup file.
:global Domain "example.com";
@@ -107,9 +107,6 @@
:global CheckHealthTemperatureDeviation 2;
:global CheckHealthVoltagePercent 10;
-# This controls what configuration is activated by bridge-port-to-default.
-:global BridgePortTo "default";
-
# Access-list entries matching this comment are updated
# with daily pseudo-random PSK.
:global DailyPskMatchComment "Daily PSK";
@@ -134,7 +131,7 @@
2=":global SendNotification; :global Identity; \$SendNotification (\"Hello...\") (\"Hello world, \" . \$Identity . \" calling!\");";
3="/ system shutdown;";
4="/ system reboot;";
- 5="/ system script run bridge-port-toggle;";
+ 5=":global BridgePortVlan; \$BridgePortVlan alt;";
# add more here...
};
# This led gives visual feedback if type is 'on' or 'off'.
@@ -142,7 +139,7 @@
# Run commands on SMS action.
:global SmsAction {
- bridge-port-toggle="/ system script run bridge-port-toggle;";
+ bridge-port-vlan-alt=":global BridgePortVlan; \$BridgePortVlan alt;";
reboot="/ system reboot;";
shutdown="/ system shutdown;";
# add more here...
diff --git a/global-config-overlay b/global-config-overlay
index 7bdc516..1570461 100644
--- a/global-config-overlay
+++ b/global-config-overlay
@@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
# Comment or remove to disable news and change notifications.
-:global GlobalConfigVersion 65;
+:global GlobalConfigVersion 66;
# Copy configuration from global-config here and modify it.
diff --git a/global-config.changes b/global-config.changes
index 6a8b145..2561506 100644
--- a/global-config.changes
+++ b/global-config.changes
@@ -69,6 +69,7 @@
63="Moved optional functions '\$IPCalc' and '\$ScriptRunOnce' to modules.";
64="Implemented '\$InspectVar' in module to inspect variables.";
65="Added module to manage VLANs on bridge ports.";
+ 66="Moved script 'bridge-port-to-default' to new module.";
};
# Migration steps to be applied on script updates
@@ -78,4 +79,5 @@
52=":global CertificateDownload; :if ([ :len [ / certificate find where fingerprint=\"67add1166b020ae61b8f5fc96813c04c2aa589960796865572a3c7e737613dfd\" or fingerprint=\"96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6\" ] ] < 2) do={ \$CertificateDownload \"R3\"; }; / certificate remove [ find where fingerprint=\"0687260331a72403d909f105e69bcf0d32e1bd2493ffc6d9206d11bcd6770739\" ];";
54=":global ScriptInstallUpdate; :global TelegramTokenId; :global TelegramChatId; :if ([ :len \$TelegramTokenId ] > 0 && [ :len \$TelegramChatId ] > 0) do={ \$ScriptInstallUpdate global-functions.d/notification-telegram; }";
61="/ system script remove [ find where name~\"^(early-errors|global-wait|mode-button-(event|scheduler)|script-updates)\\\$\" source~\"^#!rsc by RouterOS\\n\" ];";
+ 66=":global ScriptInstallUpdate; :if ([ :len [ / system script find where name=\"bridge-port-to-default\" ] ] > 0) do={ / system script remove [ find where name~\"^bridge-port-to(-default|ggle)\\\$\" ]; \$ScriptInstallUpdate global-functions.d/bridge-port-to; }";
};
diff --git a/global-functions b/global-functions
index dbfeaa1..813e4b4 100644
--- a/global-functions
+++ b/global-functions
@@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
-:global ExpectedConfigVersion 65;
+:global ExpectedConfigVersion 66;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
diff --git a/global-functions.d/bridge-port-to b/global-functions.d/bridge-port-to
new file mode 100644
index 0000000..437cba7
--- /dev/null
+++ b/global-functions.d/bridge-port-to
@@ -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;
+ }
+ }
+ }
+ }
+ }
+}