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 ( 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 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 )
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.
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.