Nut/OS  5.0.5
API Reference
ARP

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.

Typedefs

typedef struct _ARPENTRY ARPENTRY
 ARP entry type.

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.
NETBUFNutArpAllocNetBuf (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_ARPAGE   9
 Maximum age of an entry in the ARP cache in minutes.
#define MAX_ARPREQUESTS   1
 Maximum number of ARP requests generated per query.
#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.

Referenced by NutArpCacheQuery().

#define ATF_COM   0x02

Completed entry.

Referenced by NutArpCacheQuery(), and NutArpCacheUpdate().

#define ATF_PERM   0x04

Permanent entry.

Referenced by NutArpCacheUpdate().

#define MAX_ARPAGE   9

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.

#define MAX_ARPREQUESTS   1

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.

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.

Referenced by NutArpCacheQuery().


Typedef Documentation

typedef struct _ARPENTRY ARPENTRY

ARP entry type.


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:
devIdentifies the device.
ipRequested IP address in network byte order.
haPointer to a buffer which receives the MAC address.

References __tcp_trf, __tcp_trs, _ARPENTRY::ae_flags, _ARPENTRY::ae_ha, _ARPENTRY::ae_outdated, _ARPENTRY::ae_tq, ATF_COM, ATF_PERM, _NUTDEVICE::dev_icb, fprintf(), fputc(), inet_ntoa(), memcpy(), and NutEventBroadcast().

Referenced by NutArpInput().

Here is the call graph for this function:

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:
devIdentifies the device.
ipIP address of which the caller asked the MAC address.
macBuffer for the retrieved MAC address.
Returns:
0 if address resolved, -1 otherwise.

References __tcp_trf, __tcp_trs, _ARPENTRY::ae_flags, _ARPENTRY::ae_ha, _ARPENTRY::ae_tq, ARPOP_REQUEST, ATF_COM, ATF_REM, _NUTDEVICE::dev_icb, fprintf(), inet_ntoa(), MAX_ARPREQUESTS, MIN_ARPWAIT, NULL, NutArpAllocNetBuf(), NutArpOutput(), NutEventWait(), NutNetBufFree(), and rc.

Referenced by NutIpOutput().

Here is the call graph for this function:

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:
devIdentifies the device that received the packet.
nbPointer to a network buffer structure containing the ARP packet.

References arphdr::ar_hln, arphdr::ar_hrd, arphdr::ar_op, arphdr::ar_pln, arphdr::ar_pro, ether_arp::arp_sha, ether_arp::arp_spa, ether_arp::arp_tpa, ARPHRD_ETHER, ARPOP_REPLY, ARPOP_REQUEST, _NUTDEVICE::dev_icb, ether_arp::ea_hdr, ETHERTYPE_IP, htons, ifnet::if_local_ip, _NETBUF::nb_nw, ntohs, NutArpAllocNetBuf(), NutArpCacheUpdate(), NutArpOutput(), NutNetBufFree(), _NBDATA::sz, and _NBDATA::vp.

Referenced by NutEtherInput().

Here is the call graph for this function:

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

Allocate an ARP network buffer structure.

Parameters:
typeType of ARP packet.
ipTarget IP address.
macTarget MAC address, null pointer for broadcast.
Returns:
Pointer to the allocated network buffer structure or 0 on failure.

References arphdr::ar_hln, arphdr::ar_hrd, arphdr::ar_op, arphdr::ar_pln, arphdr::ar_pro, ether_arp::arp_tha, ether_arp::arp_tpa, ARPHRD_ETHER, ether_arp::ea_hdr, ETHERTYPE_IP, htons, memcpy(), memset(), _NETBUF::nb_nw, NBAF_NETWORK, NutNetBufAlloc(), and _NBDATA::vp.

Referenced by NutArpCacheQuery(), and NutArpInput().

Here is the call graph for this function:

int NutArpOutput ( NUTDEVICE dev,
NETBUF nb 
)

Send an ARP packet.

Note:
Applications typically do not call this function.
Parameters:
devIdentifies the device to use.
nbNetwork 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.

References ether_arp::arp_sha, ether_arp::arp_spa, ether_arp::arp_tha, _NUTDEVICE::dev_icb, ETHERTYPE_ARP, ifnet::if_local_ip, ifnet::if_mac, ifnet::if_output, memcpy(), _NETBUF::nb_nw, and _NBDATA::vp.

Referenced by NutArpCacheQuery(), and NutArpInput().

Here is the call graph for this function: