diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 586bf0e02c..e2f289b643 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -239,6 +239,14 @@ menu "LWIP" If rate limiting self-assignment requests, wait this long between each request. + config LWIP_IPV6_AUTOCONFIG + bool "Enable IPV6 stateless address autoconfiguration" + default n + help + Enabling this option allows the devices to IPV6 stateless address autoconfiguration. + + See RFC 4862. + menuconfig LWIP_NETIF_LOOPBACK bool "Support per-interface loopback" default y diff --git a/components/lwip/lwip b/components/lwip/lwip index b4eaf11fe5..066ffe0abb 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit b4eaf11fe5e980a2d9b655e6617d4163c11465ec +Subproject commit 066ffe0abb83eee47808bf77c1bcfef51ad077fe diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index f53191bd6f..3e10020e0e 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -757,7 +757,6 @@ #define ESP_THREAD_SAFE_DEBUG LWIP_DBG_OFF #define ESP_DHCP 1 #define ESP_DNS 1 -#define ESP_IPV6_AUTOCONFIG 1 #define ESP_PERF 0 #define ESP_RANDOM_TCP_PORT 1 #define ESP_IP4_ATON 1 @@ -781,6 +780,10 @@ #define ESP_LWIP_SELECT 1 #define ESP_LWIP_LOCK 1 +#ifdef CONFIG_LWIP_IPV6_AUTOCONFIG +#define ESP_IPV6_AUTOCONFIG CONFIG_LWIP_IPV6_AUTOCONFIG +#endif + #ifdef ESP_IRAM_ATTR #undef ESP_IRAM_ATTR #endif diff --git a/components/tcpip_adapter/include/tcpip_adapter.h b/components/tcpip_adapter/include/tcpip_adapter.h index 4c0a4af4fd..75136f906c 100644 --- a/components/tcpip_adapter/include/tcpip_adapter.h +++ b/components/tcpip_adapter/include/tcpip_adapter.h @@ -439,6 +439,21 @@ esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if); */ esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6); +/** + * @brief Get interface global IPv6 address + * + * If the specified interface is up and a preferred global IPv6 address + * has been created for the interface, return a copy of it. + * + * @param[in] tcpip_if Interface to get global IPv6 address + * @param[out] if_ip6 IPv6 information will be returned in this argument if successful. + * + * @return + * - ESP_OK + * - ESP_FAIL If interface is down, does not have a global IPv6 address, or the global IPv6 address is not a preferred address. + */ +esp_err_t tcpip_adapter_get_ip6_global(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6); + #if 0 esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac); diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 237b082a34..bbff09ac78 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -553,6 +553,29 @@ esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_ return ESP_OK; } +esp_err_t tcpip_adapter_get_ip6_global(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6) +{ + ESP_LOGD(TAG, "%s esp-netif:%p", __func__, esp_netif); + + if (tcpip_if >=TCPIP_ADAPTER_IF_MAX || if_ip6 == NULL) { + return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS; + } + + int i; + struct netif *p_netif = esp_netif[tcpip_if]; + + if (p_netif != NULL && netif_is_up(p_netif)) { + for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_ispreferred(netif_ip6_addr_state(p_netif, i))) { + memcpy(if_ip6, &p_netif->ip6_addr[i], sizeof(ip6_addr_t)); + return ESP_OK; + } + } + } + + return ESP_FAIL; +} + #if 0 esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t mac[6]) {