routeros-scripts/update-gre-address
2019-07-01 11:26:10 +02:00

21 lines
1 KiB
Text

#!rsc
# RouterOS script: update-gre-address
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
#
# update gre interface remote address with dynamic address from
# ipsec remote peer
/ 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" ];
:if ([ :len $GreInt ] > 0) do={
:local GreIntVal [ / interface gre get $GreInt ];
:if ($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || $GreIntVal->"disabled" = true) do={
:log info ("Update 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;
}
}
}