A BGP daemon that fetches IPv4/IPv6 prefixes for a list of ASNs from the ipverse/as-ip-blocks repository, summarizes them and advertises the resulting prefixes over BGP.
My home ISP has direct peering with a specific AS, which, in theory, should be the fastest way to reach that AS.
However, for some reason, that ISP decides to route the traffic through a very suboptimal path, ignoring the peering; this introduces a fairly good amount of latency, which is undesirable in my case.
To overcome this problem, I have come up with a somewhat complex but robust solution:
bgpd(this tool) is used to periodically fetch a list of IPv4/IPv6 prefixes that the problematic AS announces;- the prefixes are further summarized to reduce the computational overhead;
- in the
bgpdconfiguration,next_hop_ipv{4,6}options point to a gateway that is hosted by another ISP, which does not suffer from this routing problem; - my home router sets up BGP peering with
bgpd, picks up the summarized routes and inserts them into its RIB, guaranteeing that any home devices will route the traffic to an alternative gateway, thus avoiding the suboptimal path.
This project is my first semi-serious foray in Zig, and some of its chosen approaches may be very questionable.
Notably, TCP server backed by a ThreadPool has its own fair share of disadvantages, and the BGP FSM is pretty barebones, but, as with most of my personal projects, it has been deemed "good enough" for my wild and wacky use cases.
I should also consider migrating the project to Zig 0.16 someday; never got around to that.
- Download the latest release;
- Make a copy of
config.example.jsonand save it asconfig.json; - Open
config.jsonand add your desired AS numbers; - Replace
next_hop_ipv4andnext_hop_ipv6according to your gateway address; - Start bgpd.
A Docker image is available in GHCR.
To run the container, you should mount the directory that contains your config.json to the container's /data. The entire directory should be mounted so that the tool can persist cookies across restarts:
docker run -v ~/bgpd:/data ghcr.io/ds8088/bgpd:latestZig 0.15.1+ is required in order to build from source.
Building:
zig build -Drelease=trueTo check if all tests are passing, use:
zig build test --summary all