routeros-scripts/update-gre-address
Christian Hesse 71ad56aacc explicitly name the license
Copyright (C) 2013-2020 Christian Hesse <mail@eworm.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

https://www.gnu.org/licenses/#GPL
https://www.gnu.org/licenses/gpl.html
https://www.gnu.org/licenses/gpl.md
2020-06-19 22:17:42 +02:00

27 lines
1.3 KiB
Text

#!rsc
# RouterOS script: update-gre-address
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# 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
:global LogPrintExit;
/ 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 ([ :typeof ($PeerVal->"dynamic-address") ] = "str" && \
($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || \
$GreIntVal->"disabled" = true)) do={
$LogPrintExit info ("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;
}
}
}