packet

package
v0.0.3-pre7 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OctetLen       = 8
	MaxASNsSegment = 255
	BGP4Version    = 4
	MinOpenLen     = 29

	MarkerLen         = 16
	HeaderLen         = 19
	MinLen            = 19
	MaxLen            = 4096
	MinUpdateLen      = 4
	NLRIMaxLen        = 5
	AFILen            = 2
	SAFILen           = 1
	CommunityLen      = 4
	LargeCommunityLen = 12
	IPv4Len           = 4
	IPv6Len           = 16
	ClusterIDLen      = 4

	OpenMsg         = 1
	UpdateMsg       = 2
	NotificationMsg = 3
	KeepaliveMsg    = 4

	MessageHeaderError      = 1
	OpenMessageError        = 2
	UpdateMessageError      = 3
	HoldTimeExpired         = 4
	FiniteStateMachineError = 5
	Cease                   = 6

	// Msg Header Errors
	ConnectionNotSync = 1
	BadMessageLength  = 2
	BadMessageType    = 3

	// Open Msg Errors
	UnsupportedVersionNumber     = 1
	BadPeerAS                    = 2
	BadBGPIdentifier             = 3
	UnsupportedOptionalParameter = 4
	DeprecatedOpenMsgError5      = 5
	UnacceptableHoldTime         = 6

	// Update Msg Errors
	MalformedAttributeList    = 1
	UnrecognizedWellKnownAttr = 2
	MissingWellKnownAttr      = 3
	AttrFlagsError            = 4
	AttrLengthError           = 5
	InvalidOriginAttr         = 6
	DeprecatedUpdateMsgError7 = 7
	InvalidNextHopAttr        = 8
	OptionalAttrError         = 9
	InvalidNetworkField       = 10
	MalformedASPath           = 11

	// Notification Msg Subcodes
	AdministrativeShutdown = 2
	AdministrativeReset    = 4

	// Attribute Type Codes
	OriginAttr           = 1
	ASPathAttr           = 2
	NextHopAttr          = 3
	MEDAttr              = 4
	LocalPrefAttr        = 5
	AtomicAggrAttr       = 6
	AggregatorAttr       = 7
	CommunitiesAttr      = 8
	OriginatorIDAttr     = 9
	ClusterListAttr      = 10
	AS4PathAttr          = 17
	AS4AggregatorAttr    = 18
	LargeCommunitiesAttr = 32

	// ORIGIN values
	IGP        = 0
	EGP        = 1
	INCOMPLETE = 2

	// NOTIFICATION Cease error SubCodes (RFC4486)
	MaxPrefReached                = 1
	AdminShut                     = 2
	PeerDeconfigured              = 3
	AdminReset                    = 4
	ConnectionRejected            = 5
	OtherConfigChange             = 6
	ConnectionCollisionResolution = 7
	OutOfResources                = 8

	IPv4AFI                      = 1
	IPv6AFI                      = 2
	UnicastSAFI                  = 1
	CapabilitiesParamType        = 2
	MultiProtocolCapabilityCode  = 1
	MultiProtocolReachNLRICode   = 14
	MultiProtocolUnreachNLRICode = 15
	AddPathCapabilityCode        = 69
	ASN4CapabilityCode           = 65
	AddPathReceive               = 1
	AddPathSend                  = 2
	AddPathSendReceive           = 3
	ASTransASN                   = 23456
)
View Source
const (
	PathIdentifierLen = 4
)

Variables

This section is empty.

Functions

func AFIName

func AFIName(afi uint16) string

AFIName returns the name of an address family

func BytesInAddr

func BytesInAddr(pfxlen uint8) uint8

BytesInAddr gets the amount of bytes needed to encode an NLRI of prefix length pfxlen

func SerializeKeepaliveMsg

func SerializeKeepaliveMsg() []byte

func SerializeNotificationMsg

func SerializeNotificationMsg(msg *BGPNotification) []byte

func SerializeOpenMsg

func SerializeOpenMsg(msg *BGPOpen) []byte

Types

type ASN4Capability

type ASN4Capability struct {
	ASN4 uint32
}

type AddPathCapability

type AddPathCapability []AddPathCapabilityTuple

type AddPathCapabilityTuple

