Documentation ¶
Index ¶
Constants ¶
const ( IPv4Unicast = RouteFamily(bgp.AFI_IP)<<16 | RouteFamily(bgp.SAFI_UNICAST) IPv6Unicast = RouteFamily(bgp.AFI_IP6)<<16 | RouteFamily(bgp.SAFI_UNICAST) )
Variables ¶
var ErrDiscard = errors.New("discard")
ErrDiscard is returned by filters that have made an explicit decision to discard a path.
Functions ¶
Types ¶
type Community ¶
Community is a BGP community as defined in https://datatracker.ietf.org/doc/html/rfc1997.
func NewCommunity ¶
NewCommunity creates a community from its numeric representation.
func ParseCommunity ¶
ParseCommunity parses a community from a string like "64512:1".
type Filter ¶
A Filter is a function that runs upon import or export of a path.
Import filters always receive a new instance of a Path and may safely modify it to apply local policy. Export filters receive a shallow copy of the Path from the local table and may modify the values in it, but are responsible for deep copying any reference types that they wish to modify themselves.
A filter may return ErrDiscard to terminate the evaluation of the filter chain and prevent the path from being imported or exported.
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
A Network represents a range of addresses with a common prefix that can be reached by zero or more distinct paths.
func (*Network) AddPath ¶
AddPath adds a path by which this network can be reached. It replaces any previously added path from the same peer.
func (*Network) BestPaths ¶
BestPaths returns the best way to reach this network, and a generation number that increments any time the best path has changed. An empty slice is returned if no path is known, and multiple paths may be returned if several are equally good.
func (*Network) RemovePath ¶
RemovePath removes a path via the specified peer. It is safe to call even if no path from the peer is present.
type Path ¶
type Path struct { // Peer is the BGP neighbor from which this path was received. Peer netip.Addr // Nexthop is the IP neighbor where packets traversing the path should be // sent. It's commonly equal to the peer address, but can differ e.g. if the // peer is a route server. Nexthop netip.Addr // LocalPref specifies a priority for the path. Higher values mean the path // is more preferred. LocalPref int // ASPath is a slice of ASNs. The first element is the nexthop and the last // element is the path's origin. ASPath []uint32 // Communities are BGP communities as defined by // https://datatracker.ietf.org/doc/html/rfc1997. Communities []Community }
Path represents a single network path to a destination.
type Peer ¶
type Peer struct { // Addr is the address of the peer. This is required. Addr netip.Addr // Port is the port on which the peer listens. // If not set, port 179 is assumed. Port int // Passive inhibits dialing the peer. The local server will still listen for // incomming connections from the peer. Passive bool // LocalAddr is the local address. LocalAddr netip.Addr // ASN is the expected ASN of the peer. // If present, it will be verified upon connection establishment. ASN uint32 // Import stores the network reachability information received from the peer. // // You must initialize this to contain a non-nil table for each route family // that you want to accept from the peer, prior to adding the peer to a // server. The map must not be manipulated after adding the peer, but network // paths may be added and removed from a table at any time. // // Tables may be safely shared across multiple peers or by import and export // use cases. Import map[RouteFamily]*Table // Export stores the network reachability information to be announced to the // peer. See the documentation on Import for usage details. Export map[RouteFamily]*Table // ImportFilters run for each path received from a peer before it is inserted // into the import table. ImportFilters []Filter // ExportFilters run for each path to be announced to a peer. ExportFilters []Filter // Timers holds optional parameters to control the hold time and keepalive of // the BGP session. Timers *Timers // DialerControl is called after creating the network connection but // before actually dialing. See https://pkg.go.dev/net#Dialer.Control // for background. To configure TCP MD5 authentication, set it to // tcpmd5.DialerControl("password"). DialerControl func(network, address string, c syscall.RawConn) error // ConfigureListener is called for each of the server's listeners upon // adding the peer. To configure TCP MD5 authentication, set it to // tcpmd5.ConfigureListener("2001:db8::1234", "password"), making // sure that the IP address matches the one in Addr. ConfigureListener func(l net.Listener) error // contains filtered or unexported fields }
A Peer is a BGP neighbor.
type RouteFamily ¶
type RouteFamily uint32
func NewRouteFamily ¶
func NewRouteFamily(afi uint16, safi uint8) RouteFamily
func RouteFamilyFor ¶
func RouteFamilyFor(a netip.Addr) RouteFamily
func (RouteFamily) Split ¶
func (a RouteFamily) Split() (uint16, uint8)
type Server ¶
type Server struct { // Hostname is the server's short name. If present, it will be announced to // peers via the FQDN capability. Hostname string // Domainname is the server's domain. If present, it will be announced to // peers via the FQDN capability. Domainname string // RouterID is a unique identifier for this router within its AS. You must // populate this with a 32-bit number formatted as an IPv4 address. RouterID string // ASN is the autonomous system number. This is required. ASN uint32 // CreatePeer is called when an incomming connection doesn't match any // predefined peer. If this function is non-nil and returns a non-error, the // connection will be accepted using the dynamically created peer. Dynamic // peers are destroyed when their TCP connection is closed. CreatePeer func(localAddr, remoteAddr netip.Addr, conn net.Conn) (*Peer, error) // Logger is the destination for human readable debug logs. If you want logs, // you need to set this. To use standard Go logging set it to log.Default(). Logger Logger // contains filtered or unexported fields }
Server is a BGP server.
func (*Server) AddPeer ¶
AddPeer adds a peer.
Peers that are added to a non-running server will be held idle until Serve is called. Peers that are added after the first call to Serve will immediately have their state machine start running.
func (*Server) Close ¶
Close terminates the server and closes all listeners. It does not wait for peering connections to be closed; to do that call Shutdown instead.