Rayhaan JaufeerallyandClaude Fable 5.1 cbf0df1eef Policy scripts: the operator's own rules for routes, in Rhai
A new crate, bgp-policy, runs functions of a script on routes: on their
way in, after the general checks of a peer's import and before the
checks that can change (RPKI, next hop reachability); and on their way
out to a peer. A function is given the route and the peer, may refuse
the route, and may change its communities, large communities,
LOCAL_PREF and MED, and on the way out prepend our AS:

    fn from_peer(route, peer) {
        if route.has_community("65535:666") { return false; }
        route.add_community(LEARNED_FROM[peer.role]);
        route.local_pref = PREFERENCE[peer.role];
        true
    }

Configuration: policy { path | source, import_function, export_function }
and, for a peer, import { function } and export { function }. The script
is compiled at startup; `bgp --check` reads it and says which function
is whose. A function that fails on a route has refused it. Scripts have
no files, network or clock, and are stopped after 200,000 steps.

Route selection now goes by a LOCAL_PREF on a route from an external
peer: the decoder never lets a peer's own through, so one that is there
was set by policy.

What it costs was measured before it was built on (benches/policy.rs):
a call that tests a few communities and changes two takes 1 to 3
microseconds, some two hundred times what Rust would. So a function is
asked once for the routes of an UPDATE, which share their attributes,
unless it asks for the prefix. One peer sending 1.23 M routes over a
session: 0.37 s without a function, 0.80 s with one that marks and
ranks every route, 3.4 s if it also looks at the prefix.

Export applies to what is announced, which today is what the daemon
originates; learned routes are not passed on yet.

Tested by unit tests of the crate, sessions end to end, a fuzz target on
the example script (testdata/policy.rhai), and a lab phase in which a
script changes which of FRR's and BIRD's route is chosen and what each
of them is told.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 21:09:39 +02:00

Ferrix BGP

An implementation of the Border Gateway Protocol, which is used to exchange routing and control plane information between Autonomous Systems.

The aim of this project is to provide a modern, high performance, secure, programmatic and customizable software package that can be useful to network operators, researchers, and people interested in Internet.

Current status

The daemon holds sessions with configured peers, takes their routes through an import policy, validates them against the RPKI (route origin validation and ASPA), picks the best route for each prefix and, on Linux, installs it in the kernel. It announces the routes it originates. It does not yet pass routes learned from one peer on to another.

It has not yet run in a production network.

Not there yet

  • Announcing learned routes to other peers (the export policy for it is there: scripts)
  • TCP-AO / TCP MD5 and GTSM
  • Graceful restart, BFD, changing the configuration without a restart
  • Next hops that are not directly connected

Layout

Crate What is in it
crates/primitives Prefixes, address families, parsing helpers
crates/packet The wire format: messages, attributes, capabilities
crates/rib The routing table, best route selection, the journal of changes
crates/rpki The RTR client; origin validation and ASPA path verification
crates/fib The best routes in the Linux kernel, over netlink
crates/policy The operator's own rules for routes, as Rhai scripts
crates/server Sessions, the state machine, policy, configuration
crates/web The status page, HTTP API and metrics
bin/bgp The daemon

Development

CI runs these on every push, and fails on any warning:

cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items

It also runs the tests that need a real Linux kernel (scripts/kernel-tests.sh) and the lab with FRR, BIRD and Routinator (scripts/interop/lab.sh); scripts/linux-vm.sh runs either from macOS.

Lints are configured once, under [workspace.lints] in the root Cargo.toml. unsafe code is forbidden throughout.

cargo test includes property tests: generated messages must survive being written and read back, and no input, however damaged, may make a parser panic. They take about a second; for a longer hunt:

PROPTEST_CASES=1000000 cargo test --release -p bgp-packet --test properties

Coverage-guided fuzz targets for the same parsers are in fuzz/; see fuzz/README.md. CI runs each of them for a minute.

License

Apache License 2.0; see LICENSE.

S
Description
Ferrix BGP Speaker
Readme
5 MiB
0 Stars 0 Watchers 0 Forks
Languages
Rust 92.3%
Shell 4.2%
HTML 3.5%