A million IPv4 routes took 1.6 s to install (release build); they take 1.1 s now, and 0.5 s to remove instead of 1.15 s. Most of what is left is the kernel's own work on each route. - Nexthop objects (Linux 5.3 and later): a gateway is put in the kernel once and routes name it, so the kernel checks it once and not for every route. The daemon makes its own objects, uses nobody else's, is told when one of its own is removed and puts it back, and removes them when it stops, which takes all the routes that name them along at once. `without_nexthop_objects` turns this off; a kernel without them is noticed and served as before. - Writing to the kernel is a task of its own, fed through a short queue, so the next batch is worked out while the kernel is busy with the last. "In step" is said when the kernel has done the batch that completes the table, not when it was handed over. - What a next hop resolves to is kept, by next hop: it was looked up among the machine's addresses for every route. - A quicker hash for the plan's maps, and no lookups in the ones that are empty. Fixes a hole found on the way: when an interface went down and came back within the second it takes us to react, the kernel had dropped our routes and we did not put them back, since nothing about them had changed for us. After such a change the kernel is now asked what it actually has. scripts/in-namespace.sh runs one command in a scratch namespace; FERRIX_ROUTES sets the size of the timing test. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
19 lines
840 B
Bash
Executable File
19 lines
840 B
Bash
Executable File
#!/bin/sh
|
|
# Runs a command on Linux in a network namespace made for it, as the
|
|
# calling user with CAP_NET_ADMIN and nothing else: what the tests that
|
|
# change a kernel's routes need. For running one of them by hand, e.g.
|
|
#
|
|
# FERRIX_ROUTES=1000000 scripts/in-namespace.sh cargo test --release \
|
|
# -p bgp-fib --test kernel many -- --include-ignored --nocapture
|
|
set -eu
|
|
namespace="ferrix-ns-$$"
|
|
sudo modprobe dummy 2>/dev/null || true
|
|
sudo ip netns add "$namespace"
|
|
trap 'sudo ip netns del "$namespace"' EXIT
|
|
sudo ip netns exec "$namespace" ip link set lo up
|
|
sudo ip netns exec "$namespace" \
|
|
setpriv --reuid "$(id -u)" --regid "$(id -g)" --init-groups \
|
|
--inh-caps +net_admin --ambient-caps +net_admin \
|
|
env PATH="$PATH" HOME="$HOME" CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-}" \
|
|
FERRIX_ROUTES="${FERRIX_ROUTES:-}" "$@"
|