2018-09-26 22:18:43 +00:00
|
|
|
#!rsc
|
2018-07-05 13:29:26 +00:00
|
|
|
# RouterOS script: update-gre-address
|
|
|
|
# Copyright (c) 2013-2018 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 remote-peers find ] do={
|
|
|
|
:local id [ / ip ipsec remote-peers get $peer id ];
|
2018-12-19 16:22:36 +00:00
|
|
|
:local greint [ / interface gre find where comment=$id ];
|
|
|
|
:if ([ :len $greint ] > 0) do={
|
|
|
|
:local grename [ / interface gre get $greint name ];
|
|
|
|
:local addrold [ / interface gre get $greint remote-address ];
|
|
|
|
:local disabled [ / interface gre get $greint disabled ];
|
2018-07-05 13:29:26 +00:00
|
|
|
:local addrnew [ / ip ipsec remote-peers get $peer dynamic-address ];
|
2018-12-19 16:22:36 +00:00
|
|
|
:if ($addrnew != $addrold || $disabled = true) do={
|
|
|
|
:log info ("Update remote address for interface " . $grename . " to " . $addrnew);
|
|
|
|
/ interface gre set remote-address=0.0.0.0 disabled=yes [ find where remote-address=$addrnew name!=$grename ];
|
|
|
|
/ interface gre set $greint remote-address=$addrnew disabled=no;
|
2018-07-05 13:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|