diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index b540bd76e2..e2561a1057 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -463,6 +463,20 @@ config TCPIP_TASK_STACK_SIZE Configure TCP/IP task stack size, used by LWIP to process multi-threaded TCP/IP operations. Setting this stack too small will result in stack overflow crashes. +config LWIP_IPV6_MEMP_NUM_ND6_QUEUE + int "Max number of IPv6 packets to queue during MAC resolution" + range 3 20 + default 3 + help + Config max number of IPv6 packets to queue during MAC resolution. + +config LWIP_IPV6_ND6_NUM_NEIGHBORS + int "Max number of entries in IPv6 neighbor cache" + range 3 10 + default 5 + help + Config max number of entries in IPv6 neighbor cache + menuconfig PPP_SUPPORT bool "Enable PPP support (new/experimental)" default n diff --git a/components/lwip/core/ipv6/nd6.c b/components/lwip/core/ipv6/nd6.c index 1cec55db9e..893f73eb52 100644 --- a/components/lwip/core/ipv6/nd6.c +++ b/components/lwip/core/ipv6/nd6.c @@ -1636,6 +1636,12 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf * q) if (copy_needed) { /* copy the whole packet into new pbufs */ p = pbuf_alloc(PBUF_LINK, q->tot_len, PBUF_RAM); +#if ESP_ND6_QUEUEING + if(p == NULL) { + pbuf_free(q); + return ERR_MEM; + } +#else while ((p == NULL) && (neighbor_cache[neighbor_index].q != NULL)) { /* Free oldest packet (as per RFC recommendation) */ #if LWIP_ND6_QUEUEING @@ -1655,6 +1661,7 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf * q) p = NULL; } } +#endif } else { /* referencing the old pbuf is enough */ p = q; @@ -1675,6 +1682,7 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf * q) new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE); } if (new_entry != NULL) { + unsigned int qlen = 0; new_entry->next = NULL; new_entry->p = p; if (neighbor_cache[neighbor_index].q != NULL) { @@ -1682,12 +1690,22 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf * q) r = neighbor_cache[neighbor_index].q; while (r->next != NULL) { r = r->next; + qlen++; } r->next = new_entry; } else { /* queue did not exist, first item in queue */ neighbor_cache[neighbor_index].q = new_entry; } +#if ESP_ND6_QUEUEING + if (qlen >= MEMP_NUM_ND6_QUEUE) { + r->next = NULL; + pbuf_free(new_entry->p); + memp_free(MEMP_ND6_QUEUE, new_entry); + LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: could not queue the packet %p (queue is full)\n", (void *)q)); + return ERR_MEM; + } +#endif LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: queued packet %p on neighbor entry %"S16_F"\n", (void *)p, (s16_t)neighbor_index)); result = ERR_OK; } else { diff --git a/components/lwip/include/lwip/lwip/opt.h b/components/lwip/include/lwip/lwip/opt.h index fee9759bf0..b0d95a8e23 100644 --- a/components/lwip/include/lwip/lwip/opt.h +++ b/components/lwip/include/lwip/lwip/opt.h @@ -2537,6 +2537,14 @@ #define LWIP_ND6_QUEUEING (LWIP_IPV6) #endif +/** + * ESP_ND6_QUEUEING==1: queue outgoing IPv6 packets while MAC address + * is being resolved. + */ +#if !defined ESP_ND6_QUEUEING +#define ESP_ND6_QUEUEING (LWIP_IPV6) +#endif + /** * MEMP_NUM_ND6_QUEUE: Max number of IPv6 packets to queue during MAC resolution. */ diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index 29014f651a..f45ee472d2 100644 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -633,6 +633,16 @@ */ #define LWIP_IPV6 1 +/** + * MEMP_NUM_ND6_QUEUE: Max number of IPv6 packets to queue during MAC resolution. + */ +#define MEMP_NUM_ND6_QUEUE CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE + +/** + * LWIP_ND6_NUM_NEIGHBORS: Number of entries in IPv6 neighbor cache + */ +#define LWIP_ND6_NUM_NEIGHBORS CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS + /* --------------------------------------- ---------- Hook options ---------------