parser

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

This package is responsible for parsing a packet description, more specifically, an ordered list of layers definitions.

In its basic form, each layers is defined by a text line following the following sytnax:

TAG: prop1=val1 prop2=val2

where TAG serves two functions: 1. It specifies the type of layer. 2. It uniquely names a layer.

As an example:

IP4: Src=192.168.12.3 Dst=192.168.12.2 NextHdr=UDP
UDP_1: Src=40000 Dst=50000 Checksum=0

The above example defines a packet with two layers, IP4 and UDP, with tags IP4 and UDP_1 respectively. Tags are useful to refer to specific layers in a packet.

The parse is indentation aware, meaning that all layers need to have the same tab indentation as the first layer.

It is also possible to define a layer which consists of multiple lines:

IP4: Src=192.168.12.3 Dst=192.168.12.2 NextHdr=UDP
UDP: Src=40000 Dst=50000 Checksum=0
SCION: NextHdr=UDP CurrInfoF=4 CurrHopF=5 SrcType=IPv4 DstType=SVC
    ADDR: SrcIA=1-ff00:0:2 Src=172.16.2.1 DstIA=1-ff00:0:1 Dst=192.168.0.51
    IF_1: ISD=1 Hops=3 Flags=Peer
        HF_1: ConsIngress=261 ConsEgress=0   Flags=Xover
        HF_2: ConsIngress=211 ConsEgress=151 Flags=Xover
        HF_3: ConsIngress=0   ConsEgress=621
UDP: Src=1111 Dst=2222

From the parsing point of view, everyline with deeper indentation than the layer itself belong to the layer, so in the example above, the SCION layer would consist of:

SCION: NextHdr=UDP CurrInfoF=4 CurrHopF=5 SrcType=IPv4 DstType=SVC
    ADDR: SrcIA=1-ff00:0:2 Src=172.16.2.1 DstIA=1-ff00:0:1 Dst=192.168.0.51
    IF_1: ISD=1 Hops=3 Flags=Peer
        HF_1: ConsIngress=261 ConsEgress=0   Flags=Xover
        HF_2: ConsIngress=211 ConsEgress=151 Flags=Xover
        HF_3: ConsIngress=0   ConsEgress=621

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HexToBytes

func HexToBytes(s string) common.RawBytes

func HexToInt

func HexToInt(s string) uint

func HostAddrTypeFromString

func HostAddrTypeFromString(ht string) addr.HostAddrType

func ParseProto

func ParseProto(enumMeta []golayers.EnumMetadata, protoName string) uint

func SerializeLayers

func SerializeLayers(w gopacket.SerializeBuffer, layers ...TaggedLayer) error

SerializeLayers serializes all gopacket.Layers to Bytes. We implement our own SerializeLayers (gopacket provides one) to allow for custom SerializeOptions per layer

func StrToBool

func StrToBool(s string) bool

func StrToInt

func StrToInt(s string) int

Types

type EthernetTaggedLayer

type EthernetTaggedLayer struct {
	golayers.Ethernet
	// contains filtered or unexported fields
}

func (*EthernetTaggedLayer) Clone

func (ether *EthernetTaggedLayer) Clone() TaggedLayer

func (*EthernetTaggedLayer) Layer

func (ether *EthernetTaggedLayer) Layer() gopacket.Layer

func (EthernetTaggedLayer) SerializeOptions

