Do devices using APIPA check for address conflicts before self-allocating an IP? If so, how?
My understanding is that with APIPA, clients can automatically self-configure an IP address and subnet mask when a DHCP server isn't available. I understand that this approach isn't really practical for a number of reasons but I'm curious: Is there anything built into the protocol to check if a given IP address is in use else?
For example, let's say my host chooses to use 169.254.0.2. What if another host in the broadcast domain already has that address? Would my host even check prior to completing self-allocation?
2 Answers
It is almost impossible for two devices to choose the same IP for themselves.
Each device picks up an address and then tests to see if it is already in use, by broadcasting ARP Probe packets. All conflict cases are well covered, such as repeating requests when no answers arrive, ARP request for the same IP by another device, and others.
Finally the device announces itself to the network via ARP with its chosen IP, guaranteed by the algorithm to be unique (or almost guaranteed).
For details, seeRFC 5227that contains the standard that all ad-hoc networks must follow.
Link-local addressis a variant of this algorithm, first implemented in MacOS 9 in 1998, where each device picks a random address as its first try. The standard here isRFC 3927.
3The protocol is defined in RFC 3927, with section 2 being dedicated to address selection. In subsection 2.2 you will find:
2.2. Claiming a Link-Local Address
After it has selected an IPv4 Link-Local address, a host MUST test to see if the IPv4 Link-Local address is already in use before beginning to use it. [...]
2.2.1. Probe details
On a link-layer such as IEEE 802 that supports ARP, conflict detection is done using ARP probes. [...]
A host probes to see if an address is already in use by broadcasting an ARP Request for the desired address. The client MUST fill in the 'sender hardware address' field of the ARP Request with the hardware address of the interface through which it is sending the packet. The 'sender IP address' field MUST be set to all zeroes, to avoid polluting ARP caches in other hosts on the same link in the case where the address turns out to be already in use by another host. The 'target hardware address' field is ignored and SHOULD be set to all zeroes. The 'target IP address' field MUST be set to the address being probed. An ARP Request constructed this way with an all-zero 'sender IP address' is referred to as an "ARP Probe". [..]
[...] the host should send PROBE_NUM probe packets, each of these probe packets spaced randomly, PROBE_MIN to PROBE_MAX seconds apart. If during this period, from the beginning of the probing process until ANNOUNCE_WAIT seconds after the last probe packet is sent, the host receives any ARP packet (Request or Reply) on the interface where the probe is being performed where the packet's 'sender IP address' is the address being probed for, then the host MUST treat this address as being in use by some other host, and MUST select a new pseudo-random address and repeat the process. [...]
If, by ANNOUNCE_WAIT seconds after the transmission of the last ARP Probe no conflicting ARP Reply or ARP Probe has been received, then the host has successfully claimed the desired IPv4 Link-Local address.