Categorygithub.com/jwhited/corebgp
modulepackage
0.8.5
Repository: https://github.com/jwhited/corebgp.git
Documentation: pkg.go.dev

# 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 provides optional, composable UPDATE message decoding facilities via UpdateDecoder. CoreBGP does not manage a routing table or send its own UPDATE messages. Those responsibilities are 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.
	//
	// The four-octet AS number space capability will be implicitly handled,
	// Plugin implementations are not required to return it.
	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.
	//
	// Remote peers MUST include the four-octet AS number space capability in
	// their open message. corebgp will return a Notification message if a
	// remote peer does not support said capability, and will not invoke
	// OnOpenMessage.
	//
	// 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 netip.Addr, 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 netip.Addr, 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 := netip.MustParseAddr("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{
    RemoteAddress: netip.MustParseAddr("198.51.100.10"),
    LocalAS:       65001,
    RemoteAS:      65010,
}, p, corebgp.WithLocalAddress(routerID))
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.

# Packages

No description provided by the author

# Functions

No description provided by the author
DecodeMPIPv6AddPathPrefixes decodes IPv6 add-path prefixes in b with multiprotocol error handling consistent with RFC7606.
DecodeMPIPv6Prefixes decodes IPv6 prefixes in b with multiprotocol error handling consistent with RFC7606.
DecodeMPReachIPv6NextHops decodes one or two (RFC2545) IPv6 next hops contained in nh.
NewAddPathCapability returns an add-path Capability for the provided AddPathTuples.
NewMPExtensionsCapability returns a Multiprotocol Extensions Capability for the provided AFI and SAFI.
NewMPReachNLRIDecodeFn returns a MPPathAttrDecodeFn that can be used to compose logic for decoding a MP_REACH_NLRI path attribute through the provided closure fn.
NewMPUnreachNLRIDecodeFn returns a MPPathAttrDecodeFn that can be used to compose logic for decoding a MP_UNREACH_NLRI path attribute through the provided closure fn.
NewNLRIAddPathDecodeFn returns a DecodeFn to be used by an UpdateDecoder for decoding the NLRI field of an UPDATE message containing add-path prefixes.
NewNLRIDecodeFn returns a DecodeFn to be used by an UpdateDecoder for decoding the NLRI field of an UPDATE message.
NewServer creates a new Server.
NewUpdateDecoder returns a new instance of an UpdateDecoder where wrFn is used to decode withdrawn routes, paFn is used to decode path attributes, and nlriFn is used to decode network layer reachability info.
NewWithdrawnAddPathRoutesDecodeFn returns a DecodeFn to be used by an UpdateDecoder for decoding the withdrawn routes field of an UPDATE message containing add-path prefixes.
NewWithdrawnRoutesDecodeFn returns a DecodeFn to be used by an UpdateDecoder for decoding the withdrawn routes field of an UPDATE message.
SetLogger enables logging with the provided Logger.
SetTCPMD5Signature sets a tcp md5 signature on a socket for the provided address, prefix length, and key.
UpdateNotificationFromErr finds the highest severity *Notification in err's tree.
WithConnectRetryTime returns a PeerOption that sets the connect retry time for a peer.
WithDialerControl returns a PeerOption that sets the outbound net.Dialer Control field.
WithHoldTime returns a PeerOption that sets the hold time (in seconds) to be advertised to the peer via OPEN message.
WithIdleHoldTime returns a PeerOption that sets the idle hold time for a peer.
WithLocalAddress returns a PeerOption that specifies the source address to use when dialing outbound, and to verify as a destination for inbound connections.
WithPassive returns a PeerOption that sets a Peer to passive mode.
WithPort returns a PeerOption that sets the TCP port for a peer.

# Constants

