attrs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package attrs represents BGP path attributes.

This package can store a set of BGP attributes in a thread-unsafe map using the Attrs type, and read/write a particular BGP attribute representation using implementations of the Attr interface.

Index

Constants

View Source
const (
	// attribute flags
	ATTR_OPTIONAL   Flags = 0b10000000
	ATTR_TRANSITIVE Flags = 0b01000000
	ATTR_PARTIAL    Flags = 0b00100000
	ATTR_EXTENDED   Flags = 0b00010000
	ATTR_UNUSED     Flags = 0b00001111

	// attribute codes
	ATTR_UNSPECIFIED        Code = 0
	ATTR_ORIGIN             Code = 1
	ATTR_ASPATH             Code = 2
	ATTR_NEXTHOP            Code = 3
	ATTR_MED                Code = 4
	ATTR_LOCALPREF          Code = 5
	ATTR_AGGREGATE          Code = 6
	ATTR_AGGREGATOR         Code = 7
	ATTR_COMMUNITY          Code = 8
	ATTR_ORIGINATOR         Code = 9
	ATTR_CLUSTER_LIST       Code = 10
	ATTR_MP_REACH           Code = 14
	ATTR_MP_UNREACH         Code = 15
	ATTR_EXT_COMMUNITY      Code = 16
	ATTR_AS4PATH            Code = 17
	ATTR_AS4AGGREGATOR      Code = 18
	ATTR_PMSI_TUNNEL        Code = 22
	ATTR_TUNNEL             Code = 23
	ATTR_TRAFFIC_ENG        Code = 24
	ATTR_IPV6_EXT_COMMUNITY Code = 25
	ATTR_AIGP               Code = 26
	ATTR_PE_DISTING         Code = 27
	ATTR_BGP_LS             Code = 29
	ATTR_LARGE_COMMUNITY    Code = 32
	ATTR_BGPSEC_PATH        Code = 33
	ATTR_OTC                Code = 35
	ATTR_DPATH              Code = 36
	ATTR_SFP_ATTR           Code = 37
	ATTR_BFD_DISCRIMINATOR  Code = 38
	ATTR_RCA                Code = 39
	ATTR_PREFIX_SID         Code = 40
	ATTR_SET                Code = 128
)
View Source
const (
	EXTCOM_FLOW_ACTION_TERMINAL = 0b00000001
	EXTCOM_FLOW_ACTION_SAMPLE   = 0b00000010
)

Variables

View Source
var (
	ErrTODO   = errors.New("not implemented")
	ErrValue  = errors.New("invalid value")
	ErrLength = errors.New("invalid length")

	ErrAF          = errors.New("invalid IP version")
	ErrAttrCode    = errors.New("invalid attribute code")
	ErrAttrFlags   = errors.New("invalid attribute flags")
	ErrAttrValue   = errors.New("invalid attribute value")
	ErrSegType     = errors.New("invalid ASPATH segment type")
	ErrSegLen      = errors.New("invalid ASPATH segment length")
	ErrFlowType    = errors.New("invalid Flowspec component type")
	ErrFlowValue   = errors.New("invalid Flowspec component value")
	ErrExtcomType  = errors.New("invalid extended community type")
	ErrExtcomValue = errors.New("invalid extended community value")
)
View Source
var CodeName = map[Code]string{}
View Source
var CodeValue = _CodeNameToValueMap

DefaultFlags gives the default flags for attribute codes, in addition to ATTR_OPTIONAL

ExtcomNewFuncs maps extended community types to their new func

View Source
var ExtcomTypeName = map[ExtcomType]string{}
View Source
var ExtcomTypeValue = _ExtcomTypeNameToValueMap

FlowNewFuncs4 maps IPv4 Flowspec component types to their new funcs

FlowNewFuncs6 maps IPv6 Flowspec component types to their new funcs

View Source
var FlowTypeName = map[FlowType]string{}
View Source
var FlowTypeValue = _FlowTypeNameToValueMap

MPNewFuncs maps ATTR_MP_* afi/safi pairs to their NewFunc

NewFuncs maps attribute codes to their NewFunc

Functions

func CodeStrings

func CodeStrings() []string

CodeStrings returns a slice of all String values of the enum

func ExtcomTypeStrings

func ExtcomTypeStrings() []string

ExtcomTypeStrings returns a slice of all String values of the enum

func FlowTypeStrings

func FlowTypeStrings() []string

FlowTypeStrings returns a slice of all String values of the enum

func ParseNH

func ParseNH(buf []byte) (addr, ll netip.Addr, ok bool)

ParseNH is best-effort parser for Next Hop value in buf

func ReadPrefixes

func ReadPrefixes(dst []netip.Prefix, buf []byte, ipv6 bool) ([]netip.Prefix, error)

