| 1 | package cage |
| 2 | |
| 3 | import ( |
| 4 | "encoding/binary" |
| 5 | "net/netip" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestMacIPv6DropRequiresThisCheckingInstance(t *testing.T) { |
| 10 | g := fixtureGate(t) |
| 11 | if err := g.BeginCheck(); err != nil { |
| 12 | t.Fatal(err) |
| 13 | } |
| 14 | s := g.Status() |
| 15 | payload := []byte(MacIPv6ProbePrefix + s.RunID + " " + s.CheckID) |
| 16 | packet := make([]byte, 48+len(payload)) |
| 17 | packet[0] = 0x60 |
| 18 | packet[6] = 17 |
| 19 | packet[7] = 1 |
| 20 | binary.BigEndian.PutUint16(packet[4:6], uint16(8+len(payload))) |
| 21 | a := netip.MustParseAddr("fe80::1").As16() |
| 22 | copy(packet[8:24], a[:]) |
| 23 | a = netip.MustParseAddr("ff02::2").As16() |
| 24 | copy(packet[24:40], a[:]) |
| 25 | binary.BigEndian.PutUint16(packet[42:44], MacIPv6ProbePort) |
| 26 | binary.BigEndian.PutUint16(packet[44:46], uint16(8+len(payload))) |
| 27 | packet[47] = 1 |
| 28 | copy(packet[48:], payload) |
| 29 | for _, position := range []int{0, 5, 6, 7, 8, 24, 42, 45, 48, len(packet) - 1} { |
| 30 | wrong := append([]byte(nil), packet...) |
| 31 | wrong[position] ^= 0xff |
| 32 | g.ObserveDroppedIPv6(wrong) |
| 33 | if g.Status().IPv6LinkProbeCheck != "" { |
| 34 | t.Fatalf("unrelated datagram accepted (byte %d)", position) |
| 35 | } |
| 36 | } |
| 37 | g.ObserveDroppedIPv6(packet) |
| 38 | if g.Status().IPv6LinkProbeCheck != s.CheckID { |
| 39 | t.Fatal("matching received datagram not recorded") |
| 40 | } |
| 41 | g.Close("reset") |
| 42 | if err := g.BeginCheck(); err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | g.ObserveDroppedIPv6(packet) |
| 46 | if g.Status().IPv6LinkProbeCheck != "" { |
| 47 | t.Fatal("replayed earlier check") |
| 48 | } |
| 49 | } |