eworm-de / routeros-scripts

a collection of scripts for MikroTik RouterOS
GNU General Public License v3.0
1.32k stars 292 forks source link

ipv6-update adds 1 to the static IPv6 DNS-name's address if it ends in even number #11

Closed peeterrussak closed 3 years ago

peeterrussak commented 3 years ago

Tested on RouterOS v7.1b6 Example prefix: 2001:7d0:87cc:c600::/56

  1. Create static IPv6 DNS record ending with ::1
  2. Disable dhcpv6-client, enable dhcpv6-client -> new prefix propagates correctly, static address ends with ::1
  3. Create static IPv6 DNS record ending with ::2
  4. Disable dhcpv6-client, enable dhcpv6-client -> new prefix propagates correctly, but address ends with ::3
  5. Disable dhcpv6-client, enable dhcpv6-client -> new prefix propagates correctly, static address ends correctly with ::3
eworm-de commented 3 years ago

I have not seen this... Will try to reproduce later today. Can you please give exact commands to create the DNS records?

eworm-de commented 3 years ago

BTW... I did not test my scripts with RouterOS 7.x at all... Possibly they broke arithmetics with IPv6 addresses? I will check.

peeterrussak commented 3 years ago

Re-tested with 6.48.2 and got same result. And figured it out. This one doesn't get prefix, but IPv6-address of interface: :local Prefix [ / ipv6 address get [ find where interface=($Comment->"interface") from-pool=$Pool global ] address ];

If interface's address is smth else than :: then it's OR-ed to the static address. I had ::1, which explains +1:

Let's test: /ipv6 address add address=::100 from-pool=isp interface=bridge /ip dns static add address=::2 comment="isp-pool-isp, interface=bridge" name=test.test ttl=15m; /ipv6 dhcp-client disable ether1 /ipv6 dhcp-client enable ether1

With added logging: :log info ($Prefix); :set Prefix [ :toip6 [ :pick $Prefix 0 [ :find $Prefix "/64" ] ] ]; :log info ($Prefix); :log info ("Address is: ". ($RecordVal->"address")); :local Address ($Prefix | ([ :toip6 ($RecordVal->"address") ] & ::ffff:ffff:ffff:ffff)); :log info ("Updating DNS record for " . ($RecordVal->"name") . ($RecordVal->"regexp") . " to " . $Address);

Creates output: 21:53:29 system,info static dns entry added by admin 21:53:34 system,info DHCPv6 client on ether1 changed by admin 21:53:36 system,info DHCPv6 client on ether1 changed by admin 21:53:37 script,info Updating IPv6 address list with new IPv6 prefix 2001:7d0:87c6:7b00::/56 21:53:37 system,info address list entry changed by admin 21:53:39 script,info 2001:7d0:87c6:7b00::100/64 21:53:39 script,info 2001:7d0:87c6:7b00::100 21:53:39 script,info Address is: ::2 21:53:39 script,info Updating DNS record for test.test to 2001:7d0:87c6:7b00::102

eworm-de commented 3 years ago

Ah, got it... Can you please test?

/ system script set comment="url-suffix=\?h=next" ipv6-update
$ScriptInstallUpdate

Also fix the address in dns record, then disable and re-enable.

eworm-de commented 3 years ago

Already merged to main branch... Please complain if your issue remains. ... and leave a star if you have not.

peeterrussak commented 3 years ago

Thanks, works now as expected!