ReadPrefixes reads IP prefixes from buf into dst

func WritePrefix

func WritePrefix(dst []byte, p netip.Prefix) []byte

WritePrefix writes prefix p to dst

func WritePrefixes

func WritePrefixes(dst []byte, src []netip.Prefix) []byte

WritePrefixes writes prefixes in src to dst

Types

type Aggregator

type Aggregator struct {
	CodeFlags
	ASN  uint32
	Addr netip.Addr
}

Aggregator represents ATTR_AGGREGATOR / ATTR_AS4AGGREGATOR

func (*Aggregator) FromJSON

func (a *Aggregator) FromJSON(src []byte) error

func (*Aggregator) Marshal

func (a *Aggregator) Marshal(dst []byte, cps caps.Caps) []byte

func (*Aggregator) ToJSON

func (a *Aggregator) ToJSON(dst []byte) []byte

func (*Aggregator) Unmarshal

func (a *Aggregator) Unmarshal(buf []byte, cps caps.Caps) error

type Aspath

type Aspath struct {
	CodeFlags
	Segments []AspathSegment
}

Aspath represents ATTR_ASPATH or ATTR_AS4PATH

func (*Aspath) FromJSON

func (a *Aspath) FromJSON(src []byte) error

func (*Aspath) Marshal

func (a *Aspath) Marshal(dst []byte, cps caps.Caps) []byte

func (*Aspath) String added in v0.1.4

func (a *Aspath) String() string

func (*Aspath) ToJSON

func (a *Aspath) ToJSON(dst []byte) []byte

func (*Aspath) Unmarshal

func (a *Aspath) Unmarshal(buf []byte, cps caps.Caps) error

type AspathSegment

type AspathSegment struct {
	IsSet bool     // true iff segment is an AS_SET
	List  []uint32 // list of AS numbers
}

AspathSegment represents an AS_PATH segment

type Attr

type Attr interface {
	// Code returns attribute code
	Code() Code

	// Flags returns attribute flags
	Flags() Flags

	// SetFlags sets attribute flags
	SetFlags(Flags)

	// Unmarshal parses wire representation from src
	Unmarshal(src []byte, cps caps.Caps) error

	// Marshal appends wire representation to dst: type(16), length(8/16), and value
	Marshal(dst []byte, cps caps.Caps) []byte

	// ToJSON appends JSON representation of the value to dst
	ToJSON(dst []byte) []byte

	// FromJSON reads from JSON representation in src
	FromJSON(src []byte) error
}

Attr represents a particular BGP path attribute

func NewAggregator

func NewAggregator(at CodeFlags) Attr

func NewAspath

func NewAspath(at CodeFlags) Attr

func NewAttr

func NewAttr(ac Code) Attr

NewAttr returns a new Attr instance for given code ac and default flags.

func NewCommunity

func NewCommunity(at CodeFlags) Attr

func NewExtcom

func NewExtcom(at CodeFlags) Attr

func NewIP4

func NewIP4(at CodeFlags) Attr

func NewIP6

func NewIP6(at CodeFlags) Attr

func NewIPList4

func NewIPList4(at CodeFlags) Attr

func NewIPList6

func NewIPList6(at CodeFlags) Attr

func NewLargeCom

func NewLargeCom(at CodeFlags) Attr

func NewMP

func NewMP(at CodeFlags) Attr

func NewOrigin

func NewOrigin(at CodeFlags) Attr

func NewRaw

func NewRaw(at CodeFlags) Attr

func NewU32

func NewU32(at CodeFlags) Attr

type Attrs

type Attrs struct {
	// contains filtered or unexported fields
}

Attrs is an ordinary map that represents a set of BGP path attributes. It should not contain nil values.

Attrs and its values are not thread-safe.

func (*Attrs) AsOrigin added in v0.1.4

func (ats *Attrs) AsOrigin() uint32

AsOrigin returns the last AS in AS_PATH, or 0 on error

func (*Attrs) AsPath added in v0.1.4

func (ats *Attrs) AsPath() *Aspath

Aspath returns the ATTR_ASPATH from u, or nil if not defined. TODO: support ATTR_AS4PATH

func (*Attrs) Clear

func (ats *Attrs) Clear()

Clear drops all attributes.

func (*Attrs) Drop

func (ats *Attrs) Drop(ac Code)

Drop drops ats[ac].

func (*Attrs) Each

func (ats *Attrs) Each(cb func(i int, ac Code, at Attr))

Each executes cb for each attribute in ats, in an ascending order of attribute codes.

func (*Attrs) FromJSON

func (ats *Attrs) FromJSON(src []byte) error

func (*Attrs) Get

func (ats *Attrs) Get(ac Code) Attr

Get returns ats[ac] or nil if not possible.

