Remove policy scripts

Rhai made a decision about a route cost one to three microseconds,
some two hundred times what the same costs in Rust. That was bearable
where a function is asked once for an UPDATE, and is not where every
route is weighed against every peer, as it is when routes are passed
on. What is wanted of a policy (mark routes by where they came from,
mark what is announced, let communities say who is told what) needs no
language; it is to be configuration, done natively.

Kept from that work: route selection goes by a LOCAL_PREF that policy
set on a route from an external peer, and the lab's configuration can
be added to by a phase.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Rayhaan JaufeerallyandClaude Fable 5.1 committed 2026-10-02 22:47:57 +02:00
1 parent cbf0df1eef
commit 9367c38907
48 files changed
+21 -3435

No files matched your search

-61
View File
@@ -1,61 +0,0 @@
// An example policy script; see "Policy scripts" in bin/bgp/README.md for
// everything a function can read and change.
//
// A function is given a route and the peer it comes from (or goes to). It
// may change the route, and returns whether the route is taken (or
// announced). Which function is for which peer is said in the
// configuration: import { function: "from_peer" }.
//
// Constants defined here are for every function below.
// Where a route was learned: what the rules for announcing it go by.
const LEARNED_FROM = #{
customer: "65000:1000",
peer: "65000:2000",
provider: "65000:3000",
route_server: "65000:2000",
};
// A customer's route is preferred to a peer's, and that to a provider's:
// the first earns money, the last costs it.
const PREFERENCE = #{ customer: 300, peer: 200, route_server: 200, provider: 100 };
const BLACKHOLE = "65535:666";
const NO_EXPORT = "65535:65281";
// Routes on their way in.
fn from_peer(route, peer) {
// Not ours to act on, from just anyone.
if route.has_community(BLACKHOLE) { return false; }
// Marks in our own range mean something here: nobody else's word for
// them is taken.
route.remove_community("65000:*");
if peer.role in LEARNED_FROM {
route.add_community(LEARNED_FROM[peer.role]);
route.local_pref = PREFERENCE[peer.role];
}
// A peer can ask to be a last resort: 65000:80 on a route of its own.
if route.has_community(peer.asn % 65536, 80) {
route.local_pref = 80;
}
true
}
// Routes on their way out.
fn to_peer(route, peer) {
if route.has_community(NO_EXPORT) { return false; }
// Only customers are told what we learned from peers and providers.
let from_above = route.has_community("65000:2000") || route.has_community("65000:3000");
if from_above && peer.role != "customer" { return false; }
// Our marks are our own business.
route.remove_community("65000:*");
// Traffic from this one is wanted by another way: the path looks
// longer to it.
if peer.name == "backup-transit" { route.prepend(2); }
true
}
-11
View File
@@ -48,13 +48,7 @@ peers {
# as generated from the routing registries.
# prefixes { prefix: "193.0.0.0/21" max_length: 24 }
# origin_asns: 3333
# And then the operator's own rules: a function of the policy
# script (see `policy` below), which may refuse the route or mark
# and rank it.
# function: "from_peer"
}
# What the peer is told also goes through a function of the script.
# export { function: "to_peer" }
}
connect_retry_seconds: 5
@@ -71,11 +65,6 @@ originate {
large_communities: "65000:1:2"
}
# The operator's own rules for routes, as a script beside this file; see
# policy.rhai here for an example, and "Policy scripts" in
# bin/bgp/README.md. `bgp --check` reads it and says what is wrong.
# policy { path: "policy.rhai" }
# Validation with the RPKI: refuse routes whose origin AS is not the one the
# holder of the addresses authorised, and, from peers with a role, routes
# whose AS path is a leak. Point it at a validator's RTR server.