aboutsummaryrefslogtreecommitdiffstats
path: root/ipv6-update
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2018-07-05 15:29:26 +0200
committerGravatar Christian Hesse <mail@eworm.de>2018-07-05 15:34:08 +0200
commite1f134ead584c7b2e9ed406f5520d7f1a23294aa (patch)
tree929660280fb0acc183401d7e59a40f1cd7e8992c /ipv6-update
parent1d99dc38ff1f583d6e46adc5d1ba3455114d53c1 (diff)
add scripts
Diffstat (limited to 'ipv6-update')
-rw-r--r--ipv6-update38
1 files changed, 38 insertions, 0 deletions
diff --git a/ipv6-update b/ipv6-update
new file mode 100644
index 0000000..b434e05
--- /dev/null
+++ b/ipv6-update
@@ -0,0 +1,38 @@
+# RouterOS script: ipv6-update
+# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
+#
+# update firewall and dns settings on IPv6 prefix change
+
+:global "ipv6-interface";
+:global "ipv6-pool";
+
+:local addrlist [ / ipv6 firewall address-list find where comment=("ipv6-pool-" . $"ipv6-pool") ];
+:local oldprefix [ / ipv6 firewall address-list get $addrlist address ];
+
+# give the interfaces a moment to receive their addresses
+:delay 2s;
+
+if ($oldprefix != $"pd-prefix") do={
+ :log info ("Updating ipv6 address list with new IPv6 prefix " . $"pd-prefix");
+ / ipv6 firewall address-list set address=$"pd-prefix" $addrlist;
+
+ :local oldprefix56 [ :pick $oldprefix 0 [ :find $oldprefix "00::/56" ] ];
+ :local oldprefix64 [ :pick $oldprefix 0 [ :find $oldprefix "::/56" ] ];
+
+ :local newprefix [ / ipv6 address get [ / ipv6 address find where from-pool=$"ipv6-pool" interface=$"ipv6-interface" ] address ];
+ :local newprefix64 [ :pick $newprefix 0 [ :find $newprefix "::/64" ] ];
+
+ :foreach record in=[ / ip dns static find where address~$oldprefix56 ] do={
+ :local address [ / ip dns static get $record address ];
+ :local name [ / ip dns static get $record name ];
+
+ :if ( [ :len $name ] = 0) do={
+ :set name [ / ip dns static get $record regex ];
+ }
+
+ :local suffix [ :pick $address [ :len $oldprefix64 ] [ :len $address ] ];
+
+ :log info ("Updating dns record for " . $name . ": " . $address . " -> " . $newprefix64 . $suffix);
+ / ip dns static set address=($newprefix64 . $suffix) $record;
+ }
+}