For an electronics project I’m working on I wanted a way to check the current global routing table every five minutes for both IPv4 and IPv6. I did not want to log into anyone else’s router or looking glass as checking every 5 minutes may be considered abuse.
So I thought to spin up a bird routing instance. I just wanted to receive the routes, not actually install them into the kernel on my linux box. From there I’d be able to check the table size sent over.
Nat Morris helped me out by sending a full tables over a multihop BGP session.
Installing bird is trivial. In order to ensure I’m only running BGP and not installing into the kernel, my configuration looks pretty simple.
/etc/bird.conf:
log syslog all;
router id x.x.x.x;
protocol device { }
protocol bgp {
local as xxxxx;
neighbor x.x.x.x as xxxxx;
multihop;
password "xxxxx";
}
/etc/bird6.conf:
log syslog all;
router id x.x.x.x;
protocol device { }
protocol bgp {
local as xxxxx;
neighbor x:x:x:x:x::x as xxxxx;
source address x:x:x:x:x:x::x;
multihop;
password "xxxxx";
}
In order to get the figures I need, I’d usually have to log into the console of the daemon like so:
$ birdc
BIRD 1.3.7 ready.
bird> show protocols all bgp1
name proto table state since info
bgp1 BGP master up 19:06 Established
Preference: 100
Input filter: ACCEPT
Output filter: REJECT
Routes: 511014 imported, 0 exported, 511014 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 523721 0 0 826 522895
Import withdraws: 1313 0 --- 0 1313
Export updates: 522895 522895 0 --- 0
Export withdraws: 1313 --- --- --- 0
BGP state: Established
Neighbor address: x.x.x.x
Neighbor AS: xxxxx
Neighbor ID: x.x.x.x
Neighbor caps: refresh AS4
Session: external multihop AS4
Source address: x.x.x.x
Hold timer: 142/180
Keepalive timer: 33/60
I could get a script to log in and get the required information via regular expressions, but there has to be an easier way. Turns out you can push a command directly to bird without logging into it first:
$birdc 'show protocols all bgp1'
BIRD 1.3.7 ready.
name proto table state since info
bgp1 BGP master up 19:06 Established
Preference: 100
Input filter: ACCEPT
Output filter: REJECT
Routes: 511025 imported, 0 exported, 511025 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 523924 0 0 839 523085
Import withdraws: 1329 0 --- 0 1329
Export updates: 523085 523085 0 --- 0
Export withdraws: 1329 --- --- --- 0
BGP state: Established
Neighbor address: x.x.x.x
Neighbor AS: xxxxx
Neighbor ID: x.x.x.x.x
Neighbor caps: refresh AS4
Session: external multihop AS4
Source address: x.x.x.x
Hold timer: 161/180
Keepalive timer: 24/60
Still too much information, but we can use grep!
$birdc 'show protocols all bgp1' | grep 'Routes'
Routes: 510977 imported, 0 exported, 510977 preferred
Better, but those fields are nicely tabbed so awk to the rescue! I’d like to get that route count. Easily done.
$birdc 'show protocols all bgp1' | grep 'Routes' | awk {'print $2'}
510976
I can now cron a script that will pull those values once every 5 minutes and generate an XML file which you can see right here.
Feel free to query that page and use it for your own projects. Just be aware there is NO SLA on it :)