corebgp

package module
Version: v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

CoreBGP

GoDev

CoreBGP is a BGP library written in Go that implements the BGP FSM with an event-driven, pluggable model. It exposes an API that empowers the user to:

  • send and validate OPEN message capabilities
  • handle "important" state transitions
  • handle incoming UPDATE messages
  • send outgoing UPDATE messages

CoreBGP does not decode UPDATE messages (besides header validation), manage a routing table, or send its own UPDATE messages. These responsibilities are all passed down to the user. Therefore, the intended user is someone who wants that responsibility.

See this blog post for the background and reasoning behind the development of CoreBGP.

Plugin

The primary building block of CoreBGP is a Plugin, defined by the following interface:

// Plugin is a BGP peer 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, routerID net.IP, 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)
}

Here's an example Plugin that logs when a peer enters/leaves an established state and when an UPDATE message is received:

type plugin struct{}

func (p *plugin) GetCapabilities(c corebgp.PeerConfig) []corebgp.Capability {
	caps := make([]corebgp.Capability, 0)
	return caps
}

func (p *plugin) OnOpenMessage(peer corebgp.PeerConfig, routerID net.IP, capabilities []corebgp.Capability) *corebgp.Notification {
	return nil
}

func (p *plugin) OnEstablished(peer corebgp.PeerConfig, writer corebgp.UpdateMessageWriter) corebgp.UpdateMessageHandler {
	log.Println("peer established")
	// send End-of-Rib
	writer.WriteUpdate([]byte{0, 0, 0, 0})
	return p.handleUpdate
}

func (p *plugin) OnClose(peer corebgp.PeerConfig) {
	log.Println("peer closed")
}

func (p *plugin) handleUpdate(peer corebgp.PeerConfig, u []byte) *corebgp.Notification {
	log.Printf("got update message of len: %d", len(u))
	return nil
}

Plugins are attached to peers when they are added to the Server, which manages their lifetime:

routerID := net.ParseIP("192.0.2.1")
srv, err := corebgp.NewServer(routerID)
if err != nil {
    log.Fatalf("error constructing server: %v", err)
}
p := &plugin{}
err = srv.AddPeer(corebgp.PeerConfig{
    LocalAddress:  routerID,
    RemoteAddress: net.ParseIP("198.51.100.10"),
    LocalAS:       65001,
    RemoteAS:      65010,
}, p)
if err != nil {
    log.Fatalf("error adding peer: %v", err)
}

For more examples check out the examples directory and pkg.go.dev for the complete API.

Versioning

CoreBGP follows semver as closely as it can. Seeing as we are still major version zero (0.y.z), the public API should not be considered stable. You are encouraged to pin CoreBGP's version with your dependency management solution of choice.

Documentation

Index

Constants

View Source
const (
	CAP_MP_EXTENSIONS              uint8 = 1  // Multiprotocol Extensions for BGP-4
	CAP_ROUTE_REFRESH              uint8 = 2  // Route Refresh Capability for BGP-4
	CAP_OUTBOUND_ROUTE_FILTERING   uint8 = 3  // Outbound Route Filtering Capability
	CAP_EXTENDED_NEXT_HOP_ENCODING uint8 = 5  // Extended Next Hop Encoding
	CAP_EXTENDED_MESSSAGE          uint8 = 6  // BGP Extended Message
	CAP_BGPSEC                     uint8 = 7  // BGPsec Capability
	CAP_MULTIPLE_LABELS            uint8 = 8  // Multiple Labels Capability
	CAP_ROLE                       uint8 = 9  // BGP Role
	CAP_GRACEFUL_RESTART           uint8 = 64 // Graceful Restart Capability
	CAP_FOUR_OCTET_AS              uint8 = 65 // Support for 4-octet AS number capability
	CAP_DYNAMIC                    uint8 = 67 // Support for Dynamic Capability (capability specific)
	CAP_MULTISESSION               uint8 = 68 // Multisession BGP Capability
	CAP_ADD_PATH                   uint8 = 69 // ADD-PATH Capability
	CAP_ENHANCED_ROUTE_REFRESH     uint8 = 70 // Enhanced Route Refresh Capability
	CAP_LLGR                       uint8 = 71 // Long-Lived Graceful Restart (LLGR) Capability
	CAP_ROUTING_POLICY_DIST        uint8 = 72 // Routing Policy Distribution
	CAP_FQDN                       uint8 = 73 // FQDN Capability
)

