Documentation
¶
Overview ¶
Package msg represents BGP messages.
This package can read/write BGP messages in wire and JSON formats.
Index ¶
- Constants
- Variables
- func DstStrings() []string
- func TypeStrings() []string
- type Dst
- type Msg
- func (msg *Msg) CopyData() *Msg
- func (msg *Msg) Disown() *Msg
- func (msg *Msg) FromJSON(src []byte) (reterr error)
- func (msg *Msg) Length() int
- func (msg *Msg) MarshalUpper(caps caps.Caps) error
- func (msg *Msg) Own() *Msg
- func (msg *Msg) Parse(raw []byte) (off int, err error)
- func (msg *Msg) ParseUpper(caps caps.Caps) error
- func (msg *Msg) Reset() *Msg
- func (msg *Msg) SetData(data []byte) *Msg
- func (msg *Msg) String() string
- func (msg *Msg) ToJSON(dst []byte) []byte
- func (msg *Msg) Up(typ Type) *Msg
- func (msg *Msg) WriteTo(w io.Writer) (n int64, err error)
- type Open
- func (o *Open) FromJSON(src []byte) error
- func (o *Open) GetASN() int
- func (o *Open) Init(m *Msg)
- func (o *Open) Marshal() error
- func (o *Open) MarshalCaps() error
- func (o *Open) Parse() error
- func (o *Open) ParseCaps() error
- func (o *Open) Reset()
- func (o *Open) SetASN(asn int)
- func (o *Open) String() string
- func (o *Open) ToJSON(dst []byte) []byte
- type Type
- type Update
- func (u *Update) Afi() af.AFI
- func (u *Update) FromJSON(src []byte) error
- func (u *Update) Init(m *Msg)
- func (u *Update) Marshal(cps caps.Caps) error
- func (u *Update) MarshalAttrs(cps caps.Caps) error
- func (u *Update) Parse() error
- func (u *Update) ParseAttrs(cps caps.Caps) error
- func (u *Update) ReachMP() attrs.MPValue
- func (u *Update) Reset()
- func (u *Update) Safi() af.SAFI
- func (u *Update) String() string
- func (u *Update) ToJSON(dst []byte) []byte
- func (u *Update) UnreachMP() attrs.MPValue
- type Value
Constants ¶
const ( // BGP header length, per rfc4271/4.1 HEADLEN = 19 // = marker(16) + length(2) + type(1) // BGP maximum message length, per rfc4271 MAXLEN = 4096 // BGP maximum extended message length, per rfc8654 MAXLEN_EXT = 65535 // JSON date and time format JSON_TIME = `2006-01-02T15:04:05.000` )
const ( OPEN_MINLEN = 29 - HEADLEN // rfc4271/4.2 OPEN_VERSION = 4 OPEN_HOLDTIME = 90 PARAM_CAPS = 2 PARAM_EXTLEN = 255 AS_TRANS = 23456 )
const (
UPDATE_MINLEN = 23 - HEADLEN // rfc4271/4.3
)
Variables ¶
var ( // generic errors ErrTODO = errors.New("not implemented") ErrUnsupported = errors.New("unsupported") ErrType = errors.New("invalid type") ErrValue = errors.New("invalid value") ErrLength = errors.New("invalid length") ErrShort = errors.New("too short") ErrLong = errors.New("too long") ErrMarker = errors.New("marker not found") ErrVersion = errors.New("invalid version") ErrParams = errors.New("invalid parameters") ErrCaps = errors.New("invalid capabilities") ErrAttrDupe = errors.New("duplicate attribute") ErrAttrCode = errors.New("invalid attribute code") ErrAttrFlags = errors.New("invalid attribute flags") ErrAttrs = errors.New("invalid attributes") ErrSegType = errors.New("invalid segment type") ErrSegLen = errors.New("invalid segment length") )
Functions ¶
func DstStrings ¶
func DstStrings() []string
DstStrings returns a slice of all String values of the enum
func TypeStrings ¶
func TypeStrings() []string
TypeStrings returns a slice of all String values of the enum
Types ¶
type Dst ¶
type Dst byte
BGP message destination (message direction)
func DstString ¶
DstString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
type Msg ¶
type Msg struct { Dst Dst // message destination Seq int64 // sequence number Time time.Time // message timestamp Type Type // message type Data []byte // message data (referenced or owned), can be nil Upper Type // which of the upper layer is valid? Dirty bool // if true, probably needs a marshal (Data does not reflect Upper) Open Open // parsed BGP OPEN message Update Update // parsed BGP UPDATE message Value Value // NB: not affected by Reset() // contains filtered or unexported fields }
Msg represents a BGP message. Use NewMsg to get a new valid object.
func (*Msg) MarshalUpper ¶
MarshalUpper marshals the upper layer to msg.Data iff possible and needed. caps can infuence the upper layer encoders.
func (*Msg) Parse ¶
Parse parses the BGP message in raw. Does not copy. Returns the number of parsed bytes from raw.
func (*Msg) ParseUpper ¶
ParseUpper parses the upper layer iff needed. caps can infuence the upper layer decoders.
type Open ¶
type Open struct { Msg *Msg // parent BGP message Version byte // must be 4 ASN uint16 // 2-byte local ASN HoldTime uint16 // proposed hold time Identifier netip.Addr // router identifier Params []byte // raw Optional Parameters ParamsExt bool // true iff Params use extended length Caps caps.Caps // BGP capabilities, usually parsed from Params }
Open represents a BGP OPEN message
func (*Open) MarshalCaps ¶
MarshalCaps marshals o.Caps into o.Params. Sets o.ParamsExt.
type Type ¶
type Type byte
BGP message type
func TypeString ¶
TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
type Update ¶
type Update struct { Msg *Msg // parent BGP message Reach []netip.Prefix // reachable IPv4 unicast Unreach []netip.Prefix // unreachable IPv4 unicast RawAttrs []byte // raw attributes Attrs attrs.Attrs // parsed attributes // contains filtered or unexported fields }
Update represents a BGP UPDATE message
func (*Update) MarshalAttrs ¶
MarshalAttrs marshals u.Attrs into u.RawAttrs
func (*Update) ParseAttrs ¶
ParseAttrs parses all attributes from RawAttrs into Attrs.