Documentation
¶
Index ¶
- Constants
- Variables
- func SetLogger(l Logger)
- func SetTCPMD5Signature(fd int, address net.IP, prefixLen uint8, key string) error
- type Capability
- type Logger
- type Notification
- type PeerConfig
- type PeerOption
- type Plugin
- type Server
- func (s *Server) AddPeer(config PeerConfig, plugin Plugin, opts ...PeerOption) error
- func (s *Server) Close()
- func (s *Server) DeletePeer(ip net.IP) error
- func (s *Server) GetPeer(ip net.IP) (PeerConfig, error)
- func (s *Server) ListPeers() []PeerConfig
- func (s *Server) Serve(listeners []net.Listener) error
- type UpdateMessageHandler
- type UpdateMessageWriter
Constants ¶
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
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
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
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
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
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
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
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
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
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
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 )
const (
NOTIF_SUBCODE_INVALID_MESSAGE_LEN uint8 = 1 // Invalid Message Length
)
BGP ROUTE-REFRESH Message Error subcodes, Updated: 2022-05-13
Variables ¶
Functions ¶
func SetTCPMD5Signature ¶ added in v0.2.0
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.
Types ¶
type Capability ¶
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 Notification ¶
Notification is a Notification message.
type PeerConfig ¶
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 (*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 ¶
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.
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.