func (t EthernetTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (*EthernetTaggedLayer) String

func (ether *EthernetTaggedLayer) String() string

func (EthernetTaggedLayer) Tag

func (t EthernetTaggedLayer) Tag() string

func (*EthernetTaggedLayer) Update

func (ether *EthernetTaggedLayer) Update(lines []string)

type HBHTaggedLayer

type HBHTaggedLayer struct {
	layers.Extension
	// contains filtered or unexported fields
}

func (*HBHTaggedLayer) Clone

func (hbh *HBHTaggedLayer) Clone() TaggedLayer

func (*HBHTaggedLayer) Layer

func (hbh *HBHTaggedLayer) Layer() gopacket.Layer

func (*HBHTaggedLayer) LayerType

func (hbh *HBHTaggedLayer) LayerType() gopacket.LayerType

XXX layers.Extension is missing following method to implement gopacket.Layer

func (HBHTaggedLayer) SerializeOptions

func (t HBHTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (*HBHTaggedLayer) String

func (hbh *HBHTaggedLayer) String() string

func (HBHTaggedLayer) Tag

func (t HBHTaggedLayer) Tag() string

func (*HBHTaggedLayer) Update

func (hbh *HBHTaggedLayer) Update(lines []string)

type IFStateInfoTaggedLayer

type IFStateInfoTaggedLayer struct {
	gopacket.Payload
	path_mgmt.IFStateInfo
	RevInfo
	// contains filtered or unexported fields
}

func (*IFStateInfoTaggedLayer) Clone

func (*IFStateInfoTaggedLayer) Layer

func (IFStateInfoTaggedLayer) SerializeOptions

func (t IFStateInfoTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (IFStateInfoTaggedLayer) Tag

func (t IFStateInfoTaggedLayer) Tag() string

func (*IFStateInfoTaggedLayer) Update

func (i *IFStateInfoTaggedLayer) Update(lines []string)

type IFStateReqTaggedLayer

type IFStateReqTaggedLayer struct {
	gopacket.Payload
	path_mgmt.IFStateReq
	// contains filtered or unexported fields
}

func (*IFStateReqTaggedLayer) Clone

func (*IFStateReqTaggedLayer) Layer

func (IFStateReqTaggedLayer) SerializeOptions

func (t IFStateReqTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (IFStateReqTaggedLayer) Tag

func (t IFStateReqTaggedLayer) Tag() string

func (*IFStateReqTaggedLayer) Update

func (i *IFStateReqTaggedLayer) Update(lines []string)

type IP4TaggedLayer

type IP4TaggedLayer struct {
	layers.IPv4
	// contains filtered or unexported fields
}

func (*IP4TaggedLayer) Clone

func (ip *IP4TaggedLayer) Clone() TaggedLayer

func (*IP4TaggedLayer) Layer

func (ip *IP4TaggedLayer) Layer() gopacket.Layer

func (IP4TaggedLayer) SerializeOptions

func (t IP4TaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (*IP4TaggedLayer) String

func (ip *IP4TaggedLayer) String() string

func (IP4TaggedLayer) Tag

func (t IP4TaggedLayer) Tag() string

func (*IP4TaggedLayer) Update

func (ip *IP4TaggedLayer) Update(lines []string)

type InfoPathOffsets

type InfoPathOffsets struct {
	scmp.InfoPathOffsets
}

type InfoRevocation

type InfoRevocation struct {
	scmp.InfoRevocation
}

type LayerParser

type LayerParser func(lines []string) TaggedLayer

type RevInfo

type RevInfo struct {
	path_mgmt.RevInfo
}

type SCMPTaggedLayer

type SCMPTaggedLayer struct {
	layers.SCMP
	// contains filtered or unexported fields
}

func (*SCMPTaggedLayer) Clone

func (s *SCMPTaggedLayer) Clone() TaggedLayer

func (*SCMPTaggedLayer) Layer

func (s *SCMPTaggedLayer) Layer() gopacket.Layer

func (SCMPTaggedLayer) SerializeOptions

func (t SCMPTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (*SCMPTaggedLayer) String

func (s *SCMPTaggedLayer) String() string

func (SCMPTaggedLayer) Tag

func (t SCMPTaggedLayer) Tag() string

func (*SCMPTaggedLayer) Update

func (s *SCMPTaggedLayer) Update(lines []string)

type ScionTaggedLayer

type ScionTaggedLayer struct {
	layers.Scion
	// contains filtered or unexported fields
}

func (*ScionTaggedLayer) Clone

func (scn *ScionTaggedLayer) Clone() TaggedLayer

func (*ScionTaggedLayer) GenerateMac

func (scn *ScionTaggedLayer) GenerateMac(hMac hash.Hash, infTag, hfTag, hfMacTag string)

func (*ScionTaggedLayer) Layer

func (scn *ScionTaggedLayer) Layer() gopacket.Layer

func (ScionTaggedLayer) SerializeOptions

func (t ScionTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (*ScionTaggedLayer) String

func (scn *ScionTaggedLayer) String() string

func (ScionTaggedLayer) Tag

func (t ScionTaggedLayer) Tag() string

func (*ScionTaggedLayer) Update

func (scn *ScionTaggedLayer) Update(lines []string)

type SignedRevInfoTaggedLayer

type SignedRevInfoTaggedLayer struct {
	gopacket.Payload
	SRevInfo *path_mgmt.SignedRevInfo
	RevInfo
	// contains filtered or unexported fields
}

func (*SignedRevInfoTaggedLayer) Clone

func (*SignedRevInfoTaggedLayer) Layer

func (SignedRevInfoTaggedLayer) SerializeOptions

func (t SignedRevInfoTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (SignedRevInfoTaggedLayer) Tag

func (t SignedRevInfoTaggedLayer) Tag() string

func (*SignedRevInfoTaggedLayer) Update

func (i *SignedRevInfoTaggedLayer) Update(lines []string)

type TaggedLayer

type TaggedLayer interface {
	gopacket.SerializableLayer
	SerializeOptions() gopacket.SerializeOptions
	Tag() string
	Layer() gopacket.Layer
	Clone() TaggedLayer
	Update([]string)
}

func EthernetParser

func EthernetParser(lines []string) TaggedLayer

func HBHParser

func HBHParser(lines []string) TaggedLayer

func IFStateInfoParser

func IFStateInfoParser(lines []string) TaggedLayer

IFStateInfoParser parses an Interface State Info with the following syntax:

IFStateInfo: IfID=121 Active=true

IFStateInfo: IfID=121 Active=false

SignRevInfo: IfID=121 IA=1-ff00:0:1 Link=peer TS=now TTL=60

The SignedRevInfo is optional.

func IFStateReqParser

func IFStateReqParser(lines []string) TaggedLayer

IFStateReqParser parses an Interface State Request with the following syntax:

IFStateReq: IfID=121

func IP4Parser

func IP4Parser(lines []string) TaggedLayer

func SCMPParser

func SCMPParser(lines []string) TaggedLayer

func ScionParser

func ScionParser(lines []string) TaggedLayer

func SignedRevInfoParser

func SignedRevInfoParser(lines []string) TaggedLayer

SignedRevInfoParser parses an Interface State Info with the following syntax:

SignRevInfo: IfID=121 IA=1-ff00:0:1 Link=peer TS=now TTL=60

func UDPParser

func UDPParser(lines []string) TaggedLayer

type TaggedLayers

type TaggedLayers []TaggedLayer

func ParsePacket

func ParsePacket(packetString string) TaggedLayers

func (TaggedLayers) CloneAndUpdate

func (taggedLayers TaggedLayers) CloneAndUpdate(packetString string) TaggedLayers

func (TaggedLayers) GenerateMac

func (taggedLayers TaggedLayers) GenerateMac(scnTag string, hMac hash.Hash,
	infTag, hfTag, hfMacTag string)

func (TaggedLayers) GetTaggedLayer

func (taggedLayers TaggedLayers) GetTaggedLayer(tag string) TaggedLayer

func (TaggedLayers) Serialize

func (taggedLayers TaggedLayers) Serialize() common.RawBytes

func (TaggedLayers) SetChecksum

func (taggedLayers TaggedLayers) SetChecksum(l4Tag, l3Tag string)

func (TaggedLayers) String

func (taggedLayers TaggedLayers) String() string

func (TaggedLayers) Update

func (taggedLayers TaggedLayers) Update(packetString string)

type UDPTaggedLayer

type UDPTaggedLayer struct {
	layers.UDP
	// contains filtered or unexported fields
}

func (*UDPTaggedLayer) Clone

func (udp *UDPTaggedLayer) Clone() TaggedLayer

func (*UDPTaggedLayer) Layer

func (udp *UDPTaggedLayer) Layer() gopacket.Layer

func (UDPTaggedLayer) SerializeOptions

func (t UDPTaggedLayer) SerializeOptions() gopacket.SerializeOptions

func (*UDPTaggedLayer) String

func (udp *UDPTaggedLayer) String() string

func (UDPTaggedLayer) Tag

func (t UDPTaggedLayer) Tag() string

func (*UDPTaggedLayer) Update

func (udp *UDPTaggedLayer) Update(lines []string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL