Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:

jobs:
build-test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand All @@ -27,6 +27,8 @@ jobs:
run: cargo build --verbose

- name: Run tests
env:
FOCL_REQUIRE_TCP_AO: "1"
run: cargo test --verbose

create-release:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:
check:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand All @@ -28,5 +28,9 @@ jobs:
- name: Build
run: cargo build --verbose

# The runner kernel has CONFIG_TCP_AO=y; require it so a runner that
# loses TCP-AO fails here instead of silently skipping those tests.
- name: Run tests
env:
FOCL_REQUIRE_TCP_AO: "1"
run: cargo test --verbose
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@ All notable changes to this project will be documented in this file.

### Fixes

* **TCP-MD5 on the passive listener** - the per-peer keys are installed on the listening socket (Linux `TCP_MD5SIG`) before the accept loop, because the kernel validates the digest on the SYN and `accept()` never returns for a peer whose key is missing; the key is still applied to the accepted socket as well.
* **One peer per address** - configuration validation rejects two peers that name the same IP in different spellings (`192.0.2.1` and `::ffff:192.0.2.1`); one inbound connection could otherwise be assigned to either peer while only one of their keys was installed.
* **Listener address fallback** - `focld` falls through to the next resolved `listen_addr` when a socket cannot be created for one address, as `TcpListener::bind` does, instead of aborting startup.
* **Listener address family** - on Linux the listener reads `IPV6_V6ONLY` from the bound socket: with `bindv6only=1` an IPv4 passive peer is reported as unreachable in `focl peer show` instead of idling without a reason. Other platforms keep the previous dual-stack assumption, and their kernel authentication options bail out anyway.
* **Listener key failures stay visible** - a key that could not be installed on the listening socket is reported in `focl peer show` under `listener_key_error`, which later session errors or an established session do not clear.
* **TCPAO counters** - the README explains the counters as the kernel counts them: an unsigned segment at a socket that requires TCP-AO lands in `TCPAORequired`, while a segment carrying a TCP-AO option whose KeyID matches no installed key lands in `TCPAOKeyNotFound`.
* **Inbound peer matching** - a peer configured as an IPv4-mapped literal (`::ffff:192.0.2.1`) matches its own inbound connection again: both the configured and the remote address are canonicalized before comparing.
* **Listener key installation failures** - every key of a peer is attempted, and a peer whose listener key the kernel refused now carries that failure in `focl peer show` (`last_error`) instead of only in the startup log.
* **Peer address validation** - a peer address must be a literal IP for every authentication mode, not only for TCP-AO, because the session path and the listener already require one.
* **Interop TCP-AO probe** - `scripts/interop/run_bird_tcpao.sh` probes the socket option through `focld` instead of grepping `/proc/net/netstat`, which lists the TCPAO counters even on a kernel built without `CONFIG_TCP_AO`.
* **TCP-MD5 on active sessions** - the key is installed before `connect()` on every active session; without `local_address` it was set after the connect, so the SYN went out unsigned and a peer enforcing TCP-MD5 dropped it.
* **Dual-stack listener** - an inbound connection on a `[::]` listener is matched against IPv4 peers by its v4-mapped address, and listener keys for IPv4 peers are installed in that form; an IPv6 peer's key is no longer offered to an IPv4-only listener. A peer configured in the v4-mapped form (`::ffff:192.0.2.2`) is keyed as the IPv4 peer it is. A passive peer the listener can never accept (an IPv6 peer on an IPv4 listener, an IPv4 peer on a listener bound to one IPv6 address) gets one warning at startup and says why in `focl peer show` (`last_error`); an active peer in that position, which dials out, is no longer logged as an error.
* **Unknown peer settings are rejected** - a key that `[[peers]]` or `[[peers.tcp_ao_keys]]` does not know is a config error instead of being ignored, so a misspelled `password`, `tcp_ao_keys` or `current` cannot leave a peer without the authentication its config asks for.
* **`BgpService` validates its config** - `BgpService::new` runs `FoclConfig::validate`, so a config built in code is held to the same rules as one read by `FoclConfig::load`; a peer with both a password and TCP-AO keys was silently run with TCP-AO only.
* **TCP-MD5 on the passive listener** - the per-peer keys are installed on the listening socket (Linux `TCP_MD5SIG`) before it starts listening, because the kernel validates the digest on the SYN: without the key a signed SYN is dropped and an unsigned one is accepted. That key is the only check there is, as an accepted socket inherits it and cannot be asked whether the handshake was signed, so inbound connections from a peer whose key the listener refused are dropped instead of running unauthenticated.
* **RFC 4271 hold time** - OPEN advertises the configured hold time unchanged (0 disables the timers instead of being raised to 3), the remote OPEN's hold time is taken into account (0 on either side disables the timers, otherwise the smaller value wins), and the keepalive and hold timers are driven by that negotiated value.
* **RFC 6793 AS4_PATH fallback** - a session that did not negotiate the four-octet AS capability now carries `AS_TRANS` in AS_PATH and the real local ASN in AS4_PATH instead of a truncated 2-octet AS_PATH.
* **RFC 2918 route refresh replay** - a received ROUTE-REFRESH for a negotiated family re-sends that family's Adj-RIB-Out followed by its End-of-RIB (the hold timer reset is unchanged); a refresh for a family the session does not carry is ignored, and the RFC 7313 BoRR/EoRR subtypes are not implemented.
* **End-of-RIB for a capability-less peer** - the IPv4 End-of-RIB decision now agrees with the announcement decision, so a plain RFC 4271 peer that negotiated no capabilities gets its IPv4 marker.
* **One initial table send** - the establishment table is sent exactly once, inside the registration critical section, with the End-of-RIB markers after it; the previous pre-lock send re-sent every copy after the EoR and archived it twice.
* The TCP-MD5 socket helpers are re-exported as `focl::bgp::{TcpSocketExt, TcpStreamExt}`.
* The TCP-MD5 and TCP-AO socket helpers are re-exported as `focl::bgp::{TcpSocketExt, TcpStreamExt, TcpAoStatus, tcp_ao_supported, tcp_ao_probe}`; `tcp_ao_supported` reports a failed probe as "no TCP-AO", while `tcp_ao_probe` returns the error.