48-bit MAC.
64-bit MAC.
802 (includes all 802 media plus Ethernet "canonical format").
Appletalk.
AS Number.
Banyan Vines.
BBN 1822.
BGP-LS.
BGP SFC.
Decnet IV.
Distinguished Name.
DNS (Domain Name System).
E.163.
E.164 (SMDS, Frame Relay, ATM).
E.164 with NSAP format subaddress.
EIGRP Common Service Family.
EIGRP IPv4 Service Family.
EIGRP IPv6 Service Family.
F.69 (Telex).
Fibre Channel World-Wide Node Name.
Fibre Channel World-Wide Port Name.
GWID.
HDLC (8-bit multidrop).
IP (IP version 4).
IP6 (IP version 6).
IPv6/64.
IPX.
AFI for L2VPN information.
LISP Canonical Address Format (LCAF).
MAC/24.
MAC/40.
MPLS Namespaces.
MPLS-TP LSP Endpoint Identifier.
MPLS-TP Pseudowire Endpoint Identifier.
MPLS-TP Section Endpoint Identifier.
MT IP: Multi-Topology IP version 4.
MT IPv6: Multi-Topology IP version 6.
NSAP.
OUI.
RBridge Port ID.
Routing Policy AFI.
TRILL Nickname.
Universally Unique Identifier (UUID).
X.121 (X.25, Frame Relay).
XTP native mode XTP.
XTP over IP version 4.
XTP over IP version 6.
ADD-PATH Capability.
BFD Capability.
BGPsec Capability.
Support for Dynamic Capability (capability specific).
Enhanced Route Refresh Capability.
BGP Extended Message.
Extended Next Hop Encoding.
Support for 4-octet AS number capability.
FQDN Capability.
Graceful Restart Capability.
Long-Lived Graceful Restart (LLGR) Capability.
Multiprotocol Extensions for BGP-4.
Multiple Labels Capability.
Multisession BGP Capability.
Outbound Route Filtering Capability.
BGP Role.
Route Refresh Capability for BGP-4.
Routing Policy Distribution.
Software Version Capability.
DefaultConnectRetryTime is the default maximum time spent waiting for an outbound dial to connect.
DefaultHoldTimeSeconds is the default hold down time in seconds.
DefaultIdleHoldTime is the default idle state hold time for a peer.
DefaultPort is the default TCP port for a peer.
Cease.
Finite State Machine Error.
Hold Timer Expired.
Message Header Error.
OPEN Message Error.
ROUTE-REFRESH Message Error.
UPDATE Message Error.
Administrative Reset.
Administrative Shutdown.
Attribute Flags Error.
Attribute Length Error.
Bad BGP Identifier.
Bad Message Length.
Bad Message Type.
Bad Peer AS.
BFD Down.
Connection Collision Resolution.
Connection Not Synchronized.
Connection Rejected.
Hard Reset.
Invalid Message Length.
Invalid Network Field.
Invalid NEXT_HOP Attribute.
Invalid ORIGIN Attribute.
Malformed AS_PATH.
Malformed Attribute List.
Maximum Number of Prefixes Reached.
Missing Well-known Attribute.
Optional Attribute Error.
Other Configuration Change.
Out of Resources.
Peer De-configured.
Role Mismatch.
Receive Unexpected Message in Established State.
Receive Unexpected Message in OpenConfirm State.
Receive Unexpected Message in OpenSent State.
Unacceptable Hold Time.
Unrecognized Well-known Attribute.
Unsupported Capability.
Unsupported Optional Parameter.
Unsupported Version Number.
AGGREGATOR.
AIGP.
AS_PATH.
AS4_AGGREGATOR.
AS4_PATH.
ATOMIC_AGGREGATE.
ATTR_SET.
BFD Discriminator.
BGP-LS Attribute.
BGP Prefix-SID.
BGPsec_Path.
CLUSTER_LIST.
COMMUNITY.
EXTENDED COMMUNITIES.
IPv6 Address Specific Extended Community.
LARGE_COMMUNITY.
LOCAL_PREF.
MULTI_EXIT_DISC.
MP_REACH_NLRI.
MP_UNREACH_NLRI.
NEXT_HOP.
ORIGIN.
ORIGINATOR_ID.
Only to Customer (OTC).
PE Distinguisher Labels.
PMSI_TUNNEL.
SFP attribute.
Traffic Engineering.
Tunnel Encapsulation.
BGP 4over6 SAFI.
BGP 6over4 SAFI.
BGP CAR.
BGP-DPS (Dynamic Path Selection).
BGP EVPNs.
BGP-LS.
BGP-LS-SPF.
BGP-LS-VPN.
BGP MDT SAFI.
BGP-MUP SAFI.
BGP SFC.
BGP VPN CAR.
Classful-Transport SAFI.
Dissemination of Flow Specification rules.
Network Layer Reachability Information used for Dynamic Placement of Multi-Segment Pseudowires.
L3VPN Dissemination of Flow Specification rules.
Layer-1 VPN auto-discovery information.
MCAST-TREE.
MCAST-VPLS.
MCAST-VPN.
Network Layer Reachability Information (NLRI) with MPLS Labels.
MPLS-labeled VPN address.
Network Layer Reachability Information used for multicast forwarding.
Multicast for BGP/MPLS IP Virtual Private Networks (VPNs).
Route Target constrains.
Routing Policy SAFI.
SD-WAN Capabilities.
SR TE Policy SAFI.
Tunnel SAFI.
Tunneled Traffic Flowspec.
Network Layer Reachability Information used for unicast forwarding.
Virtual Private LAN Service (VPLS).
VPN auto-discovery.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

AddPathPrefix is a prefix with an add-path ID.
No description provided by the author
No description provided by the author
No description provided by the author
AttrDiscardUpdateErr represents an error encountered during UPDATE message handling.
Capability is a BGP capability as defined by RFC5492.
No description provided by the author
Notification is a Notification message.
PeerConfig is the required configuration for a Peer.
Server is a BGP server that manages peers.
TreatAsWithdrawUpdateErr represents an error encountered during UPDATE message handling.
UpdateDecoder decodes UPDATE messages.

# Interfaces

No description provided by the author
Plugin is a BGP peer plugin.
UpdateError represents an error handling an UPDATE message.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Logger is a log.Print-compatible function.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PathAttrFlags represents the flags for a path attribute.
PathAttrsDecodeFn is used by an instance of an UpdateDecoder to decode path attributes in an UPDATE message.
UpdateMessageHandler handles Update messages.