lwIP
2.0.2
Lightweight IP stack
|
#include "lwip/opt.h"
#include "lwip/etharp.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "netif/ethernet.h"
#include <string.h>
#include "path/to/my/lwip_hooks.h"
Macros | |
#define | ARP_AGE_REREQUEST_USED_UNICAST (ARP_MAXAGE - 30) |
#define | ARP_MAXPENDING 5 |
#define | ETHARP_FLAG_TRY_HARD 1 |
Enumerations | |
enum | etharp_state |
Functions | |
void | etharp_tmr (void) |
void | etharp_cleanup_netif (struct netif *netif) |
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) |
void | etharp_input (struct pbuf *p, struct netif *netif) |
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) |
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 ARP_AGE_REREQUEST_USED_UNICAST (ARP_MAXAGE - 30) |
Re-request a used ARP entry 1 minute before it would expire to prevent breaking a steadily used connection because the ARP entry timed out.
#define ARP_MAXPENDING 5 |
the time an ARP entry stays pending after first request, for ARP_TMR_INTERVAL = 1000, this is 10 seconds.
#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).
enum etharp_state |
ARP states
void etharp_cleanup_netif | ( | struct netif * | netif | ) |
Remove all ARP table entries of the specified netif.
netif | points to a network interface |
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.
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 |
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
i | entry number, 0 to ARP_TABLE_SIZE |
ipaddr | return value: IP address |
netif | return value: points to interface |
eth_ret | return value: ETH address |
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.
p | The ARP packet that arrived on netif. Is freed by this function. |
netif | The lwIP network interface on which the ARP packet pbuf arrived. |
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.
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. |
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.
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. |
err_t etharp_request | ( | struct netif * | netif, |
const ip4_addr_t * | ipaddr | ||
) |
Send an ARP request packet asking for ipaddr.
netif | the lwip network interface on which to send the request |
ipaddr | the IP address for which to ask |
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.