1 // Copyright 2012, Google, Inc. All rights reserved.
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
10 "github.com/google/gopacket"
15 // testPacketIPSecAHTransport is the packet:
16 // 20:45:10.325850 IP 192.168.1.1 > 192.168.1.2: AH(spi=0x00000101,seq=0x1): ICMP echo request, id 1560, seq 1, length 64
17 // 0x0000: 7ec0 ffc6 48f1 1a0e 3c4e 3b3a 0800 4500 ~...H...<N;:..E.
18 // 0x0010: 006c 650a 4000 4033 5201 c0a8 0101 c0a8 .le.@.@3R.......
19 // 0x0020: 0102 0104 0000 0000 0101 0000 0001 2533 ..............%3
20 // 0x0030: 01b1 a20b b6f1 bdbf 9d9e 0800 fbe5 0618 ................
21 // 0x0040: 0001 c6e1 a354 0000 0000 c8f7 0400 0000 .....T..........
22 // 0x0050: 0000 1011 1213 1415 1617 1819 1a1b 1c1d ................
23 // 0x0060: 1e1f 2021 2223 2425 2627 2829 2a2b 2c2d ...!"#$%&'()*+,-
24 // 0x0070: 2e2f 3031 3233 3435 3637 ./01234567
25 var testPacketIPSecAHTransport = []byte{
26 0x7e, 0xc0, 0xff, 0xc6, 0x48, 0xf1, 0x1a, 0x0e, 0x3c, 0x4e, 0x3b, 0x3a, 0x08, 0x00, 0x45, 0x00,
27 0x00, 0x6c, 0x65, 0x0a, 0x40, 0x00, 0x40, 0x33, 0x52, 0x01, 0xc0, 0xa8, 0x01, 0x01, 0xc0, 0xa8,
28 0x01, 0x02, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x25, 0x33,
29 0x01, 0xb1, 0xa2, 0x0b, 0xb6, 0xf1, 0xbd, 0xbf, 0x9d, 0x9e, 0x08, 0x00, 0xfb, 0xe5, 0x06, 0x18,
30 0x00, 0x01, 0xc6, 0xe1, 0xa3, 0x54, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xf7, 0x04, 0x00, 0x00, 0x00,
31 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
32 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
33 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
36 func TestPacketIPSecAHTransport(t *testing.T) {
37 p := gopacket.NewPacket(testPacketIPSecAHTransport, LinkTypeEthernet, gopacket.Default)
38 if p.ErrorLayer() != nil {
39 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
41 checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIPSecAH, LayerTypeICMPv4, gopacket.LayerTypePayload}, t)
42 if got, ok := p.Layer(LayerTypeIPSecAH).(*IPSecAH); ok {
47 AuthenticationData: []byte{0x25, 0x33, 0x01, 0xb1, 0xa2, 0x0b, 0xb6, 0xf1, 0xbd, 0xbf, 0x9d, 0x9e},
49 want.BaseLayer = BaseLayer{testPacketIPSecAHTransport[34:58], testPacketIPSecAHTransport[58:]}
50 want.NextHeader = IPProtocolICMPv4
51 want.HeaderLength = 0x4
52 want.ActualLength = 0x18
53 if !reflect.DeepEqual(want, got) {
54 t.Errorf("IPSecAH layer mismatch, \nwant %#v\ngot %#v\n", want, got)
59 func BenchmarkDecodePacketIPSecAHTransport(b *testing.B) {
60 for i := 0; i < b.N; i++ {
61 gopacket.NewPacket(testPacketIPSecAHTransport, LinkTypeEthernet, gopacket.NoCopy)
65 // testPacketIPSecAHTunnel is the packet:
66 // 14:45:43.252917 IP 192.168.1.1 > 192.168.1.2: AH(spi=0x00000101,seq=0x1): IP 172.16.1.1 > 172.16.2.1: ICMP echo request, id 31322, seq 1, length 64 (ipip-proto-4)
67 // 0x0000: 7220 4d91 63c9 566c ed2d 73cd 0800 4500 r.M.c.Vl.-s...E.
68 // 0x0010: 0080 0000 4000 4033 b6f7 c0a8 0101 c0a8 ....@.@3........
69 // 0x0020: 0102 0404 0000 0000 0101 0000 0001 cca4 ................
70 // 0x0030: 01da 9eb4 fb75 10fe 5a59 4500 0054 a96f .....u..ZYE..T.o
71 // 0x0040: 4000 4001 3617 ac10 0101 ac10 0201 0800 @.@.6...........
72 // 0x0050: d75f 7a5a 0001 0741 3355 0000 0000 a9db ._zZ...A3U......
73 // 0x0060: 0300 0000 0000 1011 1213 1415 1617 1819 ................
74 // 0x0070: 1a1b 1c1d 1e1f 2021 2223 2425 2627 2829 .......!"#$%&'()
75 // 0x0080: 2a2b 2c2d 2e2f 3031 3233 3435 3637 *+,-./01234567
76 var testPacketIPSecAHTunnel = []byte{
77 0x72, 0x20, 0x4d, 0x91, 0x63, 0xc9, 0x56, 0x6c, 0xed, 0x2d, 0x73, 0xcd, 0x08, 0x00, 0x45, 0x00,
78 0x00, 0x80, 0x00, 0x00, 0x40, 0x00, 0x40, 0x33, 0xb6, 0xf7, 0xc0, 0xa8, 0x01, 0x01, 0xc0, 0xa8,
79 0x01, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0xcc, 0xa4,
80 0x01, 0xda, 0x9e, 0xb4, 0xfb, 0x75, 0x10, 0xfe, 0x5a, 0x59, 0x45, 0x00, 0x00, 0x54, 0xa9, 0x6f,
81 0x40, 0x00, 0x40, 0x01, 0x36, 0x17, 0xac, 0x10, 0x01, 0x01, 0xac, 0x10, 0x02, 0x01, 0x08, 0x00,
82 0xd7, 0x5f, 0x7a, 0x5a, 0x00, 0x01, 0x07, 0x41, 0x33, 0x55, 0x00, 0x00, 0x00, 0x00, 0xa9, 0xdb,
83 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
84 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
85 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
88 func TestPacketIPSecAHTunnel(t *testing.T) {
89 p := gopacket.NewPacket(testPacketIPSecAHTunnel, LinkTypeEthernet, gopacket.Default)
90 if p.ErrorLayer() != nil {
91 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
93 checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIPSecAH, LayerTypeIPv4, LayerTypeICMPv4, gopacket.LayerTypePayload}, t)
94 if got, ok := p.Layer(LayerTypeIPSecAH).(*IPSecAH); ok {
99 AuthenticationData: []byte{0xcc, 0xa4, 0x01, 0xda, 0x9e, 0xb4, 0xfb, 0x75, 0x10, 0xfe, 0x5a, 0x59},
101 want.BaseLayer = BaseLayer{testPacketIPSecAHTunnel[34:58], testPacketIPSecAHTunnel[58:]}
102 want.NextHeader = IPProtocolIPv4
103 want.HeaderLength = 0x4
104 want.ActualLength = 0x18
105 if !reflect.DeepEqual(want, got) {
106 t.Errorf("IPSecAH layer mismatch, \nwant %#v\ngot %#v\n", want, got)
111 func BenchmarkDecodePacketIPSecAHTunnel(b *testing.B) {
112 for i := 0; i < b.N; i++ {
113 gopacket.NewPacket(testPacketIPSecAHTunnel, LinkTypeEthernet, gopacket.NoCopy)
117 // testPacketIPSecESP is the packet:
118 // 04:30:37.629376 IP 190.0.0.1 > 190.0.0.2: ESP(spi=0x0000006e,seq=0x13), length 116
119 // 0x0000: 0000 0000 0012 0011 434a d70a 0800 4500 ........CJ....E.
120 // 0x0010: 0088 0000 4000 4032 be40 be00 0001 be00 ....@.@2.@......
121 // 0x0020: 0002 0000 006e 0000 0013 82f4 1077 0418 .....n.......w..
122 // 0x0030: e8ce dc45 1bac 22bb daaf 2ad2 c2e8 315b ...E.."...*...1[
123 // 0x0040: ce9a 39da 2aae cf43 3716 70ab 7e7c 4676 ..9.*..C7.p.~|Fv
124 // 0x0050: c3fc d109 c990 274d f81c 6534 9a40 a0ef ......'M..e4.@..
125 // 0x0060: 46b1 7da5 05af dda8 d0ba 6e23 d1ee 1f10 F.}.......n#....
126 // 0x0070: 730c 7371 03b1 445c 2f70 852f 8475 12fb s.sq..D\/p./.u..
127 // 0x0080: b057 a19b a617 bae7 09ca 8836 942f 3334 .W.........6./34
128 // 0x0090: 312b 96d2 a4e3 1+....
129 var testPacketIPSecESP = []byte{
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x11, 0x43, 0x4a, 0xd7, 0x0a, 0x08, 0x00, 0x45, 0x00,
131 0x00, 0x88, 0x00, 0x00, 0x40, 0x00, 0x40, 0x32, 0xbe, 0x40, 0xbe, 0x00, 0x00, 0x01, 0xbe, 0x00,
132 0x00, 0x02, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x13, 0x82, 0xf4, 0x10, 0x77, 0x04, 0x18,
133 0xe8, 0xce, 0xdc, 0x45, 0x1b, 0xac, 0x22, 0xbb, 0xda, 0xaf, 0x2a, 0xd2, 0xc2, 0xe8, 0x31, 0x5b,
134 0xce, 0x9a, 0x39, 0xda, 0x2a, 0xae, 0xcf, 0x43, 0x37, 0x16, 0x70, 0xab, 0x7e, 0x7c, 0x46, 0x76,
135 0xc3, 0xfc, 0xd1, 0x09, 0xc9, 0x90, 0x27, 0x4d, 0xf8, 0x1c, 0x65, 0x34, 0x9a, 0x40, 0xa0, 0xef,
136 0x46, 0xb1, 0x7d, 0xa5, 0x05, 0xaf, 0xdd, 0xa8, 0xd0, 0xba, 0x6e, 0x23, 0xd1, 0xee, 0x1f, 0x10,
137 0x73, 0x0c, 0x73, 0x71, 0x03, 0xb1, 0x44, 0x5c, 0x2f, 0x70, 0x85, 0x2f, 0x84, 0x75, 0x12, 0xfb,
138 0xb0, 0x57, 0xa1, 0x9b, 0xa6, 0x17, 0xba, 0xe7, 0x09, 0xca, 0x88, 0x36, 0x94, 0x2f, 0x33, 0x34,
139 0x31, 0x2b, 0x96, 0xd2, 0xa4, 0xe3,
142 func TestPacketIPSecESP(t *testing.T) {
143 p := gopacket.NewPacket(testPacketIPSecESP, LinkTypeEthernet, gopacket.Default)
144 if p.ErrorLayer() != nil {
145 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
147 checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIPSecESP}, t)
150 func BenchmarkDecodePacketIPSecESP(b *testing.B) {
151 for i := 0; i < b.N; i++ {
152 gopacket.NewPacket(testPacketIPSecESP, LinkTypeEthernet, gopacket.NoCopy)