package mnet
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c3151b243150c7b7412bf27b08107bed0e132f0a271d5f5b34bc0fdffed8ec3e
sha512=4a70d77ed42519a547f7b13e76ccfa05192514ca84e9dc9dcb97a5d141a8cc4551a669017a48290d70f01790a83fbeba53950a2d5f975e8e51e7daf3017d6b5e
doc/mnet.arpv4/ARPv4/index.html
Module ARPv4Source
Address Resolution Protocol (ARPv4) for IPv4.
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.
Types
Errors returned by query.
`Exn exn: an unexpected exception occurred during ARP resolution.`Timeout: no ARP reply was received after a number of retries.`Clear: the ARP cache entry was cleared before resolution completed.
The ARP state. Maintains the address cache and pending query state.
The background ARP daemon that responds to requests and processes replies. Must be terminated with kill.
Initialization.
val create :
?delay:int ->
?timeout:int ->
?retries:int ->
?ipaddr:Ipaddr.V4.t ->
Ethernet.t ->
(daemon * t, [> `MTU_too_small ]) resultcreate ?delay ?timeout ?retries ?ipaddr eth creates a new ARP state and starts the background daemon.
delay(nanoseconds): initial delay before sending the first ARP request.timeout(nanoseconds): time to wait for an ARP reply before retrying.retries: number of ARP request retries before giving up.ipaddr: the local IPv4 address to announce and respond to. Can be updated later withset_ips.eth: theEthernetlayer used for sending/receiving ARP frames.
Returns `MTU_too_small if the Ethernet MTU is insufficient.
Cache operations.
macaddr t returns the local MAC address (from the underlying Ethernet device).
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).
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.