mrt

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: 13 Imported by: 1

Documentation

Overview

Package mrt supports BGP data in MRT format (RFC6396)

Index

Constants

View Source
const (
	// MRT header length
	HEADLEN = 12 // = timestamp(4) + type(2) + subtype (2) + length (4)

	// MRT maximum data length
	MAXLEN = math.MaxUint32
)
View Source
const (
	// minimum MRT BgpMsg header length
	BGPMSG_HEADLEN = 16
)

Variables

View Source
var (
	ErrShort   = errors.New("message too short")
	ErrLong    = errors.New("message too long")
	ErrLength  = errors.New("invalid length")
	ErrType    = errors.New("invalid MRT type")
	ErrSub     = errors.New("invalid MRT subtype")
	ErrAF      = errors.New("invalid Address Family")
	ErrNoData  = errors.New("no message data")
	ErrNoUpper = errors.New("no upper layer")
)

Functions

func SubStrings

func SubStrings() []string

SubStrings 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 Bgp4 added in v0.2.0

type Bgp4 struct {
	Mrt       *Mrt       // parent MRT message
	PeerAS    uint32     // peer AS
	LocalAS   uint32     // local AS
	Interface uint16     // interface index
	PeerIP    netip.Addr // peer IP address
	LocalIP   netip.Addr // local IP address
	Data      []byte     // BGP message, referenced
}

Bgp4 represents an MRT BGP4MP_MESSAGE message

func (*Bgp4) FromMsg added in v0.2.0

func (b4 *Bgp4) FromMsg(m *msg.Msg) error

FromMsg copies BGP message m into BGP4MP message b4. m must already be marshaled.

func (*Bgp4) Init added in v0.2.0

func (b4 *Bgp4) Init(mrt *Mrt)

Init initializes b4 to use parent mrt

func (*Bgp4) Marshal added in v0.2.0

func (b4 *Bgp4) Marshal() error

Marshal marshals b4 to b4.Mrt.Data. Type and Sub must already be set in b4.Mrt parent.

func (*Bgp4) Parse added in v0.2.0

func (b4 *Bgp4) Parse() error

Parse parses b4.Mrt as BGP4MP message, referencing data.

func (*Bgp4) Reset added in v0.2.0

func (b4 *Bgp4) Reset()

Reset prepares b4 for re-use

func (*Bgp4) ToMsg added in v0.2.0

func (b4 *Bgp4) ToMsg(m *msg.Msg, set_tags bool) error

ToMsg reads MRT-BGP4MP message b4 into BGP message m, referencing data.

type Mrt

type Mrt struct {
	Time time.Time // message timestamp
	Type Type      // message type
	Sub  Sub       // message subtype
	Data []byte    // message data (referenced or owned), can be nil

	Upper Type // which of the upper layers is valid?
	Bgp4  Bgp4 // BGP4MP or BGP4MP_ET
	// contains filtered or unexported fields
}

Mrt represents a bare-bones MRT message (rfc6396/2).

func NewMrt

func NewMrt() *Mrt

NewMrt returns new empty message

func (*Mrt) CopyData

func (mrt *Mrt) CopyData() *Mrt

CopyData copies the referenced data iff needed and makes mrt the owner

func (*Mrt) FromBytes added in v0.2.0

func (mrt *Mrt) FromBytes(raw []byte) (off int, err error)

FromBytes parses the MRT message in raw. Does not copy. Returns the number of parsed bytes from raw.

func (*Mrt) Length

func (mrt *Mrt) Length() int

Length returns total MRT message length, including header

func (*Mrt) Marshal added in v0.2.0

func (mrt *Mrt) Marshal() error

Marshal marshals the upper layer to mrt.Data iff possible and needed.

func (*Mrt) Parse

func (mrt *Mrt) Parse() error

Parse parses mrt.Data into the upper layer iff needed.

func (*Mrt) Reset

func (mrt *Mrt) Reset() *Mrt

Reset clears the message

func (*Mrt) Use added in v0.2.0