Capability Codes, Updated: 2022-05-10

View Source
const (
	AFI_IPV4                           uint16 = 1     // IP (IP version 4)
	AFI_IPV6                           uint16 = 2     // IP6 (IP version 6)
	AFI_NSAP                           uint16 = 3     // NSAP
	AFI_HDLC                           uint16 = 4     // HDLC (8-bit multidrop)
	AFI_BBN_1822                       uint16 = 5     // BBN 1822
	AFI_802                            uint16 = 6     // 802 (includes all 802 media plus Ethernet "canonical format")
	AFI_E163                           uint16 = 7     // E.163
	AFI_E164                           uint16 = 8     // E.164 (SMDS, Frame Relay, ATM)
	AFI_F69                            uint16 = 9     // F.69 (Telex)
	AFI_X121                           uint16 = 10    // X.121 (X.25, Frame Relay)
	AFI_IPX                            uint16 = 11    // IPX
	AFI_APPLETALK                      uint16 = 12    // Appletalk
	AFI_DECNET_IV                      uint16 = 13    // Decnet IV
	AFI_BANYAN_VINES                   uint16 = 14    // Banyan Vines
	AFI_E164_WITH_NSAP_SUBADDR         uint16 = 15    // E.164 with NSAP format subaddress
	AFI_DNS                            uint16 = 16    // DNS (Domain Name System)
	AFI_DISTINGUISHED_NAME             uint16 = 17    // Distinguished Name
	AFI_AS_NUMBER                      uint16 = 18    // AS Number
	AFI_XTP_OVER_IPV4                  uint16 = 19    // XTP over IP version 4
	AFI_XTP_OVER_IPV6                  uint16 = 20    // XTP over IP version 6
	AFI_XTP_NATIVE                     uint16 = 21    // XTP native mode XTP
	AFI_FIBRE_CHANNEL_WWPN             uint16 = 22    // Fibre Channel World-Wide Port Name
	AFI_FIBRE_CHANNEL_WWNN             uint16 = 23    // Fibre Channel World-Wide Node Name
	AFI_GWID                           uint16 = 24    // GWID
	AFI_L2VPN_INFO                     uint16 = 25    // AFI for L2VPN information
	AFI_MPLS_TP_SECTION_ENDPOINT_ID    uint16 = 26    // MPLS-TP Section Endpoint Identifier
	AFI_MPLS_TP_LSP_ENDPOINT_ID        uint16 = 27    // MPLS-TP LSP Endpoint Identifier
	AFI_MPLS_TP_PSEUDOWIRE_ENDPOINT_ID uint16 = 28    // MPLS-TP Pseudowire Endpoint Identifier
	AFI_MT_IPV4                        uint16 = 29    // MT IP: Multi-Topology IP version 4
	AFI_MT_IPV6                        uint16 = 30    // MT IPv6: Multi-Topology IP version 6
	AFI_BGP_SFC                        uint16 = 31    // BGP SFC
	AFI_EIGRP_COMMON_SERVICE_FAMILY    uint16 = 16384 // EIGRP Common Service Family
	AFI_EIGRP_IPV4_SERVICE_FAMILY      uint16 = 16385 // EIGRP IPv4 Service Family
	AFI_EIGRP_IPV6_SERVICE_FAMILY      uint16 = 16386 // EIGRP IPv6 Service Family
	AFI_LCAF                           uint16 = 16387 // LISP Canonical Address Format (LCAF)
	AFI_BGP_LS                         uint16 = 16388 // BGP-LS
	AFI_48_BIT_MAC                     uint16 = 16389 // 48-bit MAC
	AFI_64_BIT_MAC                     uint16 = 16390 // 64-bit MAC
	AFI_OUI                            uint16 = 16391 // OUI
	AFI_MAC_FINAL_24_BITS              uint16 = 16392 // MAC/24
	AFI_MAC_FINAL_40_BITS              uint16 = 16393 // MAC/40
	AFI_IPV6_INITIAL_64_BITS           uint16 = 16394 // IPv6/64
	AFI_RBRIDGE_PORT_ID                uint16 = 16395 // RBridge Port ID
	AFI_TRILL_NICKNAME                 uint16 = 16396 // TRILL Nickname
	AFI_UUID                           uint16 = 16397 // Universally Unique Identifier (UUID)
	AFI_ROUTING_POLICY                 uint16 = 16398 // Routing Policy AFI
	AFI_MPLS_NAMESPACES                uint16 = 16399 // MPLS Namespaces
)

