Web server based weather station using Sparkfun Weather Meters.

Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

etharp.c File Reference

etharp.c File Reference

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

Go to the source code of this file.

Functions

static err_t update_arp_entry (struct netif *netif, ip_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
 Update (or insert) a IP/MAC address pair in the ARP cache.
static void free_etharp_q (struct etharp_q_entry *q)
 Free a complete queue of etharp entries.
static void free_entry (int i)
 Clean up ARP table entries.
void etharp_tmr (void)
 Clears expired entries in the ARP table.
static s8_t find_entry (ip_addr_t *ipaddr, u8_t flags)
 Search the ARP table for a matching or new entry.
static err_t etharp_send_ip (struct netif *netif, struct pbuf *p, struct eth_addr *src, struct eth_addr *dst)
 Send an IP packet on the network using netif->linkoutput The ethernet header is filled in before sending.
err_t etharp_add_static_entry (ip_addr_t *ipaddr, struct eth_addr *ethaddr)
 Add a new static entry to the ARP table.
err_t etharp_remove_static_entry (ip_addr_t *ipaddr)
 Remove a static entry from the ARP table previously added with a call to etharp_add_static_entry.
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.
static void etharp_ip_input (struct netif *netif, struct pbuf *p)
 Updates the ARP table using the given IP packet.
static void etharp_arp_input (struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
 Responds to ARP requests to us.
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.
static err_t etharp_raw (struct netif *netif, const struct eth_addr *ethsrc_addr, const struct eth_addr *ethdst_addr, const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr, const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr, const u16_t opcode)
 Send a raw ARP packet (opcode and all addresses can be modified)
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.

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.

Definition in file etharp.c.


Function Documentation

err_t etharp_add_static_entry ( ip_addr_t *  ipaddr,
struct eth_addr *  ethaddr 
)

Add a new static entry to the ARP table.

If an entry exists for the specified IP address, this entry is overwritten. If packets are queued for the specified IP address, they are sent out.

Parameters:
ipaddrIP address for the new static entry
ethaddrethernet address for the new static entry
Returns:
See also:
return values of etharp_add_static_entry

Definition at line 520 of file etharp.c.

static void etharp_arp_input ( struct netif *  netif,
struct eth_addr *  ethaddr,
struct pbuf *  p 
) [static]

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:
netifThe lwIP network interface on which the ARP packet pbuf arrived.
ethaddrEthernet address of netif.
pThe ARP packet that arrived on netif. Is freed by this function.
Returns:
NULL
See also:
pbuf_free()

Definition at line 666 of file etharp.c.

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

Definition at line 581 of file etharp.c.

static void etharp_ip_input ( struct netif *  netif,
struct pbuf *  p 
) [static]

Updates the ARP table using the given IP packet.

Uses the incoming IP packet's source address to update the ARP cache for the local network. The function does not alter or free the packet. This function must be called before the packet p is passed to the IP layer.

Parameters:
netifThe lwIP network interface on which the IP packet pbuf arrived.
pThe IP packet that arrived on netif.
Returns:
NULL
See also:
pbuf_free()

Definition at line 617 of file etharp.c.

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:

Definition at line 836 of file etharp.c.

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.

Definition at line 945 of file etharp.c.

static err_t etharp_raw ( struct netif *  netif,
const struct eth_addr *  ethsrc_addr,
const struct eth_addr *  ethdst_addr,
const struct eth_addr *  hwsrc_addr,
const ip_addr_t *  ipsrc_addr,
const struct eth_addr *  hwdst_addr,
const ip_addr_t *  ipdst_addr,
const u16_t  opcode 
) [static]

Send a raw ARP packet (opcode and all addresses can be modified)

Parameters:
netifthe lwip network interface on which to send the ARP packet
ethsrc_addrthe source MAC address for the ethernet header
ethdst_addrthe destination MAC address for the ethernet header
hwsrc_addrthe source MAC address for the ARP protocol header
ipsrc_addrthe source IP address for the ARP protocol header
hwdst_addrthe destination MAC address for the ARP protocol header
ipdst_addrthe destination IP address for the ARP protocol header
opcodethe type of the ARP packet
Returns:
ERR_OK if the ARP packet has been sent ERR_MEM if the ARP packet couldn't be allocated any other err_t on failure

Definition at line 1098 of file etharp.c.

err_t etharp_remove_static_entry ( ip_addr_t *  ipaddr )

Remove a static entry from the ARP table previously added with a call to etharp_add_static_entry.

Parameters:
ipaddrIP address of the static entry to remove
Returns:
ERR_OK: entry removed ERR_MEM: entry wasn't found ERR_ARG: entry wasn't a static entry but a dynamic one

Definition at line 545 of file etharp.c.

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

Definition at line 1180 of file etharp.c.

static err_t etharp_send_ip ( struct netif *  netif,
struct pbuf *  p,
struct eth_addr *  src,
struct eth_addr *  dst 
) [static]

Send an IP packet on the network using netif->linkoutput The ethernet header is filled in before sending.

netif the lwIP network interface on which to send the packet p the packet to send, p->payload pointing to the (uninitialized) ethernet header src the source MAC address to be copied into the ethernet header dst the destination MAC address to be copied into the ethernet header

Returns:
ERR_OK if the packet was sent, any other err_t on failure

Definition at line 412 of file etharp.c.

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.

Definition at line 197 of file etharp.c.

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

Definition at line 1198 of file etharp.c.

static s8_t find_entry ( ip_addr_t *  ipaddr,
u8_t  flags 
) [static]

Search the ARP table for a matching or new entry.

If an IP address is given, return a pending or stable ARP entry that matches the address. If no match is found, create a new entry with this address set, but in state ETHARP_EMPTY. The caller must check and possibly change the state of the returned entry.

If ipaddr is NULL, return a initialized new entry in state ETHARP_EMPTY.

In all cases, attempt to create new entries from an empty entry. If no empty entries are available and ETHARP_FLAG_TRY_HARD flag is set, recycle old entries. Heuristic choose the least important entry for recycling.

Parameters:
ipaddrIP address to find in ARP cache, or to add if not found.
flags
See also:
definition of ETHARP_FLAG_*
Parameters:
netifnetif related to this address (used for NETIF_HWADDRHINT)
Returns:
The ARP entry index that matched or is created, ERR_MEM if no entry is found or could be recycled.

a) do a search through the cache, remember candidates b) select candidate entry c) create new entry

Definition at line 252 of file etharp.c.

static void free_entry ( int  i ) [static]

Clean up ARP table entries.

Definition at line 161 of file etharp.c.

static void free_etharp_q ( struct etharp_q_entry *  q ) [static]

Free a complete queue of etharp entries.

Parameters:
qa qeueue of etharp_q_entry's to free

Definition at line 144 of file etharp.c.

static err_t update_arp_entry ( struct netif *  netif,
ip_addr_t *  ipaddr,
struct eth_addr *  ethaddr,
u8_t  flags 
) [static]

Update (or insert) a IP/MAC address pair in the ARP cache.

If a pending entry is resolved, any queued packets will be sent at this point.

Parameters:
netifnetif related to this entry (used for NETIF_ADDRHINT)
ipaddrIP address of the inserted ARP entry.
ethaddrEthernet address of the inserted ARP entry.
flags
See also:
definition of ETHARP_FLAG_*
Returns:
  • ERR_OK Succesfully updated ARP cache.
  • ERR_MEM If we could not add a new ARP entry when ETHARP_FLAG_TRY_HARD was set.
  • ERR_ARG Non-unicast address given, those will not appear in ARP cache.
See also:
pbuf_free()

Definition at line 445 of file etharp.c.