diff options
author | Christian Hesse <mail@eworm.de> | 2018-12-19 16:48:34 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2018-12-19 16:48:34 +0100 |
commit | 9f077ab8bfdb6e2a5eeb62d83cfacc2b9e73d46b (patch) | |
tree | cac061829bb7b1ab9253b9992d7764bb5561ea4b /ipv6-update | |
parent | 6f606f9ca5682174d1a6c7491aabcc2994b83386 (diff) |
ipv6-update: remove settings from global-config
Instead make it more robust by reading comments.
Diffstat (limited to 'ipv6-update')
-rw-r--r-- | ipv6-update | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/ipv6-update b/ipv6-update index e43a7ef..950646e 100644 --- a/ipv6-update +++ b/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; } } |