aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-03-04 13:48:01 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-03-04 21:40:34 +0100
commitad623f069e43798da6775f77fef72cd4a8fbc05e (patch)
treeb1915c3f8d0a558b978255fc445e94cbe0f24122
parent6fd745fc0f689ce0f7b57599bf0c497dda170f93 (diff)
update-gre-address: move code into function
-rw-r--r--update-gre-address.rsc39
1 files changed, 22 insertions, 17 deletions
diff --git a/update-gre-address.rsc b/update-gre-address.rsc
index c5c699b..62cdfe1 100644
--- a/update-gre-address.rsc
+++ b/update-gre-address.rsc
@@ -9,29 +9,34 @@
# ipsec remote peer
# https://git.eworm.de/cgit/routeros-scripts/about/doc/update-gre-address.md
-:local 0 [ :jobname ];
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-:global CharacterReplace;
-:global LogPrintExit2;
-:global ScriptLock;
+:local Main do={
+ :local ScriptName [ :tostr $1 ];
-$ScriptLock $0;
+ :global CharacterReplace;
+ :global LogPrintExit2;
+ :global ScriptLock;
-/interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where !running !disabled ];
+ $ScriptLock $ScriptName;
-:foreach Peer in=[ /ip/ipsec/active-peers/find ] do={
- :local PeerVal [ /ip/ipsec/active-peers/get $Peer ];
- :local GreInt [ /interface/gre/find where comment=($PeerVal->"id") or comment=[ $CharacterReplace ($PeerVal->"id") "CN=" "" ] ];
- :if ([ :len $GreInt ] > 0) do={
- :local GreIntVal [ /interface/gre/get $GreInt ];
- :if ([ :typeof ($PeerVal->"dynamic-address") ] = "str" && \
- ($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || \
- $GreIntVal->"disabled" = true)) do={
- $LogPrintExit2 info $0 ("Updating remote address for interface " . $GreIntVal->"name" . " to " . $PeerVal->"dynamic-address") false;
- /interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where remote-address=$PeerVal->"dynamic-address" name!=$GreIntVal->"name" ];
- /interface/gre/set $GreInt remote-address=($PeerVal->"dynamic-address") disabled=no;
+ /interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where !running !disabled ];
+
+ :foreach Peer in=[ /ip/ipsec/active-peers/find ] do={
+ :local PeerVal [ /ip/ipsec/active-peers/get $Peer ];
+ :local GreInt [ /interface/gre/find where comment=($PeerVal->"id") or comment=[ $CharacterReplace ($PeerVal->"id") "CN=" "" ] ];
+ :if ([ :len $GreInt ] > 0) do={
+ :local GreIntVal [ /interface/gre/get $GreInt ];
+ :if ([ :typeof ($PeerVal->"dynamic-address") ] = "str" && \
+ ($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || \
+ $GreIntVal->"disabled" = true)) do={
+ $LogPrintExit2 info $ScriptName ("Updating remote address for interface " . $GreIntVal->"name" . " to " . $PeerVal->"dynamic-address") false;
+ /interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where remote-address=$PeerVal->"dynamic-address" name!=$GreIntVal->"name" ];
+ /interface/gre/set $GreInt remote-address=($PeerVal->"dynamic-address") disabled=no;
+ }
}
}
}
+
+$Main [ :jobname ];