1// Copyright 2018 GoPacket Authors. All rights reserved. 2// 3// Use of this source code is governed by a BSD-style license 4// that can be found in the LICENSE file in the root of the source 5// tree. 6 7package layers 8 9import ( 10 "testing" 11 12 "github.com/google/gopacket" 13) 14 15// Adapted from https://github.com/the-tcpdump-group/tcpdump/blob/master/tests/icmpv6.pcap 16// BSD licensed content 17// 18// Ethernet II, Src: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8), Dst: IPv6mcast_01 (33:33:00:00:00:01) 19// Internet Protocol Version 6, Src: fe80::b2a8:6eff:fe0c:d4e8, Dst: ff02::1 20// 0110 .... = Version: 6 21// .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) 22// .... .... .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 23// Payload Length: 36 24// Next Header: IPv6 Hop-by-Hop Option (0) 25// Hop Limit: 1 26// Source: fe80::b2a8:6eff:fe0c:d4e8 27// Destination: ff02::1 28// [Source SA MAC: JuniperN_0c:d4:e8 (b0:a8:6e:0c:d4:e8)] 29// IPv6 Hop-by-Hop Option 30// Internet Control Message Protocol v6 31// Type: Multicast Listener Query (130) 32// Code: 0 33// Checksum: 0x623a [correct] 34// [Checksum Status: Good] 35// Maximum Response Code: 10000 36// Reserved: 0000 37// Multicast Address: :: 38// Flags: 0x02 39// .... 0... = Suppress Router-Side Processing: False 40// .... .010 = QRV (Querier's Robustness Variable): 2 41// 0000 .... = Reserved: 0 42// QQIC (Querier's Query Interval Code): 60 43// Number of Sources: 0 44var testPacketMulticastListenerQueryMessageV2 = []byte{ 45 0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0xb0, 0xa8, 0x6e, 0x0c, 0xd4, 0xe8, 0x86, 0xdd, 0x60, 0x00, 46 0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0xa8, 47 0x6e, 0xff, 0xfe, 0x0c, 0xd4, 0xe8, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x82, 0x00, 49 0x62, 0x3a, 0x27, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3c, 0x00, 0x00, 51} 52 53func TestPacketMulticastListenerQueryMessageV2(t *testing.T) { 54 p := gopacket.NewPacket(testPacketMulticastListenerQueryMessageV2, LinkTypeEthernet, gopacket.Default) 55 if p.ErrorLayer() != nil { 56 t.Error("Failed to decode packet:", p.ErrorLayer().Error()) 57 } 58 checkLayers(p, []gopacket.LayerType{ 59 LayerTypeEthernet, 60 LayerTypeIPv6, 61 LayerTypeIPv6HopByHop, 62 LayerTypeICMPv6, 63 LayerTypeMLDv2MulticastListenerQuery}, t) 64 // See https://github.com/google/gopacket/issues/517 65 // checkSerialization(p, t) 66} 67 68// Adapted from https://github.com/the-tcpdump-group/tcpdump/blob/master/tests/icmpv6.pcap 69// BSD licensed content 70// 71// Frame 4: 150 bytes on wire (1200 bits), 150 bytes captured (1200 bits) 72// Ethernet II, Src: IntelCor_cc:e5:46 (00:15:17:cc:e5:46), Dst: IPv6mcast_16 (33:33:00:00:00:16) 73// Internet Protocol Version 6, Src: fe80::215:17ff:fecc:e546, Dst: ff02::16 74// 0110 .... = Version: 6 75// .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) 76// .... .... .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 77// Payload Length: 96 78// Next Header: IPv6 Hop-by-Hop Option (0) 79// Hop Limit: 1 80// Source: fe80::215:17ff:fecc:e546 81// Destination: ff02::16 82// [Source SA MAC: IntelCor_cc:e5:46 (00:15:17:cc:e5:46)] 83// IPv6 Hop-by-Hop Option 84// Internet Control Message Protocol v6 85// Type: Multicast Listener Report Message v2 (143) 86// Code: 0 87// Checksum: 0x2a0e [correct] 88// [Checksum Status: Good] 89// Reserved: 0000 90// Number of Multicast Address Records: 4 91// Multicast Address Record Exclude: ff02::db8:1122:3344 92// Record Type: Exclude (2) 93// Aux Data Len: 0 94// Number of Sources: 0 95// Multicast Address: ff02::db8:1122:3344 96// Multicast Address Record Exclude: ff02::1:ffcc:e546 97// Record Type: Exclude (2) 98// Aux Data Len: 0 99// Number of Sources: 0 100// Multicast Address: ff02::1:ffcc:e546 101// Multicast Address Record Exclude: ff02::1:ffa7:10ad 102// Record Type: Exclude (2) 103// Aux Data Len: 0 104// Number of Sources: 0 105// Multicast Address: ff02::1:ffa7:10ad 106// Multicast Address Record Exclude: ff02::1:ff00:2 107// Record Type: Exclude (2) 108// Aux Data Len: 0 109// Number of Sources: 0 110// Multicast Address: ff02::1:ff00:2 111var testPacketMulticastListenerReportMessageV2 = []byte{ 112 0x33, 0x33, 0x00, 0x00, 0x00, 0x16, 0x00, 0x15, 0x17, 0xcc, 0xe5, 0x46, 0x86, 0xdd, 0x60, 0x00, 113 0x00, 0x00, 0x00, 0x60, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x15, 114 0x17, 0xff, 0xfe, 0xcc, 0xe5, 0x46, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 115 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x3a, 0x00, 0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x8f, 0x00, 116 0x2a, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 117 0x00, 0x00, 0x00, 0x00, 0x0d, 0xb8, 0x11, 0x22, 0x33, 0x44, 0x02, 0x00, 0x00, 0x00, 0xff, 0x02, 118 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xcc, 0xe5, 0x46, 0x02, 0x00, 119 0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xa7, 120 0x10, 0xad, 0x02, 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 121 0x00, 0x01, 0xff, 0x00, 0x00, 0x02, 122} 123 124func TestPacketMulticastListenerReportMessageV2(t *testing.T) { 125 p := gopacket.NewPacket(testPacketMulticastListenerReportMessageV2, LinkTypeEthernet, gopacket.Default) 126 if p.ErrorLayer() != nil { 127 t.Error("Failed to decode packet:", p.ErrorLayer().Error()) 128 } 129 checkLayers(p, []gopacket.LayerType{ 130 LayerTypeEthernet, 131 LayerTypeIPv6, 132 LayerTypeIPv6HopByHop, 133 LayerTypeICMPv6, 134 LayerTypeMLDv2MulticastListenerReport}, t) 135 // See https://github.com/google/gopacket/issues/517 136 // checkSerialization(p, t) 137} 138