net/icmpv6: Fix icmpv6_reply function

Fix icmpv6_reply logic broken by commit 48311cc61f and 391b501639.

- 48311cc61f "Fix unaligned memory access when creating ICMP Port Unreachable messages"
  - It removed `htonl` function outside `data`, then the byte order may be wrong, so add `htons` back.
- 391b501639 "net: extract l3 header build code into new functions"
  - It mis-removed the `memmove`, and the icmpv6 has no payload copied after this commit.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2022-12-02 00:10:02 +08:00 committed by Xiang Xiao
parent 69cbcfd19f
commit 025430a964

View file

@ -112,6 +112,10 @@ void icmpv6_reply(FAR struct net_driver_s *dev, int type, int code, int data)
dev->d_len = ipicmplen + datalen;
/* Copy fields from original packet */
memmove(icmpv6 + 1, ipv6, datalen);
ipv6_build_header(IPv6BUF, dev->d_len - IPv6_HDRLEN, IP_PROTO_ICMP6,
dev->d_ipv6addr, ipv6->srcipaddr, 255);
@ -119,8 +123,8 @@ void icmpv6_reply(FAR struct net_driver_s *dev, int type, int code, int data)
icmpv6->type = type;
icmpv6->code = code;
icmpv6->data[0] = data >> 16;
icmpv6->data[1] = data & 0xffff;
icmpv6->data[0] = htons(data >> 16);
icmpv6->data[1] = htons(data & 0xffff);
/* Calculate the ICMPv6 checksum over the ICMPv6 header and payload. */