From d9d8193a856ccfdb5ad84773e5ad69832236d1b2 Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Thu, 20 Sep 2018 21:09:53 +0800 Subject: [PATCH] feat(lwip): add IPv6 support fixes: https://github.com/espressif/ESP8266_RTOS_SDK/issues/309 --- components/lwip/lwip/src/core/ipv6/nd6.c | 28 +++++++++++++++++++ components/lwip/lwip/src/include/lwip/nd6.h | 5 ++++ components/lwip/lwip/src/include/lwip/netif.h | 4 +++ components/tcpip_adapter/tcpip_adapter_lwip.c | 9 ++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/components/lwip/lwip/src/core/ipv6/nd6.c b/components/lwip/lwip/src/core/ipv6/nd6.c index 0b367181..1fe98f46 100644 --- a/components/lwip/lwip/src/core/ipv6/nd6.c +++ b/components/lwip/lwip/src/core/ipv6/nd6.c @@ -702,6 +702,22 @@ nd6_input(struct pbuf *p, struct netif *inp) pbuf_free(p); } +#ifdef ESP_LWIP + +/** Set callback for ipv6 addr status changed . + * + * @param netif the netif from which to remove the struct dhcp + * @param cb callback for dhcp + */ +void nd6_set_cb(struct netif *netif, void (*cb)(struct netif *netif, u8_t ip_index)) +{ + LWIP_ASSERT("netif != NULL", netif != NULL); + + if (netif != NULL && netif_is_up(netif)) { + netif->ipv6_addr_cb = cb; + } +} +#endif /** * Periodic timer for Neighbor discovery functions: @@ -867,8 +883,20 @@ nd6_tmr(void) if ((addr_state & IP6_ADDR_TENTATIVE_COUNT_MASK) >= LWIP_IPV6_DUP_DETECT_ATTEMPTS) { /* No NA received in response. Mark address as valid. */ netif_ip6_addr_set_state(netif, i, IP6_ADDR_PREFERRED); +#ifdef ESP_LWIP + if (netif->ipv6_addr_cb != NULL) { + netif->ipv6_addr_cb(netif, i); + } +#endif /* @todo implement preferred and valid lifetimes. */ } else if (netif->flags & NETIF_FLAG_UP) { +#if LWIP_IPV6_MLD + if ((netif_ip6_addr_state(netif, i) & 0x07) == 0) { + /* Join solicited node multicast group. */ + ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(netif, i)->addr[3]); + mld6_joingroup(netif_ip6_addr(netif, i), &multicast_address); + } +#endif /* LWIP_IPV6_MLD */ /* Send a NS for this address. */ nd6_send_ns(netif, netif_ip6_addr(netif, i), ND6_SEND_FLAG_MULTICAST_DEST); /* tentative: set next state by increasing by one */ diff --git a/components/lwip/lwip/src/include/lwip/nd6.h b/components/lwip/lwip/src/include/lwip/nd6.h index 8204fa4c..d9fba970 100644 --- a/components/lwip/lwip/src/include/lwip/nd6.h +++ b/components/lwip/lwip/src/include/lwip/nd6.h @@ -75,6 +75,11 @@ void nd6_cleanup_netif(struct netif *netif); void nd6_adjust_mld_membership(struct netif *netif, s8_t addr_idx, u8_t new_state); #endif /* LWIP_IPV6_MLD */ +#if ESP_LWIP +/** set nd6 callback when ipv6 addr state pref*/ +void nd6_set_cb(struct netif *netif, void (*cb)(struct netif *netif, u8_t ip_index)); +#endif + #ifdef __cplusplus } #endif diff --git a/components/lwip/lwip/src/include/lwip/netif.h b/components/lwip/lwip/src/include/lwip/netif.h index 67a2d24d..ecff65ad 100644 --- a/components/lwip/lwip/src/include/lwip/netif.h +++ b/components/lwip/lwip/src/include/lwip/netif.h @@ -238,6 +238,10 @@ struct netif { /** The state of each IPv6 address (Tentative, Preferred, etc). * @see ip6_addr.h */ u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; +#if ESP_LWIP + void (*ipv6_addr_cb)(struct netif* netif, u8_t ip_idex); /* callback for ipv6 addr states changed */ +#endif + #endif /* LWIP_IPV6 */ /** This function is called by the network device driver * to pass a packet up the TCP/IP stack. */ diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index bb37573a..dedd0ac9 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -22,6 +22,9 @@ #include "lwip/netif.h" #include "lwip/tcpip.h" #include "lwip/dhcp.h" +#include "lwip/ip_addr.h" +#include "lwip/ip6_addr.h" +#include "lwip/nd6.h" #include "lwip/dns.h" #include "lwip/errno.h" #include "lwip/timeouts.h" @@ -55,7 +58,7 @@ struct tcpip_adapter_api_call_data { static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX]; static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX]; static tcpip_adapter_ip_info_t esp_ip_old[TCPIP_ADAPTER_IF_MAX]; -#if 0 +#if TCPIP_ADAPTER_IPV6 /*TODO need add ip6*/ static tcpip_adapter_ip6_info_t esp_ip6[TCPIP_ADAPTER_IF_MAX]; #endif @@ -561,7 +564,7 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i return ESP_OK; } -#if 0 +#if TCPIP_ADAPTER_IPV6 static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex) { tcpip_adapter_ip6_info_t *ip6_info; @@ -609,7 +612,7 @@ esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if) if (p_netif != NULL && netif_is_up(p_netif)) { netif_create_ip6_linklocal_address(p_netif, 1); /*TODO need add ipv6 address cb*/ - //nd6_set_cb(p_netif, tcpip_adapter_nd6_cb); + nd6_set_cb(p_netif, tcpip_adapter_nd6_cb); return ESP_OK; } else {