Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions layers/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ const (

// LinkType is an enumeration of link types, and acts as a decoder for any
// link type it supports.
type LinkType uint8
type LinkType uint16

const (
// According to pcap-linktype(7) and http://www.tcpdump.org/linktypes.html
LinkTypeNull LinkType = 0
LinkTypeNull LinkType = iota
LinkTypeEthernet LinkType = 1
LinkTypeAX25 LinkType = 3
LinkTypeTokenRing LinkType = 6
Expand Down Expand Up @@ -126,6 +126,10 @@ const (
LinkTypeFC2Framed LinkType = 225
LinkTypeIPv4 LinkType = 228
LinkTypeIPv6 LinkType = 229
LinkTypeLinuxSLL2 LinkType = 276

// Warning: this const should always be 1 larger than the largest valid value
LinkTypeMax LinkType = 277
)

// PPPoECode is the PPPoE code enum, taken from http://tools.ietf.org/html/rfc2516
Expand Down Expand Up @@ -385,6 +389,7 @@ func initActualTypeData() {
LinkTypeMetadata[LinkTypeLinuxUSB] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeUSB), Name: "USB"}
LinkTypeMetadata[LinkTypeLinuxSLL] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeLinuxSLL), Name: "Linux SLL"}
LinkTypeMetadata[LinkTypePrismHeader] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodePrismHeader), Name: "Prism"}
LinkTypeMetadata[LinkTypeLinuxSLL2] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeLinuxSLL2), Name: "Linux SLL2"}

FDDIFrameControlMetadata[FDDIFrameControlLLC] = EnumMetadata{DecodeWith: gopacket.DecodeFunc(decodeLLC), Name: "LLC"}

Expand Down
151 changes: 147 additions & 4 deletions layers/enums_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package layers

// Created by gen2.go, don't edit manually
// Generated at 2017-10-23 10:20:24.458771856 -0600 MDT m=+0.001159033
// Generated at 2022-08-14 17:04:22.83449 +0200 CEST m=+0.008730827

