lwIP  2.0.2
Lightweight IP stack
etharp.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip4_addr.h"
#include "lwip/netif.h"
#include "lwip/ip4.h"
#include "lwip/prot/ethernet.h"
#include "lwip/prot/etharp.h"

Data Structures

struct  etharp_q_entry
 

Macros

#define ARP_TMR_INTERVAL   1000
 
#define etharp_gratuitous(netif)   etharp_request((netif), netif_ip4_addr(netif))
 

Functions

void etharp_tmr (void)
 
s8_t etharp_find_addr (struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr **eth_ret, const ip4_addr_t **ip_ret)
 
u8_t etharp_get_entry (u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret)
 
err_t etharp_output (struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
 
err_t etharp_query (struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
 
err_t etharp_request (struct netif *netif, const ip4_addr_t *ipaddr)
 
void etharp_cleanup_netif (struct netif *netif)
 
void etharp_input (struct pbuf *p, struct netif *netif)
 

Detailed Description

Ethernet output function - handles OUTGOING ethernet level traffic, implements ARP resolving. To be used in most low-level netif implementations

Macro Definition Documentation

◆ ARP_TMR_INTERVAL

#define ARP_TMR_INTERVAL   1000

1 seconds period

◆ etharp_gratuitous

#define etharp_gratuitous (   netif)    etharp_request((netif), netif_ip4_addr(netif))

For Ethernet network interfaces, we might want to send "gratuitous ARP"; this is an ARP packet sent by a node in order to spontaneously cause other nodes to update an entry in their ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6.

Function Documentation

◆ etharp_cleanup_netif()

void etharp_cleanup_netif ( struct netif netif)

Remove all ARP table entries of the specified netif.

Parameters
netifpoints to a network interface

◆ etharp_find_addr()

s8_t etharp_find_addr ( struct netif netif,
const ip4_addr_t ipaddr,
struct eth_addr **  eth_ret,
const ip4_addr_t **  ip_ret 
)

Finds (stable) ethernet/IP address pair from ARP table using interface and IP address index.

Note
the addresses in the ARP table are in network order!
Parameters
netifpoints to interface index
ipaddrpoints to the (network order) IP address index
eth_retpoints to return pointer
ip_retpoints to return pointer
Returns
table index if found, -1 otherwise

◆ etharp_get_entry()

u8_t etharp_get_entry ( u8_t  i,
ip4_addr_t **  ipaddr,
struct netif **  netif,
struct eth_addr **  eth_ret 
)

Possibility to iterate over stable ARP table entries

Parameters
ientry number, 0 to ARP_TABLE_SIZE
ipaddrreturn value: IP address
netifreturn value: points to interface
eth_retreturn value: ETH address
Returns
1 on valid index, 0 otherwise

◆ etharp_input()

void etharp_input ( struct pbuf p,
struct netif netif 
)

Responds to ARP requests to us. Upon ARP replies to us, add entry to cache send out queued IP packets. Updates cache with snooped address pairs.

Should be called for incoming ARP packets. The pbuf in the argument is freed by this function.

Parameters
pThe ARP packet that arrived on netif. Is freed by this function.
netifThe lwIP network interface on which the ARP packet pbuf arrived.
See also
pbuf_free()

◆ etharp_output()

err_t etharp_output ( struct netif netif,
struct pbuf q,
const ip4_addr_t ipaddr 
)

Resolve and fill-in Ethernet address header for outgoing IP packet.

For IP multicast and broadcast, corresponding Ethernet addresses are selected and the packet is transmitted on the link.

For unicast addresses, the packet is submitted to etharp_query(). In case the IP address is outside the local network, the IP address of the gateway is used.

Parameters
netifThe lwIP network interface which the IP packet will be sent on.
qThe pbuf(s) containing the IP packet to be sent.
ipaddrThe IP address of the packet destination.
Returns

◆ etharp_query()

err_t etharp_query ( struct netif netif,
const ip4_addr_t ipaddr,
struct pbuf q 
)

Send an ARP request for the given IP address and/or queue a packet.

If the IP address was not yet in the cache, a pending ARP cache entry is added and an ARP request is sent for the given address. The packet is queued on this entry.

If the IP address was already pending in the cache, a new ARP request is sent for the given address. The packet is queued on this entry.

If the IP address was already stable in the cache, and a packet is given, it is directly sent and no ARP request is sent out.

If the IP address was already stable in the cache, and no packet is given, an ARP request is sent out.

Parameters
netifThe lwIP network interface on which ipaddr must be queried for.
ipaddrThe IP address to be resolved.
qIf non-NULL, a pbuf that must be delivered to the IP address. q is not freed by this function.
Note
q must only be ONE packet, not a packet queue!
Returns
  • ERR_BUF Could not make room for Ethernet header.
  • ERR_MEM Hardware address unknown, and no more ARP entries available to query for address or queue the packet.
  • ERR_MEM Could not queue packet due to memory shortage.
  • ERR_RTE No route to destination (no gateway to external networks).
  • ERR_ARG Non-unicast address given, those will not appear in ARP cache.

◆ etharp_request()

err_t etharp_request ( struct netif netif,
const ip4_addr_t ipaddr 
)

Send an ARP request packet asking for ipaddr.

Parameters
netifthe lwip network interface on which to send the request
ipaddrthe IP address for which to ask
Returns
ERR_OK if the request has been sent ERR_MEM if the ARP packet couldn't be allocated any other err_t on failure

◆ etharp_tmr()

void etharp_tmr ( void  )

Clears expired entries in the ARP table.

This function should be called every ARP_TMR_INTERVAL milliseconds (1 second), in order to expire entries in the ARP table.