func (*Attrs) Has

func (ats *Attrs) Has(ac Code) bool

Has returns true iff ats[ac] is set and non-nil

func (*Attrs) Init

func (ats *Attrs) Init()

Init initializes Attrs. Can be called multiple times for lazy init.

func (*Attrs) Len

func (ats *Attrs) Len() int

Len returns the number of attributes

func (*Attrs) MP added in v0.1.4

func (ats *Attrs) MP(ac Code) *MP

MP returns raw MP-BGP attribute ac

func (*Attrs) MPPrefixes added in v0.1.4

func (ats *Attrs) MPPrefixes(ac Code) *MPPrefixes

MPPrefixes returns *MPPrefixes MP-BGP attribute ac

func (*Attrs) MarshalJSON

func (ats *Attrs) MarshalJSON() ([]byte, error)

func (*Attrs) Reset

func (ats *Attrs) Reset()

Reset resets Attrs back to initial state.

func (*Attrs) Set

func (ats *Attrs) Set(ac Code, value Attr)

Set overwrites ats[ac] with value.

func (*Attrs) SetFrom

func (ats *Attrs) SetFrom(src Attrs)

SetFrom sets all attributes from src, overwriting ats[ac] for existing attribute codes

func (*Attrs) ToJSON

func (ats *Attrs) ToJSON(dst []byte) []byte

func (*Attrs) Use

func (ats *Attrs) Use(ac Code) Attr

Use returns ats[ac] if its already set and non-nil. Otherwise, it adds a new instance for ac with default flags.

func (*Attrs) Valid

func (ats *Attrs) Valid() bool

Valid returns true iff Attrs has already been initialized

type Code

type Code byte

Code holds attribute type code

func CodeString

func CodeString(s string) (Code, error)

CodeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func CodeValues

func CodeValues() []Code

CodeValues returns all values of the enum

func (*Code) FromJSON

func (ac *Code) FromJSON(src string) error

FromJSON() sets ac from JSON in src

func (Code) IsACode

func (i Code) IsACode() bool

IsACode returns "true" if the value is listed in the enum definition. "false" otherwise

func (Code) String

func (i Code) String() string

func (Code) ToJSON

func (ac Code) ToJSON(dst []byte) []byte

ToJSON() appends ac name as a JSON string to dst

type CodeFlags

type CodeFlags uint16

CodeFlags holds attribute flags (MSB) and type code (LSB)

func (CodeFlags) Code

func (cf CodeFlags) Code() Code

Code returns cf code (eg. ATTR_NEXTHOP)

func (CodeFlags) Flags

func (cf CodeFlags) Flags() Flags

Flags returns cf flags (eg. ATTR_TRANSITIVE)

func (CodeFlags) HasFlags

func (cf CodeFlags) HasFlags(af Flags) bool

HasFlags returns true iff af has (at least one of) flags set

func (CodeFlags) MarshalLen

func (cf CodeFlags) MarshalLen(dst []byte, length int) []byte

MarshalLen appends to dst attribute flags, code, and length FIXME: switch to always extended and write real length after (defer retfunc?)

func (*CodeFlags) SetFlags

func (cf *CodeFlags) SetFlags(af Flags)

SetFlags overwrites flags

type Community

type Community struct {
	CodeFlags
	ASN   []uint16
	Value []uint16
}

Community represents ATTR_COMMUNITY

func (*Community) Add

func (a *Community) Add(asn uint16, value uint16)

func (*Community) FromJSON

func (a *Community) FromJSON(src []byte) error

func (*Community) Marshal

func (a *Community) Marshal(dst []byte, cps caps.Caps) []byte

func (*Community) ToJSON

func (a *Community) ToJSON(dst []byte) []byte

func (*Community) Unmarshal

func (a *Community) Unmarshal(buf []byte, cps caps.Caps) error

type Extcom

type Extcom struct {
	CodeFlags

	Type  []ExtcomType  // top 2 bytes (always the "Extended" type)
	Value []ExtcomValue // bottom 6 bytes
}

Extcom represents ATTR_EXT_COMMUNITY

func (*Extcom) Add

func (a *Extcom) Add(et ExtcomType, val ExtcomValue)

Add appends extended community type et with value val

func (*Extcom) Drop

func (a *Extcom) Drop(et ExtcomType)

Drop drops extended community type et

func (*Extcom) Find

func (a *Extcom) Find(et ExtcomType) int

Find returns index of community type et, or -1

func (*Extcom) FromJSON

func (a *Extcom) FromJSON(src []byte) error

func (*Extcom) Marshal

func (a *Extcom) Marshal(dst []byte, cps caps.Caps) []byte

func (*Extcom) ToJSON

func (a *Extcom) ToJSON(dst []byte) []byte

