Commit Graph
20 Commits
Author SHA1 Message Date
ktims 8962406c57 implement auth, improve session stats 2026-10-23 14:11:16 -07:00
ktims bdf5455a3f Expand unit tests and fix bugs they found
Add unit tests for packet parsing/serialization, interval arithmetic, the
session state machine, validation discards, poll/final, the detection
watchdog, hook scripts, and socket binding.

Fixes:
- BfdAuth parsing subtracted the header from Auth Len twice; Auth Len
  includes the 2-byte header.
- A diagnostic code above 9 panicked the session task; map it to Reserved.
- script_runner panicked on non-UTF-8 script output; decode lossily.
- BfdError::InvalidFieldValue printed field and value swapped.
- BfdInterval now panics on values exceeding u32 microseconds instead of
  silently truncating, and gains checked_mul. Detection time computation
  saturates rather than panicking on remote-supplied multipliers.
2026-10-23 09:52:57 -07:00
ktims 8fbafa455a per-peer stats 2026-10-22 18:14:05 -07:00
ktims ac154066e1 Build a static musl binary into a scratch image
The runtime image contains only the binary and an empty hooks directory, and runs as an unprivileged numeric user. Hook scripts need a shell, so they will not run in this image.
2026-10-22 17:49:12 -07:00
ktims 8321d01ffb Dump the session table on SIGUSR1
Split the receive loop into a select over the control socket and SIGUSR1, and factor the session table formatting into session_report().
2026-10-22 17:49:12 -07:00
ktims eeeef5fb73 Rate-limit logging of unmatched packets
Log the first unmatched packet per source (WARN for an unconfigured source address, INFO for an unknown Your Discriminator) and the repeats at DEBUG until a packet matches again. Removes the duplicate message in rx_packet.
2026-10-22 17:49:12 -07:00
ktims 87e2011c05 Send a control packet immediately on session state change
RFC 5880 6.8.7 says a packet SHOULD be sent between periodic transmissions when its contents would change, so peers see state changes without waiting up to a full interval.
2026-10-22 17:49:12 -07:00
ktims 0c19b955f9 Fix periodic transmit jitter to follow RFC 5880 6.8.7
Jitter was added to a fixed 0.75x clock, so gaps ranged 0.5x-1.0x with a mean of 0.75x of the negotiated interval, below the required 75-100%. Each delay is now drawn independently from 75-100% of the interval (90-100% when DetectMult is 1). Adds statistical and end-to-end sender tests.
2026-10-22 17:49:12 -07:00
ktims 5e5da0c78c Load daemon configuration from file, environment and CLI
Bind addresses and peers are now optional on the command line and merged with the config file. Per-peer timers and detect multiplier are passed through to the session. Multiple bind addresses are accepted by the model but rejected at startup until supported.
2026-10-22 17:49:12 -07:00
ktims ea56afd2f2 Add YAML configuration model and loader
Config is layered: built-in defaults, then the YAML file, then BFD_* environment variables, then CLI flags. Global defaults live under a 'defaults' mapping; per-peer settings are file-only. Includes config.yaml.dist and ScriptHookSink::with_script_dir so the hooks directory is configurable.
2026-10-22 17:48:59 -07:00
ktims 0284ee17b1 clippies 2026-10-22 15:47:16 -07:00
ktims dcbf25ebe0 Add Dockerfile
Multi-stage build producing a slim image with rust-bfdd as the entrypoint. Dependencies are built against stub sources in their own layer so source-only changes do not rebuild them.
2026-10-22 15:44:39 -07:00
ktims 146f8d4c32 Log session table at debug level
The per-packet session dump is too noisy at info.
2026-10-22 15:41:08 -07:00
ktims 4773c9e4f7 Fix protocol conformance issues found in interop testing
Implement the Poll Sequence (initiate on reaching Up when the configured interval is lower than the slow-start one; respond to Poll with Final; terminate on Final) and apply DesiredMinTxInterval changes per RFC 5880 section 6.8.3, keeping the slow rate until the peer has acknowledged. Never set the Demand bit unless demand mode is active, clear the C bit (this implementation shares fate with the control plane), discard packets whose Length exceeds the received payload, and log effective timer changes.
2026-10-22 15:41:08 -07:00
ktims 0bd4f8766a Bind session sockets without panicking
Select a random unused source port in the RFC 5881 range (retrying on EADDRINUSE) instead of unwrapping a pure-random bind. Propagate bind errors out of session start-up, store the local IP on the session instead of unwrapping local_addr(), and log (rather than panic on) receive errors in the rx loop.
2026-10-22 15:41:08 -07:00
ktims c7a6ed16e4 Add command line arguments
Replace the hard-coded addresses with clap arguments: --bind <IP> and one or more --peer <IP>. Peers must match the address family of the bind address. Also updates Cargo.lock.
2026-10-22 15:41:08 -07:00
ktims 0bb1f437ae Declare nix dependency
lib.rs and events.rs already use nix; it was missing from Cargo.toml so the crate did not build.
2026-10-22 15:41:08 -07:00
ktims 953f37d1c7 Lots of refactoring and improvements. Script hooks.
Can now establish and hold a session with BIRD, successfully detect Down
state, and call scripts on state change via an event dispatch engine.

Can't maintain a session with VyOS. I think it is calculating the timers
incorrectly, but don't trust my own implementation of course...
2024-10-07 23:56:33 -07:00
ktims 466d6462a4 Basically working version 2024-05-19 15:02:57 -07:00
ktims d00f47d004 Initial commit. Kinda does something. 2024-01-31 00:59:42 -08:00