Back to

Package corebgp

Latest Go to latest

The latest major version is .

Published: Jul 3, 2020 | License: Apache-2.0 | Module:



const (
	NotifCodeMessageHeaderErr uint8 = 1
	NotifCodeOpenMessageErr   uint8 = 2
	NotifCodeUpdateMessageErr uint8 = 3
	NotifCodeHoldTimerExpired uint8 = 4
	NotifCodeFSMErr           uint8 = 5
	NotifCodeCease            uint8 = 6

Notification code values

const (
	NotifSubcodeConnNotSync uint8 = 1
	NotifSubcodeBadLength   uint8 = 2
	NotifSubcodeBadType     uint8 = 3

message header Notification subcode values

const (
	NotifSubcodeUnsupportedVersionNumber uint8 = 1
	NotifSubcodeBadPeerAS                uint8 = 2
	NotifSubcodeBadBgpID                 uint8 = 3
	NotifSubcodeUnsupportedOptionalParam uint8 = 4
	NotifSubcodeUnacceptableHoldTime     uint8 = 5
	NotifSubcodeUnsupportedCapability    uint8 = 6

open message Notification subcode values

const (
	NotifSubcodeMalformedAttr             uint8 = 1
	NotifSubcodeUnrecognizedWellKnownAttr uint8 = 2
	NotifSubcodeMissingWellKnownAttr      uint8 = 3
	NotifSubcodeAttrFlagsError            uint8 = 4
	NotifSubcodeAttrLenError              uint8 = 5
	NotifSubcodeInvalidOrigin             uint8 = 6
	NotifSubcodeInvalidNextHop            uint8 = 8
	NotifSubcodeOptionalAttrError         uint8 = 9
	NotifSubcodeInvalidNetworkField       uint8 = 10
	NotifSubcodeMalformedASPath           uint8 = 11

update message Notification subcode values

const (
	NotifSubcodeUnexpectedMessageOpenSent    uint8 = 1
	NotifSubcodeUnexpectedMessageOpenConfirm uint8 = 2
	NotifSubcodeUnexpectedMessageEstablished uint8 = 3

finite state machine error subcode values [RFC6608]

const (
	DefaultHoldTime     = time.Second * 90
	DefaultIdleHoldTime = time.Second * 5


var (
	ErrServerClosed = errors.New("server closed")

func SetLogger

func SetLogger(l Logger)

SetLogger enables logging with the provided Logger.

type Capability

type Capability struct {
	Code  uint8
	Value []byte

Capability is a BGP capability as defined by RFC5492.

type Logger

type Logger func(...interface{})

Logger is a log.Print-compatible function

type Notification

type Notification struct {
	Code    uint8
	Subcode uint8
	Data    []byte

Notification is a Notification message.

type PeerConfig

type PeerConfig struct {
	IP       net.IP
	LocalAS  uint32
	RemoteAS uint32

PeerConfig is the required configuration for a Peer.

type PeerOption

type PeerOption interface {
	// contains filtered or unexported methods

func IdleHoldTime

func IdleHoldTime(t time.Duration) PeerOption

IdleHoldTime returns a PeerOption that sets the idle hold time for a peer. Idle hold time controls how quickly a peer can oscillate from idle to the connect state.

func Passive

func Passive() PeerOption

Passive returns a PeerOption that sets a Peer to passive mode. In passive mode a peer will not dial out and will only accept incoming connections.

type Plugin

type Plugin interface {
	// GetCapabilities is fired when a peer's FSM is in the Connect state prior
	// to sending an Open message. The returned capabilities are included in the
	// Open message sent to the peer.
	GetCapabilities(peer *PeerConfig) []*Capability

	// OnOpenMessage is fired when an Open message is received from a peer
	// during the OpenSent state. Returning a non-nil Notification will cause it
	// to be sent to the peer and the FSM will transition to the Idle state.
	// Per RFC5492 a BGP speaker should only send a Notification if a required
	// capability is missing; unknown or unsupported capabilities should be
	// ignored.
	OnOpenMessage(peer *PeerConfig, capabilities []*Capability) *Notification

	// OnEstablished is fired when a peer's FSM transitions to the Established
	// state. The returned UpdateMessageHandler will be fired when an Update
	// message is received from the peer.
	// The provided writer can be used to send Update messages to the peer for
	// the lifetime of the FSM's current, established state. It should be
	// discarded once OnClose() fires.
	OnEstablished(peer *PeerConfig, writer UpdateMessageWriter) UpdateMessageHandler

	// OnClose is fired when a peer's FSM transitions out of the Established
	// state.
	OnClose(peer *PeerConfig)

Plugin is a BGP peer plugin.

type Server

type Server struct {
	// contains filtered or unexported fields

Server is a BGP server that manages peers.

func NewServer

func NewServer(routerID net.IP) (*Server, error)

NewServer creates a new Server.

func (*Server) AddPeer

func (s *Server) AddPeer(config *PeerConfig, plugin Plugin,
	opts ...PeerOption) error

AddPeer adds a peer to the Server to be handled with the provided Plugin and PeerOptions.

func (*Server) Close

func (s *Server) Close()

Close stops the Server. An instance of a stopped Server cannot be re-used.

func (*Server) DeletePeer

func (s *Server) DeletePeer(ip net.IP) error

DeletePeer deletes a peer from the Server.

func (*Server) Serve

func (s *Server) Serve(lis net.Listener) error

Serve starts all peers' FSMs, starts handling incoming connections if a non-nil listener is provided, and then blocks. Serve returns ErrServerClosed upon Close() or a listener error if one occurs.

type UpdateMessageHandler

type UpdateMessageHandler func(peer *PeerConfig, updateMessage []byte) *Notification

UpdateMessageHandler handles Update messages. If a non-nil Notification is returned it will be sent to the peer and the FSM will transition out of the Established state.

type UpdateMessageWriter

type UpdateMessageWriter interface {
	// WriteUpdate sends an update message to the remote peer. An error is
	// returned if the write fails and/or the FSM is no longer in an established
	// state.
	WriteUpdate([]byte) error

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier