github.com/gopacket/gopacket@v1.1.0/layers/mldv2_test.go (about)

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