From adcd330ee132ff9837c35f12227b961f1e329e58 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Tue, 21 Jan 2025 11:53:28 +0800 Subject: [PATCH] ip6: clone the buf when forwarding a PBUF_REF packet --- src/core/ipv6/ip6.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index b1df7cfc..d37ea900 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -465,7 +465,19 @@ ip6_forward(struct pbuf *p, struct ip6_hdr *iphdr, struct netif *inp) IP6_ADDR_BLOCK8(ip6_current_dest_addr()))); /* transmit pbuf on chosen interface */ - netif->output_ip6(netif, p, ip6_current_dest_addr()); + + if (p->type_internal == PBUF_REF) { + struct pbuf *q = pbuf_clone(PBUF_LINK, PBUF_RAM, p); + if (q != NULL) { + netif->output_ip6(netif, q, ip6_current_dest_addr()); + pbuf_free(q); + } else { + IP6_STATS_INC(ip6.drop); + } + } else { + netif->output_ip6(netif, p, ip6_current_dest_addr()); + } + IP6_STATS_INC(ip6.fw); IP6_STATS_INC(ip6.xmit); return;