ARP
[Base Protocols]

RFC 826 address resolution protocol. More...

Collaboration diagram for ARP:

Data Structures

struct  ARPENTRY
 ARP entry structure. More...

Defines

#define ATF_REM   0x01
 Entry marked for removal.
#define ATF_COM   0x02
 Completed entry.
#define ATF_PERM   0x04
 Permanent entry.

Functions

void NutArpCacheUpdate (NUTDEVICE *dev, uint32_t ip, uint8_t *ha)
 Update an ARP entry.
int NutArpCacheQuery (NUTDEVICE *dev, CONST uint32_t ip, uint8_t *mac)
 Query MAC address for a specified IP address.
void NutArpInput (NUTDEVICE *dev, NETBUF *nb)
 Handle incoming ARP packets.
NETBUF * NutArpAllocNetBuf (uint16_t type, uint32_t ip, uint8_t *mac)
 Allocate an ARP network buffer structure.
int NutArpOutput (NUTDEVICE *dev, NETBUF *nb)
 Send an ARP packet.

ARP Configuration

The Nut/OS Configurator may be used to override the default values.



#define MAX_ARPREQUESTS   1
 Maximum age of an entry in the ARP cache in minutes.
#define MIN_ARPWAIT   500
 Minimum wait before sending out a new ARP request.

Detailed Description

RFC 826 address resolution protocol.

ARP is used to map IP addresses to hardware addresses. Each network interface of Nut/Net keeps its own mapping table.

When an IP packet has to be sent out, IP needs the hardware address to pass it to the Ethernet layer. If the mapping is not in the ARP cache, an Ethernet broadcast packet is sent to the local network requesting the physical hardware address for the given IP address.

Todo:

Add functions to manually add or remove ARP entries.

Add function to query ARP tables.

Todo:
Response may reuse received ARP packet.

Define Documentation

#define ATF_REM   0x01

Entry marked for removal.

Definition at line 125 of file if_var.h.

Referenced by NutArpCacheQuery().

#define ATF_COM   0x02

Completed entry.

Definition at line 126 of file if_var.h.

Referenced by NutArpCacheQuery(), and NutArpCacheUpdate().

#define ATF_PERM   0x04

Permanent entry.

Definition at line 127 of file if_var.h.

Referenced by NutArpCacheUpdate().

#define MAX_ARPREQUESTS   1

Maximum age of an entry in the ARP cache in minutes.

Outdated entries will be regularly removed, forcing the Ethernet interface to generate new ARP requests. This way MAC address changes are detected.

Maximum number of ARP requests generated per query. If no ARP response is received after sending out the specified number of request, the related IP address is considered unreachable.

Definition at line 211 of file arpcache.c.

Referenced by NutArpCacheQuery().

#define MIN_ARPWAIT   500

Minimum wait before sending out a new ARP request.

The specified number of milliseconds will be doubled on each retry.

Definition at line 221 of file arpcache.c.

Referenced by NutArpCacheQuery().


Function Documentation

void NutArpCacheUpdate ( NUTDEVICE *  dev,
uint32_t  ip,
uint8_t ha 
)

Update an ARP entry.

If an entry with the same IP address exists, then this entry is updated. If no entry exists, a new one is created. All threads waiting for address resolution are woken up.

Note:
This function is automatically called on each incoming ARP telegram. Applications typically do not call this function.
Parameters:
dev Identifies the device.
ip Requested IP address in network byte order.
ha Pointer to a buffer which receives the MAC address.

Definition at line 393 of file arpcache.c.

References __tcp_trf, __tcp_trs, ATF_COM, ATF_PERM, fprintf(), fputc(), inet_ntoa(), memcpy(), and NutEventBroadcast().

Referenced by NutArpInput().

int NutArpCacheQuery ( NUTDEVICE *  dev,
CONST uint32_t  ip,
uint8_t mac 
)

Query MAC address for a specified IP address.

If no entry is available in the ARP cache, an incomplete entry is created and ARP requests are generated on increasing time intervals. The calling thread is suspended until a matching ARP response is received or until a number of requests have been generated without receiving a response.

Note:
This function is automatically called on each outgoing IP packet. Applications typically do not call this function.
Parameters:
dev Identifies the device.
ip IP address of which the caller asked the MAC address.
mac Buffer for the retrieved MAC address.
Returns:
0 if address resolved, -1 otherwise.

Definition at line 448 of file arpcache.c.

References __tcp_trf, __tcp_trs, ARPOP_REQUEST, ATF_COM, ATF_REM, fprintf(), inet_ntoa(), MAX_ARPREQUESTS, MIN_ARPWAIT, NutArpAllocNetBuf(), NutArpOutput(), NutEventWait(), and NutNetBufFree().

void NutArpInput ( NUTDEVICE *  dev,
NETBUF *  nb 
)

Handle incoming ARP packets.

Packets not destined to us or packets with unsupported address type or item length are silently discarded.

Note:
This routine is called by the Ethernet layer on incoming ARP packets. Applications typically do not call this function.
Parameters:
dev Identifies the device that received the packet.
nb Pointer to a network buffer structure containing the ARP packet.

Definition at line 143 of file arpin.c.

References ARPHDR::ar_hln, ARPHDR::ar_hrd, ARPHDR::ar_op, ARPHDR::ar_pln, ARPHDR::ar_pro, ETHERARP::arp_sha, ETHERARP::arp_spa, ETHERARP::arp_tpa, ARPHRD_ETHER, ARPOP_REPLY, ARPOP_REQUEST, ETHERARP::ea_hdr, ETHERTYPE_IP, htons, ntohs, NutArpAllocNetBuf(), NutArpCacheUpdate(), NutArpOutput(), and NutNetBufFree().

Referenced by NutEtherInput().

NETBUF* NutArpAllocNetBuf ( uint16_t  type,
uint32_t  ip,
uint8_t mac 
)

Allocate an ARP network buffer structure.

Parameters:
type Type of ARP packet.
ip Target IP address.
mac Target MAC address, null pointer for broadcast.
Returns:
Pointer to the allocated network buffer structure or 0 on failure.

Definition at line 141 of file arpout.c.

References ARPHDR::ar_hln, ARPHDR::ar_hrd, ARPHDR::ar_op, ARPHDR::ar_pln, ARPHDR::ar_pro, ETHERARP::arp_tha, ETHERARP::arp_tpa, ARPHRD_ETHER, ETHERARP::ea_hdr, ETHERTYPE_IP, htons, memcpy(), memset(), NBAF_NETWORK, and NutNetBufAlloc().

Referenced by NutArpCacheQuery(), and NutArpInput().

int NutArpOutput ( NUTDEVICE *  dev,
NETBUF *  nb 
)

Send an ARP packet.

Note:
Applications typically do not call this function.
Parameters:
dev Identifies the device to use.
nb Network buffer structure containing the packet to be sent. The structure must have been allocated by a previous call NutNetBufAlloc().
Returns:
0 on success, -1 in case of any errors.

Definition at line 186 of file arpout.c.

References ETHERARP::arp_sha, ETHERARP::arp_spa, ETHERARP::arp_tha, ETHERTYPE_ARP, and memcpy().

Referenced by NutArpCacheQuery(), and NutArpInput().


© 2000-2010 by contributors - visit http://www.ethernut.de/