### New features

* **TCP-AO (RFC 5925)** - a peer can authenticate with `[[peers.tcp_ao_keys]]` (send/recv KeyID, `hmac-sha1-96` or `aes-128-cmac-96`, secret, optional `current`) instead of a TCP-MD5 `password`, on Linux 6.7+ with `CONFIG_TCP_AO`. Keys go on active sockets before `connect()` with segments without TCP-AO refused, and on the listening socket for passive peers; an accepted connection from a TCP-AO peer is verified to be TCP-AO protected before it can replace an existing session. `current` picks the signing key on a connection focl opens; on one the peer opens, the peer's SYN picks the keys and focl logs a warning when they are not the `current` ones. Config validation rejects a peer with both a password and TCP-AO keys, duplicate KeyIDs, more than one current key, and secrets or passwords outside 1-80 bytes. `focld` refuses to start when an enabled peer has TCP-AO keys and the kernel has no TCP-AO, naming the peers. `focl peer show` reports `auth_mode` (`none`, `md5` or `tcp_ao`). The socket definitions come from `linux-raw-sys` (Linux only), as `libc` has no TCP-AO yet. Keys change on restart only.
* **Real peering collector (Phase 1)** - the established session loop no longer discards UPDATEs: raw frames go to the archive and parsed prefixes fill a per-peer Adj-RIB-In that `focl rib in` reads, cleared on session end. OPEN advertises MP-BGP IPv4 and IPv6 unicast plus four-octet AS (AS_TRANS on the wire for a 4-byte local ASN) and, when configured, route refresh; peer capabilities are parsed from the raw frame with negotiated families, ASN4 and route refresh tracked per session, and the remote ASN validated including AS_TRANS resolution. A peer that negotiates no capabilities still establishes plain IPv4 unicast. IPv4 prefixes are announced with classic NLRI and NEXT_HOP, IPv6 through MP_REACH_NLRI, and an invalid non-IPv6 configured next hop is rejected instead of malformed-encoded.
* **Global passive listener** - one bind of `global.listen_addr` serves every inbound connection; a connection is matched against the configured peers before any state change (unmatched ones are dropped with a log), TCP-MD5 is applied to accepted sockets, an inbound connection wins a collision with a simultaneous outbound attempt, and the active loop resumes once it ends.
* **Global passive listener** - one bind of `global.listen_addr` serves every inbound connection; a connection is matched against the configured peers before any state change (unmatched ones are dropped with a log), TCP-MD5 is enforced through per-peer keys on the listening socket, an inbound connection wins a collision with a simultaneous outbound attempt, and the active loop resumes once it ends.
* **Dual-stack archive with raw-frame passthrough (Phase 0)** - archive record types carry `IpAddr`/`IpNet` peers and prefixes, so both families share the update and RIB paths. An UPDATE is written as the original wire frame inside a `BGP4MP_MESSAGE_AS4` envelope instead of being parsed and re-encoded, preserving wire fidelity and unknown attributes. TABLE_DUMP_V2 groups IPv4 and IPv6 entries per (family, prefix) with snapshot-global sequence numbers and ADD-PATH subtypes when a path id is present. Dependencies move to `bgpkit-parser` 0.20 and `bzip2` 0.6, with a new `ipnet-trie` dependency.
* **Runtime prefix control** - `focl prefix add|remove|list` announces or withdraws an originated prefix on the running daemon without restarting it or resetting any session. The effective set is (configured `[[prefixes]]` + runtime additions) minus runtime suppressions: `prefix remove` suppresses a configured prefix (a runtime-only one is dropped), `prefix add` announces it again and clears the suppression, and `prefix list` shows each prefix as `announced`/`suppressed` with a `config`/`runtime` source. Runtime overrides are in-memory only and are never written back to the config file. Address family is inferred from the prefix, `--next-hop` defaults to the configured next hop of the same family, `--dry-run` reports what would be sent without changing state, and `--json` prints the control response.
* **`focl reload` applies the config's prefix delta** - reload re-reads the config file, announces prefixes added since the last read, withdraws removed ones, and clears runtime overrides; the response reports the delta and how many overrides were reset. Peer and archive settings still require a restart.
Expand Down
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] }
zstd = "0.13"