func (*Extcom) Unmarshal

func (a *Extcom) Unmarshal(buf []byte, cps caps.Caps) error

type ExtcomASN

type ExtcomASN struct {
	ASN   uint32
	Value uint32
	// contains filtered or unexported fields
}

2- or 4-byte ASN-specific value

func (*ExtcomASN) FromJSON

func (e *ExtcomASN) FromJSON(src []byte) error

func (*ExtcomASN) Marshal

func (e *ExtcomASN) Marshal(cps caps.Caps) uint64

func (*ExtcomASN) ToJSON

func (e *ExtcomASN) ToJSON(dst []byte) []byte

func (*ExtcomASN) Unmarshal

func (e *ExtcomASN) Unmarshal(raw uint64) error

type ExtcomAddr

type ExtcomAddr struct {
	Addr  netip.Addr
	Value uint16
}

func (*ExtcomAddr) FromJSON

func (e *ExtcomAddr) FromJSON(src []byte) error

func (*ExtcomAddr) Marshal

func (e *ExtcomAddr) Marshal(cps caps.Caps) uint64

func (*ExtcomAddr) ToJSON

func (e *ExtcomAddr) ToJSON(dst []byte) []byte

func (*ExtcomAddr) Unmarshal

func (e *ExtcomAddr) Unmarshal(raw uint64) error

type ExtcomFlowAction

type ExtcomFlowAction struct {
	Terminal bool // if set, keep collecting rules and apply all that match
	Sample   bool // if set, enable sampling and logging
}

func (*ExtcomFlowAction) FromJSON

func (e *ExtcomFlowAction) FromJSON(src []byte) error

func (*ExtcomFlowAction) Marshal

func (e *ExtcomFlowAction) Marshal(cps caps.Caps) uint64

func (*ExtcomFlowAction) ToJSON

func (e *ExtcomFlowAction) ToJSON(dst []byte) []byte

func (*ExtcomFlowAction) Unmarshal

func (e *ExtcomFlowAction) Unmarshal(raw uint64) error

type ExtcomFlowDSCP

type ExtcomFlowDSCP struct {
	DSCP uint8
}

func (*ExtcomFlowDSCP) FromJSON

func (e *ExtcomFlowDSCP) FromJSON(src []byte) error

func (*ExtcomFlowDSCP) Marshal

func (e *ExtcomFlowDSCP) Marshal(cps caps.Caps) uint64

func (*ExtcomFlowDSCP) ToJSON

func (e *ExtcomFlowDSCP) ToJSON(dst []byte) []byte

func (*ExtcomFlowDSCP) Unmarshal

func (e *ExtcomFlowDSCP) Unmarshal(raw uint64) error

type ExtcomFlowRate

type ExtcomFlowRate struct {
	Id   uint16
	Rate float32
}

func (*ExtcomFlowRate) FromJSON

func (e *ExtcomFlowRate) FromJSON(src []byte) error

func (*ExtcomFlowRate) Marshal

func (e *ExtcomFlowRate) Marshal(cps caps.Caps) uint64

func (*ExtcomFlowRate) ToJSON

func (e *ExtcomFlowRate) ToJSON(dst []byte) []byte

func (*ExtcomFlowRate) Unmarshal

func (e *ExtcomFlowRate) Unmarshal(raw uint64) error

type ExtcomFlowRedirectNH

type ExtcomFlowRedirectNH struct {
	Copy bool
}

func (*ExtcomFlowRedirectNH) FromJSON

func (e *ExtcomFlowRedirectNH) FromJSON(src []byte) error

func (*ExtcomFlowRedirectNH) Marshal

func (e *ExtcomFlowRedirectNH) Marshal(cps caps.Caps) uint64

func (*ExtcomFlowRedirectNH) ToJSON

func (e *ExtcomFlowRedirectNH) ToJSON(dst []byte) []byte

func (*ExtcomFlowRedirectNH) Unmarshal

func (e *ExtcomFlowRedirectNH) Unmarshal(raw uint64) error

type ExtcomNewFunc

type ExtcomNewFunc func(ExtcomType) ExtcomValue

ExtcomNewFunc returns a new ExtcomValue for given type

type ExtcomRaw

type ExtcomRaw struct {
	// contains filtered or unexported fields
}

The basic (raw) Extended Community value

func (*ExtcomRaw) FromJSON

func (e *ExtcomRaw) FromJSON(src []byte) error

func (*ExtcomRaw) Marshal

func (e *ExtcomRaw) Marshal(cps caps.Caps) uint64

func (*ExtcomRaw) ToJSON

func (e *ExtcomRaw) ToJSON(dst []byte) []byte

func (*ExtcomRaw) Unmarshal

func (e *ExtcomRaw) Unmarshal(src uint64) error

