Skip to content

Commit 2b5e7b2

Browse files
ignoramousCopilot
andcommitted
core/wire: truncated icmp pkt test
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 05df474 commit 2b5e7b2

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

intra/core/wire/parsed_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2025 RethinkDNS and its authors.
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
//
7+
// This file incorporates work covered by the following copyright and
8+
// permission notice:
9+
//
10+
// SPDX-License-Identifier: BSD-3-Clause
11+
// Copyright (c) Tailscale Inc & AUTHORS
12+
13+
package wire
14+
15+
import (
16+
"encoding/binary"
17+
"encoding/hex"
18+
"net/netip"
19+
"testing"
20+
)
21+
22+
func TestParsedDecodeICMPv6EchoRequest(t *testing.T) {
23+
// IPv6 ICMP echo request packet (no fragmentation, truncated)
24+
hexpkt := "600eb68300403a40fd66f83ac65000000000000000000001260647000000000000000000681084e58000c964116c0002832a586900000000f15b030000000000101112131415161718191a1b1c1d1e1f"
25+
26+
pkt, err := hex.DecodeString(hexpkt)
27+
if err != nil {
28+
t.Fatalf("hex decode failed: %v", err)
29+
}
30+
31+
expectedLen := int(binary.BigEndian.Uint16(pkt[4:6])) + IP6HeaderLength
32+
if len(pkt) < expectedLen {
33+
pkt = append(pkt, make([]byte, expectedLen-len(pkt))...)
34+
}
35+
36+
var p Parsed
37+
p.DecodeTrunc(pkt, true)
38+
39+
if p.IPVersion != Version6 {
40+
t.Fatalf("IPVersion got %d, want %d", p.IPVersion, Version6)
41+
}
42+
if p.IPProto != ICMPv6 {
43+
t.Fatalf("IPProto got %v, want %v", p.IPProto, ICMPv6)
44+
}
45+
46+
wantSrc := netip.MustParseAddr("fd66:f83a:c650::1")
47+
wantDst := netip.MustParseAddr("2606:4700::6810:84e5")
48+
49+
if p.Src.Addr() != wantSrc {
50+
t.Fatalf("Src got %v, want %v", p.Src.Addr(), wantSrc)
51+
}
52+
if p.Dst.Addr() != wantDst {
53+
t.Fatalf("Dst got %v, want %v", p.Dst.Addr(), wantDst)
54+
}
55+
if p.Src.Port() != 0 || p.Dst.Port() != 0 {
56+
t.Fatalf("expected zero ports for ICMPv6, got src=%d dst=%d", p.Src.Port(), p.Dst.Port())
57+
}
58+
59+
if !p.IsEchoRequest() {
60+
t.Fatalf("expected packet to be ICMPv6 echo request")
61+
}
62+
t.Log(p.ICMPHeaderString())
63+
}

0 commit comments

Comments
 (0)