import (
"fmt"
Expand All @@ -28,16 +28,29 @@ func init() {

// Decoder calls LinkTypeMetadata.DecodeWith's decoder.
func (a LinkType) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 277 {
errDecoder := errorDecoderForLinkType(a)
return &errDecoder
}

return LinkTypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns LinkTypeMetadata.Name.
func (a LinkType) String() string {
if int(a) >= 277 {
return "UnknownLinkType"
}

return LinkTypeMetadata[a].Name
}

// LayerType returns LinkTypeMetadata.LayerType.
func (a LinkType) LayerType() gopacket.LayerType {
if int(a) >= 277 {
return 0
}

return LinkTypeMetadata[a].LayerType
}

Expand All @@ -50,11 +63,11 @@ func (a *errorDecoderForLinkType) Error() string {
return fmt.Sprintf("Unable to decode LinkType %d", int(*a))
}

var errorDecodersForLinkType [256]errorDecoderForLinkType
var LinkTypeMetadata [256]EnumMetadata
var errorDecodersForLinkType [277]errorDecoderForLinkType
var LinkTypeMetadata [277]EnumMetadata

func initUnknownTypesForLinkType() {
for i := 0; i < 256; i++ {
for i := 0; i < 277; i++ {
errorDecodersForLinkType[i] = errorDecoderForLinkType(i)
LinkTypeMetadata[i] = EnumMetadata{
DecodeWith: &errorDecodersForLinkType[i],
Expand All @@ -65,16 +78,29 @@ func initUnknownTypesForLinkType() {

// Decoder calls EthernetTypeMetadata.DecodeWith's decoder.
func (a EthernetType) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 65536 {
errDecoder := errorDecoderForEthernetType(a)
return &errDecoder
}

return EthernetTypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns EthernetTypeMetadata.Name.
func (a EthernetType) String() string {
if int(a) >= 65536 {
return "UnknownEthernetType"
}

return EthernetTypeMetadata[a].Name
}

// LayerType returns EthernetTypeMetadata.LayerType.
func (a EthernetType) LayerType() gopacket.LayerType {
if int(a) >= 65536 {
return 0
}

return EthernetTypeMetadata[a].LayerType
}

Expand Down Expand Up @@ -102,16 +128,29 @@ func initUnknownTypesForEthernetType() {

// Decoder calls PPPTypeMetadata.DecodeWith's decoder.
func (a PPPType) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 65536 {
errDecoder := errorDecoderForPPPType(a)
return &errDecoder
}

return PPPTypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns PPPTypeMetadata.Name.
func (a PPPType) String() string {
if int(a) >= 65536 {
return "UnknownPPPType"
}

return PPPTypeMetadata[a].Name
}

// LayerType returns PPPTypeMetadata.LayerType.
func (a PPPType) LayerType() gopacket.LayerType {
if int(a) >= 65536 {
return 0
}

return PPPTypeMetadata[a].LayerType
}

Expand Down Expand Up @@ -139,16 +178,29 @@ func initUnknownTypesForPPPType() {

// Decoder calls IPProtocolMetadata.DecodeWith's decoder.
func (a IPProtocol) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForIPProtocol(a)
return &errDecoder
}

return IPProtocolMetadata[a].DecodeWith.Decode(data, p)
}

// String returns IPProtocolMetadata.Name.
func (a IPProtocol) String() string {
if int(a) >= 256 {
return "UnknownIPProtocol"
}

return IPProtocolMetadata[a].Name
}

// LayerType returns IPProtocolMetadata.LayerType.
func (a IPProtocol) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return IPProtocolMetadata[a].LayerType
}

Expand Down Expand Up @@ -176,16 +228,29 @@ func initUnknownTypesForIPProtocol() {

// Decoder calls SCTPChunkTypeMetadata.DecodeWith's decoder.
func (a SCTPChunkType) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForSCTPChunkType(a)
return &errDecoder
}

return SCTPChunkTypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns SCTPChunkTypeMetadata.Name.
func (a SCTPChunkType) String() string {
if int(a) >= 256 {
return "UnknownSCTPChunkType"
}

return SCTPChunkTypeMetadata[a].Name
}

// LayerType returns SCTPChunkTypeMetadata.LayerType.
func (a SCTPChunkType) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return SCTPChunkTypeMetadata[a].LayerType
}

Expand Down Expand Up @@ -213,16 +278,29 @@ func initUnknownTypesForSCTPChunkType() {

// Decoder calls PPPoECodeMetadata.DecodeWith's decoder.
func (a PPPoECode) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForPPPoECode(a)
return &errDecoder
}

return PPPoECodeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns PPPoECodeMetadata.Name.
func (a PPPoECode) String() string {
if int(a) >= 256 {
return "UnknownPPPoECode"
}

return PPPoECodeMetadata[a].Name
}

// LayerType returns PPPoECodeMetadata.LayerType.
func (a PPPoECode) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return PPPoECodeMetadata[a].LayerType
}

Expand Down Expand Up @@ -250,16 +328,29 @@ func initUnknownTypesForPPPoECode() {

// Decoder calls FDDIFrameControlMetadata.DecodeWith's decoder.
func (a FDDIFrameControl) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForFDDIFrameControl(a)
return &errDecoder
}

return FDDIFrameControlMetadata[a].DecodeWith.Decode(data, p)
}

// String returns FDDIFrameControlMetadata.Name.
func (a FDDIFrameControl) String() string {
if int(a) >= 256 {
return "UnknownFDDIFrameControl"
}

return FDDIFrameControlMetadata[a].Name
}

// LayerType returns FDDIFrameControlMetadata.LayerType.
func (a FDDIFrameControl) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return FDDIFrameControlMetadata[a].LayerType
}

Expand Down Expand Up @@ -287,16 +378,29 @@ func initUnknownTypesForFDDIFrameControl() {

// Decoder calls EAPOLTypeMetadata.DecodeWith's decoder.
func (a EAPOLType) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForEAPOLType(a)
return &errDecoder
}

return EAPOLTypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns EAPOLTypeMetadata.Name.
func (a EAPOLType) String() string {
if int(a) >= 256 {
return "UnknownEAPOLType"
}

return EAPOLTypeMetadata[a].Name
}

// LayerType returns EAPOLTypeMetadata.LayerType.
func (a EAPOLType) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return EAPOLTypeMetadata[a].LayerType
}

Expand Down Expand Up @@ -324,16 +428,29 @@ func initUnknownTypesForEAPOLType() {

// Decoder calls ProtocolFamilyMetadata.DecodeWith's decoder.
func (a ProtocolFamily) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForProtocolFamily(a)
return &errDecoder
}

return ProtocolFamilyMetadata[a].DecodeWith.Decode(data, p)
}

// String returns ProtocolFamilyMetadata.Name.
func (a ProtocolFamily) String() string {
if int(a) >= 256 {
return "UnknownProtocolFamily"
}

return ProtocolFamilyMetadata[a].Name
}

// LayerType returns ProtocolFamilyMetadata.LayerType.
func (a ProtocolFamily) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return ProtocolFamilyMetadata[a].LayerType
}

Expand Down Expand Up @@ -361,16 +478,29 @@ func initUnknownTypesForProtocolFamily() {

// Decoder calls Dot11TypeMetadata.DecodeWith's decoder.
func (a Dot11Type) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForDot11Type(a)
return &errDecoder
}

return Dot11TypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns Dot11TypeMetadata.Name.
func (a Dot11Type) String() string {
if int(a) >= 256 {
return "UnknownDot11Type"
}

return Dot11TypeMetadata[a].Name
}

// LayerType returns Dot11TypeMetadata.LayerType.
func (a Dot11Type) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return Dot11TypeMetadata[a].LayerType
}

Expand Down Expand Up @@ -398,16 +528,29 @@ func initUnknownTypesForDot11Type() {

// Decoder calls USBTransportTypeMetadata.DecodeWith's decoder.
func (a USBTransportType) Decode(data []byte, p gopacket.PacketBuilder) error {
if int(a) >= 256 {
errDecoder := errorDecoderForUSBTransportType(a)
return &errDecoder
}

return USBTransportTypeMetadata[a].DecodeWith.Decode(data, p)
}

// String returns USBTransportTypeMetadata.Name.
func (a USBTransportType) String() string {
if int(a) >= 256 {
return "UnknownUSBTransportType"
}

return USBTransportTypeMetadata[a].Name
}

// LayerType returns USBTransportTypeMetadata.LayerType.
func (a USBTransportType) LayerType() gopacket.LayerType {
if int(a) >= 256 {
return 0
}

return USBTransportTypeMetadata[a].LayerType
}

Expand Down
Loading