Classes | Defines | Enumerations | Functions | Variables

alexb/lib/lwip/contrib/src/netif/etharp.c File Reference

Address Resolution Protocol module for IP over Ethernet. More...

#include "lwip/opt.h"
#include "lwip/ip_addr.h"
#include "lwip/def.h"
#include "lwip/ip.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "netif/etharp.h"
#include <string.h>

Classes

struct  etharp_entry

Defines

#define ARP_MAXAGE   240
 the time an ARP entry stays valid after its last update, for ARP_TMR_INTERVAL = 5000, this is (240 * 5) seconds = 20 minutes.
#define ARP_MAXPENDING   2
 the time an ARP entry stays pending after first request, for ARP_TMR_INTERVAL = 5000, this is (2 * 5) seconds = 10 seconds.
#define HWTYPE_ETHERNET   1
#define ETHARP_FLAG_TRY_HARD   1
 Try hard to create a new entry - we want the IP address to appear in the cache (even if this means removing an active entry or so).
#define ETHARP_FLAG_FIND_ONLY   2
#define ETHARP_FLAG_STATIC_ENTRY   4
#define ETHARP_SET_HINT(netif, hint)   (etharp_cached_entry = (hint))
#define free_etharp_q(q)   pbuf_free(q)
 Compatibility define: free the queued pbuf.

Enumerations

enum  etharp_state { ETHARP_STATE_EMPTY = 0, ETHARP_STATE_PENDING, ETHARP_STATE_STABLE }

Functions

void etharp_tmr (void)
 Clears expired entries in the ARP table.
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.
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.
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.
err_t etharp_request (struct netif *netif, ip_addr_t *ipaddr)
 Send an ARP request packet asking for ipaddr.
err_t ethernet_input (struct pbuf *p, struct netif *netif)
 Process received ethernet frames.

Variables

struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}
struct eth_addr ethzero = {{0,0,0,0,0,0}}

Detailed Description

Address Resolution Protocol module for IP over Ethernet.

Functionally, ARP is divided into two parts. The first maps an IP address to a physical address when sending a packet, and the second part answers requests from other machines for our physical address.

This implementation complies with RFC 826 (Ethernet ARP). It supports Gratuitious ARP from RFC3220 (IP Mobility Support for IPv4) section 4.6 if an interface calls etharp_gratuitous(our_netif) upon address change.


Define Documentation

#define ARP_MAXAGE   240

the time an ARP entry stays valid after its last update, for ARP_TMR_INTERVAL = 5000, this is (240 * 5) seconds = 20 minutes.

#define ARP_MAXPENDING   2

the time an ARP entry stays pending after first request, for ARP_TMR_INTERVAL = 5000, this is (2 * 5) seconds = 10 seconds.

#define ETHARP_FLAG_FIND_ONLY   2
#define ETHARP_FLAG_STATIC_ENTRY   4
#define ETHARP_FLAG_TRY_HARD   1

Try hard to create a new entry - we want the IP address to appear in the cache (even if this means removing an active entry or so).

#define ETHARP_SET_HINT (   netif,
  hint 
)    (etharp_cached_entry = (hint))
#define free_etharp_q (   q  )     pbuf_free(q)

Compatibility define: free the queued pbuf.

#define HWTYPE_ETHERNET   1

Enumeration Type Documentation

Enumerator:
ETHARP_STATE_EMPTY 
ETHARP_STATE_PENDING 
ETHARP_STATE_STABLE 

Function Documentation

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:
netif points to interface index
ipaddr points to the (network order) IP address index
eth_ret points to return pointer
ip_ret points to return pointer
Returns:
table index if found, -1 otherwise
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:
netif The lwIP network interface which the IP packet will be sent on.
q The pbuf(s) containing the IP packet to be sent.
ipaddr The IP address of the packet destination.
Returns:
  • ERR_RTE No route to destination (no gateway to external networks), or the return type of either etharp_query() or etharp_send_ip().
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:
netif The lwIP network interface on which ipaddr must be queried for.
ipaddr The IP address to be resolved.
q If 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.
err_t etharp_request ( struct netif netif,
ip_addr_t ipaddr 
)

Send an ARP request packet asking for ipaddr.

Parameters:
netif the lwip network interface on which to send the request
ipaddr the 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
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.

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:
p the recevied packet, p->payload pointing to the ethernet header
netif the network interface on which the packet was received

Variable Documentation

struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}
struct eth_addr ethzero = {{0,0,0,0,0,0}}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines