openwrt / odhcpd

This repository is a mirror of https://git.openwrt.org/?p=project/odhcpd.git. Pull requests will be accepted which will be merged in odhcpd.git
GNU General Public License v2.0
160 stars 96 forks source link

Static leases assigns the same IPv6 to multiple NICs #175

Open lslqtz opened 2 years ago

lslqtz commented 2 years ago

My computer has multiple NICs (Ethernet, Wi-Fi), these NICs share the same DUID, they will get the same IPv6 address, resulting in a conflict. IAID can distinguish different NICs, but IAID seem to be randomly assigned by the OS. I tried not to specify a DUID, but it doesn't seem to work. Edit: I am trying to update to the latest version of odhcpd and will supplement it again after confirmation Jun 14, 2021 (564d25e53fad925fa3ed56e3004c107d40925fa4) still happens

image

(same DUID and different IAID)

My /etc/config/dhcp file

config dnsmasq
    option localise_queries '1'
    option local '/lan/,/r.acgn.xyz/'
    option expandhosts '1'
    option leasefile '/tmp/dhcp.leases'
    option localservice '1'
    option authoritative '1'
    option rebind_protection '0'
    option nonwildcard '0'
    option cachesize '0'
    option domain 'lan'
    option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
    list server '127.0.0.1#5333'
    option noresolv '1'

config dhcp 'lan'
    option interface 'lan'
    option ra_slaac '0'
    list ra_flags 'managed-config'
    list ra_flags 'other-config'
    option ignore '1'
    option dhcpv6 'server'
    option ra 'server'
    option ra_useleasetime '1'
    option ra_management '2'
    option ra_lifetime '600'
    option leasetime '10m'
    option preferred_lifetime '10m'

config dhcp 'wan'
    option interface 'wan'
    option ignore '1'

config odhcpd 'odhcpd'
    option maindhcp '0'
    option leasefile '/tmp/hosts/odhcpd'
    option leasetrigger '/usr/sbin/odhcpd-update'
    option loglevel '4'

config srvhost
    option srv '_vlmcs._tcp'
    option target 'asd'
    option port '1688'
    option class '0'
    option weight '100'

config host
    option name 'asdde-iMac'
    option mac '30:5a:3a:05:e6:15'
    option ip '192.168.233.2'
    option leasetime '10m'
    option hostid '2'

config domain
    option name 'r.acgn.xyz'
    option ip '192.168.233.233'
mpeleshenko commented 1 year ago

I noticed the same behavior just now after recently getting IPv6 from my ISP and trying to assign different IPv6 addresses to 2 different interfaces on the same Windows server.

Looking through the code, I came across the below which looks for a static lease in the config trying to match first on DUID, and falling back to MAC address. https://github.com/openwrt/odhcpd/blob/860ca900e41c5d0f98cc85e67b39977f6f2cb355/src/dhcpv6-ia.c#L1279-L1281

Now as far as I understand, IPv6 does not actually look at the Layer 2 MAC address of the incoming packet and odhcpd is actually parsing it out of the DUID, which is defined to have the MAC address if it's a Type 1 or Type 3 DUID (See here for details on the different DUID types). https://github.com/openwrt/odhcpd/blob/860ca900e41c5d0f98cc85e67b39977f6f2cb355/src/dhcpv6-ia.c#L1252-L1259

Given the DUID, or even embedded MAC address, are the same between both interfaces, odhcpd picks up the same static lease from the config to give to both interfaces, resulting in a conflict.

I think it would make sense to add an IAID option for static leases and have odhcpd match on that as well when looking for a static lease in the config.