type ExtcomType

type ExtcomType uint16

Extended Community Type

const (
	// bitmasks
	EXTCOM_TYPE       ExtcomType = 0b1011111100000000
	EXTCOM_SUBTYPE    ExtcomType = 0b0000000011111111
	EXTCOM_TRANSITIVE ExtcomType = 0b0100000000000000

	// types
	EXTCOM_AS2 ExtcomType = 0x0000
	EXTCOM_IP4 ExtcomType = 0x0100
	EXTCOM_AS4 ExtcomType = 0x0200

	// subtypes
	EXTCOM_TARGET ExtcomType = 0x0002
	EXTCOM_ORIGIN ExtcomType = 0x0003

	// target
	EXTCOM_AS2_TARGET ExtcomType = EXTCOM_AS2 | EXTCOM_TARGET
	EXTCOM_AS4_TARGET ExtcomType = EXTCOM_AS4 | EXTCOM_TARGET
	EXTCOM_IP4_TARGET ExtcomType = EXTCOM_IP4 | EXTCOM_TARGET

	// origin
	EXTCOM_AS2_ORIGIN ExtcomType = EXTCOM_AS2 | EXTCOM_ORIGIN
	EXTCOM_AS4_ORIGIN ExtcomType = EXTCOM_AS4 | EXTCOM_ORIGIN
	EXTCOM_IP4_ORIGIN ExtcomType = EXTCOM_IP4 | EXTCOM_ORIGIN

	// flowspec
	EXTCOM_FLOW_RATE_BYTES   ExtcomType = 0x8006
	EXTCOM_FLOW_RATE_PACKETS ExtcomType = 0x800c
	EXTCOM_FLOW_ACTION       ExtcomType = 0x8007
	EXTCOM_FLOW_REDIRECT_AS2 ExtcomType = 0x8008
	EXTCOM_FLOW_REDIRECT_IP4 ExtcomType = 0x8108
	EXTCOM_FLOW_REDIRECT_AS4 ExtcomType = 0x8208
	EXTCOM_FLOW_REDIRECT_NH  ExtcomType = 0x0800 // draft-simpson-idr-flowspec-redirect-02.txt
	EXTCOM_FLOW_DSCP         ExtcomType = 0x8009
)

func ExtcomTypeString

func ExtcomTypeString(s string) (ExtcomType, error)

ExtcomTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ExtcomTypeValues

func ExtcomTypeValues() []ExtcomType

ExtcomTypeValues returns all values of the enum

func (*ExtcomType) FromJSON

func (et *ExtcomType) FromJSON(src []byte) error

func (ExtcomType) IsAExtcomType

func (i ExtcomType) IsAExtcomType() bool

IsAExtcomType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ExtcomType) IsTransitive

func (et ExtcomType) IsTransitive() bool

IsTransitive returns true iff et is transitive across ASes

func (ExtcomType) String

func (i ExtcomType) String() string

func (ExtcomType) Subtype

func (et ExtcomType) Subtype() ExtcomType

Subtype returns et with the type set to 0

func (ExtcomType) ToJSON

func (et ExtcomType) ToJSON(dst []byte) []byte

func (ExtcomType) Type

func (et ExtcomType) Type() ExtcomType

Type returns et with the transitive bit and subtype set to 0

func (ExtcomType) Value

func (et ExtcomType) Value() ExtcomType

Value returns et with the transitive bit set to 0 (meaning transitive across ASes)

type ExtcomValue

type ExtcomValue interface {
	// Unmarshal NewExtcoms wire representation from src
	Unmarshal(src uint64) error

	// Marshal returns wire representation of the value
	Marshal(cps caps.Caps) uint64

	// ToJSON appends JSON representation of the value to dst
	ToJSON(dst []byte) []byte

	// FromJSON reads value from JSON representation in src
	FromJSON(src []byte) error
}

Extended Community Value

func NewExtcomASN

func NewExtcomASN(et ExtcomType) ExtcomValue

func NewExtcomAddr

func NewExtcomAddr(et ExtcomType) ExtcomValue

func NewExtcomFlowAction

func NewExtcomFlowAction(et ExtcomType) ExtcomValue

func NewExtcomFlowDSCP

func NewExtcomFlowDSCP(et ExtcomType) ExtcomValue

func NewExtcomFlowRate

func NewExtcomFlowRate(et ExtcomType) ExtcomValue

func NewExtcomFlowRedirectNH

func NewExtcomFlowRedirectNH(et ExtcomType) ExtcomValue

func NewExtcomRaw

func NewExtcomRaw(et ExtcomType) ExtcomValue

func NewExtcomValue

func NewExtcomValue(et ExtcomType) ExtcomValue

NewExtcomValue returns a new ExtcomValue for given ExtcomType