Address Family Numbers, Updated: 2021-10-19

View Source
const (
	SAFI_UNICAST                               uint8 = 1   // Network Layer Reachability Information used for unicast forwarding
	SAFI_MULTICAST                             uint8 = 2   // Network Layer Reachability Information used for multicast forwarding
	SAFI_MPLS                                  uint8 = 4   // Network Layer Reachability Information (NLRI) with MPLS Labels
	SAFI_MCAST_VPN                             uint8 = 5   // MCAST-VPN
	SAFI_DYN_PLACEMENT_MULTI_SEGMENT_PW        uint8 = 6   // Network Layer Reachability Information used for Dynamic Placement of Multi-Segment Pseudowires
	SAFI_MCAST_VPLS                            uint8 = 8   // MCAST-VPLS
	SAFI_BGP_SFC                               uint8 = 9   // BGP SFC
	SAFI_TUNNEL                                uint8 = 64  // Tunnel SAFI
	SAFI_VPLS                                  uint8 = 65  // Virtual Private LAN Service (VPLS)
	SAFI_BGP_MDT                               uint8 = 66  // BGP MDT SAFI
	SAFI_BGP_4OVER6                            uint8 = 67  // BGP 4over6 SAFI
	SAFI_BGP_6OVER4                            uint8 = 68  // BGP 6over4 SAFI
	SAFI_LAYER_1_VPN_AUTO_DISCOVERY_INFO       uint8 = 69  // Layer-1 VPN auto-discovery information
	SAFI_BGP_EVPNS                             uint8 = 70  // BGP EVPNs
	SAFI_BGP_LS                                uint8 = 71  // BGP-LS
	SAFI_BGP_LS_VPN                            uint8 = 72  // BGP-LS-VPN
	SAFI_SR_TE_POLICY                          uint8 = 73  // SR TE Policy SAFI
	SAFI_SD_WAN_CAPABILITIES                   uint8 = 74  // SD-WAN Capabilities
	SAFI_ROUTING_POLICY                        uint8 = 75  // Routing Policy SAFI
	SAFI_CLASSFUL_TRANSPORT                    uint8 = 76  // Classful-Transport SAFI
	SAFI_TUNNELED_TRAFFIC_FLOWSPEC             uint8 = 77  // Tunneled Traffic Flowspec
	SAFI_MCAST_TREE                            uint8 = 78  // MCAST-TREE
	SAFI_BGP_DPS                               uint8 = 79  // BGP-DPS (Dynamic Path Selection)
	SAFI_BGP_LS_SPF                            uint8 = 80  // BGP-LS-SPF
	SAFI_BGP_CAR                               uint8 = 83  // BGP CAR
	SAFI_BGP_VPN_CAR                           uint8 = 84  // BGP VPN CAR
	SAFI_MPLS_LABELED_VPN_ADDR                 uint8 = 128 // MPLS-labeled VPN address
	SAFI_MULTICAST_BGP_MPLS_IP_VPNS            uint8 = 129 // Multicast for BGP/MPLS IP Virtual Private Networks (VPNs)
	SAFI_ROUTE_TARGET_CONSTRAINS               uint8 = 132 // Route Target constrains
	SAFI_DISSEMINATION_OF_FLOWSPEC_RULES       uint8 = 133 // Dissemination of Flow Specification rules
	SAFI_L3VPN_DISSEMINATION_OF_FLOWSPEC_RULES uint8 = 134 // L3VPN Dissemination of Flow Specification rules
	SAFI_VPN_AUTO_DISCOVERY                    uint8 = 140 // VPN auto-discovery
)