[target.'cfg(target_os = "linux")'.dependencies]
linux-raw-sys = { version = "0.12", default-features = false, features = ["std", "net"] }

[dev-dependencies]
tempfile = "3"
tokio = { version = "1", features = ["test-util"] }
Expand Down
73 changes: 69 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The project consists of:

- [x] IPv4 and IPv6 unicast support
- [x] TCP-MD5 authentication (RFC 2385) for BGP session security
- [x] TCP-AO authentication (RFC 5925) for BGP session security
- [x] Static prefix announcements
- [x] Runtime prefix announce/withdraw via `focl prefix` (in-memory overrides)
- [x] Full BGP FSM with proper timers (hold/keepalive)
Expand Down Expand Up @@ -170,7 +171,7 @@ See `focl-vultr-example.toml` for a complete production-style example with docum
- **bgpkit-parser** - BGP message parsing and MRT encoding
- **tokio** - Async runtime
- **serde/toml** - Configuration handling
- **libc** - TCP-MD5 socket options (Linux only)
- **libc** / **linux-raw-sys** - TCP-MD5 and TCP-AO socket options (Linux only)

## Platform Support

Expand All @@ -179,9 +180,68 @@ See `focl-vultr-example.toml` for a complete production-style example with docum
| BGP Speaker | ✓ | ✓ | ✓ | ? |
| IPv4/IPv6 | ✓ | ✓ | ✓ | ? |
| TCP-MD5 Auth | ✓ | ✗ | ✗ | ✗ |
| TCP-AO Auth | ✓ | ✗ | ✗ | ✗ |
| MRT Archival | ✓ | ✓ | ✓ | ? |

*Note: TCP-MD5 (RFC 2385) requires Linux kernel support*
*Note: TCP-MD5 (RFC 2385) requires Linux kernel support; TCP-AO (RFC 5925) requires Linux 6.7+ built with `CONFIG_TCP_AO`*

## TCP Authentication

A peer authenticates its TCP connection with either TCP-MD5 (`password`) or
TCP-AO (`tcp_ao_keys`), never both. TCP-AO takes one or more master key
tuples:

```toml
[[peers]]
name = "upstream"
address = "192.0.2.2"
remote_as = 65002

[[peers.tcp_ao_keys]]
send_id = 1 # KeyID we sign with = the peer's recv id
recv_id = 2 # KeyID the peer signs with = its send id
algorithm = "hmac-sha1-96" # or "aes-128-cmac-96" (RFC 5926)
secret = "[REDACTED]" # 1-80 bytes
```

On a connection focl opens, the key marked `current = true` (else the first)
signs and is the one focl asks the peer to sign with; the others stay
installed for the peer to use. On a connection the peer opens, the peer's SYN
picks both keys (Linux does not let a listener choose), so `current` has no
effect there and focl logs a warning when the session runs on other keys.

The keys are installed before `connect()` on active sessions and on the
listening socket, before it starts listening, for passive ones, so the kernel
verifies the very first SYN; an accepted connection from a TCP-AO peer is
also checked to really be TCP-AO protected. If the listening socket refuses a
peer's key, focl logs the error and `focl peer show` reports it as the peer's
`last_error`. Inbound connections from a peer the listener holds no key for
are dropped, as nothing would have verified them. Changing keys requires a
restart.
`focl peer show` reports `auth_mode` (`none`, `md5` or `tcp_ao`), and a key the
kernel refused to install on the listening socket appears there as
`listener_key_error`; the peer keeps running without that key and a later
session error does not clear the field.