type Flags

type Flags byte

Flags holds attribute flags

func (*Flags) FromJSON

func (af *Flags) FromJSON(src []byte) error

func (Flags) ToJSON

func (af Flags) ToJSON(dst []byte) []byte

type FlowGeneric

type FlowGeneric struct {
	Type FlowType
	Op   []FlowOp
	Val  []uint64
}

FlowGeneric represents a generic flowtype with a list of (operator, value) pairs

func (*FlowGeneric) FromJSON

func (f *FlowGeneric) FromJSON(src []byte) (err error)

func (*FlowGeneric) Marshal

func (f *FlowGeneric) Marshal(dst []byte, cps caps.Caps) []byte

func (*FlowGeneric) ToJSON

func (f *FlowGeneric) ToJSON(dst []byte) []byte

func (*FlowGeneric) Unmarshal

func (fv *FlowGeneric) Unmarshal(buf []byte, cps caps.Caps) (int, error)

type FlowNewFunc

type FlowNewFunc func(FlowType) FlowValue

FlowNewFunc returns a new FlowValue for given FlowType

type FlowOp

type FlowOp uint16

FlowOp represents a Flowspec operator (numeric or bitmask)

const (
	FLOW_OP_IS_BITMASK FlowOp = 0x0100

	FLOW_OP_LAST FlowOp = 0b10000000
	FLOW_OP_AND  FlowOp = 0b01000000
	FLOW_OP_LEN  FlowOp = 0b00110000

	FLOW_OP_NUM FlowOp = 0b00000111 // numeric
	FLOW_OP_LT  FlowOp = 0b00000100 // numeric
	FLOW_OP_GT  FlowOp = 0b00000010 // numeric
	FLOW_OP_EQ  FlowOp = 0b00000001 // numeric

	FLOW_OP_BIT   FlowOp = 0b00000011 // bitmask
	FLOW_OP_NOT   FlowOp = 0b00000010 // bitmask
	FLOW_OP_MATCH FlowOp = 0b00000001 // bitmask
)

func (FlowOp) Len

func (op FlowOp) Len() int

Len returns the length of the corresponding value: either 1, 2, 4, or 8

type FlowPrefix4

type FlowPrefix4 struct{ netip.Prefix }

FlowPrefix4 holds IPv4 prefix

func (*FlowPrefix4) FromJSON

func (f *FlowPrefix4) FromJSON(src []byte) (err error)

func (*FlowPrefix4) Marshal

func (f *FlowPrefix4) Marshal(dst []byte, cps caps.Caps) []byte

func (*FlowPrefix4) ToJSON

func (f *FlowPrefix4) ToJSON(dst []byte) []byte

func (*FlowPrefix4) Unmarshal

func (f *FlowPrefix4) Unmarshal(buf []byte, cps caps.Caps) (int, error)

type FlowPrefix6

type FlowPrefix6 struct {
	Prefix netip.Prefix
	Offset int
}

FlowPrefix6 holds IPv6 prefix and offset

func (*FlowPrefix6) FromJSON

func (f *FlowPrefix6) FromJSON(src []byte) (err error)

func (*FlowPrefix6) Marshal

func (f *FlowPrefix6) Marshal(dst []byte, cps caps.Caps) []byte

func (*FlowPrefix6) ToJSON

func (f *FlowPrefix6) ToJSON(dst []byte) []byte

ToJSON encodes f as JSON. It writes "ipv6address/offset-length", if offset>0. Otherwise, just an ordinary prefix.

func (*FlowPrefix6) Unmarshal

func (f *FlowPrefix6) Unmarshal(buf []byte, cps caps.Caps) (int, error)

type FlowRaw

type FlowRaw struct{ Raw []byte }

FlowRaw represents a Flowspec component as raw bytes

func (*FlowRaw) FromJSON

func (f *FlowRaw) FromJSON(src []byte) (err error)

func (*FlowRaw) Marshal

func (f *FlowRaw) Marshal(dst []byte, cps caps.Caps) []byte

func (*FlowRaw) ToJSON

func (f *FlowRaw) ToJSON(dst []byte) []byte

func (*FlowRaw) Unmarshal

func (f *FlowRaw) Unmarshal(src []byte, cps caps.Caps) (int, error)

type FlowRule

type FlowRule map[FlowType]FlowValue

FlowRule represents a Flowspec rule, which is a set of type-value components

func (FlowRule) FromJSON

func (fr FlowRule) FromJSON(src []byte, afi af.AFI) error

func (FlowRule) Marshal

func (fr FlowRule) Marshal(dst []byte, cps caps.Caps) []byte

Marshal writes wire representation of all components in fr to dst, without the length

func (FlowRule) ToJSON

func (fr FlowRule) ToJSON(dst []byte) []byte

