diff options
| author | Joel Cunningham <joel.cunningham@me.com> | 2017-11-14 14:38:10 -0600 |
|---|---|---|
| committer | Joel Cunningham <joel.cunningham@me.com> | 2017-11-16 13:59:33 -0600 |
| commit | c47d161d4a8946028fff6143160e9f58d1a4be49 (patch) | |
| tree | ac4f7a52af6dc56150f9fa17d45c1b8054bd65fd | |
| parent | 40a563cdd3ca845e3d49f6199ada01a0617f1622 (diff) | |
| download | lwip-c47d161d4a8946028fff6143160e9f58d1a4be49.tar.gz | |
netifapi: add thread safe ARP APIs (task #14724)
This adds thread safe netifapi ARP cache APIs for add/remove
| -rw-r--r-- | CHANGELOG | 3 | ||||
| -rw-r--r-- | src/api/netifapi.c | 64 | ||||
| -rw-r--r-- | src/include/lwip/netifapi.h | 14 |
3 files changed, 81 insertions, 0 deletions
@@ -6,6 +6,9 @@ HISTORY ++ New features: + 2017-11-14: Joel Cunningham + * netifapi: Add thread safe ARP cache APIs (task #14724) + 2017-11-06: Axel Lin * TCP: kill existing connections with a LOWER priority than the one currently being opened. Previous implementations also kill existing connections of the SAME priority. diff --git a/src/api/netifapi.c b/src/api/netifapi.c index 415574e..25957cd 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -42,6 +42,7 @@ #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ +#include "lwip/etharp.h" #include "lwip/netifapi.h" #include "lwip/memp.h" #include "lwip/priv/tcpip_priv.h" @@ -147,6 +148,69 @@ netifapi_do_netif_common(struct tcpip_api_call_data *m) } } +#if LWIP_ARP && LWIP_IPV4 +/** + * @ingroup netifapi_arp + * Add or update an entry in the ARP cache. + * For an update, ipaddr is used to find the cache entry. + * + * @param ipaddr IPv4 address of cache entry + * @param ethaddr hardware address mapped to ipaddr + * @param type type of ARP cache entry + * @return ERR_OK: entry added/updated, else error from err_t + */ +err_t +netifapi_arp_add(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, enum netifapi_arp_entry type) +{ + err_t err; + + /* We only support permanent entries currently */ + LWIP_UNUSED_ARG(type); + +#if ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING + LOCK_TCPIP_CORE(); + err = etharp_add_static_entry(ipaddr, ethaddr); + UNLOCK_TCPIP_CORE(); +#else + /* @todo add new vars to struct netifapi_msg and create a 'do' func */ + LWIP_UNUSED_ARG(ipaddr); + LWIP_UNUSED_ARG(ethaddr); + err = ERR_VAL; +#endif /* ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING */ + + return err; +} + +/** + * @ingroup netifapi_arp + * Remove an entry in the ARP cache identified by ipaddr + * + * @param ipaddr IPv4 address of cache entry + * @param type type of ARP cache entry + * @return ERR_OK: entry removed, else error from err_t + */ +err_t +netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type) +{ + err_t err; + + /* We only support permanent entries currently */ + LWIP_UNUSED_ARG(type); + +#if ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING + LOCK_TCPIP_CORE(); + err = etharp_remove_static_entry(ipaddr); + UNLOCK_TCPIP_CORE(); +#else + /* @todo add new vars to struct netifapi_msg and create a 'do' func */ + LWIP_UNUSED_ARG(ipaddr); + err = ERR_VAL; +#endif /* ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING */ + + return err; +} +#endif /* LWIP_ARP && LWIP_IPV4 */ + /** * @ingroup netifapi_netif * Call netif_add() in a thread-safe way by running that function inside the diff --git a/src/include/lwip/netifapi.h b/src/include/lwip/netifapi.h index 546f03f..e063179 100644 --- a/src/include/lwip/netifapi.h +++ b/src/include/lwip/netifapi.h @@ -42,12 +42,26 @@ #include "lwip/autoip.h" #include "lwip/priv/tcpip_priv.h" #include "lwip/priv/api_msg.h" +#include "lwip/prot/ethernet.h" #ifdef __cplusplus extern "C" { #endif /* API for application */ +#if LWIP_ARP && LWIP_IPV4 +/* Used for netfiapi_arp_* APIs */ +enum netifapi_arp_entry { + NETIFAPI_ARP_PERM /* Permanent entry */ + /* Other entry types can be added here */ +}; + +/** @ingroup netifapi_arp */ +err_t netifapi_arp_add(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, enum netifapi_arp_entry type); +/** @ingroup netifapi_arp */ +err_t netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type); +#endif /* LWIP_ARP && LWIP_IPV4 */ + err_t netifapi_netif_add(struct netif *netif, #if LWIP_IPV4 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, |
