ARP maps IPv4 addresses to MAC (link-layer) addresses on a local network. When the IPv4 layer needs to send a packet to a destination, it uses ARP to find the destination's MAC address (or the gateway's MAC address for non-local destinations).
Security: DoS prevention.
The ARP cache distinguishes between trusted entries (configured by the user, e.g. the local IP address) and disposable entries (learned from the network). Disposable entries are subject to eviction under memory pressure, preventing an attacker from exhausting memory by flooding the network with ARP replies for many different addresses.
Daemon model.
create spawns a background daemon that processes incoming ARP requests and replies. The daemon responds to ARP requests for the locally configured IP address and updates the cache with ARP replies.
set_ips t ips sets the list of IPv4 addresses that this ARP instance responds to. ARP requests for any of these addresses will receive a reply with the local MAC address. These entries are marked as trusted (not disposable).
set_on_conflict t fn installs the callback invoked when an address conflict persists: as per RFC 5227 (section 2.4, policy (b)), upon receiving an ARP packet whose sender IP is one of our addresses but whose sender MAC is not ours, the address is first defended with a single ARP announcement; if another conflicting packet arrives within DEFEND_INTERVAL (10s), fn ip mac is called (from the ARP daemon) with the disputed address and the MAC address of the conflicting host. The upper layer should then stop using the address (e.g. DHCPDECLINE and acquire a new lease). Defaults to a no-op; conflicts are logged in all cases.
query t ipv4 resolves the MAC address for the given ipv4 address. If the address is already in the cache, the result is returned immediately. Otherwise, an ARP request is sent and the current Miou task is suspended until a reply is received (or timeout/retries are exhausted).
ask t ipv4 looks up ipv4 in the ARP cache without sending any ARP request. Returns Some mac if the address is cached, None otherwise.
Unlike query, this function never suspends the caller (no effects, no rescheduling). Useful when you want to check the cache speculatively without blocking.