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.
This commit is contained in:
ktims committed 2026-10-22 17:48:59 -07:00
1 parent 0284ee17b1
commit ea56afd2f2
6 files changed
+754 -2

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
# rust-bfd configuration. Install as /etc/rust-bfd/config.yaml (or pass --config / set BFD_CONFIG).
#
# Precedence, lowest to highest: built-in defaults < this file < BFD_* environment < command line.
# Values shown below are the built-in defaults unless noted. Unknown keys are an error.
# Local address(es) to bind and use as the source of BFD control packets. Required (here, in BFD_BIND, or via --bind).
# Accepts a single address, a list, or a comma-separated string. The daemon currently supports exactly one address;
# the list form is accepted so configs do not need to change once multiple binds are implemented.
# Env: BFD_BIND="192.0.2.1" (or "192.0.2.1,2001:db8::1")
# CLI: --bind 192.0.2.1 [--bind ...] (replaces the addresses configured here)
bind: 192.0.2.1
# bind: [192.0.2.1, "2001:db8::1"]
# Directory of executable scripts run, in lexical order, on every session state change.
# Env: BFD_HOOKS_DIR
hooks_dir: /etc/rust-bfd/hooks.d
# Settings inherited by every peer that does not override them. Durations are humantime strings (300ms, 1s, 2m).
# A peer is never allowed a zero interval or a detect_mult of 0.
defaults:
# Minimum interval between transmitted control packets that we would like to use once the session is Up. Sessions
# that are not Up transmit no faster than once per second regardless (RFC 5880 section 6.8.3).
# Env: BFD_DEFAULTS_DESIRED_MIN_TX
desired_min_tx: 300ms
# Minimum interval between received control packets we can support.
# Env: BFD_DEFAULTS_REQUIRED_MIN_RX
required_min_rx: 300ms
# Detection time multiplier: we declare the session down after this many missed packets.
# Env: BFD_DEFAULTS_DETECT_MULT
detect_mult: 3
# Peers to establish sessions with. Peers can only be configured here and with --peer (repeatable, addresses only,
# default settings); they cannot be set from the environment. Each peer's address must match the family of at least
# one bind address.
peers:
- address: 192.0.2.2
# Per-peer overrides of any `defaults` key:
# - address: 192.0.2.3
# desired_min_tx: 1s
# required_min_rx: 1s
# detect_mult: 5