Skip to content

Commit 3906826

Browse files
freakyxuedavid-cermak
authored andcommitted
napt: Fix PBUF_REF type to clone the pbuf before forwarding
1 parent 2b92291 commit 3906826

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/core/ipv4/ip4.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,23 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
421421
return;
422422
}
423423
/* transmit pbuf on chosen interface */
424+
#if ESP_IP_FORWARD
425+
if (p->type_internal == PBUF_REF)
426+
{
427+
struct pbuf *q = pbuf_clone(PBUF_LINK, PBUF_RAM, p);
428+
if (q != NULL) {
429+
netif->output(netif, q, ip4_current_dest_addr());
430+
pbuf_free(q);
431+
} else {
432+
MIB2_STATS_INC(mib2.ipinaddrerrors);
433+
MIB2_STATS_INC(mib2.ipindiscards);
434+
}
435+
} else {
436+
netif->output(netif, p, ip4_current_dest_addr());
437+
}
438+
#else
424439
netif->output(netif, p, ip4_current_dest_addr());
440+
#endif /* ESP_IP_FORWARD */
425441
return;
426442
return_noroute:
427443
MIB2_STATS_INC(mib2.ipoutnoroutes);

test/unit/lwipopts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
#define ESP_THREAD_PROTECTION 0
111111
#define ESP_DHCP_DISABLE_CLIENT_ID 0
112112
#define ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER 0
113+
#define ESP_IP_FORWARD 1
114+
113115

114116
#ifdef IP_NAPT
115117
#define IP_NAPT_MAX 16

0 commit comments

Comments
 (0)