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
- Variables
- func CodeStrings() []string
- func ExtcomTypeStrings() []string
- func FlowTypeStrings() []string
- func ParseNH(buf []byte) (addr, ll netip.Addr, ok bool)
- type Aggregator
- type Aspath
- func (a *Aspath) FromJSON(src []byte) error
- func (ap *Aspath) HasAsn(asn uint32, as_set int) bool
- func (ap *Aspath) HasOrigin(asn uint32, as_set int) bool
- func (a *Aspath) Marshal(dst []byte, cps caps.Caps, dir dir.Dir) []byte
- func (ap *Aspath) Origin() uint32
- func (a *Aspath) String() string
- func (a *Aspath) ToJSON(dst []byte) []byte
- func (a *Aspath) Unmarshal(buf []byte, cps caps.Caps, dir dir.Dir) error
- type AspathSegment
- type Attr
- func NewAggregator(at CodeFlags) Attr
- func NewAspath(at CodeFlags) Attr
- func NewAttr(ac Code) Attr
- func NewCommunity(at CodeFlags) Attr
- func NewExtcom(at CodeFlags) Attr
- func NewIP4(at CodeFlags) Attr
- func NewIP6(at CodeFlags) Attr
- func NewIPList4(at CodeFlags) Attr
- func NewIPList6(at CodeFlags) Attr
- func NewLargeCom(at CodeFlags) Attr
- func NewMP(at CodeFlags) Attr
- func NewOrigin(at CodeFlags) Attr
- func NewRaw(at CodeFlags) Attr
- func NewU32(at CodeFlags) Attr
- type Attrs
- func (ats *Attrs) Clear()
- func (ats *Attrs) Drop(ac Code)
- func (ats *Attrs) Each(cb func(i int, ac Code, at Attr))
- func (ats *Attrs) FromJSON(src []byte) error
- func (ats *Attrs) Get(ac Code) Attr
- func (ats *Attrs) Has(ac Code) bool
- func (ats *Attrs) Init()
- func (ats *Attrs) Len() int
- func (ats *Attrs) MarshalJSON() ([]byte, error)
- func (ats *Attrs) Reset()
- func (ats *Attrs) Set(ac Code, value Attr)
- func (ats *Attrs) SetFrom(src Attrs)
- func (ats *Attrs) ToJSON(dst []byte) []byte
- func (ats *Attrs) Use(ac Code) Attr
- func (ats *Attrs) Valid() bool
- type Code
- type CodeFlags
- type Community
- type Extcom
- func (a *Extcom) Add(et ExtcomType, val ExtcomValue)
- func (a *Extcom) Drop(et ExtcomType)
- func (a *Extcom) Find(et ExtcomType) int
- func (a *Extcom) FromJSON(src []byte) error
- func (a *Extcom) Marshal(dst []byte, cps caps.Caps, dir dir.Dir) []byte
- func (a *Extcom) ToJSON(dst []byte) []byte
- func (a *Extcom) Unmarshal(buf []byte, cps caps.Caps, dir dir.Dir) error
- type ExtcomASN
- type ExtcomAddr
- type ExtcomFlowAction
- type ExtcomFlowDSCP
- type ExtcomFlowRate
- type ExtcomFlowRedirectNH
- type ExtcomNewFunc
- type ExtcomRaw
- type ExtcomType
- func (et *ExtcomType) FromJSON(src []byte) error
- func (i ExtcomType) IsAExtcomType() bool
- func (et ExtcomType) IsTransitive() bool
- func (i ExtcomType) String() string
- func (et ExtcomType) Subtype() ExtcomType
- func (et ExtcomType) ToJSON(dst []byte) []byte
- func (et ExtcomType) Type() ExtcomType
- func (et ExtcomType) Value() ExtcomType
- type ExtcomValue
- func NewExtcomASN(et ExtcomType) ExtcomValue
- func NewExtcomAddr(et ExtcomType) ExtcomValue
- func NewExtcomFlowAction(et ExtcomType) ExtcomValue
- func NewExtcomFlowDSCP(et ExtcomType) ExtcomValue
- func NewExtcomFlowRate(et ExtcomType) ExtcomValue
- func NewExtcomFlowRedirectNH(et ExtcomType) ExtcomValue
- func NewExtcomRaw(et ExtcomType) ExtcomValue
- func NewExtcomValue(et ExtcomType) ExtcomValue
- type Flags
- type FlowGeneric
- type FlowNewFunc
- type FlowOp
- type FlowPrefix4
- type FlowPrefix6
- type FlowRaw
- type FlowRule
- type FlowType
- type FlowValue
- type IP
- type IPList
- type LargeCom
- type MP
- type MPFlowspec
- type MPNewFunc
- type MPPrefixes
- type MPValue
- type NewFunc
- type Origin
- type Raw
- type U32
Constants ¶
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 )
const ( EXTCOM_FLOW_ACTION_TERMINAL = 0b00000001 EXTCOM_FLOW_ACTION_SAMPLE = 0b00000010 )
Variables ¶
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") )
var CodeName = map[Code]string{}
var CodeValue = _CodeNameToValueMap
var DefaultFlags = map[Code]Flags{ ATTR_COMMUNITY: ATTR_TRANSITIVE, ATTR_EXT_COMMUNITY: ATTR_TRANSITIVE, ATTR_LARGE_COMMUNITY: ATTR_TRANSITIVE, ATTR_AGGREGATOR: ATTR_TRANSITIVE, }
DefaultFlags gives the default flags for attribute codes, in addition to ATTR_OPTIONAL
var ExtcomNewFuncs = map[ExtcomType]ExtcomNewFunc{ EXTCOM_FLOW_RATE_BYTES: NewExtcomFlowRate, EXTCOM_FLOW_RATE_PACKETS: NewExtcomFlowRate, EXTCOM_FLOW_ACTION: NewExtcomFlowAction, EXTCOM_FLOW_REDIRECT_AS2: NewExtcomASN, EXTCOM_FLOW_REDIRECT_IP4: NewExtcomAddr, EXTCOM_FLOW_REDIRECT_AS4: NewExtcomASN, EXTCOM_FLOW_REDIRECT_NH: NewExtcomFlowRedirectNH, EXTCOM_FLOW_DSCP: NewExtcomFlowDSCP, EXTCOM_AS2: NewExtcomASN, EXTCOM_AS4: NewExtcomASN, EXTCOM_IP4: NewExtcomAddr, }
ExtcomNewFuncs maps extended community types to their new func
var ExtcomTypeName = map[ExtcomType]string{}
var ExtcomTypeValue = _ExtcomTypeNameToValueMap
var FlowNewFuncs4 = map[FlowType]FlowNewFunc{ FLOW_SRC: NewFlowPrefix4, FLOW_DST: NewFlowPrefix4, FLOW_PROTO: NewFlowGeneric, FLOW_PORT: NewFlowGeneric, FLOW_PORT_DST: NewFlowGeneric, FLOW_PORT_SRC: NewFlowGeneric, FLOW_ICMP_TYPE: NewFlowGeneric, FLOW_ICMP_CODE: NewFlowGeneric, FLOW_TCP_FLAGS: NewFlowGeneric, FLOW_PKTLEN: NewFlowGeneric, FLOW_DSCP: NewFlowGeneric, FLOW_FRAG: NewFlowGeneric, }
FlowNewFuncs4 maps IPv4 Flowspec component types to their new funcs
var FlowNewFuncs6 = map[FlowType]FlowNewFunc{ FLOW_SRC: NewFlowPrefix6, FLOW_DST: NewFlowPrefix6, FLOW_PROTO: NewFlowGeneric, FLOW_PORT: NewFlowGeneric, FLOW_PORT_DST: NewFlowGeneric, FLOW_PORT_SRC: NewFlowGeneric, FLOW_ICMP_TYPE: NewFlowGeneric, FLOW_ICMP_CODE: NewFlowGeneric, FLOW_TCP_FLAGS: NewFlowGeneric, FLOW_PKTLEN: NewFlowGeneric, FLOW_DSCP: NewFlowGeneric, FLOW_FRAG: NewFlowGeneric, FLOW_LABEL: NewFlowGeneric, }
FlowNewFuncs6 maps IPv6 Flowspec component types to their new funcs
var FlowTypeName = map[FlowType]string{}
var FlowTypeValue = _FlowTypeNameToValueMap
var MPNewFuncs = map[afi.AS]MPNewFunc{ afi.AS_IPV4_UNICAST: NewMPPrefixes, afi.AS_IPV4_FLOWSPEC: NewMPFlowspec, afi.AS_IPV6_UNICAST: NewMPPrefixes, afi.AS_IPV6_FLOWSPEC: NewMPFlowspec, }
MPNewFuncs maps ATTR_MP_* afi/safi pairs to their NewFunc
var NewFuncs = map[Code]NewFunc{ ATTR_ORIGIN: NewOrigin, ATTR_ASPATH: NewAspath, ATTR_AS4PATH: NewAspath, ATTR_NEXTHOP: NewIP4, ATTR_MED: NewU32, ATTR_LOCALPREF: NewU32, ATTR_MP_REACH: NewMP, ATTR_MP_UNREACH: NewMP, ATTR_COMMUNITY: NewCommunity, ATTR_EXT_COMMUNITY: NewExtcom, ATTR_LARGE_COMMUNITY: NewLargeCom, ATTR_AGGREGATOR: NewAggregator, ATTR_AS4AGGREGATOR: NewAggregator, ATTR_ORIGINATOR: NewIP4, ATTR_CLUSTER_LIST: NewIPList4, }
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
Types ¶
type Aggregator ¶
Aggregator represents ATTR_AGGREGATOR / ATTR_AS4AGGREGATOR
func (*Aggregator) FromJSON ¶
func (a *Aggregator) FromJSON(src []byte) error
func (*Aggregator) ToJSON ¶
func (a *Aggregator) ToJSON(dst []byte) []byte
type Aspath ¶
type Aspath struct {
CodeFlags
Segments []AspathSegment
}
Aspath represents ATTR_ASPATH or ATTR_AS4PATH
func (*Aspath) HasAsn ¶ added in v0.4.0
HasAsn returns true if ap has given asn anywhere in AS_PATH. If as_set=1, scans AS_SETs only; if -1, ignores AS_SETs completely.
func (*Aspath) HasOrigin ¶ added in v0.4.0
HasOrigin returns true iff ap has given asn at the origin. If as_set=1, requires an AS_SET origin; if -1, requires a non-AS_SET origin. For an AS_SET origin to match the asn must be one of its elements.
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, dir dir.Dir) error
// Marshal appends wire representation to dst: type(16), length(8/16), and value
Marshal(dst []byte, cps caps.Caps, dir dir.Dir) []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 NewCommunity ¶
func NewIPList4 ¶
func NewIPList6 ¶
func NewLargeCom ¶
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) Each ¶
Each executes cb for each attribute in ats, in an ascending order of attribute codes.
func (*Attrs) Init ¶
func (ats *Attrs) Init()
Init initializes Attrs. Can be called multiple times for lazy init.
func (*Attrs) MarshalJSON ¶
func (*Attrs) SetFrom ¶
SetFrom sets all attributes from src, overwriting ats[ac] for existing attribute codes
type Code ¶
type Code byte
Code holds attribute type code
func CodeString ¶
CodeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
type CodeFlags ¶
type CodeFlags uint16
CodeFlags holds attribute flags (MSB) and type code (LSB)
func (CodeFlags) MarshalLen ¶
MarshalLen appends to dst attribute flags, code, and length FIXME: switch to always extended and write real length after (defer retfunc?)
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) Find ¶
func (a *Extcom) Find(et ExtcomType) int
Find returns index of community type et, or -1
type ExtcomAddr ¶
func (*ExtcomAddr) FromJSON ¶
func (e *ExtcomAddr) FromJSON(src []byte) error
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) 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) ToJSON ¶
func (e *ExtcomFlowDSCP) ToJSON(dst []byte) []byte
func (*ExtcomFlowDSCP) Unmarshal ¶
func (e *ExtcomFlowDSCP) Unmarshal(raw uint64) error
type ExtcomFlowRate ¶
func (*ExtcomFlowRate) FromJSON ¶
func (e *ExtcomFlowRate) FromJSON(src []byte) error
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) 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
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 FlowGeneric ¶
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) ToJSON ¶
func (f *FlowGeneric) ToJSON(dst []byte) []byte
type FlowNewFunc ¶
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 )
type FlowPrefix4 ¶
FlowPrefix4 holds IPv4 prefix
func (*FlowPrefix4) FromJSON ¶
func (f *FlowPrefix4) FromJSON(src []byte) (err error)
func (*FlowPrefix4) ToJSON ¶
func (f *FlowPrefix4) ToJSON(dst []byte) []byte
type FlowPrefix6 ¶
FlowPrefix6 holds IPv6 prefix and offset
func (*FlowPrefix6) FromJSON ¶
func (f *FlowPrefix6) FromJSON(src []byte) (err error)
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.
type FlowRaw ¶
type FlowRaw struct{ Raw []byte }
FlowRaw represents a Flowspec component as raw bytes
type FlowRule ¶
FlowRule represents a Flowspec rule, which is a set of type-value components
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 ¶
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 ¶
IsAFlowType returns "true" if the value is listed in the enum definition. "false" otherwise
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 NewFlowPrefix4 ¶
func NewFlowPrefix6 ¶
func NewFlowRaw ¶
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
type MP ¶
type MP struct {
CodeFlags
afi.AS
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) Prefixes ¶ added in v0.4.0
func (mp *MP) Prefixes() *MPPrefixes
Prefixes returns mp.Value interpreted as MPPrefixes, or nil on 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) ToJSON ¶
func (a *MPFlowspec) ToJSON(dst []byte) []byte
type MPPrefixes ¶
type MPPrefixes struct {
*MP
NextHop netip.Addr // only for ATTR_MP_REACH
LinkLocal netip.Addr // only for IPv6 NextHop, if given
Prefixes []nlri.NLRI
}
MPPrefixes represents ATTR_MP for the generic RFC4760 IP prefix encoding
func (*MPPrefixes) FromJSON ¶
func (a *MPPrefixes) FromJSON(src []byte) error
func (*MPPrefixes) ToJSON ¶
func (a *MPPrefixes) ToJSON(dst []byte) []byte
type MPValue ¶
type MPValue interface {
// Afi returns the AFI of the parent
Afi() afi.AFI
// Safi returns the SAFI of the parent
Safi() afi.SAFI
// Unmarshal parses wire representation from the parent
Unmarshal(cps caps.Caps, dir dir.Dir) error
// Marshal writes wire representation to the parent
Marshal(cps caps.Caps, dir dir.Dir)
// 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 ¶
NewMPFlowspec returns, for a parent mp attribute, a new MPValue implementing Flowspec
func NewMPPrefixes ¶
func NewMPValue ¶
NewMPValue returns a new MPValue for parent mp, or nil if its AFI/SAFI pair is not supported.