rtr7 / router7

router7 is a small home internet router completely written in Go. It is implemented as a gokrazy appliance.
https://router7.org
Apache License 2.0
2.69k stars 110 forks source link

dhcp4d causes an IP address conflict #18

Closed stapelberg closed 5 years ago

stapelberg commented 5 years ago
2018/12/14 23:10:13 dhcp4d.go:122: DHCPACK &{Num:1 Addr:10.0.0.3 HardwareAddr:00:e0:4c:68:fe:07 Hostname:xps Expiry:2018-12-15 01:10:13.724814008 +0100 CET m=+64928.993070360}
[…]
2018/12/14 23:16:54 dhcp4d.go:122: DHCPACK &{Num:1 Addr:10.0.0.3 HardwareAddr:80:e6:50:21:3a:36 Hostname:mbp Expiry:2018-12-15 01:16:54.061257234 +0100 CET m=+65329.329513710}

Unfortunately I don’t have a full capture because of issue #17

stapelberg commented 5 years ago

Suspicion: when another MAC address new obtains an expired lease, h.leasesHW[old] is not updated, hence https://github.com/rtr7/router7/blob/badee1eef80baafefc353a463bae29bbbae4af15/internal/dhcp4d/dhcp4d.go#L220-L223 returns true and the lease is handed out again.

I’ll write a test to verify this tomorrow. A good fix would probably be to make leasesHW a map from hwaddr to leaseNum, so that there is precisely one data structure which needs to be updated, not two.