Files
eworm-de-routeros-scripts/ipv6-update
T

41 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

2018-09-27 00:18:43 +02:00
#!rsc
2018-07-05 15:29:26 +02:00
# RouterOS script: ipv6-update
2020-01-01 17:00:39 +01:00
# Copyright (c) 2013-2020 Christian Hesse <[email protected]>
2020-06-19 22:17:42 +02:00
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
2018-07-05 15:29:26 +02:00
#
# update firewall and dns settings on IPv6 prefix change
2020-03-27 21:47:13 +01:00
# https://git.eworm.de/cgit/routeros-scripts/about/doc/ipv6-update.md
2018-07-05 15:29:26 +02:00
2019-01-03 17:45:43 +01:00
:local PdPrefix $"pd-prefix";
:global LogPrintExit;
2020-02-28 15:26:26 +01:00
:global ParseKeyValueStore;
2019-07-17 16:28:10 +02:00
2019-07-05 16:09:49 +02:00
:if ([ :typeof $PdPrefix ] = "nothing") do={
$LogPrintExit error "This script is supposed to run from ipv6 dhcp-client." true;
2019-07-05 16:09:49 +02:00
}
2019-01-03 17:45:43 +01:00
:local Pool [ / ipv6 pool get [ find where prefix=$PdPrefix ] name ];
:local AddrList [ / ipv6 firewall address-list find where comment=("ipv6-pool-" . $Pool) ];
:local OldPrefix [ / ipv6 firewall address-list get $AddrList address ];
2018-07-05 15:29:26 +02:00
# give the interfaces a moment to receive their addresses
:delay 2s;
2019-01-03 17:45:43 +01:00
if ($OldPrefix != $PdPrefix) do={
:log info ("Updating IPv6 address list with new IPv6 prefix " . $PdPrefix);
/ ipv6 firewall address-list set address=$PdPrefix $AddrList;
2018-07-05 15:29:26 +02:00
2019-07-17 16:28:10 +02:00
:foreach Record in=[ / ip dns static find where comment~("^ipv6-pool-" . $Pool . ",") ] do={
2019-08-29 13:58:18 +02:00
:local RecordVal [ / ip dns static get $Record ];
:local Comment [ $ParseKeyValueStore ($RecordVal->"comment") ];
2018-07-05 15:29:26 +02:00
2019-07-17 16:28:10 +02:00
:local Prefix [ / ipv6 address get [ find where interface=($Comment->"interface") from-pool=$Pool global ] address ];
:set Prefix [ :toip6 [ :pick $Prefix 0 [ :find $Prefix "/64" ] ] ];
:local Address ($Prefix | ([ :toip6 ($RecordVal->"address") ] & ::ffff:ffff:ffff:ffff));
:log info ("Updating DNS record for " . ($RecordVal->"name") . ($RecordVal->"regexp") . " to " . $Address);
/ ip dns static set address=$Address $Record;
2018-07-05 15:29:26 +02:00
}
}