diff --git a/packet/network.go b/packet/network.go index e6aaa87e..72044750 100644 --- a/packet/network.go +++ b/packet/network.go @@ -54,6 +54,9 @@ type IPv6Header struct { Dst string // destination address } +type OtherTransportLayer struct { +} + const ( // IPv4HLen is IPv4 header length size IPv4HLen = 20 @@ -78,7 +81,6 @@ var ( errShortIPv4HeaderLength = errors.New("short ipv4 header length") errShortIPv6HeaderLength = errors.New("short ipv6 header length") errShortEthernetLength = errors.New("short ethernet header length") - errUnknownTransportLayer = errors.New("unknown transport layer") errUnknownL3Protocol = errors.New("unknown network layer protocol") ) @@ -124,7 +126,8 @@ func (p *Packet) decodeNextLayer() error { p.L4 = udp len = 8 default: - return errUnknownTransportLayer + p.L4 = OtherTransportLayer{} + len = 0 } p.data = p.data[len:] diff --git a/packet/packet_test.go b/packet/packet_test.go index 925d63f0..28cdce83 100644 --- a/packet/packet_test.go +++ b/packet/packet_test.go @@ -45,6 +45,27 @@ func TestDecodeEthernetIPv4TCP(t *testing.T) { } } +func TestDecodedIpProtocol50(t *testing.T) { + b := []byte{ + 0xe4, 0x8d, 0x8c, 0x2f, 0x9b, 0x17, 0xd4, 0xca, 0x6d, 0x8e, 0x52, 0x2e, 0x81, 0x00, 0x01, 0x0a, + 0x08, 0x00, 0x45, 0x00, 0x05, 0xb8, 0x12, 0xe1, 0x00, 0x00, 0xfe, 0x32, 0x2a, 0xda, 0x48, 0x09, + 0x74, 0x0d, 0x48, 0x09, 0x75, 0x39, 0x04, 0x60, 0xa5, 0xd4, 0x00, 0x0b, 0x6f, 0x6b, 0x04, 0xf5, + 0xfa, 0x78, 0x6a, 0x4a, 0x93, 0xcb, 0xad, 0x94, 0xb1, 0x86, 0x3c, 0x42, 0xf6, 0x03, 0x8c, 0xa5, + 0xc8, 0x96, 0x0a, 0xba, 0x66, 0x24, 0xca, 0x8d, 0x7c, 0x78, 0x96, 0x70, 0x46, 0x44, 0xce, 0x7a, + 0x12, 0x23, 0x83, 0xe6, 0x99, 0x85, 0x5b, 0x91, 0x25, 0x73, 0x8d, 0x5a, 0x09, 0x82, 0xa4, 0xb9, + 0x1b, 0x42, 0x5f, 0xf1, 0xdb, 0xf9, 0xb9, 0x1c, 0x84, 0x32, 0xfe, 0x34, 0x03, 0x00, 0x91, 0x18, + 0x2a, 0xd3, 0xed, 0xdf, 0x41, 0x46, 0xa4, 0xcc, 0x74, 0x79, 0x58, 0x21, 0x6c, 0x3c, 0x55, 0x96, + } + p := NewPacket() + _, err := p.Decoder(b, headerProtocolEthernet) + if err != nil { + t.Error("unexpected error", err) + } + if p.L3.(IPv4Header).Protocol != 50 { + t.Error("decoding failure") + } +} + func BenchmarkDecodeEthernetIPv4TCP(b *testing.B) { data := []byte{ 0xde, 0xad, 0x7a, 0x48, 0xcc, 0x37, 0xd4, 0x4, 0xff, 0x1, 0x18, 0x1e,