parser

package
v0.0.0-...-60746fa Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: GPL-3.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EcnMagicMap = map[string]uint64{
		"ce":   0b11,
		"ect1": 0b01,
		"ect0": 0b10,
	}
	EtypeMagicMap = map[string]uint64{
		"ipv4": 0x0800,
		"arp":  0x0806,
		"ipv6": 0x86DD,
	}
	ProtoMagicMap = map[string]uint64{"icmp": 1,
		"tcp":    6,
		"udp":    17,
		"icmpv6": 58,
		"ipip":   94,
		"vrrp":   112}
	StatusMagicMap = map[string]uint64{
		"forwarded":   0b01000000,
		"dropped":     0b10000000,
		"acldeny":     0b10000001,
		"acldrop":     0b10000010,
		"unroutable":  0b10000011,
		"consumed":    0b11000000,
		"policerdrop": 0b10001010,
	}
	TcpFlagsMagicMap = map[string]uint64{
		"fin":    0b000000001,
		"finack": 0b000010001,
		"syn":    0b000000010,
		"rst":    0b000000100,
		"psh":    0b000001000,
		"ack":    0b000010000,
		"urg":    0b000100000,
		"synack": 0b000010010,
		"cwr":    0b010000000,
		"ece":    0b100000000,
	}
	DscpMagicMap = map[string]uint64{
		"default": 0b000000,
	}
	RpkiMagicMap = map[string]uint64{"unknown": 0,
		"valid":    1,
		"notfound": 2,
		"invalid":  3,
	}
)

Functions

func Visit

func Visit(node Node, visitor func(node Node, next func() error) error) error

Visit for all nodes in the AST The visitor can call "next()" to continue traversal of child nodes.

Types

type Address

type Address net.IP

Basic data type nodes which are mostly just aliases

type AddressMatch

type AddressMatch struct {
	BranchNode
	Address *net.IP `@Address`
	Mask    *Number `( "/" @Number)?`
}

type AsnRangeMatch

type AsnRangeMatch struct{ NumericRange }

type Boolean

type Boolean bool

type BpsRangeMatch

type BpsRangeMatch struct{ NumericRange }

type BranchNode

type BranchNode struct {
	EvalResult    bool
	EvalResultSrc bool
	EvalResultDst bool
}

Branch Nodes have this struct embedded, as these fields can be used to pass evaluation results from children.

type ByteRangeMatch

type ByteRangeMatch struct{ NumericRange }

type CidRangeMatch

type CidRangeMatch struct{ NumericRange }

type DirectionalMatchGroup

type DirectionalMatchGroup struct {
	BranchNode
	Direction *String            `@Direction?`
	Address   *AddressMatch      `( "address" @@`
	Interface *InterfaceMatch    `| ("iface"|"interface") @@`
	Port      *PortRangeMatch    `| "port" @@`
	Asn       *AsnRangeMatch     `| "asn" @@`
	Netsize   *NetsizeRangeMatch `| "netsize" @@`
	Cid       *CidRangeMatch     `| "cid" @@`
	Vrf       *VrfRangeMatch     `| "vrf" @@ )`
}

Directional Matches: * anything that has further sub commands or accepts fancy data * no direction * several dedicated Match structs for different data types and sub commands

type DscpKey

type DscpKey Number

func (*DscpKey) Capture

func (o *DscpKey) Capture(values []string) error

type DscpMatch

type DscpMatch struct {
	BranchNode
	Dscp    *Number  `  @Number` // first 6 bits of iptos
	DscpKey *DscpKey `| @DscpMagic`
}

type DurationRangeMatch

type DurationRangeMatch struct{ NumericRange }

type EcnKey

type EcnKey Number

func (*EcnKey) Capture

func (o *EcnKey) Capture(values []string) error

type EcnMatch

type EcnMatch struct {
	BranchNode
	Ecn    *Number `  @Number` // last 2 bits of iptos
	EcnKey *EcnKey `| @EcnMagic`
}

type EtypeKey

type EtypeKey Number

func (*EtypeKey) Capture

func (o *EtypeKey) Capture(values []string) error

type EtypeMatch

type EtypeMatch struct {
	BranchNode
	Etype    *Number   `  @Number`
	EtypeKey *EtypeKey `| @EtypeMagic`
}

type Expression

type Expression struct {
	BranchNode
	Left        *Statement  `(@@ (`
	Conjunction *String     `@Conjunction`
	Right       *Expression `@@ )?)?`
}

The overall structure of this grammar. Expressions are made up of statements in conjunction with more expressions. A statement consists of any matcher or a subexpression in parenthesis and is optionally negated.

func Parse

func Parse(input string) (*Expression, error)

type FlowDirectionMatch

type FlowDirectionMatch struct {
	BranchNode
	FlowDirection *String `@("incoming"|"outgoing")`
}

type IPTosRangeMatch

type IPTosRangeMatch struct{ NumericRange }

type IcmpMatch

type IcmpMatch struct {
	BranchNode
	Type *Number `  ( "type" @Number )`
	Code *Number `| ( "code" @Number )`
}

type IfSpeedRangeMatch

type IfSpeedRangeMatch struct{ NumericRange }

type InterfaceMatch

type InterfaceMatch struct {
	BranchNode
	SnmpId      *Number            `  (   "id"? @Number )`
	Name        *String            `| ( "name"  @String )`
	Description *String            `| ( "desc"  @String )`
	Speed       *IfSpeedRangeMatch `| ("speed"  @@)`
}