Subsequent Address Family Identifiers (SAFI) Parameters, Updated: 2022-04-13

View Source
const (
	PATH_ATTR_ORIGIN                                uint8 = 1   // ORIGIN
	PATH_ATTR_AS_PATH                               uint8 = 2   // AS_PATH
	PATH_ATTR_NEXT_HOP                              uint8 = 3   // NEXT_HOP
	PATH_ATTR_MED                                   uint8 = 4   // MULTI_EXIT_DISC
	PATH_ATTR_LOCAL_PREF                            uint8 = 5   // LOCAL_PREF
	PATH_ATTR_ATOMIC_AGGREGATE                      uint8 = 6   // ATOMIC_AGGREGATE
	PATH_ATTR_AGGREGATOR                            uint8 = 7   // AGGREGATOR
	PATH_ATTR_COMMUNITY                             uint8 = 8   // COMMUNITY
	PATH_ATTR_ORIGINATOR_ID                         uint8 = 9   // ORIGINATOR_ID
	PATH_ATTR_CLUSTER_LIST                          uint8 = 10  // CLUSTER_LIST
	PATH_ATTR_MP_REACH_NLRI                         uint8 = 14  // MP_REACH_NLRI
	PATH_ATTR_MP_UNREACH_NLRI                       uint8 = 15  // MP_UNREACH_NLRI
	PATH_ATTR_EXTENDED_COMMUNITIES                  uint8 = 16  // EXTENDED COMMUNITIES
	PATH_ATTR_AS4_PATH                              uint8 = 17  // AS4_PATH
	PATH_ATTR_AS4_AGGREGATOR                        uint8 = 18  // AS4_AGGREGATOR
	PATH_ATTR_PMSI_TUNNEL                           uint8 = 22  // PMSI_TUNNEL
	PATH_ATTR_TUNNEL_ENCAPSULATION                  uint8 = 23  // Tunnel Encapsulation
	PATH_ATTR_TRAFFIC_ENGINEERING                   uint8 = 24  // Traffic Engineering
	PATH_ATTR_IPV6_ADDR_SPECIFIC_EXTENDED_COMMUNITY uint8 = 25  // IPv6 Address Specific Extended Community
	PATH_ATTR_AIGP                                  uint8 = 26  // AIGP
	PATH_ATTR_PE_DISTINGUISHER_LABELS               uint8 = 27  // PE Distinguisher Labels
	PATH_ATTR_BGP_LS                                uint8 = 29  // BGP-LS Attribute
	PATH_ATTR_LARGE_COMMUNITY                       uint8 = 32  // LARGE_COMMUNITY
	PATH_ATTR_BGPSEC_PATH                           uint8 = 33  // BGPsec_Path
	PATH_ATTR_OTC                                   uint8 = 35  // Only to Customer (OTC)
	PATH_ATTR_SFP_ATTR                              uint8 = 37  // SFP attribute
	PATH_ATTR_BFD_DISCRIMINATOR                     uint8 = 38  // BFD Discriminator
	PATH_ATTR_BGP_PREFIX_SID                        uint8 = 40  // BGP Prefix-SID
	PATH_ATTR_ATTR_SET                              uint8 = 128 // ATTR_SET
)

BGP Path Attributes, Updated: 2022-05-13

View Source
const (
	NOTIF_CODE_MESSAGE_HEADER_ERR        uint8 = 1 // Message Header Error
	NOTIF_CODE_OPEN_MESSAGE_ERR          uint8 = 2 // OPEN Message Error
	NOTIF_CODE_UPDATE_MESSAGE_ERR        uint8 = 3 // UPDATE Message Error
	NOTIF_CODE_HOLD_TIMER_EXPIRED        uint8 = 4 // Hold Timer Expired
	NOTIF_CODE_FSM_ERR                   uint8 = 5 // Finite State Machine Error
	NOTIF_CODE_CEASE                     uint8 = 6 // Cease
	NOTIF_CODE_ROUTE_REFRESH_MESSAGE_ERR uint8 = 7 // ROUTE-REFRESH Message Error
)

