From affc4530a2414de0ac9e5c0609b6afb91d06b394 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 8 Dec 2021 21:15:46 -0800 Subject: [PATCH] net/packet: don't make IP6Header.marshalPseudo assume UDP It will be used for ICMPv6 next, so pass in the proto. Also, use the ipproto constants rather than hardcoding the mysterious number. Change-Id: I57b68bdd2d39fff75f82affe955aff9245de246b Signed-off-by: Brad Fitzpatrick --- net/packet/ip6.go | 4 ++-- net/packet/udp6.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/packet/ip6.go b/net/packet/ip6.go index e181f1dde..374e9459b 100644 --- a/net/packet/ip6.go +++ b/net/packet/ip6.go @@ -57,7 +57,7 @@ func (h *IP6Header) ToResponse() { // marshalPseudo serializes h into buf in the "pseudo-header" form // required when calculating UDP checksums. -func (h IP6Header) marshalPseudo(buf []byte) error { +func (h IP6Header) marshalPseudo(buf []byte, proto ipproto.Proto) error { if len(buf) < h.Len() { return errSmallBuffer } @@ -72,6 +72,6 @@ func (h IP6Header) marshalPseudo(buf []byte) error { buf[36] = 0 buf[37] = 0 buf[38] = 0 - buf[39] = 17 // NextProto + buf[39] = byte(proto) // NextProto return nil } diff --git a/net/packet/udp6.go b/net/packet/udp6.go index 18213c1fb..ce776ee72 100644 --- a/net/packet/udp6.go +++ b/net/packet/udp6.go @@ -40,7 +40,7 @@ func (h UDP6Header) Marshal(buf []byte) error { binary.BigEndian.PutUint16(buf[46:48], 0) // blank checksum // UDP checksum with IP pseudo header. - h.IP6Header.marshalPseudo(buf) + h.IP6Header.marshalPseudo(buf, ipproto.UDP) binary.BigEndian.PutUint16(buf[46:48], ip4Checksum(buf[:])) h.IP6Header.Marshal(buf)