func (mrt *Mrt) Use(typ Type) *Mrt

Use selects the upper layer of given type for active use. Drop mrt.Data, but does not touch the upper layer at all. Use Reset() on mrt or the selected layer if needed.

func (*Mrt) WriteTo

func (mrt *Mrt) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes raw MRT mrt.Data message to w, implementing io.WriterTo. Call mrt.Marshal() first if needed.

type Reader

type Reader struct {
	NoTags bool        // ignore message tags?
	Stats  ReaderStats // our stats
	// contains filtered or unexported fields
}

Reader reads MRT-BGP4MP messages into a pipe.Input.

func NewReader

func NewReader(p *pipe.Pipe, input *pipe.Input) *Reader

NewReader returns a new Reader.

func (*Reader) FromBytes added in v0.2.0

func (br *Reader) FromBytes(buf []byte, m *msg.Msg, mrt *Mrt) (n int, err error)

FromBytes parses the first MRT-BGP4MP message in buf, and references it in m. Does not buffer or copy buf. Can be used concurrently. mrt may be nil

func (*Reader) Write

func (br *Reader) Write(src []byte) (n int, err error)

Write implements io.Writer and reads all MRT-BGP4MP messages from src into br.in. Must not be used concurrently.

func (*Reader) WriteFunc added in v0.2.0

func (br *Reader) WriteFunc(src []byte, cb pipe.CallbackFunc) (n int, err error)

WriteFunc is the same as Write(), but takes an optional callback function to be called just before the message is accepted for processing. If the callback returns false, the message is silently dropped instead.

type ReaderStats

type ReaderStats struct {
	Parsed     uint64 // parsed messages (total)
	ParsedBgp  uint64 // parsed BGP4MP messages
	ParsedSkip uint64 // skipped non-BGP4MP messages
	Short      uint64 // data in buffer too short, should retry
	Garbled    uint64 // parse error
}

BGP reader statistics

type Sub

type Sub uint16

MRT message subtype, see https://www.iana.org/assignments/mrt/mrt.xhtml

const (
	BGP4_STATE_CHANGE     Sub = 0
	BGP4_STATE_CHANGE_AS4 Sub = 5

	BGP4_MESSAGE               Sub = 1
	BGP4_MESSAGE_LOCAL         Sub = 6
	BGP4_MESSAGE_ADDPATH       Sub = 8
	BGP4_MESSAGE_LOCAL_ADDPATH Sub = 10

	BGP4_MESSAGE_AS4               Sub = 4
	BGP4_MESSAGE_AS4_LOCAL         Sub = 7
	BGP4_MESSAGE_AS4_ADDPATH       Sub = 9
	BGP4_MESSAGE_AS4_LOCAL_ADDPATH Sub = 11
)

from https://www.iana.org/assignments/mrt/mrt.xhtml

func SubString

func SubString(s string) (Sub, error)

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

func SubValues

func SubValues() []Sub

SubValues returns all values of the enum

func (Sub) IsASub

func (i Sub) IsASub() bool

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

func (Sub) String

func (i Sub) String() string

type Type

type Type uint16

MRT message type, see https://www.iana.org/assignments/mrt/mrt.xhtml

const (
	INVALID Type = 0

	OSPF2    Type = 11
	OSPF3    Type = 48
	OSPF3_ET Type = 49

	TABLE_DUMP  Type = 12
	TABLE_DUMP2 Type = 13

	BGP4MP    Type = 16
	BGP4MP_ET Type = 17

	ISIS    Type = 32
	ISIS_ET Type = 33
)

func TypeString

func TypeString(s string) (Type, error)

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

func TypeValues

func TypeValues() []Type

TypeValues returns all values of the enum

func (Type) IsAType

func (i Type) IsAType() bool

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

func (Type) IsBGP4 added in v0.2.0

func (t Type) IsBGP4() bool

IsBGP returns true iff t is of BGP4MP type

func (Type) IsET added in v0.2.0

func (t Type) IsET() bool

IsET returns true iff t is of Extended Timestamp type

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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