aboutsummaryrefslogtreecommitdiffstats
path: root/update-gre-address
blob: 7e70a6d71238380d4c3d91b094b316928f0f2156 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!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 Id [ / ip ipsec active-peers get $Peer id ];
  :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 ];
    :local AddrNew [ / ip ipsec active-peers get $Peer dynamic-address ];
    :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;
    }
  }
}