From 37b10cbdec4bab7d577b504cfa781d9c4698aa83 Mon Sep 17 00:00:00 2001 From: xiehang Date: Tue, 4 Aug 2020 19:57:12 +0800 Subject: [PATCH] arp: Return ERR_MEM if ARP queue is full 2.1.3-esp: 00585644 arp: Return ERR_MEM on ARP queue full --- contrib/examples/example_app/lwipopts.h | 1 + src/core/ipv4/etharp.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/examples/example_app/lwipopts.h b/contrib/examples/example_app/lwipopts.h index 1c2837ab..994460f2 100644 --- a/contrib/examples/example_app/lwipopts.h +++ b/contrib/examples/example_app/lwipopts.h @@ -328,5 +328,6 @@ void lwip_example_app_platform_assert(const char *msg, int line, const char *fil #define ESP_LWIP_IGMP_TIMERS_ONDEMAND ESP_LWIP #define ESP_LWIP_MLD6_TIMERS_ONDEMAND ESP_LWIP #define ESP_DNS ESP_LWIP +#define ESP_LWIP_ARP ESP_LWIP #endif /* LWIP_LWIPOPTS_H */ diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 3092dc94..367b7c13 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -1038,12 +1038,12 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) /* allocate a new arp queue entry */ new_entry = (struct etharp_q_entry *)memp_malloc(MEMP_ARP_QUEUE); if (new_entry != NULL) { + struct etharp_q_entry *r; unsigned int qlen = 0; new_entry->next = NULL; new_entry->p = p; if (arp_table[i].q != NULL) { /* queue was already existent, append the new entry to the end */ - struct etharp_q_entry *r; r = arp_table[i].q; qlen++; while (r->next != NULL) { @@ -1057,11 +1057,19 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) } #if ARP_QUEUE_LEN if (qlen >= ARP_QUEUE_LEN) { +#if ESP_LWIP_ARP + r->next = NULL; + pbuf_free(new_entry->p); + memp_free(MEMP_ARP_QUEUE, new_entry); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not queue the packet %p (queue is full)\n", (void *)q)); + return ERR_MEM; +#else struct etharp_q_entry *old; old = arp_table[i].q; arp_table[i].q = arp_table[i].q->next; pbuf_free(old->p); memp_free(MEMP_ARP_QUEUE, old); +#endif } #endif LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: queued packet %p on ARP entry %"U16_F"\n", (void *)q, i));