BGP Error (Notification) Codes, Updated: 2022-05-13

View Source
const (
	NOTIF_SUBCODE_CONN_NOT_SYNCHRONIZED uint8 = 1 // Connection Not Synchronized
	NOTIF_SUBCODE_BAD_MESSAGE_LEN       uint8 = 2 // Bad Message Length
	NOTIF_SUBCODE_BAD_MESSAGE_TYPE      uint8 = 3 // Bad Message Type
)

Message Header Error subcodes, Updated: 2022-05-13

View Source
const (
	NOTIF_SUBCODE_UNSUPPORTED_VERSION_NUM    uint8 = 1  // Unsupported Version Number
	NOTIF_SUBCODE_BAD_PEER_AS                uint8 = 2  // Bad Peer AS
	NOTIF_SUBCODE_BAD_BGP_ID                 uint8 = 3  // Bad BGP Identifier
	NOTIF_SUBCODE_UNSUPPORTED_OPTIONAL_PARAM uint8 = 4  // Unsupported Optional Parameter
	NOTIF_SUBCODE_UNACCEPTABLE_HOLD_TIME     uint8 = 6  // Unacceptable Hold Time
	NOTIF_SUBCODE_UNSUPPORTED_CAPABILITY     uint8 = 7  // Unsupported Capability
	NOTIF_SUBCODE_ROLE_MISMATCH              uint8 = 11 // Role Mismatch
)

OPEN Message Error subcodes, Updated: 2022-05-13

View Source
const (
	NOTIF_SUBCODE_MALFORMED_ATTR_LIST          uint8 = 1  // Malformed Attribute List
	NOTIF_SUBCODE_UNRECOGNIZED_WELL_KNOWN_ATTR uint8 = 2  // Unrecognized Well-known Attribute
	NOTIF_SUBCODE_MISSING_WELL_KNOWN_ATTR      uint8 = 3  // Missing Well-known Attribute
	NOTIF_SUBCODE_ATTR_FLAGS_ERR               uint8 = 4  // Attribute Flags Error
	NOTIF_SUBCODE_ATTR_LEN_ERR                 uint8 = 5  // Attribute Length Error
	NOTIF_SUBCODE_INVALID_ORIGIN_ATTR          uint8 = 6  // Invalid ORIGIN Attribute
	NOTIF_SUBCODE_INVALID_NEXT_HOP_ATTR        uint8 = 8  // Invalid NEXT_HOP Attribute
	NOTIF_SUBCODE_OPTIONAL_ATTR_ERR            uint8 = 9  // Optional Attribute Error
	NOTIF_SUBCODE_INVALID_NETWORK_FIELD        uint8 = 10 // Invalid Network Field
	NOTIF_SUBCODE_MALFORMED_AS_PATH            uint8 = 11 // Malformed AS_PATH
)

UPDATE Message Error subcodes, Updated: 2022-05-13

View Source
const (
	NOTIF_SUBCODE_RX_UNEXPECTED_MESSAGE_OPENSENT    uint8 = 1 // Receive Unexpected Message in OpenSent State
	NOTIF_SUBCODE_RX_UNEXPECTED_MESSAGE_OPENCONFIRM uint8 = 2 // Receive Unexpected Message in OpenConfirm State
	NOTIF_SUBCODE_RX_UNEXPECTED_MESSAGE_ESTABLISHED uint8 = 3 // Receive Unexpected Message in Established State
)

BGP Finite State Machine Error Subcodes, Updated: 2022-05-13

