mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
ipv6-update: remove settings from global-config
Instead make it more robust by reading comments.
This commit is contained in:
parent
6f606f9ca5
commit
9f077ab8bf
|
@ -37,10 +37,6 @@
|
|||
# This controls what configuration is activated by bridge-port-to-default.
|
||||
:global "bridge-port-to" "default";
|
||||
|
||||
# This is used to update AAAA records and firewall address-list.
|
||||
:global "ipv6-interface" "br-local";
|
||||
:global "ipv6-pool" "telekom";
|
||||
|
||||
# These settings are used to update gre interface settings based on
|
||||
# remote peer configuration.
|
||||
:global "gre-cert-prefix" "ikev2-";
|
||||
|
|
29
ipv6-update
29
ipv6-update
|
@ -4,36 +4,31 @@
|
|||
#
|
||||
# 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 pool [ / ipv6 pool get [ find where prefix=$"pd-prefix" ] name ];
|
||||
:local addrlist [ / ipv6 firewall address-list find where comment=("ipv6-pool-" . $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");
|
||||
: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" ] ];
|
||||
:foreach record in=[ / ip dns static find where comment~("ipv6-pool-" . $pool) ] do={
|
||||
:local comment [ :toarray [ / ip dns static get $record comment ] ];
|
||||
:local intname [ :pick [ :pick $comment 1 ] 10 99 ];
|
||||
:local suffix [ :pick [ :pick $comment 2 ] 7 99 ];
|
||||
|
||||
: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" ] ];
|
||||
:local prefix [ / ipv6 address get [ find where interface=$intname from-pool=$pool global ] address ];
|
||||
:local prefix64 [ :pick $prefix 0 [ :find $prefix "::/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={
|
||||
: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;
|
||||
:log info ("Updating DNS record for " . $name . " to " . $prefix64 . ":" . $suffix);
|
||||
/ ip dns static set address=($prefix64 . ":" . $suffix) $record;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue