update-gre-address 1.08 KB
Newer Older
1
#!rsc
Christian Hesse's avatar
Christian Hesse committed
2
# RouterOS script: update-gre-address
Christian Hesse's avatar
Christian Hesse committed
3
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
Christian Hesse's avatar
Christian Hesse committed
4 5 6 7 8 9
#
# 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 ];

10
:foreach Peer in=[ / ip ipsec active-peers find ] do={
11 12
  :local PeerVal [ / ip ipsec active-peers get $Peer ];
  :local GreInt [ / interface gre find where comment=$PeerVal->"id" ];
13
  :if ([ :len $GreInt ] > 0) do={
14
    :local GreIntVal [ / interface gre get $GreInt ];
15 16 17 18
    :if ([ :typeof ($PeerVal->"dynamic-address") ] = "str" && \
         ($PeerVal->"dynamic-address" != $GreIntVal->"remote-address" || \
          $GreIntVal->"disabled" = true)) do={
      :log info ("Updating remote address for interface " . $GreIntVal->"name" . " to " . $PeerVal->"dynamic-address");
19 20
      / 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;
Christian Hesse's avatar
Christian Hesse committed
21 22 23
    }
  }
}