diff options
| author | Our Air Quality <[email protected]> | 2019-04-04 13:13:18 +1100 |
|---|---|---|
| committer | Dirk Ziegelmeier <[email protected]> | 2019-04-30 12:34:43 +0200 |
| commit | c156cd2a3375f6c6df3d3a39344559f436f971ee (patch) | |
| tree | 6918bf6ca40940d56b80896248a8b0995cc94c75 | |
| parent | 46bbfe4ee284bd017c581969f1ba3b2e255a871c (diff) | |
ND6: add an explicit queue size check.
When using the MEMP_MEM_MALLOC option, memp_malloc() can not be relied on to
limit the number of allocations allowed for each MEMP queue, as the ND6 code
had been. This caused the ND6 queue to keep growing until the heap allocation
failed when using the MEMP_MEM_MALLOC option. So add an explicit queue size
check in ND6.
| -rw-r--r-- | src/core/ipv6/nd6.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 1817fd56..267ee671 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -83,6 +83,10 @@ struct nd6_router_list_entry default_router_list[LWIP_ND6_NUM_ROUTERS]; u32_t reachable_time = LWIP_ND6_REACHABLE_TIME; u32_t retrans_timer = LWIP_ND6_RETRANS_TIMER; /* @todo implement this value in timer */ +#if LWIP_ND6_QUEUEING +u8_t nd6_queue_size = 0; +#endif + /* Index for cache entries. */ static u8_t nd6_cached_neighbor_index; static netif_addr_idx_t nd6_cached_destination_index; @@ -2109,7 +2113,11 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf *q) /* queue packet ... */ #if LWIP_ND6_QUEUEING /* allocate a new nd6 queue entry */ - new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE); + new_entry = NULL; + if (nd6_queue_size < MEMP_NUM_ND6_QUEUE) { + new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE); + nd6_queue_size++; + } if ((new_entry == NULL) && (neighbor_cache[neighbor_index].q != NULL)) { /* Free oldest packet (as per RFC recommendation) */ r = neighbor_cache[neighbor_index].q; @@ -2117,6 +2125,7 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf *q) r->next = NULL; nd6_free_q(r); new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE); + nd6_queue_size++; } if (new_entry != NULL) { new_entry->next = NULL; @@ -2175,6 +2184,7 @@ nd6_free_q(struct nd6_q_entry *q) LWIP_ASSERT("r->p != NULL", (r->p != NULL)); pbuf_free(r->p); memp_free(MEMP_ND6_QUEUE, r); + nd6_queue_size--; } } #endif /* LWIP_ND6_QUEUEING */ @@ -2215,6 +2225,7 @@ nd6_send_q(s8_t i) pbuf_free(q->p); /* now queue entry can be freed */ memp_free(MEMP_ND6_QUEUE, q); + nd6_queue_size--; } #else /* LWIP_ND6_QUEUEING */ if (neighbor_cache[i].q != NULL) { |
