odhcpd: support assignments on the basis of IAID
With this patch, IAIDs are actually taken into account when creating
assignments, which allows per-IAID assignments.
The old odhcpd behaviour is still kept for assignments which only
specify a DUID. That behaviour is a first-come-first-serve basis, where
the first request (no matter what the IAID is) will get the static
address, and later requests with different IAIDs will get a NoAddrsAvail
error message (in other words, assignments are not re-assigned and
random adresses are not provided when the "main" address is already
assigned, if the DUID is known in a static config).
The old odhcpd behaviour can be described as follows:
Imagine a "dhcp" configuration file with a single static assignment:
config host
option name 'test'
option ip '192.168.44.2'
option mac '00:00:00:00:ca:fe'
option duid '
0003000100000000cafe'
option hostid '02'
And odhcpd running on an interface with IPv6 addr fd00:aaaa::1/48, using
a simple test client (command line parameters should be self-evident
here, foo-client is the client part of a veth interface pair, odhcpd is
listening to the peer interface foo-server):
$ sudo dhcpdig --iaid=0x01 --duid=f000 foo-client
IPv6: fd00:aaaa::9c5
$ sudo dhcpdig --iaid=0x01 --duid=f000 foo-client
IPv6: fd00:aaaa::9c5
$ sudo dhcpdig --iaid=0x02 --duid=f000 foo-client
IPv6: fd00:aaaa::817
$ sudo dhcpdig --iaid=0x02 --duid=f000 foo-client
IPv6: fd00:aaaa::817
$ sudo dhcpdig --iaid=0x01 --duid=f000 foo-client
IPv6: fd00:aaaa::9c5
$ sudo dhcpdig --iaid=0x01 --duid=
0003000100000000cafe foo-client
IPv6: fd00:aaaa::2
$ sudo dhcpdig --iaid=0x01 --duid=
0003000100000000cafe foo-client
IPv6: fd00:aaaa::2
$ sudo dhcpdig --iaid=0x02 --duid=
0003000100000000cafe foo-client
STATUS: NoAddrsAvail (2)
IOW, unknown DUIDs get randomly assigned per-IAID IPv6 addresses. Known
statically determined DUIDs will be awarded to the first client
attempting a lease, no matter what the IAID is, but the IAID will be
remembered and subsequent requests with other IAIDs will fail.
With this patch applied, assume a "dhcp" configuration file with the
following assignments:
config host
option name 'testcafe'
option ip '192.168.44.2'
option mac '00:00:00:00:ca:fe'
option hostid '02'
option duid '
0003000100000000cafe%123'
config host
option name 'testbeef'
option ip '192.168.44.3'
option mac '00:00:00:00:be:ef'
option hostid '03'
option duid '
0003000100000000beef'
config host
option name 'testfood'
option ip '192.168.44.4'
option mac '00:00:00:00:f0:0d'
option hostid '04'
option duid '
0003000100000000f00d'
config host
option name 'testfood2'
option ip '192.168.44.5'
option mac '00:00:00:00:f0:0d'
option hostid '05'
option duid '
0003000100000000f00d%123'
Now, using the same test client:
$ sudo ./build/dhcpdig --iaid=0x000 --duid=
0003000100000000cafe foo-client
IPv6: fd00:aaaa::9c4
$ sudo ./build/dhcpdig --iaid=0x123 --duid=
0003000100000000cafe foo-client
IPv6: fd00:aaaa::2
$ sudo ./build/dhcpdig --iaid=0x000 --duid=
0003000100000000cafe foo-client
IPv6: fd00:aaaa::9c4
$ sudo ./build/dhcpdig --iaid=0xabc --duid=
0003000100000000beef foo-client
IPv6: fd00:aaaa::3
$ sudo ./build/dhcpdig --iaid=0x123 --duid=
0003000100000000beef foo-client
STATUS: NoAddrsAvail (2)
$ sudo ./build/dhcpdig --iaid=0xabc --duid=
0003000100000000f00d foo-client
IPv6: fd00:aaaa::4
$ sudo ./build/dhcpdig --iaid=0xabc --duid=
0003000100000000f00d foo-client
IPv6: fd00:aaaa::4
$ sudo ./build/dhcpdig --iaid=0x123 --duid=
0003000100000000f00d foo-client
IPv6: fd00:aaaa::5
See also: https://github.com/openwrt/odhcpd/issues/175
Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/255
Signed-off-by: Álvaro Fernández Rojas <[email protected]>