type AddPathCapabilityTuple struct {
	AFI         uint16
	SAFI        uint8
	SendReceive uint8
}

type BGPError

type BGPError struct {
	ErrorCode    uint8
	ErrorSubCode uint8
	ErrorStr     string
}

func (BGPError) Error

func (b BGPError) Error() string

type BGPHeader

type BGPHeader struct {
	Length uint16
	Type   uint8
}

type BGPMessage

type BGPMessage struct {
	Header *BGPHeader
	Body   interface{}
}

func Decode

func Decode(buf *bytes.Buffer, opt *DecodeOptions) (*BGPMessage, error)

Decode decodes a BGP message

type BGPNotification

type BGPNotification struct {
	ErrorCode    uint8
	ErrorSubcode uint8
}

type BGPOpen

type BGPOpen struct {
	Version       uint8
	ASN           uint16
	HoldTime      uint16
	BGPIdentifier uint32
	OptParmLen    uint8
	OptParams     []OptParam
}

func DecodeOpenMsg

func DecodeOpenMsg(buf *bytes.Buffer) (*BGPOpen, error)

DecodeOpenMsg decodes a BGP OPEN message

type BGPUpdate

type BGPUpdate struct {
	WithdrawnRoutesLen uint16
	WithdrawnRoutes    *NLRI
	TotalPathAttrLen   uint16
	PathAttributes     *PathAttribute
	NLRI               *NLRI
}

func (*BGPUpdate) SerializeUpdate

func (b *BGPUpdate) SerializeUpdate(opt *EncodeOptions) ([]byte, error)

SerializeUpdate serializes an BGPUpdate to wire format

func (*BGPUpdate) SerializeUpdateAddPath

func (b *BGPUpdate) SerializeUpdateAddPath(opt *EncodeOptions) ([]byte, error)

type Capabilities

type Capabilities []Capability

type Capability

type Capability struct {
	Code   uint8
	Length uint8
	Value  Serializable
}

type DecodeOptions

type DecodeOptions struct {
	AddPathIPv4Unicast bool
	AddPathIPv6Unicast bool
	Use32BitASN        bool
}

DecodeOptions represents options for the BGP message decoder

type EncodeOptions

type EncodeOptions struct {
	Use32BitASN bool
	UseAddPath  bool
}

type MultiProtocolCapability

type MultiProtocolCapability struct {
	AFI  uint16
	SAFI uint8
}

type MultiProtocolReachNLRI

type MultiProtocolReachNLRI struct {
	AFI     uint16
	SAFI    uint8
	NextHop *bnet.IP
	NLRI    *NLRI
}

MultiProtocolReachNLRI represents network layer reachability information for an IP address family (rfc4760)

type MultiProtocolUnreachNLRI

type MultiProtocolUnreachNLRI struct {
	AFI  uint16
	SAFI uint8
	NLRI *NLRI
}

MultiProtocolUnreachNLRI represents network layer withdraw information for one prefix of an IP address family (rfc4760)

type NLRI

type NLRI struct {
	PathIdentifier uint32
	Prefix         *bnet.Prefix
	Next           *NLRI
}

NLRI represents a Network Layer Reachability Information

type OptParam

type OptParam struct {
	Type   uint8
	Length uint8
	Value  Serializable
}

type PathAttribute

type PathAttribute struct {
	Length         uint16
	Optional       bool
	Transitive     bool
	Partial        bool
	ExtendedLength bool
	TypeCode       uint8
	Value          interface{}
	Next           *PathAttribute
}

func PathAttributes

func PathAttributes(p *route.Path, iBGP bool, rrClient bool) (*PathAttribute, error)

PathAttributes converts a path object into a linked list of path attributes

func (*PathAttribute) AddOptionalPathAttributes

func (pa *PathAttribute) AddOptionalPathAttributes(p *route.Path) *PathAttribute

AddOptionalPathAttributes adds optional path attributes to linked list pa

func (*PathAttribute) Copy

func (pa *PathAttribute) Copy() *PathAttribute

Copy create a copy of a path attribute

func (*PathAttribute) Serialize

func (pa *PathAttribute) Serialize(buf *bytes.Buffer, opt *EncodeOptions) uint16

Serialize serializes a path attribute

type Serializable

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

Jump to

Keyboard shortcuts

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