type FlowType

type FlowType uint8

FlowType represents a Flowspec component type

const (
	FLOW_DST       FlowType = 1
	FLOW_SRC       FlowType = 2
	FLOW_PROTO     FlowType = 3
	FLOW_PORT      FlowType = 4
	FLOW_PORT_DST  FlowType = 5
	FLOW_PORT_SRC  FlowType = 6
	FLOW_ICMP_TYPE FlowType = 7
	FLOW_ICMP_CODE FlowType = 8
	FLOW_TCP_FLAGS FlowType = 9
	FLOW_PKTLEN    FlowType = 10
	FLOW_DSCP      FlowType = 11
	FLOW_FRAG      FlowType = 12
	FLOW_LABEL     FlowType = 13
)

func FlowTypeString

func FlowTypeString(s string) (FlowType, error)

FlowTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func FlowTypeValues

func FlowTypeValues() []FlowType

FlowTypeValues returns all values of the enum

func (FlowType) IsAFlowType

func (i FlowType) IsAFlowType() bool

IsAFlowType returns "true" if the value is listed in the enum definition. "false" otherwise

func (FlowType) String

func (i FlowType) String() string

type FlowValue

type FlowValue interface {
	// Unmarshal parses wire representation from src
	Unmarshal(src []byte, cps caps.Caps) (int, error)

	// Marshal appends wire representation to dst, without type
	Marshal(dst []byte, cps caps.Caps) []byte

	// ToJSON appends JSON representation of the component to dst
	ToJSON(dst []byte) []byte

	// FromJSON reads from JSON representation in src
	FromJSON(src []byte) error
}

FlowValue represents a Flowspec component value

func NewFlowGeneric

func NewFlowGeneric(ft FlowType) FlowValue

func NewFlowPrefix4

func NewFlowPrefix4(_ FlowType) FlowValue

func NewFlowPrefix6

func NewFlowPrefix6(_ FlowType) FlowValue

func NewFlowRaw

func NewFlowRaw(FlowType) FlowValue

func NewFlowValue

func NewFlowValue(ft FlowType, afi af.AFI) FlowValue

NewFlowValue returns a new FlowValue for given FlowType and AFI

type IP

type IP struct {
	CodeFlags
	IPv6 bool
	Addr netip.Addr
}

IP represents IP address attributes, eg. ATTR_NEXTHOP / ATTR_ORIGINATOR

func (*IP) FromJSON

func (a *IP) FromJSON(src []byte) (err error)

func (*IP) Marshal

func (a *IP) Marshal(dst []byte, cps caps.Caps) []byte

func (*IP) ToJSON

func (a *IP) ToJSON(dst []byte) []byte

func (*IP) Unmarshal

func (a *IP) Unmarshal(buf []byte, cps caps.Caps) error

type IPList

type IPList struct {
	CodeFlags
	IPv6 bool
	Addr []netip.Addr
}

IPList represents IP prefix list attributes, eg. ATTR_CLUSTER_LIST

func (*IPList) FromJSON

func (a *IPList) FromJSON(src []byte) (reterr error)

func (*IPList) Marshal

func (a *IPList) Marshal(dst []byte, cps caps.Caps) []byte

func (*IPList) ToJSON

func (a *IPList) ToJSON(dst []byte) []byte

func (*IPList) Unmarshal

func (a *IPList) Unmarshal(buf []byte, cps caps.Caps) error

type LargeCom

type LargeCom struct {
	CodeFlags

	ASN    []uint32 // Global Administrator
	Value1 []uint32 // Local Data Part 1
	Value2 []uint32 // Local Data Part 2
}

LargeCom represents ATTR_LARGE_COMMUNITY

func (*LargeCom) Add

func (a *LargeCom) Add(asn, value1, value2 uint32)

func (*LargeCom) FromJSON

func (a *LargeCom) FromJSON(src []byte) error

func (*LargeCom) Marshal

func (a *LargeCom) Marshal(dst []byte, cps caps.Caps) []byte

func (*LargeCom) ToJSON

func (a *LargeCom) ToJSON(dst []byte) []byte

func (*LargeCom) Unmarshal

func (a *LargeCom) Unmarshal(buf []byte, cps caps.Caps) error

type MP

type MP struct {
	CodeFlags
	af.AF

	NH    []byte  // only for ATTR_MP_REACH
	Data  []byte  // NLRI or unreachable
	Value MPValue // interpreted NH / Data (may be nil)
}

MP represents ATTR_MP_REACH and ATTR_MP_UNREACH attributes

func (*MP) FromJSON

func (mp *MP) FromJSON(src []byte) error

func (*MP) Marshal

func (mp *MP) Marshal(dst []byte, cps caps.Caps) []byte

