From a26ea96f3bca2e9b5a221bdab26820474c22be1f Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Thu, 24 Nov 2022 16:59:31 +0800 Subject: [PATCH] net/icmpv6: Fix `datalen` in icmpv6_reply The `datalen` indicates the whole len of original packet, which will become the payload inside icmpv6 packet. Using `datalen = (ipv4->len[0] << 8) + ipv4->len[1]` in icmp_reply is correct, because it includes IPv4 header, but when coming to IPv6, the `len` does not include the header, so we need to add it back. Signed-off-by: Zhe Weng --- net/icmpv6/icmpv6_reply.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/icmpv6/icmpv6_reply.c b/net/icmpv6/icmpv6_reply.c index 3bd4192d52..b6be31624e 100644 --- a/net/icmpv6/icmpv6_reply.c +++ b/net/icmpv6/icmpv6_reply.c @@ -99,9 +99,9 @@ void icmpv6_reply(FAR struct net_driver_s *dev, int type, int code, int data) return; } - /* Get the data size of the packet. */ + /* Get the data (whole original packet) size of the packet. */ - datalen = (ipv6->len[0] << 8) + ipv6->len[1]; + datalen = (ipv6->len[0] << 8) + ipv6->len[1] + IPv6_HDRLEN; /* RFC says return as much as we can without exceeding 1280 bytes. */