mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(lwip): Add IPv6 static neighbor cache entry support
Add esp_netif_add_static_neighbor() and esp_netif_remove_static_neighbor(), gated by CONFIG_LWIP_ND6_SUPPORT_STATIC_ENTRIES. These API's let callers install/remove permanent IPv6->MAC mappings that bypass Neighbor Discovery (no NS/NA). The calls run in the TCP/IP context and wrap the underlying lwIP nd6_add_static_neighbor()/nd6_remove_static_neighbor() functions.
This commit is contained in:
@@ -862,6 +862,43 @@ int esp_netif_get_all_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[]);
|
||||
*/
|
||||
int esp_netif_get_all_preferred_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[]);
|
||||
|
||||
#if CONFIG_LWIP_ND6_SUPPORT_STATIC_ENTRIES
|
||||
/**
|
||||
* @brief Add or update a static (permanent) IPv6 neighbor cache entry
|
||||
*
|
||||
* Installs a fixed IPv6 -> link-layer address mapping that bypasses Neighbor
|
||||
* Discovery: no Neighbor Solicitation/Advertisement is exchanged for this
|
||||
* address, the entry never ages out and is never overwritten by incoming
|
||||
* advertisements. Calling again with the same address updates the mapping.
|
||||
*
|
||||
* @param[in] esp_netif Handle to esp-netif instance
|
||||
* @param[in] addr Neighbor's IPv6 address
|
||||
* @param[in] mac Neighbor's link-layer address (interface hwaddr_len bytes)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS on invalid arguments
|
||||
* - ESP_FAIL if the entry could not be installed (e.g. neighbor cache full)
|
||||
*/
|
||||
esp_err_t esp_netif_add_static_neighbor(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr, const uint8_t *mac);
|
||||
|
||||
/**
|
||||
* @brief Remove a static IPv6 neighbor cache entry
|
||||
*
|
||||
* Removes an entry previously added with esp_netif_add_static_neighbor().
|
||||
* Dynamic (non-static) entries are left untouched.
|
||||
*
|
||||
* @param[in] esp_netif Handle to esp-netif instance
|
||||
* @param[in] addr Neighbor's IPv6 address
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS on invalid arguments
|
||||
* - ESP_FAIL if no matching static entry exists
|
||||
*/
|
||||
esp_err_t esp_netif_remove_static_neighbor(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr);
|
||||
#endif /* CONFIG_LWIP_ND6_SUPPORT_STATIC_ENTRIES */
|
||||
|
||||
/**
|
||||
* @brief Cause the TCP/IP stack to add an IPv6 address to the interface
|
||||
*
|
||||
|
||||
@@ -2483,6 +2483,56 @@ int esp_netif_get_all_preferred_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip
|
||||
}
|
||||
return addr_count;
|
||||
}
|
||||
|
||||
#if CONFIG_LWIP_ND6_SUPPORT_STATIC_ENTRIES
|
||||
typedef struct {
|
||||
const esp_ip6_addr_t *addr;
|
||||
const uint8_t *mac;
|
||||
} esp_netif_static_neighbor_t;
|
||||
|
||||
static esp_err_t esp_netif_add_static_neighbor_api(esp_netif_api_msg_t *msg)
|
||||
{
|
||||
esp_netif_t *esp_netif = msg->esp_netif;
|
||||
const esp_netif_static_neighbor_t *nbr = msg->data;
|
||||
ip6_addr_t ip6;
|
||||
|
||||
memcpy(&ip6, nbr->addr, sizeof(ip6_addr_t));
|
||||
if (nd6_add_static_neighbor(esp_netif->lwip_netif, &ip6, nbr->mac) != ERR_OK) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_netif_add_static_neighbor(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr, const uint8_t *mac)
|
||||
{
|
||||
if (esp_netif == NULL || esp_netif->lwip_netif == NULL || addr == NULL || mac == NULL) {
|
||||
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
|
||||
}
|
||||
esp_netif_static_neighbor_t nbr = { .addr = addr, .mac = mac };
|
||||
return esp_netif_lwip_ipc_call(esp_netif_add_static_neighbor_api, esp_netif, &nbr);
|
||||
}
|
||||
|
||||
static esp_err_t esp_netif_remove_static_neighbor_api(esp_netif_api_msg_t *msg)
|
||||
{
|
||||
esp_netif_t *esp_netif = msg->esp_netif;
|
||||
const esp_ip6_addr_t *addr = msg->data;
|
||||
ip6_addr_t ip6;
|
||||
|
||||
memcpy(&ip6, addr, sizeof(ip6_addr_t));
|
||||
if (nd6_remove_static_neighbor(esp_netif->lwip_netif, &ip6) != ERR_OK) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_netif_remove_static_neighbor(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr)
|
||||
{
|
||||
if (esp_netif == NULL || esp_netif->lwip_netif == NULL || addr == NULL) {
|
||||
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
|
||||
}
|
||||
return esp_netif_lwip_ipc_call(esp_netif_remove_static_neighbor_api, esp_netif, (void *)addr);
|
||||
}
|
||||
#endif /* CONFIG_LWIP_ND6_SUPPORT_STATIC_ENTRIES */
|
||||
#endif
|
||||
|
||||
esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif)
|
||||
|
||||
Reference in New Issue
Block a user