Documentation
¶
Overview ¶
The FrameSerde (fserde) package provides a framework to deserialize/serialize frames from text string format to a binary byte slice or binary to text string.
Serialize - Converts a ethernet binary frame to a text string. ToString Deserialize - Converts a ethernet text string to a binary ethernet frame. ToBinary
Index ¶
- Constants
- Variables
- func IPv4AddrChecksum(hdr *ipv4.Header) uint32
- func IPv4HeaderChecksum(hdr *ipv4.Header) uint16
- func IPv4ICMPChecksum(hdr *ipv4.Header, icmp *ICMPHeader, data []byte) uint16
- func IPv4TCPChecksum(ip *ipv4.Header, tcp *TCPHdr, data []byte) uint16
- func IPv4UDPChecksum(ip *ipv4.Header, udp *UDPHdr, data []byte) uint16
- func IPv6AddrChecksum(ip *ipv6.Header) uint32
- func IPv6ICMPChecksum(ip *ipv6.Header, icmp *ICMPHeader, data []byte) uint16
- func IPv6TCPChecksum(ip *ipv6.Header, tcp *TCPHdr, data []byte) uint16
- func IPv6UDPChecksum(ip *ipv6.Header, udp *UDPHdr, data []byte) uint16
- func PseudoHdrIPv4Checksum(ipSrc, ipDst net.IP, proto int, length uint16) uint32
- func PseudoHdrIPv4TCPChecksum(hdr *ipv4.Header) uint16
- func PseudoHdrIPv4UDPChecksum(hdr *ipv4.Header, udp *UDPHdr) uint16
- func PseudoHdrIPv6TCPChecksum(hdr *ipv6.Header) uint16
- func PseudoHdrIPv6UDPChecksum(hdr *ipv6.Header, udp *UDPHdr) uint16
- func Roundup(v, mul uint64) uint64
- func SwapIPv4Addr(x net.IP) net.IP
- func SwapUint16(x uint16) uint16
- func SwapUint32(x uint32) uint32
- func TCPChecksum(tcp *TCPHdr) uint32
- func ToHardwareAddr(mac string) (net.HardwareAddr, error)
- type CountLayer
- type DefaultsLayer
- type Dot1Q
- type Dot1adLayer
- type Dot1qLayer
- type EchoLayer
- type EtherHdr
- type EtherLayer
- type Frame
- func (fr *Frame) AddProtocol(proto *ProtoInfo) error
- func (fr *Frame) FrameDump() string
- func (fr *Frame) GetLayer(name LayerName) interface{}
- func (fr *Frame) GetLength(name LayerName) uint16
- func (fr *Frame) GetOffset(name LayerName) uint16
- func (fr *Frame) GetProtocol(name LayerName) *ProtoInfo
- func (fr *Frame) GetProtocolID() int
- func (f *Frame) String() string
- type FrameKey
- type FrameMap
- type FrameSerde
- func (f *FrameSerde) DefaultToBinary(frameString string) error
- func (f *FrameSerde) DefaultsToBinary(frameStrings []string) error
- func (f *FrameSerde) Delete()
- func (f *FrameSerde) DeleteFrame(frameName string, ftype FrameType) error
- func (f *FrameSerde) Destroy()
- func (f *FrameSerde) FrameMap(ftype FrameType) FrameMap
- func (f *FrameSerde) FrameNames(ftype FrameType) []string
- func (f *FrameSerde) GetFrame(frameName string, ftype FrameType) (*Frame, error)
- func (f *FrameSerde) GetFrames(ftype FrameType) []*Frame
- func (f *FrameSerde) StringToBinary(frameString string) error
- func (f *FrameSerde) StringsToBinary(frameStrings []string) error
- func (fg *FrameSerde) WritePCAP(path string, frameType FrameType) error
- type FrameSerdeConfig
- type FrameType
- type ICMPHeader
- type ICMPv4Layer
- type ICMPv6Layer
- type IPv4Layer
- type IPv6Layer
- type LayerHdr
- type LayerInfo
- type LayerMap
- type LayerName
- type LayerType
- type MyBuffer
- func (b *MyBuffer) Append(val interface{})
- func (b *MyBuffer) BufferDump() string
- func (b *MyBuffer) Bytes() []byte
- func (b *MyBuffer) Cap() int
- func (b *MyBuffer) Len() int
- func (b *MyBuffer) Read(p []byte) (n int, err error)
- func (b *MyBuffer) Reset()
- func (b *MyBuffer) Write(p []byte) (n int, err error)
- func (b *MyBuffer) WriteAt(index int, val []byte) error
- func (b *MyBuffer) WriteByte(p byte) error
- func (b *MyBuffer) WriteValueAt(index int, val interface{}) error
- type NewFuncs
- type PayloadLayer
- type ProtoInfo
- type ProtoMap
- type QinQLayer
- type SCTPLayer
- type TCPHdr
- type TCPLayer
- type TCPOptions
- type TSCLayer
- type ToBinaryConverter
- type UDPHdr
- type UDPLayer
- type VxLanLayer
Constants ¶
const ( EtherTypeIPv4 = 0x0800 // IPv4 EtherType value EtherTypeIPv6 = 0x86dd // IPv6 EtherType value EtherTypeARP = 0x0806 // ARP EtherType value Dot1QID = 0x8100 // IEEE 802.1Q VLAN ID EtherType value QinQID = 0x88a8 // IEEE 802.1Q QinQ VLAN ID EtherType value HardwareAddrLen = 6 // Length of hardware MAC address MinPacketLen = 60 // Minimum Ethernet frame length without FCS MaxPacketLen = 1514 // Maximum Ethernet frame length without FCS ProtocolUDP = 17 // UDP protocol number ProtocolTCP = 6 // TCP protocol number ProtocolIPv4 = 4 // IPv4 protocol number ProtocolIPv6 = 41 // IPv6 protocol number ProtocolICMPv4 = 1 // ICMPv4 protocol number ProtocolICMPv6 = 58 // ICMPv6 protocol number )
const ( ProtoL2 = iota ProtoL3 ProtoL4 ProtoL5 ProtoL6 ProtoL7 MaxProtocols )
const ( Tag8021Q = 0x8100 DefaultVid = 0x0001 )
const ( NormalFrameType = iota DefaultFrameType AllFrameTypes )
const ( ICMPv4MinLen = 8 ICMPv6MinLen = 40 )
const ( IPv4MinLen = 20 IPv4DefaultID = 1234 DefaultTTL = 64 )
const ( TCPMinLen = 20 TCPHeaderLen = 20 TCPDefaultLen = 20 TCPChecksumOffset = 16 )
const ( TCPFinFlag = 1 << iota TCPSynFlag TCPRstFlag TCPPshFlag TCPAckFlag TCPUrgFlag TCPEceFlag TCPCwrFlag )
Flags that may be set in a TCP segment.
const ( UDPHeaderLen = 8 UDPDefaultLen = 8 UDPChecksumOffset = 6 )
Variables ¶
var LayerNames = [...]LayerName{ LayerEther, LayerDot1Q, LayerQinQ, LayerDot1AD, LayerIPv4, LayerIPv6, LayerTCP, LayerUDP, LayerICMPv4, LayerICMPv6, LayerSCTP, LayerVxLan, LayerEcho, LayerTSC, LayerPayload, LayerDefaults, LayerCount, LayerDone, }
Functions ¶
func IPv4AddrChecksum ¶
func IPv4HeaderChecksum ¶
IPv4HeaderChecksum calculates checksum of IP header
func IPv4ICMPChecksum ¶
func IPv4ICMPChecksum(hdr *ipv4.Header, icmp *ICMPHeader, data []byte) uint16
IPv4ICMPChecksum calculates ICMP checksum in case if L3 protocol is IPv4.
func IPv4TCPChecksum ¶
IPv4TCPChecksum calculates TCP checksum for case if L3 protocol is IPv4. Here data pointer should point to end of minimal TCP header because we consider TCP options as part of data.
func IPv4UDPChecksum ¶
IPv4UDPChecksum calculates UDP checksum for case if L3 protocol is IPv4.
func IPv6AddrChecksum ¶
func IPv6ICMPChecksum ¶
func IPv6ICMPChecksum(ip *ipv6.Header, icmp *ICMPHeader, data []byte) uint16
IPv6ICMPChecksum calculates ICMP checksum in case if L3 protocol is IPv6.
func IPv6TCPChecksum ¶
IPv6TCPChecksum calculates TCP checksum for case if L3 protocol is IPv6.
func IPv6UDPChecksum ¶
IPv6UDPChecksum calculates UDP checksum for case if L3 protocol is IPv6.
func PseudoHdrIPv4Checksum ¶
func PseudoHdrIPv4TCPChecksum ¶
PseudoHdrIPv4TCPChecksum implements one step of TCP checksum calculation. Separately computes checksum for TCP pseudo-header for case if L3 protocol is IPv4. This precalculation is required for checksum compute by hardware offload. Result should be put into TCP.Cksum field.
func PseudoHdrIPv4UDPChecksum ¶
PseudoHdrIPv4UDPChecksum implements one step of UDP checksum calculation. Separately computes checksum for UDP pseudo-header for case if L3 protocol is IPv4. This precalculation is required for checksum compute by hardware offload. Result should be put into UDP.DgramCksum field.
func PseudoHdrIPv6TCPChecksum ¶
PseudoHdrIPv6TCPChecksum implements one step of TCP checksum calculation. Separately computes checksum for TCP pseudo-header for case if L3 protocol is IPv6. This precalculation is required for checksum compute by hardware offload. Result should be put into TCP.Cksum field.
func PseudoHdrIPv6UDPChecksum ¶
PseudoHdrIPv6UDPChecksum implements one step of UDP checksum calculation. Separately computes checksum for UDP pseudo-header for case if L3 protocol is IPv6. This precalculation is required for checksum compute by hardware offload. Result should be put into UDP.DgramCksum field.
func SwapUint16 ¶
SwapBytesUint16 swaps uint16 in Little Endian and Big Endian
func SwapUint32 ¶
SwapBytesUint32 swaps uint32 in Little Endian and Big Endian
func TCPChecksum ¶
func ToHardwareAddr ¶
func ToHardwareAddr(mac string) (net.HardwareAddr, error)
Types ¶
type CountLayer ¶
type CountLayer struct {
// contains filtered or unexported fields
}
CountLayer the structure holding the information on each layer.
func CountNew ¶
func CountNew(fr *Frame) *CountLayer
CountNew creates a new CountLayer and is called the NewFuncs structure.
func (*CountLayer) ApplyDefaults ¶
func (l *CountLayer) ApplyDefaults() error
ApplyDefaults applies the default values for the layer.
func (*CountLayer) Parse ¶
func (l *CountLayer) Parse(opts string) error
Parse parses the layer options string.
func (*CountLayer) String ¶
func (l *CountLayer) String() string
func (*CountLayer) WriteLayer ¶
func (l *CountLayer) WriteLayer() error
WriteLayer writes the layer to hdr.frame []byte.
type DefaultsLayer ¶
type DefaultsLayer struct {
// contains filtered or unexported fields
}
DefaultsLayer is the default implementation of the Layer interface.
func DefaultsNew ¶
func DefaultsNew(fr *Frame) *DefaultsLayer
func (*DefaultsLayer) ApplyDefaults ¶
func (l *DefaultsLayer) ApplyDefaults() error
func (*DefaultsLayer) Name ¶
func (l *DefaultsLayer) Name() LayerName
func (*DefaultsLayer) Parse ¶
func (l *DefaultsLayer) Parse(opts string) error
func (*DefaultsLayer) String ¶
func (l *DefaultsLayer) String() string
String returns a string representation of the layer.
func (*DefaultsLayer) WriteLayer ¶
func (l *DefaultsLayer) WriteLayer() error
type Dot1adLayer ¶
type Dot1adLayer struct {
// contains filtered or unexported fields
}
func Dot1adNew ¶
func Dot1adNew(fr *Frame) *Dot1adLayer
func (*Dot1adLayer) ApplyDefaults ¶
func (l *Dot1adLayer) ApplyDefaults() error
func (*Dot1adLayer) Name ¶
func (d *Dot1adLayer) Name() LayerName
func (*Dot1adLayer) Parse ¶
func (l *Dot1adLayer) Parse(opts string) error
func (*Dot1adLayer) String ¶
func (l *Dot1adLayer) String() string
func (*Dot1adLayer) WriteLayer ¶
func (l *Dot1adLayer) WriteLayer() error
type Dot1qLayer ¶
type Dot1qLayer struct {
// contains filtered or unexported fields
}
func Dot1qNew ¶
func Dot1qNew(fr *Frame) *Dot1qLayer
func (*Dot1qLayer) ApplyDefaults ¶
func (l *Dot1qLayer) ApplyDefaults() error
func (*Dot1qLayer) Name ¶
func (d *Dot1qLayer) Name() LayerName
func (*Dot1qLayer) Parse ¶
func (d *Dot1qLayer) Parse(opts string) error
func (*Dot1qLayer) ParseDot1q ¶
func (d *Dot1qLayer) ParseDot1q(opts string) error
func (*Dot1qLayer) String ¶
func (d *Dot1qLayer) String() string
func (*Dot1qLayer) WriteLayer ¶
func (l *Dot1qLayer) WriteLayer() error
type EchoLayer ¶
type EchoLayer struct {
// contains filtered or unexported fields
}
func (*EchoLayer) ApplyDefaults ¶
func (*EchoLayer) WriteLayer ¶
type EtherHdr ¶
type EtherHdr struct {
DstMac, SrcMac net.HardwareAddr
EtherType uint16
}
type EtherLayer ¶
type EtherLayer struct {
// contains filtered or unexported fields
}
func EtherNew ¶
func EtherNew(fr *Frame) *EtherLayer
func (*EtherLayer) ApplyDefaults ¶
func (l *EtherLayer) ApplyDefaults() error
func (*EtherLayer) Name ¶
func (e *EtherLayer) Name() LayerName
func (*EtherLayer) Parse ¶
func (el *EtherLayer) Parse(opts string) error
parseEther a formatted string into a byte array or frame.
func (*EtherLayer) String ¶
func (e *EtherLayer) String() string
func (*EtherLayer) WriteLayer ¶
func (l *EtherLayer) WriteLayer() error
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is the representation of a packet in text and binary format. A frame string or binary representation of a packet string is deserialized/serialized into this structure.
func (*Frame) AddProtocol ¶
func (*Frame) FrameDump ¶
frameDump is a helper function that returns a string representation of the given frame.
func (*Frame) GetLength ¶
GetLength returns the length of the following layers starting with the given layer name.
func (*Frame) GetOffset ¶
GetOffset returns the offset to the given layer name. The offset is the offset to the beginning of the protocol layer name
func (*Frame) GetProtocol ¶
GetProtocol returns a pointer to the protocol with the given name.
func (*Frame) GetProtocolID ¶
type FrameSerde ¶
type FrameSerde struct {
// contains filtered or unexported fields
}
Serde is the main structure of the fserde package. Holding the deserialized and serialized frame data.
func Create ¶
func Create(name string, cfg *FrameSerdeConfig) (*FrameSerde, error)
Create a FrameSerde structure from the default values. If the default values are present then parse them to the FrameSerde structure.
func (*FrameSerde) DefaultToBinary ¶
func (f *FrameSerde) DefaultToBinary(frameString string) error
func (*FrameSerde) DefaultsToBinary ¶
func (f *FrameSerde) DefaultsToBinary(frameStrings []string) error
func (*FrameSerde) Delete ¶
func (f *FrameSerde) Delete()
func (*FrameSerde) DeleteFrame ¶
func (f *FrameSerde) DeleteFrame(frameName string, ftype FrameType) error
func (*FrameSerde) Destroy ¶
func (f *FrameSerde) Destroy()
func (*FrameSerde) FrameMap ¶
func (f *FrameSerde) FrameMap(ftype FrameType) FrameMap
func (*FrameSerde) FrameNames ¶
func (f *FrameSerde) FrameNames(ftype FrameType) []string
func (*FrameSerde) GetFrame ¶
func (f *FrameSerde) GetFrame(frameName string, ftype FrameType) (*Frame, error)
func (*FrameSerde) GetFrames ¶
func (f *FrameSerde) GetFrames(ftype FrameType) []*Frame
func (*FrameSerde) StringToBinary ¶
func (f *FrameSerde) StringToBinary(frameString string) error
StringToBinary converts a string formatted frame to a binary frame
func (*FrameSerde) StringsToBinary ¶
func (f *FrameSerde) StringsToBinary(frameStrings []string) error
StringsToBinary converts a slice of string frames to a binary formatted frames
type FrameSerdeConfig ¶
type FrameSerdeConfig struct {
Defaults []string // List of default layers to apply to the frames
}
FrameSerdeConfig is the configuration structure for the FrameSerde.Create() call.
type ICMPHeader ¶
type ICMPHeader struct { Type uint8 // Message type Code uint8 // Message code Cksum uint16 // Checksum set to zero Identifier uint16 // Message identifier in some messages SeqNum uint16 // Message sequence number in some messages }
ICMPHdr L4 header.
type ICMPv4Layer ¶
type ICMPv4Layer struct {
// contains filtered or unexported fields
}
func ICMPv4New ¶
func ICMPv4New(fr *Frame) *ICMPv4Layer
func (*ICMPv4Layer) ApplyDefaults ¶
func (l *ICMPv4Layer) ApplyDefaults() error
func (*ICMPv4Layer) Name ¶
func (l *ICMPv4Layer) Name() LayerName
func (*ICMPv4Layer) Parse ¶
func (l *ICMPv4Layer) Parse(opts string) error
func (*ICMPv4Layer) String ¶
func (l *ICMPv4Layer) String() string
func (*ICMPv4Layer) WriteLayer ¶
func (l *ICMPv4Layer) WriteLayer() error
type ICMPv6Layer ¶
type ICMPv6Layer struct {
// contains filtered or unexported fields
}
func ICMPv6New ¶
func ICMPv6New(fr *Frame) *ICMPv6Layer
func (*ICMPv6Layer) ApplyDefaults ¶
func (l *ICMPv6Layer) ApplyDefaults() error
func (*ICMPv6Layer) Name ¶
func (l *ICMPv6Layer) Name() LayerName
func (*ICMPv6Layer) Parse ¶
func (el *ICMPv6Layer) Parse(opts string) error
func (*ICMPv6Layer) String ¶
func (l *ICMPv6Layer) String() string
func (*ICMPv6Layer) WriteLayer ¶
func (l *ICMPv6Layer) WriteLayer() error
type IPv4Layer ¶
type IPv4Layer struct {
// contains filtered or unexported fields
}
func (*IPv4Layer) ApplyDefaults ¶
func (*IPv4Layer) WriteLayer ¶
type IPv6Layer ¶
type IPv6Layer struct {
// contains filtered or unexported fields
}
func (*IPv6Layer) ApplyDefaults ¶
func (*IPv6Layer) WriteLayer ¶
type LayerHdr ¶
type LayerHdr struct {
// contains filtered or unexported fields
}
LayerHdr is the header for each layer containing common fields
func LayerConstructor ¶
LayerConstructor is a function that creates a new layer header
type LayerName ¶
type LayerName string // Layer type name
const ( // These strings are used for displaying layer names. // Must match the order of the layers above. LayerEther LayerName = "Ether" LayerDot1Q LayerName = "Dot1Q" LayerQinQ LayerName = "QinQ" LayerDot1AD LayerName = "Dot1AD" LayerIPv4 LayerName = "IPv4" LayerIPv6 LayerName = "IPv6" LayerTCP LayerName = "TCP" LayerUDP LayerName = "UDP" LayerICMPv4 LayerName = "ICMPv4" LayerICMPv6 LayerName = "ICMPv6" LayerSCTP LayerName = "SCTP" LayerVxLan LayerName = "VxLan" LayerEcho LayerName = "Echo" LayerTSC LayerName = "TSC" LayerPayload LayerName = "Payload" LayerDefaults LayerName = "Defaults" LayerCount LayerName = "Count" LayerDone LayerName = "Done" )
type LayerType ¶
type LayerType int // Layer type index value
const ( // Index values for each layer, must match the list below set of constants. LayerEtherType LayerType = iota LayerDot1QType LayerQinQType LayerDot1ADType LayerIPv4Type LayerIPv6Type LayerTCPType LayerUDPType LayerICMPv4Type LayerICMPv6Type LayerSCTPType LayerVxLanType LayerEchoType LayerTSCType LayerPayloadType LayerDefaultsType LayerCountType MaxLayerType )
type MyBuffer ¶
func (*MyBuffer) BufferDump ¶
BufferDump is a helper function that returns a string representation of the given frame.
func (*MyBuffer) WriteValueAt ¶
type NewFuncs ¶
type NewFuncs struct {
// contains filtered or unexported fields
}
Structure to hold all of the layer create functions
type PayloadLayer ¶
type PayloadLayer struct {
// contains filtered or unexported fields
}
func PayloadNew ¶
func PayloadNew(fr *Frame) *PayloadLayer
func (*PayloadLayer) ApplyDefaults ¶
func (l *PayloadLayer) ApplyDefaults() error
func (*PayloadLayer) Name ¶
func (l *PayloadLayer) Name() LayerName
func (*PayloadLayer) Parse ¶
func (l *PayloadLayer) Parse(opts string) error
func (*PayloadLayer) String ¶
func (pl *PayloadLayer) String() string
func (*PayloadLayer) WriteLayer ¶
func (l *PayloadLayer) WriteLayer() error
type ProtoInfo ¶
type ProtoInfo struct {
// contains filtered or unexported fields
}
ProtoInfo is the protocol offset and length information in the packet data.
type QinQLayer ¶
type QinQLayer struct {
// contains filtered or unexported fields
}
func (*QinQLayer) ApplyDefaults ¶
func (*QinQLayer) WriteLayer ¶
type SCTPLayer ¶
type SCTPLayer struct {
// contains filtered or unexported fields
}
func (*SCTPLayer) ApplyDefaults ¶
func (*SCTPLayer) WriteLayer ¶
type TCPHdr ¶
type TCPHdr struct { SrcPort uint16 // TCP source port DstPort uint16 // TCP destination port SeqNum uint32 // TCP sequence number AckNum uint32 // TCP acknowledgment number Flags uint16 // TCP flags Window uint16 // TCP window size Checksum uint16 // Always 0 and not configurable Urgent uint16 // TCP urgent pointer HdrLen uint16 // TCP header length Options []byte // TCP options bytes total length multiple of 4, max 40 bytes // contains filtered or unexported fields }
type TCPLayer ¶
type TCPLayer struct {
// contains filtered or unexported fields
}
func (*TCPLayer) ApplyDefaults ¶
func (*TCPLayer) WriteLayer ¶
type TCPOptions ¶
type TCPOptions struct {
// contains filtered or unexported fields
}
type TSCLayer ¶
type TSCLayer struct {
// contains filtered or unexported fields
}
func (*TSCLayer) ApplyDefaults ¶
func (*TSCLayer) WriteLayer ¶
type ToBinaryConverter ¶
type UDPLayer ¶
type UDPLayer struct {
// contains filtered or unexported fields
}
func (*UDPLayer) ApplyDefaults ¶
func (*UDPLayer) WriteLayer ¶
type VxLanLayer ¶
type VxLanLayer struct {
// contains filtered or unexported fields
}
func VxLanNew ¶
func VxLanNew(fr *Frame) *VxLanLayer
func (*VxLanLayer) ApplyDefaults ¶
func (l *VxLanLayer) ApplyDefaults() error
func (*VxLanLayer) Name ¶
func (l *VxLanLayer) Name() LayerName
func (*VxLanLayer) Parse ¶
func (l *VxLanLayer) Parse(opts string) error
func (*VxLanLayer) String ¶
func (vx *VxLanLayer) String() string
func (*VxLanLayer) WriteLayer ¶
func (l *VxLanLayer) WriteLayer() error