Microchip® Advanced Software Framework

etharp.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/ip.h"

Data Structures

struct  eth_addr
 
struct  eth_hdr
 Ethernet header. More...
 
struct  etharp_hdr
 the ARP message, see RFC 826 ("Packet format") More...
 

Macros

#define ARP_REPLY   2
 
#define ARP_REQUEST   1
 ARP message types (opcodes) More...
 
#define ARP_TMR_INTERVAL   5000
 5 seconds period More...
 
#define eth_addr_cmp(addr1, addr2)   (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
 
#define ETHADDR16_COPY(src, dst)   SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
 MEMCPY-like macro to copy to/from struct eth_addr's that are no local variables and known to be 16-bit aligned within the protocol header. More...
 
#define ETHADDR32_COPY(src, dst)   SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
 MEMCPY-like macro to copy to/from struct eth_addr's that are local variables or known to be 32-bit aligned within the protocol header. More...
 
#define etharp_gratuitous(netif)   etharp_request((netif), &(netif)->ip_addr)
 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. More...
 
#define ETHARP_HWADDR_LEN   6
 
#define etharp_init()   /* Compatibility define, not init needed. */
 
#define ETHTYPE_ARP   0x0806U
 
#define ETHTYPE_IP   0x0800U
 
#define ETHTYPE_PPPOE   0x8864U /* PPP Over Ethernet Session Stage */
 
#define ETHTYPE_PPPOEDISC   0x8863U /* PPP Over Ethernet Discovery Stage */
 
#define ETHTYPE_VLAN   0x8100U
 
#define LWIP_ARP_FILTER_NETIF   0
 Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type) to a filter function that returns the correct netif when using multiple netifs on one hardware interface where the netif's low-level receive routine cannot decide for the correct netif (e.g. More...
 
#define SIZEOF_ETH_HDR   (14 + ETH_PAD_SIZE)
 
#define SIZEOF_ETHARP_HDR   28
 
#define SIZEOF_ETHARP_PACKET   (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
 

Functions

void etharp_cleanup_netif (struct netif *netif)
 Remove all ARP table entries of the specified netif. More...
 
s8_t etharp_find_addr (struct netif *netif, ip_addr_t *ipaddr, struct eth_addr **eth_ret, ip_addr_t **ip_ret)
 Finds (stable) ethernet/IP address pair from ARP table using interface and IP address index. More...
 
err_t etharp_output (struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
 Resolve and fill-in Ethernet address header for outgoing IP packet. More...
 
err_t etharp_query (struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q)
 Send an ARP request for the given IP address and/or queue a packet. More...
 
err_t etharp_request (struct netif *netif, ip_addr_t *ipaddr)
 Send an ARP request packet asking for ipaddr. More...
 
void etharp_tmr (void)
 Clears expired entries in the ARP table. More...
 
err_t ethernet_input (struct pbuf *p, struct netif *netif)
 Process received ethernet frames. More...
 

Variables

struct eth_addr ethbroadcast ethzero
 
PACK_STRUCT_BEGIN struct eth_addr PACK_STRUCT_STRUCT
 

#define ARP_REPLY   2

Referenced by etharp_arp_input().

#define ARP_REQUEST   1

ARP message types (opcodes)

Referenced by etharp_arp_input(), and etharp_request().

#define ARP_TMR_INTERVAL   5000

5 seconds period

Referenced by arp_timer(), and sys_timeouts_init().

#define eth_addr_cmp (   addr1,
  addr2 
)    (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)

Referenced by ethernet_input().

#define ETHADDR16_COPY (   src,
  dst 
)    SMEMCPY(src, dst, ETHARP_HWADDR_LEN)

MEMCPY-like macro to copy to/from struct eth_addr's that are no local variables and known to be 16-bit aligned within the protocol header.

Referenced by etharp_arp_input(), etharp_raw(), and etharp_send_ip().

#define ETHADDR32_COPY (   src,
  dst 
)    SMEMCPY(src, dst, ETHARP_HWADDR_LEN)

MEMCPY-like macro to copy to/from struct eth_addr's that are local variables or known to be 32-bit aligned within the protocol header.

Referenced by etharp_send_ip(), and etharp_update_arp_entry().

#define etharp_gratuitous (   netif)    etharp_request((netif), &(netif)->ip_addr)

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.

Referenced by netif_set_link_up(), and netif_set_up().

#define ETHARP_HWADDR_LEN   6
#define etharp_init ( )    /* Compatibility define, not init needed. */

Referenced by lwip_init().

#define ETHTYPE_ARP   0x0806U
#define ETHTYPE_IP   0x0800U
#define ETHTYPE_PPPOE   0x8864U /* PPP Over Ethernet Session Stage */

Referenced by ethernet_input(), and ethernetif_input().

#define ETHTYPE_PPPOEDISC   0x8863U /* PPP Over Ethernet Discovery Stage */

Referenced by ethernet_input(), and ethernetif_input().

#define ETHTYPE_VLAN   0x8100U

Referenced by etharp_arp_input(), and ethernet_input().

#define LWIP_ARP_FILTER_NETIF   0

Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type) to a filter function that returns the correct netif when using multiple netifs on one hardware interface where the netif's low-level receive routine cannot decide for the correct netif (e.g.

