update-gre-address: move code into function

This commit is contained in:
Christian Hesse 2024-03-04 13:48:01 +01:00
parent 6fd745fc0f
commit ad623f069e

View file

@ -9,15 +9,17 @@
# 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; }
:local Main do={
:local ScriptName [ :tostr $1 ];
:global CharacterReplace;
:global LogPrintExit2;
:global ScriptLock;
$ScriptLock $0;
$ScriptLock $ScriptName;
/interface/gre/set remote-address=0.0.0.0 disabled=yes [ find where !running !disabled ];
@ -29,9 +31,12 @@ $ScriptLock $0;
: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;
$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 ];