BGPd-rs
BGP service daemon built in Rust
Features
- Listen for Incoming BGP sessions
- Specified peers can be an IP address or Network+Mask
- Initiate outbound TCP connection to idle peers
- Will attempt connection based on configured poll interval
- Negotiate OPEN Capabilities
- Receive and respond to Keepalives (on hold time based interval)
- Process UPDATE messages, store in RIB
- Config reloading for Peer status (enable, passive, etc.)
- Update static route advertisements mid-session
- CLI interface for viewing peer status, routes, etc.
- Advertise routes to peers (specified from API and/or Config)
- API/CLI interface for interacting with BGPd
- Flowspec Support
- Route Refresh
- Neighbor MD5 Authentication
- Route Policy for filtering of learned & advertised routes
Peer config
Peers and their config are defined in TOML
format; see an example here.
Details of config values:
= "1.1.1.1" # Default Router ID for the service
= 65000 # Used as the local-as if `local_as` is not defined for a peer
= "127.0.0.1:1179" # BGP address & port
= "0.0.0.0:8080" # API address & port [Listen on all interfaces (IPv4 & IPv6)]
[[]]
= "127.0.0.2" # This can also be an IPv6 address, see next peer
# remote_ip = "10.0.0.0/24" # Network+Mask will accept inbound connections from any source in the subnet
= 65000
= true # If passive, bgpd won't attempt outbound connections
= "127.0.0.1" # Can override local Router ID for this peer
= 90 # Set the hold timer for the peer, defaults to 180 seconds
= [ # Define the families this session should support
"ipv4 unicast",
"ipv6 unicast",
]
[[]] # Add static routes (advertised at session start)
= "9.9.9.0/24"
= "127.0.0.1"
[[]]
= "3001:100::/64"
= "3001:1::1"
[[]] # Add static Flowspec rules too!
= 2
= "traffic-rate 24000"
= [
"source 3001:100::/56",
"destination-port >8000 <=8080",
"packet-length >100",
]
= ["65000", "500"]
= ["101", "202", "65000:99"]
[[]]
= "::2"
= false # Peer is essentially de-configured
= 100
= 200
= [
"ipv6 unicast",
]
You can send the BGPd process a SIGHUP
[E.g. pkill -HUP bgpd$
] to reload and update peer configs. The following items can be updated:
Peers
- Added & removed
- Enabled/disabled
- Active/passive polling for idle peers
- *Hold Timer
- *Supported Families
- When not in an active session only, since these are negotiated in the OPEN
View BGPd Information
BGPd offers an JSON RCP API that can be queried to view operational info like neighbors and routes:
Neighbor uptime & prefixes received
|
{
}
{
}
{
}
Learned routes (with attributes)
|
{
}
{
}
The bgpd
CLI can also be used to view peer & route information via the BGPd API (and announce routes too!)
Development
I'm currently using ExaBGP (Python) and GoBGP (Go) to act as my BGP peers for testing.
- Here's an intro article about installing & getting started with ExaBGP.
ExaBGP setup
With ExaBGP installed, you can use a config from the examples/exabgp
dir:
conf_127.0.0.2.ini
neighbor 127.0.0.1 {
router-id 2.2.2.2;
local-address 127.0.0.2; # Our local update-source
local-as 65000; # Our local AS
peer-as 65000; # Peer's AS
announce {
ipv4 {
unicast 2.100.0.0/24 next-hop self med 500 extended-community [ target:65000:1.1.1.1 ];
unicast 2.200.0.0/24 next-hop self as-path [ 100 200 ];
unicast 2.10.0.0/24 next-hop self med 10 community [404 65000:10];
}
}
}
Running the exabgp service with the command:
--once only attempts a single connection, auto-quits when session ends
Gobgp
With GoBGP installed, you can use a config from the examples/gobgp
dir:
gobgpd.toml
[]
= 65000
= "4.4.4.4"
= 1179
= ["127.0.0.4"]
[[]]
[]
= "127.0.0.1"
= 65000
[]
= false
= "127.0.0.4"
= 1179
[]
= 5
= 30
= 10
Running the gobgpd service with the command:
BGPd Setup
And then running bgpd
as follows:
Using IPv6
or IPv4 (defaults to 127.0.0.1)
You may notice that I'm using TCP port 1179 for testing, if you want/need to use TCP 179 for testing with a peer that can't change the port (coughCiscocough), you need to run bgpd with sudo permissions:
Thanks to
- bgp-rs for the BGP Message Parsing
- tokio for the Runtime
- ParityTech for the JSON RPC API