View Source
const (
	NOTIF_SUBCODE_MAX_NUM_OF_PREFIXES_REACHED uint8 = 1 // Maximum Number of Prefixes Reached
	NOTIF_SUBCODE_ADMIN_SHUTDOWN              uint8 = 2 // Administrative Shutdown
	NOTIF_SUBCODE_PEER_DECONFIGURED           uint8 = 3 // Peer De-configured
	NOTIF_SUBCODE_ADMIN_RESET                 uint8 = 4 // Administrative Reset
	NOTIF_SUBCODE_CONN_REJECTED               uint8 = 5 // Connection Rejected
	NOTIF_SUBCODE_OTHER_CONFIG_CHANGE         uint8 = 6 // Other Configuration Change
	NOTIF_SUBCODE_CONN_COLLISION_RESOLUTION   uint8 = 7 // Connection Collision Resolution
	NOTIF_SUBCODE_OUT_OF_RESOURCES            uint8 = 8 // Out of Resources
	NOTIF_SUBCODE_HARD_RESET                  uint8 = 9 // Hard Reset
)

BGP Cease NOTIFICATION message subcodes, Updated: 2022-05-13

View Source
const (
	// DefaultHoldTime is the default hold down time.
	DefaultHoldTime = time.Second * 90
	// DefaultIdleHoldTime is the default idle state hold time for a peer.
	DefaultIdleHoldTime = time.Second * 5
	// DefaultConnectRetryTime is the default maximum time spent waiting for an
	// outbound dial to connect.
	//
	// https://tools.ietf.org/html/rfc4271#section-8.2.2
	// The exact value of the ConnectRetryTimer is a local matter, but it
	// SHOULD be sufficiently large to allow TCP initialization.
	DefaultConnectRetryTime = time.Second * 5
	// DefaultPort is the default TCP port for a peer.
	DefaultPort = 179
)
View Source
const (
	NOTIF_SUBCODE_INVALID_MESSAGE_LEN uint8 = 1 // Invalid Message Length
)

BGP ROUTE-REFRESH Message Error subcodes, Updated: 2022-05-13

Variables

View Source
var (
	ErrServerClosed      = errors.New("server closed")
	ErrPeerNotExist      = errors.New("peer does not exist")
	ErrPeerAlreadyExists = errors.New("peer already exists")
)

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger enables logging with the provided Logger.

func SetTCPMD5Signature added in v0.2.0

func SetTCPMD5Signature(fd int, address net.IP, prefixLen uint8,
	key string) error

SetTCPMD5Signature sets a tcp md5 signature on a socket for the provided address, prefix length, and key. This function is only supported on Linux. To unset a signature provide an empty key. Prefix length is ignored on kernels < 4.13.

https://tools.ietf.org/html/rfc2385

Types

type Capability

type Capability struct {
	Code  uint8
	Value []byte
}

Capability is a BGP capability as defined by RFC5492.

func NewMPExtensionsCapability added in v0.3.0

func NewMPExtensionsCapability(afi uint16, safi uint8) Capability

NewMPExtensionsCapability returns a Multiprotocol Extensions Capability for the provided AFI and SAFI.

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 {
	LocalAddress  net.IP
	RemoteAddress 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 WithConnectRetryTime added in v0.2.0

func WithConnectRetryTime(t time.Duration) PeerOption

WithConnectRetryTime returns a PeerOption that sets the connect retry time for a peer.

func WithDialerControl added in v0.2.0

func WithDialerControl(fn func(network, address string,
	c syscall.RawConn) error) PeerOption

WithDialerControl returns a PeerOption that sets the outbound net.Dialer Control field. This is commonly used to set socket options, e.g. ip TTL, tcp md5, tcp_nodelay, etc...

func WithIdleHoldTime added in v0.2.0

func WithIdleHoldTime(t time.Duration) PeerOption

WithIdleHoldTime 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 WithPassive added in v0.2.0

func WithPassive() PeerOption

WithPassive 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.

func WithPort added in v0.2.0

func WithPort(p int) PeerOption

WithPort returns a PeerOption that sets the TCP port for a peer.

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, routerID net.IP, 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) GetPeer added in v0.2.0

func (s *Server) GetPeer(ip net.IP) (PeerConfig, error)

GetPeer returns the configuration for the provided peer, or an error if it does not exist.

func (*Server) ListPeers added in v0.2.0

func (s *Server) ListPeers() []PeerConfig

ListPeers returns the configuration for all peers.

func (*Server) Serve

func (s *Server) Serve(listeners []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
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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