From 4219b7a8b9bbf047075ea4a1903dffb1ab24afc5 Mon Sep 17 00:00:00 2001 From: xueyunfei Date: Sun, 25 Apr 2021 17:19:23 +0800 Subject: [PATCH] bugfix for Packet forwarding failed --- src/core/ipv4/ip4.c | 11 ++++++++++- test/unit/lwipopts.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index e3fc1dc9..ec50a114 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -334,6 +334,8 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) { struct netif *netif; + struct pbuf *q; + PERF_START; LWIP_UNUSED_ARG(inp); @@ -421,7 +423,14 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) return; } /* transmit pbuf on chosen interface */ - netif->output(netif, p, ip4_current_dest_addr()); + q = pbuf_clone(PBUF_LINK, PBUF_RAM, p); + if (q != NULL) { + netif->output(netif, q, ip4_current_dest_addr()); + pbuf_free(q); + } else { + MIB2_STATS_INC(mib2.ipinaddrerrors); + MIB2_STATS_INC(mib2.ipindiscards); + } return; return_noroute: MIB2_STATS_INC(mib2.ipoutnoroutes); diff --git a/test/unit/lwipopts.h b/test/unit/lwipopts.h index ee419ad4..91b470aa 100644 --- a/test/unit/lwipopts.h +++ b/test/unit/lwipopts.h @@ -107,6 +107,7 @@ #define ESP_DHCP_DISABLE_CLIENT_ID 0 #define ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER 0 + #ifdef IP_NAPT #define IP_NAPT_MAX 16 #undef LWIP_RAND -- 2.17.1