`focld` refuses to start when an enabled peer has `tcp_ao_keys` and the
kernel has no TCP-AO: such a peer could never get a session. Remove the keys
or set `enabled = false` on the peer to run the others.

A peer that never connects usually has mismatched keys: the kernel drops
segments that fail authentication silently. Its counters say why:

```bash
nstat -az | grep -E 'TCPAO(Good|Bad|KeyNotFound|Required)'
```

* `TCPAOBad`: a segment failed its MAC (wrong secret or algorithm).
* `TCPAOKeyNotFound`: a segment carried a TCP-AO option whose KeyID matched no
installed key, which includes a signed SYN from a peer the socket has no key
for.
* `TCPAORequired`: an unsigned segment reached a socket that requires TCP-AO.
That is a listener holding a key for the peer, a session we opened with
`ao_required`, or an accepted session whose keys were copied from such a
listener.

## Development

Expand All @@ -195,6 +255,7 @@ cargo test
cd scripts/interop
./run_gobgp_smoke.sh # Basic test
./run_gobgp_md5.sh # MD5 authentication test (Linux only)
./run_bird_tcpao.sh # TCP-AO test against BIRD 2.17+/3.1+ (Linux only)
```

### Code Quality
Expand Down Expand Up @@ -224,7 +285,7 @@ cargo clippy --no-default-features
| `asn` | u32 | required | Local AS number |
| `router_id` | string | required | Router ID (IPv4) |
| `listen` | bool | true | Accept incoming connections |
| `listen_addr` | string | "0.0.0.0:179" | Bind address |
| `listen_addr` | string | "0.0.0.0:179" | Bind address; `[::]:179` accepts IPv4 peers as v4-mapped while the socket's `IPV6_V6ONLY` is 0, which is the Linux default |
| `control_socket` | path | "/tmp/focld.sock" | CLI socket path |
| `log_level` | string | "info" | Log level |

Expand All @@ -239,9 +300,13 @@ cargo clippy --no-default-features
| `hold_time_secs` | u16 | 90 | BGP hold timer |
| `connect_retry_secs` | u16 | 5 | Reconnect interval |
| `passive` | bool | false | Wait for peer to connect |
| `password` | string | none | TCP-MD5 password |
| `password` | string | none | TCP-MD5 password (1-80 bytes) |
| `tcp_ao_keys` | array | none | TCP-AO keys: `send_id`, `recv_id`, `algorithm`, `secret`, optional `current` |
| `route_refresh` | bool | true | Enable route refresh |

A key that a `[[peers]]` or `[[peers.tcp_ao_keys]]` table does not know is a
config error, so a misspelled `password` cannot leave a peer unauthenticated.

### Prefix Settings

| Option | Type | Default | Description |
Expand Down
8 changes: 4 additions & 4 deletions docs/collector-revision-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ MRT; the archive knows nothing about BMP/BGP sessions.
## Phase 2 — BMP station mode

1. **`BmpListener`** on a configurable port per station; per-router
TCP-MD5 (TCP-AO is a documentation-level non-goal for v1; focl
implements TCP-MD5 only); accept many routers concurrently. Parsing via
TCP-MD5 (focl's BGP sessions support TCP-MD5 and TCP-AO; the BMP
listener plans MD5 only); accept many routers concurrently. Parsing via
bgpkit-parser 0.20's BMP module.
2. **Feed key (from review blocker 1).** Every route-monitoring feed is
keyed by a canonical `BmpFeedKey`:
Expand Down Expand Up @@ -415,8 +415,8 @@ platform other tools can build on.
3. BMP router identity: one collector_id per router (recommended), resolved
from trusted `[[bmp.routers]]` config matched by source identity —
never derived from untrusted BMP Init sysName.
4. BMP listener MD5: yes (focl implements Linux TCP-MD5 today; TCP-AO is
not implemented and stays out of v1 docs).
4. BMP listener MD5: yes (focl implements Linux TCP-MD5 and, for BGP
sessions, TCP-AO; TCP-AO on the BMP listener is not planned).
5. Trigger delivery semantics: at-least-once with durable per-trigger
delivery records (pending/running/acknowledged/unknown); exec exit 0 =
acknowledged; `unknown` retriable. Document clearly, don't pretend
Expand Down
Loading
Loading