Detecting IP Address Conflicts with µC/TCP-IP

This blog will briefly show how to probe a local area network for IP address conflicts by using two API functions in µC/TCP-IP.

What is ARP?

The address resolution protocol (ARP) is the mechanism through which IP addresses are converted to physical addresses so that hosts may be uniquely identified in a local network. In other words, it translates a 32-bit Network (IPv4) address to a 48-bit media access control (MAC) Data-Link layer address, which allows data to flow between the Data-Link and Network layers. Each host maintains an internal cache of other hosts’ physical addresses which gets updated on a regular basis (typically 10 to 20 minutes although this timeout is implementation-specific). This timeout applies to dynamic cache entries and is necessary in case there are changes to a device’s hardware, IP address, or the device has been removed from the network altogether.

ARP-Cache-Table

Figure 1: Typical ARP cache table obtained with the ‘arp -a’ command.

When a host tries to communicate with another host on the LAN, say a PC trying to ping a remote host it has never communicated with or is unreachable, it first needs to resolve the physical address of the remote host before the ICMP datagrams can ever be replied. It does this by sending broadcast Ethernet frames (sent to the FF:FF:FF:FF:FF:FF:FF physical address) which are received by all the hosts on the network. If a host happens to have the requested IP address in its internal ARP cache, it sends an ARP reply to the PC that originated the request. For instance, frames 29 – 63 in Figure 2 show a situation just like the one described above where the host at 192.168.2.4 is trying to ping 192.168.2.3 but first its MAC address needs to be resolved. Once 192.168.2.3 comes online it tells 192.168.2.4 that it is located at 00:AB:CD:EF:80:01 (seen in frame 64) and 192.168.2.4 is then able to send out the ICMP ping request.

Ping-Unreachable-Host

Figure 2: Pinging an unreachable host.

What is a Gratuitous ARP?

A gratuitous ARP is an ARP request whose sender and target IP addresses are identical and is also sent to the broadcast address. They are used to make sure that no other host on the network has the same IP address as the device that sent the request. If there are no clashes with the IP address, the gratuitous ARP should remain unanswered. They can also be used to prompt other hosts on the network to update their internal caches in case the sender changes its IP or physical address. It is important to note that IP clashes are far more common in systems with statically assigned IP addresses. Those with DHCP servers don’t typically suffer from it unless there are changes in a device’s network interface card (and therefore changes to its MAC address).

Gratuitous-ARP

Figure 3: Sample gratuitous ARP.

In µC/TCP-IP, gratuitous ARPs are used internally after the DHCP process fails and the stack assigns a link-local address to the host. The DHCP client sends a gratuitous ARP request to announce itself to the network and to ensure the address is unique within the local link. However, they can actively be sent at the application level by calling the NetARP_TxReqGratuitous() API from an application task AppTask_IP_ConflictDetect() as shown in Figure 4. The NetARP_IsAddrProtocolConflict() function can then be used to check if a IP address conflict was in fact detected. AppTask_IP_ConflictDetect() may then signal another application task that uses network resources to inform it that an IP conflict exists; which can be done by posting to a kernel object like a global semaphore or a flag.

Task-Checks-IP-Address-Conflict

Figure 4: Simple application task that checks for IP address conflicts.

Tags: ,

Questions or Comments?

Have a question or a suggestion for a future article?
Don't hesitate to contact us and let us know!
All comments and ideas are welcome.