type LocalPrefRangeMatch

type LocalPrefRangeMatch struct{ NumericRange }

type MedRangeMatch

type MedRangeMatch struct{ NumericRange }

type NetsizeRangeMatch

type NetsizeRangeMatch struct{ NumericRange }

type NextHopAsnMatch

type NextHopAsnMatch struct {
	BranchNode
	Asn *uint32 `@Number`
}

type NextHopMatch

type NextHopMatch struct {
	BranchNode
	Address *net.IP `@Address`
}

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node is an interface implemented by all AST nodes

type NormalizedMatch

type NormalizedMatch struct {
	BranchNode
	Normalized bool `@"normalized"`
}

type Number

type Number uint64

type NumericRange

type NumericRange struct {
	BranchNode
	Lower  *Number   `(@Number`
	Upper  *RangeEnd `"-" @Number) |`
	Unary  *String   `( @Unary?`
	Number *Number   `  @Number )`
}

type PacketRangeMatch

type PacketRangeMatch struct{ NumericRange }

type PassesThroughListMatch

type PassesThroughListMatch struct {
	BranchNode
	Numbers []Number `@Number @Number*`
}

type PortRangeMatch

type PortRangeMatch struct{ NumericRange }

type PpsRangeMatch

type PpsRangeMatch struct{ NumericRange }

type ProtoKey

type ProtoKey Number

func (*ProtoKey) Capture

func (o *ProtoKey) Capture(values []string) error

type ProtoMatch

type ProtoMatch struct {
	BranchNode
	Proto    *Number   `  @Number`
	ProtoKey *ProtoKey `| @ProtoMagic`
}

type RangeEnd

type RangeEnd Number

FIXME: pseudo "negative" Number used by the printer visitor only, for emitting a "-" between children

type RegularMatchGroup

type RegularMatchGroup struct {
	BranchNode
	Router        *RouterMatch            `"router" @@`
	NextHop       *NextHopMatch           `| "nexthop" @@`
	NextHopAsn    *NextHopAsnMatch        `| "nexthopasn" @@`
	Bytes         *ByteRangeMatch         `| "bytes" @@`
	Packets       *PacketRangeMatch       `| "packets" @@`
	RemoteCountry *RemoteCountryMatch     `| "country" @@`
	FlowDirection *FlowDirectionMatch     `| "direction"? @@`
	Normalized    *NormalizedMatch        `| @@`
	Duration      *DurationRangeMatch     `| "duration" @@`
	Etype         *EtypeMatch             `| "etype" @@`
	Proto         *ProtoMatch             `| "proto" @@`
	Status        *StatusMatch            `| "status" @@`
	TcpFlags      *TcpFlagsMatch          `| "tcpflags" @@`
	IPTos         *IPTosRangeMatch        `| "iptos" @@`
	Dscp          *DscpMatch              `| "dscp" @@`
	Ecn           *EcnMatch               `| "ecn" @@`
	SamplingRate  *SamplingRateRangeMatch `| "samplingrate" @@`
	Icmp          *IcmpMatch              `| "icmp" @@`
	Bps           *BpsRangeMatch          `| "bps" @@`
	Pps           *PpsRangeMatch          `| "pps" @@`
	PassesThrough *PassesThroughListMatch `| "passes-through" @@`
	Med           *MedRangeMatch          `| "med" @@`
	LocalPref     *LocalPrefRangeMatch    `| "localpref" @@`
	Rpki          *RpkiMatch              `| "rpki" @@`
}

Regular Matches: * anything that has further sub commands or accepts fancy data * no direction * several dedicated Match structs for different data types and sub commands

type RemoteCountryMatch

type RemoteCountryMatch struct {
	BranchNode
	CountryCode *String `@CountryCode`
}

type RouterMatch

type RouterMatch struct {
	BranchNode
	Address *net.IP `@Address`
}

type RpkiKey

type RpkiKey Number

func (*RpkiKey) Capture

func (o *RpkiKey) Capture(values []string) error

type RpkiMatch

type RpkiMatch struct {
	BranchNode
	RpkiKey *RpkiKey `@RpkiMagic`
}

type SamplingRateRangeMatch

type SamplingRateRangeMatch struct{ NumericRange }

type Statement

type Statement struct {
	BranchNode
	Negated          *Boolean               `@Negation? (`
	DirectionalMatch *DirectionalMatchGroup `  @@`
	RegularMatch     *RegularMatchGroup     `| @@`
	SubExpression    *Expression            `| "(" @@ ")" )`
}

type StatusKey

type StatusKey Number

func (*StatusKey) Capture

func (o *StatusKey) Capture(values []string) error

type StatusMatch

type StatusMatch struct {
	BranchNode
	Status    *Number    `  @Number`
	StatusKey *StatusKey `| @StatusMagic`
}

type String

type String string

type TcpFlagsKey

type TcpFlagsKey Number

func (*TcpFlagsKey) Capture

func (o *TcpFlagsKey) Capture(values []string) error

type TcpFlagsMatch

type TcpFlagsMatch struct {
	BranchNode
	TcpFlags    *Number      `  @Number`
	TcpFlagsKey *TcpFlagsKey `| @TcpFlagsMagic`
}

type VrfRangeMatch

type VrfRangeMatch struct{ NumericRange }

Jump to

Keyboard shortcuts

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