aboutsummaryrefslogtreecommitdiffstats
path: root/update-gre-address.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'update-gre-address.rsc')
-rw-r--r--update-gre-address.rsc51
1 files changed, 31 insertions, 20 deletions
diff --git a/update-gre-address.rsc b/update-gre-address.rsc
index e38839c..cddfa92 100644
--- a/update-gre-address.rsc
+++ b/update-gre-address.rsc
@@ -1,35 +1,46 @@
#!rsc by RouterOS
# RouterOS script: update-gre-address
-# Copyright (c) 2013-2023 Christian Hesse <mail@eworm.de>
-# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
+# Copyright (c) 2013-2025 Christian Hesse <mail@eworm.de>
+# https://rsc.eworm.de/COPYING.md
+#
+# requires RouterOS, version=7.15
#
# update gre interface remote address with dynamic address from
# ipsec remote peer
-# https://git.eworm.de/cgit/routeros-scripts/about/doc/update-gre-address.md
+# https://rsc.eworm.de/doc/update-gre-address.md
-:local 0 "update-gre-address";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-:global CharacterReplace;
-:global LogPrintExit2;
-:global ScriptLock;
+:local ExitOK false;
+:do {
+ :local ScriptName [ :jobname ];
+
+ :global CharacterReplace;
+ :global LogPrint;
+ :global ScriptLock;
-$ScriptLock $0;
+ :if ([ $ScriptLock $ScriptName ] = false) do={
+ :set ExitOK true;
+ :error false;
+ }
-/interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where !running !disabled ];
+ /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 $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;
+ :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={
+ $LogPrint info $ScriptName ("Updating remote address for interface " . $GreIntVal->"name" . " to " . $PeerVal->"dynamic-address");
+ /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;
+ }
}
}
+} on-error={
+ :global ExitError; $ExitError $ExitOK [ :jobname ];
}