func (*MP) ToJSON

func (mp *MP) ToJSON(dst []byte) []byte

func (*MP) Unmarshal

func (mp *MP) Unmarshal(buf []byte, cps caps.Caps) error

type MPFlowspec

type MPFlowspec struct {
	*MP

	NextHop   netip.Addr // best-effort
	LinkLocal netip.Addr // best-effort
	Rules     []FlowRule // see RFC8955 Fig1
}

MPFlowspec represents ATTR_MP attributes for RFC8955 and RFC8956 Flowspec

func (*MPFlowspec) FromJSON

func (a *MPFlowspec) FromJSON(src []byte) error

func (*MPFlowspec) Marshal

func (a *MPFlowspec) Marshal(cps caps.Caps)

func (*MPFlowspec) ToJSON

func (a *MPFlowspec) ToJSON(dst []byte) []byte

func (*MPFlowspec) Unmarshal

func (a *MPFlowspec) Unmarshal(cps caps.Caps) error

type MPNewFunc

type MPNewFunc func(mp *MP) MPValue

MPNewFunc returns new ATTR_MP_* value for afi/safi in mp

type MPPrefixes

type MPPrefixes struct {
	*MP

	NextHop   netip.Addr // only for ATTR_MP_REACH
	LinkLocal netip.Addr // only for IPv6 NextHop, if given
	Prefixes  []netip.Prefix
}

MPPrefixes represents ATTR_MP for the generic RFC4760 IP prefix encoding

func (*MPPrefixes) FromJSON

func (a *MPPrefixes) FromJSON(src []byte) error

func (*MPPrefixes) Marshal

func (a *MPPrefixes) Marshal(cps caps.Caps)

func (*MPPrefixes) ToJSON

func (a *MPPrefixes) ToJSON(dst []byte) []byte

func (*MPPrefixes) Unmarshal

func (a *MPPrefixes) Unmarshal(cps caps.Caps) error

type MPValue

type MPValue interface {
	// Afi returns the AFI of the parent
	Afi() af.AFI

	// Safi returns the SAFI of the parent
	Safi() af.SAFI

	// Unmarshal parses wire representation from the parent
	Unmarshal(cps caps.Caps) error

	// Marshal writes wire representation to the parent
	Marshal(cps caps.Caps)

	// ToJSON appends *JSON keys* to dst (will be embedded in the parent object)
	ToJSON(dst []byte) []byte

	// FromJSON reads from JSON object in src (full parent object)
	FromJSON(src []byte) error
}

MP attribute Value

func NewMPFlowspec

func NewMPFlowspec(mp *MP) MPValue

NewMPFlowspec returns, for a parent mp attribute, a new MPValue implementing Flowspec

func NewMPPrefixes

func NewMPPrefixes(mp *MP) MPValue

func NewMPValue

func NewMPValue(mp *MP) MPValue

NewMPValue returns a new MPValue for parent mp, or nil if its AFI/SAFI pair is not supported.

type NewFunc

type NewFunc func(cf CodeFlags) Attr

NewFunc returns new Attr for given type at.

type Origin

type Origin struct {
	CodeFlags
	Origin byte
}

Origin represents ATTR_ORIGIN

func (*Origin) FromJSON

func (a *Origin) FromJSON(src []byte) (err error)

func (*Origin) Marshal

func (a *Origin) Marshal(dst []byte, cps caps.Caps) []byte

func (*Origin) ToJSON

func (a *Origin) ToJSON(dst []byte) []byte

func (*Origin) Unmarshal

func (a *Origin) Unmarshal(buf []byte, cps caps.Caps) error

type Raw

type Raw struct {
	CodeFlags
	Raw []byte
}

Raw represents generic raw attribute

func (*Raw) FromJSON

func (a *Raw) FromJSON(src []byte) (err error)

func (*Raw) Marshal

func (a *Raw) Marshal(dst []byte, cps caps.Caps) []byte

func (*Raw) ToJSON

func (a *Raw) ToJSON(dst []byte) []byte

func (*Raw) Unmarshal

func (a *Raw) Unmarshal(buf []byte, cps caps.Caps) error

type U32

type U32 struct {
	CodeFlags
	Val uint32
}

U32 represents uint32 valued attributes, eg. ATTR_MULTI_EXIT_DISC / ATTR_LOCALPREF

func (*U32) FromJSON

func (a *U32) FromJSON(src []byte) (err error)

func (*U32) Marshal

func (a *U32) Marshal(dst []byte, cps caps.Caps) []byte

func (*U32) ToJSON

func (a *U32) ToJSON(dst []byte) []byte

func (*U32) Unmarshal

func (a *U32) Unmarshal(buf []byte, cps caps.Caps) error

Jump to

Keyboard shortcuts

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