when mapping multiple IP addresses to one hardware interface).

#define SIZEOF_ETH_HDR   (14 + ETH_PAD_SIZE)
#define SIZEOF_ETHARP_HDR   28
#define SIZEOF_ETHARP_PACKET   (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)

Referenced by etharp_arp_input(), and etharp_raw().

void etharp_cleanup_netif ( struct netif netif)

Remove all ARP table entries of the specified netif.

Parameters
netifpoints to a network interface

References arp_table, etharp_free_entry(), ETHARP_STATE_EMPTY, etharp_entry::state, and netif::state.

Referenced by netif_set_down().

s8_t etharp_find_addr ( struct netif netif,
ip_addr_t ipaddr,
struct eth_addr **  eth_ret,
ip_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

References arp_table, etharp_entry::ethaddr, etharp_find_entry(), ETHARP_FLAG_FIND_ONLY, ETHARP_STATE_STABLE, etharp_entry::ipaddr, LWIP_ASSERT, LWIP_UNUSED_ARG, NULL, and netif::state.

err_t etharp_output ( struct netif netif,
struct pbuf q,
ip_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

References arp_table, ERR_BUF, ERR_RTE, etharp_cached_entry, ETHARP_DEBUG, etharp_output_to_arp_index(), etharp_query(), etharp_send_ip(), ETHARP_SET_HINT, ETHARP_STATE_STABLE, ETHARP_STATS_INC, netif::gw, netif::hwaddr, ip4_addr2, ip4_addr3, ip4_addr4, netif::ip_addr, ip_addr_cmp, ip_addr_isany, ip_addr_isbroadcast, ip_addr_islinklocal, ip_addr_ismulticast, ip_addr_netcmp, LINK_STATS_INC, LL_MULTICAST_ADDR_0, LL_MULTICAST_ADDR_1, LL_MULTICAST_ADDR_2, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::netmask, NULL, pbuf::payload, and pbuf_header().

Referenced by ethernetif_init().

err_t etharp_query ( struct netif netif,
ip_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.

References arp_table, ERR_ARG, ERR_MEM, ERR_OK, ETHARP_DEBUG, etharp_find_entry(), ETHARP_FLAG_TRY_HARD, etharp_request(), etharp_send_ip(), ETHARP_SET_HINT, ETHARP_STATE_EMPTY, ETHARP_STATE_PENDING, ETHARP_STATE_STABLE, ETHARP_STATS_INC, netif::hwaddr, if(), ip_addr_isany, ip_addr_isbroadcast, ip_addr_ismulticast, pbuf::len, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, memp_malloc(), pbuf::next, NULL, pbuf_alloc(), pbuf_copy(), pbuf_free(), PBUF_RAM, PBUF_RAW, pbuf_ref(), PBUF_ROM, etharp_entry::q, S16_F, etharp_entry::state, pbuf::tot_len, and pbuf::type.

Referenced by dhcp_check(), and etharp_output().

err_t etharp_request ( struct netif netif,
ip_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

References ARP_REQUEST, ETHARP_DEBUG, etharp_raw(), netif::hwaddr, netif::ip_addr, LWIP_DBG_TRACE, and LWIP_DEBUGF.

Referenced by etharp_output_to_arp_index(), and etharp_query().

void etharp_tmr ( void  )

Clears expired entries in the ARP table.

This function should be called every ETHARP_TMR_INTERVAL milliseconds (5 seconds), in order to expire entries in the ARP table.

References ARP_MAXAGE, ARP_MAXPENDING, arp_table, etharp_entry::ctime, ETHARP_DEBUG, etharp_free_entry(), ETHARP_STATE_EMPTY, ETHARP_STATE_PENDING, ETHARP_STATE_STABLE, ETHARP_STATE_STABLE_REREQUESTING, LWIP_DEBUGF, etharp_entry::state, and U16_F.

Referenced by arp_timer().

err_t ethernet_input ( struct pbuf p,
struct netif netif 
)

Process received ethernet frames.

Using this function instead of directly calling ip_input and passing ARP frames through etharp in ethernetif_input, the ARP cache is protected from concurrent access.

Parameters
pthe recevied packet, p->payload pointing to the ethernet header
netifthe network interface on which the packet was received

References ERR_OK, eth_addr_cmp, etharp_arp_input(), ETHARP_DEBUG, ETHARP_STATS_INC, ETHTYPE_ARP, ETHTYPE_IP, ETHTYPE_PPPOE, ETHTYPE_PPPOEDISC, ETHTYPE_VLAN, pbuf::flags, netif::flags, htons, netif::hwaddr, ip_input(), pbuf::len, LL_MULTICAST_ADDR_0, LL_MULTICAST_ADDR_1, LL_MULTICAST_ADDR_2, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, NETIF_FLAG_ETHARP, pbuf::payload, PBUF_FLAG_LLBCAST, PBUF_FLAG_LLMCAST, pbuf_free(), pbuf_header(), PP_HTONS, SIZEOF_ETH_HDR, and X8_F.

Referenced by tcpip_input(), and tcpip_thread().

struct eth_addr ethbroadcast ethzero

Referenced by etharp_free_entry().

PACK_STRUCT_BEGIN struct etharp_hdr PACK_STRUCT_STRUCT