Compare commits
2
Commits
8fbafa455a
...
8962406c57
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8962406c57 | ||
|
|
bdf5455a3f |
No files matched your search
Generated
+210
-3
@@ -88,6 +88,15 @@ version = "2.13.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa"
|
||||||
|
dependencies = [
|
||||||
|
"hybrid-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytemuck"
|
name = "bytemuck"
|
||||||
version = "1.25.2"
|
version = "1.25.2"
|
||||||
@@ -184,6 +193,21 @@ version = "1.0.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const-oid"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.7.2"
|
version = "0.7.2"
|
||||||
@@ -195,6 +219,15 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453"
|
||||||
|
dependencies = [
|
||||||
|
"hybrid-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "defmt"
|
name = "defmt"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -223,7 +256,18 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0"
|
checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror",
|
"thiserror 2.0.21",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer",
|
||||||
|
"const-oid",
|
||||||
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -404,6 +448,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hybrid-array"
|
||||||
|
version = "0.4.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.14.2"
|
version = "2.14.2"
|
||||||
@@ -412,6 +465,8 @@ checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -429,6 +484,15 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
@@ -499,6 +563,16 @@ version = "0.4.34"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "md-5"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.5",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.8.3"
|
version = "2.8.3"
|
||||||
@@ -576,6 +650,15 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell_polyfill"
|
name = "once_cell_polyfill"
|
||||||
version = "1.70.2"
|
version = "1.70.2"
|
||||||
@@ -750,19 +833,25 @@ dependencies = [
|
|||||||
"bytemuck",
|
"bytemuck",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"clap",
|
"clap",
|
||||||
|
"digest",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures 0.3.34",
|
"futures 0.3.34",
|
||||||
"humantime",
|
"humantime",
|
||||||
"humantime-serde",
|
"humantime-serde",
|
||||||
"itertools",
|
"itertools 0.12.1",
|
||||||
"log",
|
"log",
|
||||||
|
"md-5",
|
||||||
"nix",
|
"nix",
|
||||||
"nom",
|
"nom",
|
||||||
"nom-derive",
|
"nom-derive",
|
||||||
"proc-bitfield",
|
"proc-bitfield",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_bytes",
|
||||||
|
"serde_valid",
|
||||||
"serde_yaml_ng",
|
"serde_yaml_ng",
|
||||||
|
"sha1",
|
||||||
|
"subtle",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-timer",
|
"tokio-timer",
|
||||||
]
|
]
|
||||||
@@ -795,6 +884,16 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_bytes"
|
||||||
|
version = "0.11.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_core"
|
name = "serde_core"
|
||||||
version = "1.0.229"
|
version = "1.0.229"
|
||||||
@@ -815,6 +914,59 @@ dependencies = [
|
|||||||
"syn 3.0.9",
|
"syn 3.0.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.154"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
"zmij",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_valid"
|
||||||
|
version = "3.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a812672d5d6c94c0fa540e62dc318728410c78f40d60ae6c07afc845616da5f6"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"num-traits",
|
||||||
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_valid_derive",
|
||||||
|
"serde_valid_literal",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
"unicode-segmentation",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_valid_derive"
|
||||||
|
version = "3.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "539cd22aaf48cb9a8932c8b7f5d54f51719b2f826564f9da1a9902ee411d753c"
|
||||||
|
dependencies = [
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"strsim",
|
||||||
|
"syn 3.0.9",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_valid_literal"
|
||||||
|
version = "3.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "433e602b939d2e8e8b47f30f919b27a984183974079de2262ca876c2162657c8"
|
||||||
|
dependencies = [
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_yaml_ng"
|
name = "serde_yaml_ng"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@@ -828,6 +980,17 @@ dependencies = [
|
|||||||
"unsafe-libyaml",
|
"unsafe-libyaml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha1"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.5",
|
||||||
|
"cpufeatures",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.8"
|
version = "1.4.8"
|
||||||
@@ -872,6 +1035,12 @@ version = "0.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
@@ -905,13 +1074,33 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "2.0.21"
|
version = "2.0.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl 2.0.21",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -975,12 +1164,24 @@ dependencies = [
|
|||||||
"tokio-executor",
|
"tokio-executor",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.20.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.27"
|
version = "1.0.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-segmentation"
|
||||||
|
version = "1.13.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unsafe-libyaml"
|
name = "unsafe-libyaml"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -1033,3 +1234,9 @@ dependencies = [
|
|||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zmij"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||||
@@ -8,18 +8,24 @@ atomic = "0.6.0"
|
|||||||
bytemuck = { version = "1.14.1", features = ["derive"] }
|
bytemuck = { version = "1.14.1", features = ["derive"] }
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.5.0"
|
||||||
clap = { version = "4", features = ["derive", "env"] }
|
clap = { version = "4", features = ["derive", "env"] }
|
||||||
|
digest = "0.11.3"
|
||||||
env_logger = "0.11.1"
|
env_logger = "0.11.1"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
humantime = "2.4.0"
|
humantime = "2.4.0"
|
||||||
humantime-serde = "1.1.1"
|
humantime-serde = "1.1.1"
|
||||||
itertools = "0.12.1"
|
itertools = "0.12.1"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
|
md-5 = "0.11.0"
|
||||||
nix = { version = "0.31.3", features = ["fs", "socket"] }
|
nix = { version = "0.31.3", features = ["fs", "socket"] }
|
||||||
nom = "7.1.3"
|
nom = "7.1.3"
|
||||||
nom-derive = "0.10.1"
|
nom-derive = "0.10.1"
|
||||||
proc-bitfield = "0.3.1"
|
proc-bitfield = "0.3.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
serde = { version = "1.0.229", features = ["derive"] }
|
serde = { version = "1.0.229", features = ["derive"] }
|
||||||
|
serde_bytes = "0.11.19"
|
||||||
|
serde_valid = "3.2.0"
|
||||||
serde_yaml_ng = "0.10.0"
|
serde_yaml_ng = "0.10.0"
|
||||||
|
sha1 = "0.11.0"
|
||||||
|
subtle = "2.6"
|
||||||
tokio = { version = "1.35.1", features = ["net", "full"] }
|
tokio = { version = "1.35.1", features = ["net", "full"] }
|
||||||
tokio-timer = "0.2.13"
|
tokio-timer = "0.2.13"
|
||||||
@@ -39,3 +39,34 @@ peers:
|
|||||||
# desired_min_tx: 1s
|
# desired_min_tx: 1s
|
||||||
# required_min_rx: 1s
|
# required_min_rx: 1s
|
||||||
# detect_mult: 5
|
# detect_mult: 5
|
||||||
|
#
|
||||||
|
# Authentication (RFC 5880 section 6.7), per peer and off by default. Both ends must be configured identically; a
|
||||||
|
# peer that does not authenticate as configured is discarded. `key_id` is a number (0-255) that must match the remote's.
|
||||||
|
# Keys are used verbatim (not hashed or derived), so they must be exactly the length shown. Give them as a string;
|
||||||
|
# use YAML double-quoted escapes (\x00, \x1b, ...) for bytes that are not printable. Strings are UTF-8, so only bytes
|
||||||
|
# 0x00-0x7f can be written this way. To use bytes 0x80-0xff, give the key as a list of integers instead, one per
|
||||||
|
# byte (hex is fine), with the same length requirement:
|
||||||
|
# key: [0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x80, 0xff]
|
||||||
|
#
|
||||||
|
# Keyed MD5: `key` is exactly 16 bytes. `meticulous` (default true) selects Meticulous Keyed MD5, in which every
|
||||||
|
# packet must carry a newer sequence number; the remote must be set to the same mode.
|
||||||
|
# - address: 192.0.2.4
|
||||||
|
# auth:
|
||||||
|
# type: md5
|
||||||
|
# key_id: 1
|
||||||
|
# key: "0123456789abcdef"
|
||||||
|
# meticulous: true
|
||||||
|
#
|
||||||
|
# Keyed SHA1: `key` is exactly 20 bytes. `meticulous` as above.
|
||||||
|
# - address: 192.0.2.5
|
||||||
|
# auth:
|
||||||
|
# type: sha1
|
||||||
|
# key_id: 1
|
||||||
|
# key: "0123456789abcdef\x00\x01\x7f\x1b"
|
||||||
|
#
|
||||||
|
# Simple password: 1 to 16 bytes, sent in the clear. Provides no protection against an attacker on the path.
|
||||||
|
# - address: 192.0.2.6
|
||||||
|
# auth:
|
||||||
|
# type: password
|
||||||
|
# key_id: 1
|
||||||
|
# password: "secret"
|
||||||
+951
-60
File diff suppressed because it is too large.
Load diff
+788
-30
@@ -3,7 +3,9 @@ use futures::future;
|
|||||||
use rust_bfd::config::{Config, ConfigError, ResolvedConfig, ResolvedPeer};
|
use rust_bfd::config::{Config, ConfigError, ResolvedConfig, ResolvedPeer};
|
||||||
use rust_bfd::events::{EventMessageSink, ScriptHookSink, StateChangeEvent};
|
use rust_bfd::events::{EventMessageSink, ScriptHookSink, StateChangeEvent};
|
||||||
use rust_bfd::{bfd::*, events::EventMessage};
|
use rust_bfd::{bfd::*, events::EventMessage};
|
||||||
use rust_bfd::{set_ttl_or_hop_limit, AtomicInstant, AtomicIntervalStats, BfdSessionStats};
|
use rust_bfd::{
|
||||||
|
set_ttl_or_hop_limit, AtomicInstant, AtomicIntervalStats, AuthStats, BfdSessionStats,
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
error::Error,
|
error::Error,
|
||||||
@@ -91,13 +93,21 @@ impl Display for BfdError {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::InvalidFieldValue(field, value) => {
|
Self::InvalidFieldValue(field, value) => {
|
||||||
write!(f, "invalid value `{}` for field `{}`", field, value)
|
write!(f, "invalid value `{}` for field `{}`", value, field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Error for BfdError {}
|
impl Error for BfdError {}
|
||||||
|
|
||||||
|
/// RFC 5880 6.7.3: a received sequence number must lie in [last, last + 3 * detect_mult] (or [last + 1, ..] when
|
||||||
|
/// meticulous), treated as an unsigned 32-bit circular number space.
|
||||||
|
fn seq_in_window(last: u32, seq: u32, detect_mult: u8, meticulous: bool) -> bool {
|
||||||
|
let lo = last.wrapping_add(meticulous as u32);
|
||||||
|
let hi = last.wrapping_add(3 * detect_mult as u32);
|
||||||
|
seq.wrapping_sub(lo) <= hi.wrapping_sub(lo)
|
||||||
|
}
|
||||||
|
|
||||||
/// Data structure to store the state of the Bfd machine. The impl does *not*
|
/// Data structure to store the state of the Bfd machine. The impl does *not*
|
||||||
/// implement any Bfd logic, it is merely a thread-safe data structure
|
/// implement any Bfd logic, it is merely a thread-safe data structure
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -116,10 +126,10 @@ struct BfdSessionState {
|
|||||||
demand_mode: Atomic<bool>, // mutable by rx thread
|
demand_mode: Atomic<bool>, // mutable by rx thread
|
||||||
remote_demand_mode: Atomic<bool>, // mutable by rx thread
|
remote_demand_mode: Atomic<bool>, // mutable by rx thread
|
||||||
detect_mult: Atomic<u8>, // mutable by control thread
|
detect_mult: Atomic<u8>, // mutable by control thread
|
||||||
auth_type: Atomic<BfdAuthType>, // mutable by control thread
|
rcv_auth_seq: Mutex<u32>, // must guard validation against parallel reception
|
||||||
rcv_auth_seq: Atomic<u32>, // mutable by rx thread
|
xmit_auth_seq: Mutex<u32>, // must guard against OOO parallel transmission e.g. in rx task
|
||||||
xmit_auth_seq: Atomic<u32>, // mutable by tx thread?
|
|
||||||
auth_seq_known: Atomic<bool>, // mutable by rx thread?
|
auth_seq_known: Atomic<bool>, // mutable by rx thread?
|
||||||
|
auth_type: Atomic<BfdAuthType>, // immutable after construction
|
||||||
|
|
||||||
detection_time: Atomic<BfdInterval>, // mutable by rx thread
|
detection_time: Atomic<BfdInterval>, // mutable by rx thread
|
||||||
poll_mode: Atomic<bool>, // mutable by rx thread
|
poll_mode: Atomic<bool>, // mutable by rx thread
|
||||||
@@ -193,6 +203,12 @@ impl BfdSessionState {
|
|||||||
fn auth_type(&self) -> BfdAuthType {
|
fn auth_type(&self) -> BfdAuthType {
|
||||||
self.auth_type.load(ORDERING)
|
self.auth_type.load(ORDERING)
|
||||||
}
|
}
|
||||||
|
fn auth_seq_known(&self) -> bool {
|
||||||
|
self.auth_seq_known.load(ORDERING)
|
||||||
|
}
|
||||||
|
fn set_auth_seq_known(&self, value: bool) {
|
||||||
|
self.auth_seq_known.store(value, ORDERING)
|
||||||
|
}
|
||||||
fn detect_mult(&self) -> u8 {
|
fn detect_mult(&self) -> u8 {
|
||||||
self.detect_mult.load(ORDERING)
|
self.detect_mult.load(ORDERING)
|
||||||
}
|
}
|
||||||
@@ -265,6 +281,7 @@ struct BfdSession {
|
|||||||
// DesiredMinTxInterval actually used for the transmit rate; lags the advertised value during a Poll Sequence
|
// DesiredMinTxInterval actually used for the transmit rate; lags the advertised value during a Poll Sequence
|
||||||
effective_desired_min_tx: BfdInterval,
|
effective_desired_min_tx: BfdInterval,
|
||||||
event_dispatcher: EventDispatcherHandle,
|
event_dispatcher: EventDispatcherHandle,
|
||||||
|
auth: Option<BfdAuth>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&BfdSessionState> for BfdSessionStats {
|
impl From<&BfdSessionState> for BfdSessionStats {
|
||||||
@@ -283,6 +300,7 @@ impl From<&BfdSessionState> for BfdSessionStats {
|
|||||||
last_change: state.last_state_change(),
|
last_change: state.last_state_change(),
|
||||||
detect_time: state.detection_time(),
|
detect_time: state.detection_time(),
|
||||||
base_interval: BfdInterval::from_secs(0), // TODO: This is a hack and will be patched up in the session
|
base_interval: BfdInterval::from_secs(0), // TODO: This is a hack and will be patched up in the session
|
||||||
|
auth: None, // filled in by the session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -463,6 +481,9 @@ impl BfdSession {
|
|||||||
// .connect(SocketAddr::new(remote_addr, CONTROL_PORT))
|
// .connect(SocketAddr::new(remote_addr, CONTROL_PORT))
|
||||||
// .await?;
|
// .await?;
|
||||||
|
|
||||||
|
let auth: Option<BfdAuth> = peer.auth.map(Into::into);
|
||||||
|
let auth_type = auth.as_ref().map_or(BfdAuthType::None, BfdAuth::auth_type);
|
||||||
|
|
||||||
// Incoming packets will come over the channel from the mux, since they don't send to the reciprocal port
|
// Incoming packets will come over the channel from the mux, since they don't send to the reciprocal port
|
||||||
Self {
|
Self {
|
||||||
rx,
|
rx,
|
||||||
@@ -473,6 +494,7 @@ impl BfdSession {
|
|||||||
configured_desired_min_tx,
|
configured_desired_min_tx,
|
||||||
effective_desired_min_tx: slow_desired_min_tx,
|
effective_desired_min_tx: slow_desired_min_tx,
|
||||||
event_dispatcher,
|
event_dispatcher,
|
||||||
|
auth,
|
||||||
state: BfdSessionState {
|
state: BfdSessionState {
|
||||||
control_sock: Arc::new(control_sock),
|
control_sock: Arc::new(control_sock),
|
||||||
local_ip: local_addr,
|
local_ip: local_addr,
|
||||||
@@ -488,10 +510,10 @@ impl BfdSession {
|
|||||||
demand_mode: Atomic::new(false),
|
demand_mode: Atomic::new(false),
|
||||||
remote_demand_mode: Atomic::new(false),
|
remote_demand_mode: Atomic::new(false),
|
||||||
detect_mult: Atomic::new(peer.detect_mult),
|
detect_mult: Atomic::new(peer.detect_mult),
|
||||||
auth_type: Atomic::new(BfdAuthType::None),
|
rcv_auth_seq: Mutex::new(0),
|
||||||
rcv_auth_seq: Atomic::new(0),
|
xmit_auth_seq: Mutex::new(rng.gen()),
|
||||||
xmit_auth_seq: Atomic::new(rng.gen()),
|
|
||||||
auth_seq_known: Atomic::new(false),
|
auth_seq_known: Atomic::new(false),
|
||||||
|
auth_type: Atomic::new(auth_type),
|
||||||
detection_time: Atomic::new(BfdInterval::from_secs(0)),
|
detection_time: Atomic::new(BfdInterval::from_secs(0)),
|
||||||
poll_mode: Atomic::new(false),
|
poll_mode: Atomic::new(false),
|
||||||
|
|
||||||
@@ -568,16 +590,41 @@ impl BfdSession {
|
|||||||
self.transmit_control_packet(false).await;
|
self.transmit_control_packet(false).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn auth_stats(&self) -> Option<AuthStats> {
|
||||||
|
let auth = self.auth.as_ref()?;
|
||||||
|
let uses_seq = !matches!(auth, BfdAuth::SimplePassword(_));
|
||||||
|
let rcv_seq = if uses_seq && self.state.auth_seq_known() {
|
||||||
|
Some(*self.state.rcv_auth_seq.lock().await)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let xmit_seq = if uses_seq {
|
||||||
|
Some(*self.state.xmit_auth_seq.lock().await)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
Some(AuthStats {
|
||||||
|
auth_type: self.state.auth_type(),
|
||||||
|
key_id: auth.key_id(),
|
||||||
|
rcv_seq,
|
||||||
|
xmit_seq,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async fn run(&mut self) {
|
async fn run(&mut self) {
|
||||||
while let Some(cmd) = self.rx.recv().await {
|
while let Some(cmd) = self.rx.recv().await {
|
||||||
|
let mut missed_detect_times = 0;
|
||||||
match cmd {
|
match cmd {
|
||||||
SessionControlCommand::Quit => return,
|
SessionControlCommand::Quit => return,
|
||||||
SessionControlCommand::RxPacket(packet) => {
|
SessionControlCommand::RxPacket(packet) => {
|
||||||
|
missed_detect_times = 0;
|
||||||
self.receive_control_packet(&packet).await;
|
self.receive_control_packet(&packet).await;
|
||||||
}
|
}
|
||||||
SessionControlCommand::GetSessionStats { respond_to } => {
|
SessionControlCommand::GetSessionStats { respond_to } => {
|
||||||
let stats =
|
let auth = self.auth_stats().await;
|
||||||
BfdSessionStats::from(&self.state).with_base_interval(self.cur_interval);
|
let stats = BfdSessionStats::from(&self.state)
|
||||||
|
.with_base_interval(self.cur_interval)
|
||||||
|
.with_auth(auth);
|
||||||
respond_to.send(stats).unwrap()
|
respond_to.send(stats).unwrap()
|
||||||
}
|
}
|
||||||
SessionControlCommand::TxControlPacket { poll_response } => {
|
SessionControlCommand::TxControlPacket { poll_response } => {
|
||||||
@@ -585,15 +632,19 @@ impl BfdSession {
|
|||||||
}
|
}
|
||||||
SessionControlCommand::ReceiveTimeout => {
|
SessionControlCommand::ReceiveTimeout => {
|
||||||
self.state.set_local_diag(BfdDiagnostic::TimeExpired);
|
self.state.set_local_diag(BfdDiagnostic::TimeExpired);
|
||||||
|
missed_detect_times += 1;
|
||||||
self.transition(BfdState::Down).await;
|
self.transition(BfdState::Down).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if missed_detect_times == 2 {
|
||||||
|
self.state.set_auth_seq_known(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
println!("Session command channel closed");
|
println!("Session command channel closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn transmit_control_packet(&self, poll_response: bool) {
|
async fn transmit_control_packet(&mut self, poll_response: bool) {
|
||||||
let packet = BfdPacket {
|
let mut packet = BfdPacket {
|
||||||
flags: BfdFlags(0)
|
flags: BfdFlags(0)
|
||||||
.with_vers(1)
|
.with_vers(1)
|
||||||
.with_diag(self.state.local_diag().into())
|
.with_diag(self.state.local_diag().into())
|
||||||
@@ -607,18 +658,32 @@ impl BfdSession {
|
|||||||
.with_cpi(false)
|
.with_cpi(false)
|
||||||
.with_demand(self.state.demand_mode())
|
.with_demand(self.state.demand_mode())
|
||||||
.with_detect_mult(self.state.detect_mult())
|
.with_detect_mult(self.state.detect_mult())
|
||||||
.with_length(24),
|
.with_length(24 + self.auth.as_ref().map_or(0, BfdAuth::auth_len))
|
||||||
|
.with_auth_present(self.auth.is_some()),
|
||||||
my_disc: self.state.local_discr(),
|
my_disc: self.state.local_discr(),
|
||||||
your_disc: self.state.remote_discr(),
|
your_disc: self.state.remote_discr(),
|
||||||
desired_min_tx: self.state.desired_min_tx_interval(),
|
desired_min_tx: self.state.desired_min_tx_interval(),
|
||||||
required_min_rx: self.state.required_min_rx_interval(),
|
required_min_rx: self.state.required_min_rx_interval(),
|
||||||
required_min_echo_rx: BfdInterval::from_secs(0),
|
required_min_echo_rx: BfdInterval::from_secs(0),
|
||||||
auth: None,
|
auth: self.auth.clone(), // put configured method and key into packet
|
||||||
};
|
};
|
||||||
let socket = self.state.control_sock.clone();
|
let socket = self.state.control_sock.clone();
|
||||||
let dest = self.state.peer_addr;
|
let dest = self.state.peer_addr;
|
||||||
|
|
||||||
|
// Held until the packet is sent so sequence numbers hit the wire in order
|
||||||
|
let mut xmit_seq = match packet.auth {
|
||||||
|
Some(_) => Some(self.state.xmit_auth_seq.lock().await),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
if let (Some(auth), Some(seq)) = (&mut packet.auth, xmit_seq.as_mut()) {
|
||||||
|
**seq = seq.wrapping_add(1);
|
||||||
|
auth.set_seq(**seq);
|
||||||
|
}
|
||||||
|
packet.sign().unwrap();
|
||||||
|
|
||||||
self.state.record_tx();
|
self.state.record_tx();
|
||||||
debug!("tx packet: {:?}", packet);
|
debug!("tx packet: {:?}", packet);
|
||||||
|
|
||||||
if let Err(e) = socket
|
if let Err(e) = socket
|
||||||
.send_to(
|
.send_to(
|
||||||
packet.serialize().unwrap().as_ref(),
|
packet.serialize().unwrap().as_ref(),
|
||||||
@@ -755,7 +820,6 @@ impl BfdSession {
|
|||||||
warn!("Got packet with auth enabled when we disagree, discarding");
|
warn!("Got packet with auth enabled when we disagree, discarding");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the A bit is clear and authentication is in use (bfd.AuthType is nonzero), the packet MUST be discarded.
|
// If the A bit is clear and authentication is in use (bfd.AuthType is nonzero), the packet MUST be discarded.
|
||||||
if !p.flags.auth_present() && self.state.auth_type() != BfdAuthType::None {
|
if !p.flags.auth_present() && self.state.auth_type() != BfdAuthType::None {
|
||||||
warn!("Got packet without auth when we expect it, discarding");
|
warn!("Got packet without auth when we expect it, discarding");
|
||||||
@@ -764,8 +828,48 @@ impl BfdSession {
|
|||||||
|
|
||||||
// If the A bit is set, the packet MUST be authenticated under the rules of section 6.7, based on the
|
// If the A bit is set, the packet MUST be authenticated under the rules of section 6.7, based on the
|
||||||
// authentication type in use (bfd.AuthType). This may cause the packet to be discarded.
|
// authentication type in use (bfd.AuthType). This may cause the packet to be discarded.
|
||||||
if p.flags.auth_present() {
|
if let Some(expected) = self.auth.as_ref().filter(|_| p.flags.auth_present()) {
|
||||||
unimplemented!("Authentication is not implemented");
|
let received_seq = p.auth.as_ref().and_then(BfdAuth::seq);
|
||||||
|
let mut rcv_auth_seq = self.state.rcv_auth_seq.lock().await;
|
||||||
|
|
||||||
|
if let Some(seq) = received_seq {
|
||||||
|
// If bfd.AuthSeqKnown is 1, examine the Sequence Number field. [...] if the sequence number lies
|
||||||
|
// outside of the valid range the received packet MUST be discarded.
|
||||||
|
if self.state.auth_seq_known() {
|
||||||
|
if !seq_in_window(
|
||||||
|
*rcv_auth_seq,
|
||||||
|
seq,
|
||||||
|
p.flags.detect_mult(),
|
||||||
|
expected.meticulous(),
|
||||||
|
) {
|
||||||
|
warn!(
|
||||||
|
"Got packet with out of window sequence number {} (last {}), discarding",
|
||||||
|
seq, *rcv_auth_seq
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise (bfd.AuthSeqKnown is 0), set bfd.AuthSeqKnown to 1.
|
||||||
|
self.state.set_auth_seq_known(true);
|
||||||
|
}
|
||||||
|
// bfd.RcvAuthSeq is set to the Sequence Number field.
|
||||||
|
*rcv_auth_seq = seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
match p.verify(expected) {
|
||||||
|
Ok(true) => {}
|
||||||
|
Ok(false) => {
|
||||||
|
warn!("Got packet failing authentication, discarding");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!(
|
||||||
|
"Error verifying packet authentication ({:?}), discarding",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set bfd.RemoteDiscr to the value of My Discriminator.
|
// Set bfd.RemoteDiscr to the value of My Discriminator.
|
||||||
@@ -777,7 +881,8 @@ impl BfdSession {
|
|||||||
// Set bfd.RemoteMinRxInterval to the value of Required Min RX Interval.
|
// Set bfd.RemoteMinRxInterval to the value of Required Min RX Interval.
|
||||||
self.state.set_remote_min_rx_interval(p.required_min_rx);
|
self.state.set_remote_min_rx_interval(p.required_min_rx);
|
||||||
// Not in spec: store the received diagnostic
|
// Not in spec: store the received diagnostic
|
||||||
self.state.set_last_remote_diag(p.flags.diag().unwrap());
|
self.state
|
||||||
|
.set_last_remote_diag(p.flags.diag().unwrap_or(BfdDiagnostic::Reserved));
|
||||||
|
|
||||||
// If the Required Min Echo RX Interval field is zero, the transmission of Echo packets, if any, MUST cease.
|
// If the Required Min Echo RX Interval field is zero, the transmission of Echo packets, if any, MUST cease.
|
||||||
if p.required_min_echo_rx == BfdInterval::from_secs(0) {
|
if p.required_min_echo_rx == BfdInterval::from_secs(0) {
|
||||||
@@ -908,14 +1013,24 @@ impl BfdSession {
|
|||||||
// https://datatracker.ietf.org/doc/html/rfc5880#section-6.8.4
|
// https://datatracker.ietf.org/doc/html/rfc5880#section-6.8.4
|
||||||
async fn update_detection_time(&mut self, p: &BfdPacket) {
|
async fn update_detection_time(&mut self, p: &BfdPacket) {
|
||||||
let old = self.state.detection_time();
|
let old = self.state.detection_time();
|
||||||
|
// Remote-supplied values can overflow the 32-bit microsecond range; saturate rather than panic.
|
||||||
|
let saturating = |mult: u8, interval: BfdInterval| {
|
||||||
|
interval
|
||||||
|
.checked_mul(mult as u32)
|
||||||
|
.unwrap_or(BfdInterval::from_micros(u32::MAX))
|
||||||
|
};
|
||||||
self.state.set_detection_time(if !self.state.demand_mode() {
|
self.state.set_detection_time(if !self.state.demand_mode() {
|
||||||
p.flags.detect_mult() as u32
|
saturating(
|
||||||
* std::cmp::max(self.state.required_min_rx_interval(), p.desired_min_tx)
|
p.flags.detect_mult(),
|
||||||
|
std::cmp::max(self.state.required_min_rx_interval(), p.desired_min_tx),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
self.state.detect_mult() as u32
|
saturating(
|
||||||
* std::cmp::max(
|
self.state.detect_mult(),
|
||||||
|
std::cmp::max(
|
||||||
self.state.desired_min_tx_interval(),
|
self.state.desired_min_tx_interval(),
|
||||||
self.state.remote_min_rx_interval(),
|
self.state.remote_min_rx_interval(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
if old != self.state.detection_time() {
|
if old != self.state.detection_time() {
|
||||||
@@ -1072,7 +1187,7 @@ impl Bfdd {
|
|||||||
}
|
}
|
||||||
let session = BfdSessionHandle::new(
|
let session = BfdSessionHandle::new(
|
||||||
self.local.ip(),
|
self.local.ip(),
|
||||||
*peer,
|
peer.clone(),
|
||||||
local_discr,
|
local_discr,
|
||||||
self.event_dispatcher.clone(),
|
self.event_dispatcher.clone(),
|
||||||
)
|
)
|
||||||
@@ -1153,13 +1268,22 @@ impl Bfdd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn session_report(&self) -> String {
|
async fn session_report(&self) -> String {
|
||||||
future::join_all(
|
let mut stats = future::join_all(
|
||||||
self.sessions_by_discr
|
self.sessions_by_discr
|
||||||
.values()
|
.values()
|
||||||
.map(|session| async { session.get_stats().await.unwrap().to_string() }),
|
.map(|session| async { session.get_stats().await.unwrap() }),
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
.join("\n\t")
|
stats.sort_by_key(|s| s.remote_ip);
|
||||||
|
stats
|
||||||
|
.iter()
|
||||||
|
.flat_map(|s| {
|
||||||
|
s.to_string()
|
||||||
|
.lines()
|
||||||
|
.map(|l| format!("\n {l}"))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
async fn handle_datagram(&self, data: &[u8], addr: SocketAddr) {
|
async fn handle_datagram(&self, data: &[u8], addr: SocketAddr) {
|
||||||
let Ok((_leftover, packet)) = BfdPacket::parse(data) else {
|
let Ok((_leftover, packet)) = BfdPacket::parse(data) else {
|
||||||
@@ -1178,7 +1302,7 @@ impl Bfdd {
|
|||||||
async fn run(mut self) -> io::Result<()> {
|
async fn run(mut self) -> io::Result<()> {
|
||||||
info!("rust-bfd starting up");
|
info!("rust-bfd starting up");
|
||||||
self.start_peers().await?;
|
self.start_peers().await?;
|
||||||
info!("configured sessions: {}", self.session_report().await);
|
info!("configured sessions:{}", self.session_report().await);
|
||||||
|
|
||||||
let mut sigusr1 = signal(SignalKind::user_defined1())?;
|
let mut sigusr1 = signal(SignalKind::user_defined1())?;
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
@@ -1193,14 +1317,14 @@ impl Bfdd {
|
|||||||
Ok((len, addr)) => {
|
Ok((len, addr)) => {
|
||||||
self.handle_datagram(&buf[..len], addr).await;
|
self.handle_datagram(&buf[..len], addr).await;
|
||||||
if log_enabled!(log::Level::Debug) {
|
if log_enabled!(log::Level::Debug) {
|
||||||
debug!("configured sessions: {}", self.session_report().await);
|
debug!("configured sessions:{}", self.session_report().await);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => warn!("Error receiving from socket {e:?}"),
|
Err(e) => warn!("Error receiving from socket {e:?}"),
|
||||||
},
|
},
|
||||||
_ = sigusr1.recv() => {
|
_ = sigusr1.recv() => {
|
||||||
info!("SIGUSR1 received");
|
info!("SIGUSR1 received");
|
||||||
info!("configured sessions: {}", self.session_report().await);
|
info!("configured sessions:{}", self.session_report().await);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1237,6 +1361,45 @@ async fn main() -> io::Result<()> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn seq_window_non_meticulous_bounds() {
|
||||||
|
// RFC 5880 6.7.3: [RcvAuthSeq, RcvAuthSeq + 3*DetectMult]
|
||||||
|
assert!(seq_in_window(100, 100, 3, false));
|
||||||
|
assert!(seq_in_window(100, 101, 3, false));
|
||||||
|
assert!(seq_in_window(100, 109, 3, false));
|
||||||
|
assert!(!seq_in_window(100, 110, 3, false));
|
||||||
|
assert!(!seq_in_window(100, 99, 3, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn seq_window_meticulous_bounds() {
|
||||||
|
// RFC 5880 6.7.4: [RcvAuthSeq + 1, RcvAuthSeq + 3*DetectMult]
|
||||||
|
assert!(!seq_in_window(100, 100, 3, true));
|
||||||
|
assert!(seq_in_window(100, 101, 3, true));
|
||||||
|
assert!(seq_in_window(100, 109, 3, true));
|
||||||
|
assert!(!seq_in_window(100, 110, 3, true));
|
||||||
|
assert!(!seq_in_window(100, 99, 3, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn seq_window_scales_with_detect_mult() {
|
||||||
|
assert!(seq_in_window(0, 3, 1, false));
|
||||||
|
assert!(!seq_in_window(0, 4, 1, false));
|
||||||
|
assert!(seq_in_window(0, 255 * 3, 255, false));
|
||||||
|
assert!(!seq_in_window(0, 255 * 3 + 1, 255, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn seq_window_wraps_at_u32_max() {
|
||||||
|
assert!(seq_in_window(u32::MAX, u32::MAX, 3, false));
|
||||||
|
assert!(!seq_in_window(u32::MAX, u32::MAX, 3, true));
|
||||||
|
assert!(seq_in_window(u32::MAX, 0, 3, true));
|
||||||
|
assert!(seq_in_window(u32::MAX - 2, 6, 3, true));
|
||||||
|
assert!(!seq_in_window(u32::MAX - 2, 7, 3, true));
|
||||||
|
assert!(!seq_in_window(u32::MAX - 2, u32::MAX - 3, 3, true));
|
||||||
|
assert!(!seq_in_window(5, u32::MAX, 3, true));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn jitter_is_uniform_over_rfc_range() {
|
fn jitter_is_uniform_over_rfc_range() {
|
||||||
// RFC 5880 6.8.7: each interval is reduced by a random 0-25% (0-10% when DetectMult is 1), so delays are
|
// RFC 5880 6.8.7: each interval is reduced by a random 0-25% (0-10% when DetectMult is 1), so delays are
|
||||||
@@ -1327,4 +1490,599 @@ mod tests {
|
|||||||
assert_eq!(args.bind.len(), 2);
|
assert_eq!(args.bind.len(), 2);
|
||||||
assert_eq!(args.peers.len(), 2);
|
assert_eq!(args.peers.len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
|
||||||
|
const LOCAL: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
||||||
|
const PEER: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 2));
|
||||||
|
const LOCAL_DISCR: u32 = 1000;
|
||||||
|
const REMOTE_DISCR: u32 = 2000;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct CaptureSink {
|
||||||
|
tx: mpsc::Sender<EventMessage>,
|
||||||
|
rx: mpsc::Receiver<EventMessage>,
|
||||||
|
out: mpsc::UnboundedSender<StateChangeEvent>,
|
||||||
|
}
|
||||||
|
impl EventMessageSink for CaptureSink {
|
||||||
|
fn channel(&self) -> mpsc::Sender<EventMessage> {
|
||||||
|
self.tx.clone()
|
||||||
|
}
|
||||||
|
fn run(mut self: Box<Self>) -> JoinHandle<()> {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
while let Some(EventMessage::StateChange(ev)) = self.rx.recv().await {
|
||||||
|
let _ = self.out.send(ev);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn capture_dispatcher() -> (
|
||||||
|
EventDispatcherHandle,
|
||||||
|
mpsc::UnboundedReceiver<StateChangeEvent>,
|
||||||
|
) {
|
||||||
|
let dispatcher = EventDispatcherHandle::new().await;
|
||||||
|
let (tx, rx) = mpsc::channel(16);
|
||||||
|
let (out, events) = mpsc::unbounded_channel();
|
||||||
|
dispatcher
|
||||||
|
.add_sink(Box::new(CaptureSink { tx, rx, out }))
|
||||||
|
.await;
|
||||||
|
(dispatcher, events)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn peer_cfg(desired_ms: u32, required_ms: u32, detect_mult: u8) -> ResolvedPeer {
|
||||||
|
ResolvedPeer {
|
||||||
|
address: PEER,
|
||||||
|
desired_min_tx: BfdInterval::from_millis(desired_ms),
|
||||||
|
required_min_rx: BfdInterval::from_millis(required_ms),
|
||||||
|
detect_mult,
|
||||||
|
auth: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pkt(state: BfdState, my: u32, your: u32) -> BfdPacket {
|
||||||
|
BfdPacket {
|
||||||
|
flags: BfdFlags(0)
|
||||||
|
.with_vers(1)
|
||||||
|
.with_state(state as u8)
|
||||||
|
.with_detect_mult(3)
|
||||||
|
.with_length(24),
|
||||||
|
my_disc: BfdDiscriminator(my),
|
||||||
|
your_disc: BfdDiscriminator(your),
|
||||||
|
desired_min_tx: BfdInterval::from_millis(300),
|
||||||
|
required_min_rx: BfdInterval::from_millis(300),
|
||||||
|
required_min_echo_rx: BfdInterval::from_micros(0),
|
||||||
|
auth: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_flags(mut p: BfdPacket, f: impl FnOnce(BfdFlags) -> BfdFlags) -> BfdPacket {
|
||||||
|
p.flags = f(p.flags);
|
||||||
|
p
|
||||||
|
}
|
||||||
|
async fn session(
|
||||||
|
peer: ResolvedPeer,
|
||||||
|
) -> (BfdSession, mpsc::UnboundedReceiver<StateChangeEvent>) {
|
||||||
|
let (dispatcher, events) = capture_dispatcher().await;
|
||||||
|
let (tx, rx) = mpsc::channel(32);
|
||||||
|
let sock = UdpSocket::bind((LOCAL, 0)).await.unwrap();
|
||||||
|
let s = BfdSession::new(
|
||||||
|
rx,
|
||||||
|
BfdSessionHandle { tx },
|
||||||
|
sock,
|
||||||
|
LOCAL,
|
||||||
|
peer,
|
||||||
|
BfdDiscriminator(LOCAL_DISCR),
|
||||||
|
dispatcher,
|
||||||
|
);
|
||||||
|
(s, events)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn next_event(
|
||||||
|
events: &mut mpsc::UnboundedReceiver<StateChangeEvent>,
|
||||||
|
) -> StateChangeEvent {
|
||||||
|
time::timeout(Duration::from_secs(2), events.recv())
|
||||||
|
.await
|
||||||
|
.expect("timed out waiting for event")
|
||||||
|
.expect("event channel closed")
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn assert_no_event(events: &mut mpsc::UnboundedReceiver<StateChangeEvent>) {
|
||||||
|
time::sleep(Duration::from_millis(50)).await;
|
||||||
|
assert!(events.try_recv().is_err(), "unexpected state change event");
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn session_in(
|
||||||
|
state: BfdState,
|
||||||
|
) -> (BfdSession, mpsc::UnboundedReceiver<StateChangeEvent>) {
|
||||||
|
let (mut s, mut events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
let path: &[BfdState] = match state {
|
||||||
|
BfdState::Down => &[],
|
||||||
|
BfdState::Init => &[BfdState::Down],
|
||||||
|
_ => &[BfdState::Down, BfdState::Init],
|
||||||
|
};
|
||||||
|
for (i, remote) in path.iter().enumerate() {
|
||||||
|
let your = if i == 0 { 0 } else { LOCAL_DISCR };
|
||||||
|
s.receive_control_packet(&pkt(*remote, REMOTE_DISCR, your))
|
||||||
|
.await;
|
||||||
|
next_event(&mut events).await;
|
||||||
|
}
|
||||||
|
assert_eq!(s.state.session_state(), state);
|
||||||
|
(s, events)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn new_session_starts_down_and_slow() {
|
||||||
|
let (s, _events) = session(peer_cfg(300, 200, 3)).await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
assert_eq!(s.state.remote_discr(), BfdDiscriminator(0));
|
||||||
|
assert_eq!(s.state.local_diag(), BfdDiagnostic::None);
|
||||||
|
assert_eq!(s.state.desired_min_tx_interval(), BfdInterval::from_secs(1));
|
||||||
|
assert_eq!(
|
||||||
|
s.state.required_min_rx_interval(),
|
||||||
|
BfdInterval::from_millis(200)
|
||||||
|
);
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_secs(1));
|
||||||
|
assert_eq!(s.state.detect_mult(), 3);
|
||||||
|
assert!(!s.state.poll_mode());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn new_session_keeps_configured_interval_above_one_second() {
|
||||||
|
let (s, _events) = session(peer_cfg(2500, 300, 3)).await;
|
||||||
|
assert_eq!(
|
||||||
|
s.state.desired_min_tx_interval(),
|
||||||
|
BfdInterval::from_millis(2500)
|
||||||
|
);
|
||||||
|
assert_eq!(s.effective_desired_min_tx, BfdInterval::from_millis(2500));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn three_way_handshake_and_poll_sequence() {
|
||||||
|
let (mut s, mut events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, REMOTE_DISCR, 0))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Init);
|
||||||
|
assert_eq!(s.state.remote_discr(), BfdDiscriminator(REMOTE_DISCR));
|
||||||
|
let ev = next_event(&mut events).await;
|
||||||
|
assert_eq!(
|
||||||
|
(ev.from_state, ev.to_state),
|
||||||
|
(BfdState::Down, BfdState::Init)
|
||||||
|
);
|
||||||
|
assert_eq!(ev.local_discr, BfdDiscriminator(LOCAL_DISCR));
|
||||||
|
assert_eq!(ev.remote_discr, BfdDiscriminator(REMOTE_DISCR));
|
||||||
|
assert_eq!((ev.local_ip, ev.remote_ip), (LOCAL, PEER));
|
||||||
|
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Init, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Up);
|
||||||
|
let ev = next_event(&mut events).await;
|
||||||
|
assert_eq!((ev.from_state, ev.to_state), (BfdState::Init, BfdState::Up));
|
||||||
|
assert!(s.state.last_up.load().is_some());
|
||||||
|
assert_eq!(s.state.local_diag(), BfdDiagnostic::None);
|
||||||
|
// Advertise the fast interval now, but keep transmitting slowly until the poll sequence completes
|
||||||
|
assert_eq!(
|
||||||
|
s.state.desired_min_tx_interval(),
|
||||||
|
BfdInterval::from_millis(300)
|
||||||
|
);
|
||||||
|
assert!(s.state.poll_mode());
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_secs(1));
|
||||||
|
|
||||||
|
let fin = with_flags(pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR), |f| {
|
||||||
|
f.with_final_(true)
|
||||||
|
});
|
||||||
|
s.receive_control_packet(&fin).await;
|
||||||
|
assert!(!s.state.poll_mode());
|
||||||
|
assert_eq!(s.effective_desired_min_tx, BfdInterval::from_millis(300));
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_millis(300));
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn up_without_poll_when_configured_interval_is_not_faster() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(2000, 300, 3)).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, REMOTE_DISCR, 0))
|
||||||
|
.await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Init, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Up);
|
||||||
|
assert!(!s.state.poll_mode());
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_secs(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn down_goes_straight_to_up_when_remote_is_init() {
|
||||||
|
let (mut s, mut events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Init, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Up);
|
||||||
|
let ev = next_event(&mut events).await;
|
||||||
|
assert_eq!((ev.from_state, ev.to_state), (BfdState::Down, BfdState::Up));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn down_ignores_remote_up_and_admin_down() {
|
||||||
|
let (mut s, mut events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
s.receive_control_packet(&pkt(BfdState::AdminDown, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
assert_no_event(&mut events).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn init_transitions() {
|
||||||
|
let (mut s, mut events) = session_in(BfdState::Init).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Init);
|
||||||
|
assert_no_event(&mut events).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Up);
|
||||||
|
|
||||||
|
let (mut s, mut events) = session_in(BfdState::Init).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::AdminDown, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
assert_eq!(s.state.local_diag(), BfdDiagnostic::NeighborDown);
|
||||||
|
let ev = next_event(&mut events).await;
|
||||||
|
assert_eq!(
|
||||||
|
(ev.from_state, ev.to_state),
|
||||||
|
(BfdState::Init, BfdState::Down)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[tokio::test]
|
||||||
|
async fn up_goes_down_when_remote_goes_down() {
|
||||||
|
let (mut s, mut events) = session_in(BfdState::Up).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_no_event(&mut events).await;
|
||||||
|
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
assert_eq!(s.state.local_diag(), BfdDiagnostic::NeighborDown);
|
||||||
|
let ev = next_event(&mut events).await;
|
||||||
|
assert_eq!((ev.from_state, ev.to_state), (BfdState::Up, BfdState::Down));
|
||||||
|
assert!(s.state.last_down.load().is_some());
|
||||||
|
// Back to the slow rate and no poll sequence in flight
|
||||||
|
assert_eq!(s.state.desired_min_tx_interval(), BfdInterval::from_secs(1));
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_secs(1));
|
||||||
|
assert!(!s.state.poll_mode());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn up_goes_down_on_remote_admin_down() {
|
||||||
|
let (mut s, mut events) = session_in(BfdState::Up).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::AdminDown, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
assert_eq!(s.state.local_diag(), BfdDiagnostic::NeighborDown);
|
||||||
|
assert_eq!(next_event(&mut events).await.to_state, BfdState::Down);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn restarted_peer_relearns_discriminator() {
|
||||||
|
let (mut s, mut events) = session_in(BfdState::Up).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, 3000, 0))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down);
|
||||||
|
assert_eq!(s.state.remote_discr(), BfdDiscriminator(3000));
|
||||||
|
assert_eq!(next_event(&mut events).await.to_state, BfdState::Down);
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, 3000, 0))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Init);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn up_resets_stats_and_down_records_time() {
|
||||||
|
let (mut s, _events) = session_in(BfdState::Init).await;
|
||||||
|
s.state.record_tx();
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Up);
|
||||||
|
// The Up transition resets the counters, then sends one packet announcing the new state
|
||||||
|
assert_eq!(s.state.rx_stats.snapshot().count(), 0);
|
||||||
|
assert_eq!(s.state.tx_stats.snapshot().count(), 1);
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.rx_stats.snapshot().count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn invalid_packets_are_discarded() {
|
||||||
|
type Mutation = fn(BfdPacket) -> BfdPacket;
|
||||||
|
let cases: [(&str, Mutation); 8] = [
|
||||||
|
("version", |p| with_flags(p, |f| f.with_vers(2))),
|
||||||
|
("short length", |p| with_flags(p, |f| f.with_length(23))),
|
||||||
|
("zero detect mult", |p| {
|
||||||
|
with_flags(p, |f| f.with_detect_mult(0))
|
||||||
|
}),
|
||||||
|
("multipoint", |p| with_flags(p, |f| f.with_multipoint(true))),
|
||||||
|
("zero my discr", |mut p| {
|
||||||
|
p.my_disc = BfdDiscriminator(0);
|
||||||
|
p
|
||||||
|
}),
|
||||||
|
("wrong your discr", |mut p| {
|
||||||
|
p.your_disc = BfdDiscriminator(LOCAL_DISCR + 1);
|
||||||
|
p
|
||||||
|
}),
|
||||||
|
("zero your discr, not down", |mut p| {
|
||||||
|
p.your_disc = BfdDiscriminator(0);
|
||||||
|
p.flags = p.flags.with_state(BfdState::Up as u8);
|
||||||
|
p
|
||||||
|
}),
|
||||||
|
("auth without auth in use", |p| {
|
||||||
|
with_flags(p, |f| f.with_auth_present(true).with_length(26))
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
for (name, mutate) in cases {
|
||||||
|
let (mut s, mut events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
s.receive_control_packet(&mutate(pkt(BfdState::Down, REMOTE_DISCR, 0)))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Down, "{name}");
|
||||||
|
assert_eq!(s.state.remote_discr(), BfdDiscriminator(0), "{name}");
|
||||||
|
assert_eq!(
|
||||||
|
s.state.remote_min_rx_interval(),
|
||||||
|
BfdInterval::from_millis(300),
|
||||||
|
"{name}"
|
||||||
|
);
|
||||||
|
assert_no_event(&mut events).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn auth_length_minimum_is_26() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
let p = with_flags(pkt(BfdState::Down, REMOTE_DISCR, 0), |f| {
|
||||||
|
f.with_auth_present(true).with_length(25)
|
||||||
|
});
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.remote_discr(), BfdDiscriminator(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn unknown_diagnostic_does_not_panic() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
let p = with_flags(pkt(BfdState::Down, REMOTE_DISCR, 0), |f| f.with_diag(20));
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.session_state(), BfdState::Init);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn remote_diag_is_recorded() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
let p = with_flags(pkt(BfdState::Down, REMOTE_DISCR, 0), |f| {
|
||||||
|
f.with_diag(BfdDiagnostic::PathDown as u8)
|
||||||
|
});
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.last_remote_diag(), BfdDiagnostic::PathDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn poll_bit_elicits_final_response() {
|
||||||
|
let (mut s, _events) = session_in(BfdState::Up).await;
|
||||||
|
let before = s.state.tx_stats.snapshot().count();
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.tx_stats.snapshot().count(), before);
|
||||||
|
let poll = with_flags(pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR), |f| {
|
||||||
|
f.with_poll(true)
|
||||||
|
});
|
||||||
|
s.receive_control_packet(&poll).await;
|
||||||
|
assert_eq!(s.state.tx_stats.snapshot().count(), before + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn state_change_sends_immediate_packet() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, REMOTE_DISCR, 0))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.tx_stats.snapshot().count(), 1);
|
||||||
|
s.receive_control_packet(&pkt(BfdState::Down, REMOTE_DISCR, 0))
|
||||||
|
.await;
|
||||||
|
assert_eq!(s.state.tx_stats.snapshot().count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transmit_interval_follows_remote_min_rx() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
let mut p = pkt(BfdState::Down, REMOTE_DISCR, 0);
|
||||||
|
p.required_min_rx = BfdInterval::from_secs(2);
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.remote_min_rx_interval(), BfdInterval::from_secs(2));
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_secs(2));
|
||||||
|
p.required_min_rx = BfdInterval::from_millis(100);
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
// never faster than our own effective desired-min-tx, which is 1s while not Up
|
||||||
|
assert_eq!(s.cur_interval, BfdInterval::from_secs(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn detection_time_saturates_on_remote_overflow() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 300, 3)).await;
|
||||||
|
let mut p = pkt(BfdState::Down, REMOTE_DISCR, 0);
|
||||||
|
p.flags = p.flags.with_detect_mult(255);
|
||||||
|
p.desired_min_tx = BfdInterval::from_micros(u32::MAX);
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.detection_time(), BfdInterval::from_micros(u32::MAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn detection_time_uses_remote_mult_and_larger_interval() {
|
||||||
|
let (mut s, _events) = session(peer_cfg(300, 500, 3)).await;
|
||||||
|
let mut p = pkt(BfdState::Down, REMOTE_DISCR, 0);
|
||||||
|
p.flags = p.flags.with_detect_mult(5);
|
||||||
|
p.desired_min_tx = BfdInterval::from_millis(400);
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.detection_time(), BfdInterval::from_millis(2500));
|
||||||
|
p.desired_min_tx = BfdInterval::from_millis(800);
|
||||||
|
s.receive_control_packet(&p).await;
|
||||||
|
assert_eq!(s.state.detection_time(), BfdInterval::from_millis(4000));
|
||||||
|
}
|
||||||
|
#[tokio::test]
|
||||||
|
async fn watchdog_expires_only_without_packets() {
|
||||||
|
let (dispatcher, mut events) = capture_dispatcher().await;
|
||||||
|
let handle = BfdSessionHandle::new(
|
||||||
|
LOCAL,
|
||||||
|
peer_cfg(20, 20, 3),
|
||||||
|
BfdDiscriminator(LOCAL_DISCR),
|
||||||
|
dispatcher,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let fast = |state, your| {
|
||||||
|
let mut p = pkt(state, REMOTE_DISCR, your);
|
||||||
|
p.flags = p.flags.with_detect_mult(10);
|
||||||
|
p.desired_min_tx = BfdInterval::from_millis(20);
|
||||||
|
p.required_min_rx = BfdInterval::from_millis(20);
|
||||||
|
p
|
||||||
|
};
|
||||||
|
let send = |p| handle.tx.send(SessionControlCommand::RxPacket(p));
|
||||||
|
send(fast(BfdState::Down, 0)).await.unwrap();
|
||||||
|
send(fast(BfdState::Init, LOCAL_DISCR)).await.unwrap();
|
||||||
|
assert_eq!(next_event(&mut events).await.to_state, BfdState::Init);
|
||||||
|
assert_eq!(next_event(&mut events).await.to_state, BfdState::Up);
|
||||||
|
|
||||||
|
// detection time is 10 x 20ms; keep-alives at 20ms must hold the session up
|
||||||
|
for _ in 0..15 {
|
||||||
|
send(fast(BfdState::Up, LOCAL_DISCR)).await.unwrap();
|
||||||
|
time::sleep(Duration::from_millis(20)).await;
|
||||||
|
}
|
||||||
|
assert!(
|
||||||
|
events.try_recv().is_err(),
|
||||||
|
"session dropped despite keep-alives"
|
||||||
|
);
|
||||||
|
|
||||||
|
let ev = next_event(&mut events).await;
|
||||||
|
assert_eq!((ev.from_state, ev.to_state), (BfdState::Up, BfdState::Down));
|
||||||
|
let stats = handle.get_stats().await.unwrap();
|
||||||
|
assert_eq!(stats.state, BfdState::Down);
|
||||||
|
assert!(stats.last_down.is_some());
|
||||||
|
handle.tx.send(SessionControlCommand::Quit).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bfd_error_display_orders_value_and_field() {
|
||||||
|
let e = BfdError::InvalidFieldValue("state", "bogus");
|
||||||
|
assert_eq!(e.to_string(), "invalid value `bogus` for field `state`");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn control_socket_uses_source_port_range_and_ttl_255() {
|
||||||
|
let a = bind_control_socket(LOCAL).await.unwrap();
|
||||||
|
let b = bind_control_socket(LOCAL).await.unwrap();
|
||||||
|
for s in [&a, &b] {
|
||||||
|
let addr = s.local_addr().unwrap();
|
||||||
|
assert!(SOURCE_PORT_RANGE.contains(&addr.port()), "{addr}");
|
||||||
|
assert_eq!(addr.ip(), LOCAL);
|
||||||
|
assert_eq!(s.ttl().unwrap(), 255);
|
||||||
|
}
|
||||||
|
assert_ne!(
|
||||||
|
a.local_addr().unwrap().port(),
|
||||||
|
b.local_addr().unwrap().port()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn control_socket_bind_error_is_propagated() {
|
||||||
|
let err = bind_control_socket(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 1)))
|
||||||
|
.await
|
||||||
|
.unwrap_err();
|
||||||
|
assert_ne!(err.kind(), ErrorKind::AddrInUse);
|
||||||
|
}
|
||||||
|
|
||||||
|
const OTHER: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 3));
|
||||||
|
|
||||||
|
async fn bfdd() -> (Bfdd, mpsc::Receiver<SessionControlCommand>) {
|
||||||
|
let (tx, rx) = mpsc::channel(8);
|
||||||
|
let discr = BfdDiscriminator(LOCAL_DISCR);
|
||||||
|
let d = Bfdd {
|
||||||
|
local: SocketAddr::new(LOCAL, CONTROL_PORT),
|
||||||
|
peers: vec![peer_cfg(300, 300, 3)],
|
||||||
|
sessions_by_ip: HashMap::from([((LOCAL, PEER), discr)]),
|
||||||
|
sessions_by_discr: HashMap::from([(discr, BfdSessionHandle { tx })]),
|
||||||
|
unmatched_sources: std::sync::Mutex::new(HashSet::new()),
|
||||||
|
control_socket: Arc::new(UdpSocket::bind((LOCAL, 0)).await.unwrap()),
|
||||||
|
event_dispatcher: EventDispatcherHandle::new().await,
|
||||||
|
};
|
||||||
|
(d, rx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from(ip: IpAddr) -> SocketAddr {
|
||||||
|
SocketAddr::new(ip, 49152)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn demux_by_source_when_your_discr_is_zero() {
|
||||||
|
let (d, _rx) = bfdd().await;
|
||||||
|
let p = pkt(BfdState::Down, REMOTE_DISCR, 0);
|
||||||
|
assert!(d.session_for_packet(&from(PEER), &p).is_some());
|
||||||
|
assert!(d.session_for_packet(&from(OTHER), &p).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn demux_by_discriminator_ignores_source_address() {
|
||||||
|
let (d, _rx) = bfdd().await;
|
||||||
|
let p = pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR);
|
||||||
|
assert!(d.session_for_packet(&from(PEER), &p).is_some());
|
||||||
|
assert!(d.session_for_packet(&from(OTHER), &p).is_some());
|
||||||
|
let p = pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR + 1);
|
||||||
|
assert!(d.session_for_packet(&from(PEER), &p).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn unmatched_sources_are_tracked_until_they_match() {
|
||||||
|
let (d, _rx) = bfdd().await;
|
||||||
|
let miss = pkt(BfdState::Down, REMOTE_DISCR, 0);
|
||||||
|
let hit = pkt(BfdState::Up, REMOTE_DISCR, LOCAL_DISCR);
|
||||||
|
assert!(d.session_for_packet(&from(OTHER), &miss).is_none());
|
||||||
|
assert!(d.unmatched_sources.lock().unwrap().contains(&OTHER));
|
||||||
|
assert!(d.session_for_packet(&from(OTHER), &hit).is_some());
|
||||||
|
assert!(!d.unmatched_sources.lock().unwrap().contains(&OTHER));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn datagram_is_parsed_and_delivered_to_session() {
|
||||||
|
let (d, mut rx) = bfdd().await;
|
||||||
|
let bytes = pkt(BfdState::Down, REMOTE_DISCR, 0).serialize().unwrap();
|
||||||
|
d.handle_datagram(&bytes, from(PEER)).await;
|
||||||
|
match rx.try_recv() {
|
||||||
|
Ok(SessionControlCommand::RxPacket(p)) => {
|
||||||
|
assert_eq!(p.my_disc, BfdDiscriminator(REMOTE_DISCR))
|
||||||
|
}
|
||||||
|
_ => panic!("expected RxPacket"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn bad_datagrams_are_dropped() {
|
||||||
|
let (d, mut rx) = bfdd().await;
|
||||||
|
let good = pkt(BfdState::Down, REMOTE_DISCR, 0).serialize().unwrap();
|
||||||
|
d.handle_datagram(&good[..23], from(PEER)).await;
|
||||||
|
d.handle_datagram(&[], from(PEER)).await;
|
||||||
|
d.handle_datagram(&[0xff; 7], from(PEER)).await;
|
||||||
|
let long = with_flags(pkt(BfdState::Down, REMOTE_DISCR, 0), |f| f.with_length(48));
|
||||||
|
d.handle_datagram(&long.serialize().unwrap(), from(PEER))
|
||||||
|
.await;
|
||||||
|
let unknown = pkt(BfdState::Down, REMOTE_DISCR, 0);
|
||||||
|
d.handle_datagram(&unknown.serialize().unwrap(), from(OTHER))
|
||||||
|
.await;
|
||||||
|
assert!(rx.try_recv().is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn bfdd_rejects_multiple_bind_addresses() {
|
||||||
|
let cfg = ResolvedConfig {
|
||||||
|
bind: vec![LOCAL, PEER],
|
||||||
|
hooks_dir: PathBuf::from("/nonexistent"),
|
||||||
|
peers: vec![],
|
||||||
|
};
|
||||||
|
let err = Bfdd::new(cfg).await.err().expect("should fail");
|
||||||
|
assert!(err.to_string().contains("only one"), "{err}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+83
-7
@@ -17,8 +17,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use serde::{de, Deserialize, Deserializer, Serialize};
|
use serde::{de, Deserialize, Deserializer, Serialize};
|
||||||
|
use serde_valid::Validate;
|
||||||
|
|
||||||
use crate::bfd::BfdInterval;
|
use crate::bfd::{BfdAuth, BfdAuthKeyedMD5, BfdAuthKeyedSHA1, BfdAuthSimplePassword, BfdInterval};
|
||||||
|
|
||||||
pub const DEFAULT_CONFIG_PATH: &str = "/etc/rust-bfd/config.yaml";
|
pub const DEFAULT_CONFIG_PATH: &str = "/etc/rust-bfd/config.yaml";
|
||||||
pub const DEFAULT_HOOKS_DIR: &str = "/etc/rust-bfd/hooks.d";
|
pub const DEFAULT_HOOKS_DIR: &str = "/etc/rust-bfd/hooks.d";
|
||||||
@@ -29,6 +30,10 @@ pub const ENV_DEFAULTS_DESIRED_MIN_TX: &str = "BFD_DEFAULTS_DESIRED_MIN_TX";
|
|||||||
pub const ENV_DEFAULTS_REQUIRED_MIN_RX: &str = "BFD_DEFAULTS_REQUIRED_MIN_RX";
|
pub const ENV_DEFAULTS_REQUIRED_MIN_RX: &str = "BFD_DEFAULTS_REQUIRED_MIN_RX";
|
||||||
pub const ENV_DEFAULTS_DETECT_MULT: &str = "BFD_DEFAULTS_DETECT_MULT";
|
pub const ENV_DEFAULTS_DETECT_MULT: &str = "BFD_DEFAULTS_DETECT_MULT";
|
||||||
|
|
||||||
|
fn default_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
Io {
|
Io {
|
||||||
@@ -94,6 +99,71 @@ impl Default for Defaults {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Validate)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct PasswordAuthConfig {
|
||||||
|
pub key_id: u8,
|
||||||
|
#[serde(with = "serde_bytes")]
|
||||||
|
// The password is a binary string, and MUST be 1 to 16 bytes in
|
||||||
|
// length.
|
||||||
|
#[validate(min_items = 1)]
|
||||||
|
#[validate(max_items = 16)]
|
||||||
|
pub password: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Validate)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct Md5AuthConfig {
|
||||||
|
pub key_id: u8,
|
||||||
|
#[serde(with = "serde_bytes")]
|
||||||
|
// The key is given verbatim (not derived) and must be exactly 16 bytes
|
||||||
|
pub key: [u8; 16],
|
||||||
|
#[serde(default = "default_true")]
|
||||||
|
pub meticulous: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Validate)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct Sha1AuthConfig {
|
||||||
|
pub key_id: u8,
|
||||||
|
#[serde(with = "serde_bytes")]
|
||||||
|
// The key is given verbatim (not derived) and must be exactly 20 bytes
|
||||||
|
pub key: [u8; 20],
|
||||||
|
#[serde(default = "default_true")]
|
||||||
|
pub meticulous: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields, tag = "type", rename_all = "lowercase")]
|
||||||
|
pub enum AuthConfig {
|
||||||
|
Password(PasswordAuthConfig),
|
||||||
|
Md5(Md5AuthConfig),
|
||||||
|
Sha1(Sha1AuthConfig),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AuthConfig> for BfdAuth {
|
||||||
|
fn from(value: AuthConfig) -> Self {
|
||||||
|
match value {
|
||||||
|
AuthConfig::Password(ac) => BfdAuth::SimplePassword(BfdAuthSimplePassword {
|
||||||
|
key_id: ac.key_id,
|
||||||
|
password: ac.password,
|
||||||
|
}),
|
||||||
|
AuthConfig::Md5(ac) => BfdAuth::KeyedMD5(BfdAuthKeyedMD5 {
|
||||||
|
key_id: ac.key_id,
|
||||||
|
meticulous: ac.meticulous,
|
||||||
|
digest: ac.key,
|
||||||
|
seq: 0, // set during signing
|
||||||
|
}),
|
||||||
|
AuthConfig::Sha1(ac) => BfdAuth::KeyedSHA1(BfdAuthKeyedSHA1 {
|
||||||
|
key_id: ac.key_id,
|
||||||
|
meticulous: ac.meticulous,
|
||||||
|
digest: ac.key,
|
||||||
|
seq: 0, // set during signing
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct PeerConfig {
|
pub struct PeerConfig {
|
||||||
@@ -112,6 +182,8 @@ pub struct PeerConfig {
|
|||||||
pub required_min_rx: Option<Duration>,
|
pub required_min_rx: Option<Duration>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub detect_mult: Option<u8>,
|
pub detect_mult: Option<u8>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub auth: Option<AuthConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PeerConfig {
|
impl PeerConfig {
|
||||||
@@ -121,6 +193,7 @@ impl PeerConfig {
|
|||||||
desired_min_tx: None,
|
desired_min_tx: None,
|
||||||
required_min_rx: None,
|
required_min_rx: None,
|
||||||
detect_mult: None,
|
detect_mult: None,
|
||||||
|
auth: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,7 +326,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validate and apply defaults to each peer.
|
/// Validate and apply defaults to each peer.
|
||||||
pub fn resolve(&self) -> Result<ResolvedConfig, ConfigError> {
|
pub fn resolve(self) -> Result<ResolvedConfig, ConfigError> {
|
||||||
let invalid = |message: String| ConfigError::Invalid(message);
|
let invalid = |message: String| ConfigError::Invalid(message);
|
||||||
|
|
||||||
if self.bind.is_empty() {
|
if self.bind.is_empty() {
|
||||||
@@ -269,7 +342,7 @@ impl Config {
|
|||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
let peers = self
|
let peers = self
|
||||||
.peers
|
.peers
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|peer| {
|
.map(|peer| {
|
||||||
if !seen.insert(peer.address) {
|
if !seen.insert(peer.address) {
|
||||||
return Err(invalid(format!("duplicate peer {}", peer.address)));
|
return Err(invalid(format!("duplicate peer {}", peer.address)));
|
||||||
@@ -304,6 +377,7 @@ impl Config {
|
|||||||
&what("required_min_rx"),
|
&what("required_min_rx"),
|
||||||
)?,
|
)?,
|
||||||
detect_mult,
|
detect_mult,
|
||||||
|
auth: peer.auth,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
@@ -351,12 +425,13 @@ pub struct ResolvedConfig {
|
|||||||
pub peers: Vec<ResolvedPeer>,
|
pub peers: Vec<ResolvedPeer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ResolvedPeer {
|
pub struct ResolvedPeer {
|
||||||
pub address: IpAddr,
|
pub address: IpAddr,
|
||||||
pub desired_min_tx: BfdInterval,
|
pub desired_min_tx: BfdInterval,
|
||||||
pub required_min_rx: BfdInterval,
|
pub required_min_rx: BfdInterval,
|
||||||
pub detect_mult: u8,
|
pub detect_mult: u8,
|
||||||
|
pub auth: Option<AuthConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -418,7 +493,7 @@ peers:
|
|||||||
#[test]
|
#[test]
|
||||||
fn peers_inherit_defaults_and_override() {
|
fn peers_inherit_defaults_and_override() {
|
||||||
let resolved = Config::from_yaml(FULL).unwrap().resolve().unwrap();
|
let resolved = Config::from_yaml(FULL).unwrap().resolve().unwrap();
|
||||||
let (a, b) = (resolved.peers[0], resolved.peers[1]);
|
let (a, b) = (&resolved.peers[0], &resolved.peers[1]);
|
||||||
assert_eq!(a.desired_min_tx, BfdInterval::from_millis(500));
|
assert_eq!(a.desired_min_tx, BfdInterval::from_millis(500));
|
||||||
assert_eq!(a.required_min_rx, BfdInterval::from_millis(250));
|
assert_eq!(a.required_min_rx, BfdInterval::from_millis(250));
|
||||||
assert_eq!(a.detect_mult, 5);
|
assert_eq!(a.detect_mult, 5);
|
||||||
@@ -500,10 +575,10 @@ peers:
|
|||||||
#[test]
|
#[test]
|
||||||
fn dist_config_is_valid() {
|
fn dist_config_is_valid() {
|
||||||
let config = Config::from_yaml(include_str!("../config.yaml.dist")).unwrap();
|
let config = Config::from_yaml(include_str!("../config.yaml.dist")).unwrap();
|
||||||
let resolved = config.resolve().unwrap();
|
|
||||||
assert_eq!(resolved.peers.len(), 1);
|
|
||||||
assert_eq!(config.defaults, Defaults::default());
|
assert_eq!(config.defaults, Defaults::default());
|
||||||
assert_eq!(config.hooks_dir, PathBuf::from(DEFAULT_HOOKS_DIR));
|
assert_eq!(config.hooks_dir, PathBuf::from(DEFAULT_HOOKS_DIR));
|
||||||
|
let resolved = config.resolve().unwrap();
|
||||||
|
assert_eq!(resolved.peers.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -582,6 +657,7 @@ peers:
|
|||||||
let mut c = base();
|
let mut c = base();
|
||||||
c.peers.push(PeerConfig::new(ip("2001:db8::2")));
|
c.peers.push(PeerConfig::new(ip("2001:db8::2")));
|
||||||
assert!(c
|
assert!(c
|
||||||
|
.clone()
|
||||||
.resolve()
|
.resolve()
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string()
|
.to_string()
|
||||||
|
|||||||
+214
-9
@@ -1,4 +1,4 @@
|
|||||||
use core::{fmt, str};
|
use core::fmt;
|
||||||
use std::{
|
use std::{
|
||||||
ffi::{OsStr, OsString},
|
ffi::{OsStr, OsString},
|
||||||
net::IpAddr,
|
net::IpAddr,
|
||||||
@@ -92,16 +92,10 @@ impl ScriptHookSink {
|
|||||||
);
|
);
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
if !output.stdout.is_empty() {
|
if !output.stdout.is_empty() {
|
||||||
warn!(
|
warn!(" stdout: \n{}", String::from_utf8_lossy(&output.stdout));
|
||||||
" stdout: \n{}",
|
|
||||||
str::from_utf8(output.stdout.as_slice()).unwrap()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if !output.stderr.is_empty() {
|
if !output.stderr.is_empty() {
|
||||||
warn!(
|
warn!(" stderr: \n{}", String::from_utf8_lossy(&output.stderr));
|
||||||
" stderr: \n{}",
|
|
||||||
str::from_utf8(output.stderr.as_slice()).unwrap()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,3 +171,214 @@ impl ScriptHookSink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::{
|
||||||
|
fs::{self as stdfs, Permissions},
|
||||||
|
net::{Ipv4Addr, Ipv6Addr},
|
||||||
|
os::unix::fs::PermissionsExt,
|
||||||
|
path::Path,
|
||||||
|
sync::atomic::{AtomicU32, Ordering},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
|
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
|
struct TempDir(PathBuf);
|
||||||
|
impl TempDir {
|
||||||
|
fn new() -> Self {
|
||||||
|
let n = COUNTER.fetch_add(1, Ordering::Relaxed);
|
||||||
|
let path =
|
||||||
|
std::env::temp_dir().join(format!("rust-bfd-hooks-{}-{}", std::process::id(), n));
|
||||||
|
stdfs::create_dir_all(path.join("hooks")).unwrap();
|
||||||
|
Self(path)
|
||||||
|
}
|
||||||
|
fn hooks(&self) -> PathBuf {
|
||||||
|
self.0.join("hooks")
|
||||||
|
}
|
||||||
|
fn out(&self) -> PathBuf {
|
||||||
|
self.0.join("out")
|
||||||
|
}
|
||||||
|
fn script(&self, name: &str, mode: u32, body: &str) {
|
||||||
|
let path = self.hooks().join(name);
|
||||||
|
stdfs::write(&path, format!("#!/bin/sh\n{body}\n")).unwrap();
|
||||||
|
stdfs::set_permissions(&path, Permissions::from_mode(mode)).unwrap();
|
||||||
|
}
|
||||||
|
fn append_script(&self, name: &str, mode: u32, line: &str) {
|
||||||
|
self.script(
|
||||||
|
name,
|
||||||
|
mode,
|
||||||
|
&format!("echo \"{line}\" >> {}", self.out().display()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fn output(&self) -> Vec<String> {
|
||||||
|
stdfs::read_to_string(self.out())
|
||||||
|
.map(|s| s.lines().map(str::to_owned).collect())
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Drop for TempDir {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = stdfs::remove_dir_all(&self.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn event(local: IpAddr, remote: IpAddr, from: BfdState, to: BfdState) -> EventMessage {
|
||||||
|
EventMessage::StateChange(StateChangeEvent {
|
||||||
|
local_discr: BfdDiscriminator(11),
|
||||||
|
remote_discr: BfdDiscriminator(22),
|
||||||
|
local_ip: local,
|
||||||
|
remote_ip: remote,
|
||||||
|
from_state: from,
|
||||||
|
to_state: to,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn v4_event() -> EventMessage {
|
||||||
|
event(
|
||||||
|
Ipv4Addr::new(192, 0, 2, 1).into(),
|
||||||
|
Ipv4Addr::new(192, 0, 2, 2).into(),
|
||||||
|
BfdState::Init,
|
||||||
|
BfdState::Up,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ENV_LINE: &str = "$1|$2|$BFD_STATE|$BFD_LAST_STATE|$BFD_LOCAL_ADDR|$BFD_PEER_ADDR|$BFD_LOCAL_DISCRIMINATOR|$BFD_PEER_DISCRIMINATOR";
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn passes_args_and_environment() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
t.append_script("10-env", 0o755, ENV_LINE);
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
t.output(),
|
||||||
|
["Up|192.0.2.2|Up|Init|192.0.2.1|192.0.2.2|11|22"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn passes_ipv6_addresses() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
t.append_script("10-env", 0o755, ENV_LINE);
|
||||||
|
let ev = event(
|
||||||
|
Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).into(),
|
||||||
|
Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 2).into(),
|
||||||
|
BfdState::Up,
|
||||||
|
BfdState::Down,
|
||||||
|
);
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&ev)
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
t.output(),
|
||||||
|
["Down|2001:db8::2|Down|Up|2001:db8::1|2001:db8::2|11|22"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn environment_is_cleared() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
std::env::set_var("RUST_BFD_TEST_LEAK", "leaked");
|
||||||
|
t.append_script(
|
||||||
|
"10-env",
|
||||||
|
0o755,
|
||||||
|
"${RUST_BFD_TEST_LEAK:-unset}|${HOME:-unset}",
|
||||||
|
);
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert_eq!(t.output(), ["unset|unset"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn runs_scripts_in_lexicographic_order() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
t.append_script("20-b", 0o755, "b");
|
||||||
|
t.append_script("30-c", 0o755, "c");
|
||||||
|
t.append_script("10-a", 0o755, "a");
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert_eq!(t.output(), ["a", "b", "c"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn skips_non_executable_files_and_directories() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
t.append_script("10-run", 0o755, "run");
|
||||||
|
t.append_script("20-noexec", 0o644, "noexec");
|
||||||
|
let dir = t.hooks().join("30-dir");
|
||||||
|
stdfs::create_dir(&dir).unwrap();
|
||||||
|
stdfs::set_permissions(&dir, Permissions::from_mode(0o755)).unwrap();
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert_eq!(t.output(), ["run"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn failing_script_does_not_stop_later_scripts() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
t.script(
|
||||||
|
"10-fail",
|
||||||
|
0o755,
|
||||||
|
"printf '\\377\\376'; printf '\\377' >&2; exit 3",
|
||||||
|
);
|
||||||
|
t.append_script("20-ok", 0o755, "ok");
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert_eq!(t.output(), ["ok"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn missing_script_dir_is_not_fatal() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
let missing: &Path = &t.0.join("nope");
|
||||||
|
ScriptHookSink::with_script_dir(missing)
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert!(t.output().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn empty_script_dir_is_a_noop() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
ScriptHookSink::with_script_dir(t.hooks())
|
||||||
|
.handle_event(&v4_event())
|
||||||
|
.await;
|
||||||
|
assert!(t.output().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn events_sent_over_channel_run_hooks() {
|
||||||
|
let t = TempDir::new();
|
||||||
|
t.append_script("10-env", 0o755, ENV_LINE);
|
||||||
|
let sink = ScriptHookSink::with_script_dir(t.hooks());
|
||||||
|
let tx = sink.channel();
|
||||||
|
let handle = Box::new(sink).run();
|
||||||
|
tx.send(v4_event()).await.unwrap();
|
||||||
|
tx.send(event(
|
||||||
|
Ipv4Addr::new(192, 0, 2, 1).into(),
|
||||||
|
Ipv4Addr::new(192, 0, 2, 2).into(),
|
||||||
|
BfdState::Up,
|
||||||
|
BfdState::Down,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
for _ in 0..100 {
|
||||||
|
if t.output().len() >= 2 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
}
|
||||||
|
handle.abort();
|
||||||
|
let out = t.output();
|
||||||
|
assert_eq!(out.len(), 2);
|
||||||
|
assert!(out[0].starts_with("Up|") && out[1].starts_with("Down|"));
|
||||||
|
}
|
||||||
|
}
|
||||||
+178
@@ -167,6 +167,28 @@ fn fmt_ago(t: Option<Instant>) -> String {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A snapshot of a session's authentication state. Sequence numbers are `None` when not applicable or not yet known.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct AuthStats {
|
||||||
|
pub auth_type: BfdAuthType,
|
||||||
|
pub key_id: u8,
|
||||||
|
pub rcv_seq: Option<u32>,
|
||||||
|
pub xmit_seq: Option<u32>,
|
||||||
|
}
|
||||||
|
impl Display for AuthStats {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let seq = |s: Option<u32>| s.map_or("-".to_string(), |s| s.to_string());
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{} KeyId:{} RcvSeq:{} XmitSeq:{}",
|
||||||
|
self.auth_type,
|
||||||
|
self.key_id,
|
||||||
|
seq(self.rcv_seq),
|
||||||
|
seq(self.xmit_seq)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BfdSessionStats {
|
pub struct BfdSessionStats {
|
||||||
pub local_ip: IpAddr,
|
pub local_ip: IpAddr,
|
||||||
@@ -183,8 +205,14 @@ pub struct BfdSessionStats {
|
|||||||
pub last_change: Instant,
|
pub last_change: Instant,
|
||||||
pub detect_time: BfdInterval,
|
pub detect_time: BfdInterval,
|
||||||
pub base_interval: BfdInterval,
|
pub base_interval: BfdInterval,
|
||||||
|
/// `None` when the session does not use authentication
|
||||||
|
pub auth: Option<AuthStats>,
|
||||||
}
|
}
|
||||||
impl BfdSessionStats {
|
impl BfdSessionStats {
|
||||||
|
pub fn with_auth(mut self, auth: Option<AuthStats>) -> Self {
|
||||||
|
self.auth = auth;
|
||||||
|
self
|
||||||
|
}
|
||||||
pub fn with_base_interval(mut self, base_interval: BfdInterval) -> Self {
|
pub fn with_base_interval(mut self, base_interval: BfdInterval) -> Self {
|
||||||
self.base_interval = base_interval;
|
self.base_interval = base_interval;
|
||||||
self
|
self
|
||||||
@@ -212,6 +240,10 @@ impl Display for BfdSessionStats {
|
|||||||
)?;
|
)?;
|
||||||
writeln!(f, " Rx: {}", self.rx)?;
|
writeln!(f, " Rx: {}", self.rx)?;
|
||||||
writeln!(f, " Tx: {}", self.tx)?;
|
writeln!(f, " Tx: {}", self.tx)?;
|
||||||
|
match &self.auth {
|
||||||
|
Some(auth) => writeln!(f, " Auth: {auth}")?,
|
||||||
|
None => writeln!(f, " Auth: none")?,
|
||||||
|
}
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
" Last Up: {} Last Down: {}",
|
" Last Up: {} Last Down: {}",
|
||||||
@@ -300,4 +332,150 @@ mod tests {
|
|||||||
a.clear();
|
a.clear();
|
||||||
assert_eq!(a.load(), None);
|
assert_eq!(a.load(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn atomic_instant_swap_returns_previous() {
|
||||||
|
let a = AtomicInstant::new();
|
||||||
|
let t1 = Instant::now() + Duration::from_secs(1);
|
||||||
|
let t2 = t1 + Duration::from_secs(1);
|
||||||
|
a.store(t1);
|
||||||
|
assert_eq!(a.swap(t2), Some(t1));
|
||||||
|
assert_eq!(a.load(), Some(t2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn atomic_instant_clamps_before_epoch() {
|
||||||
|
let a = AtomicInstant::new();
|
||||||
|
let before = Instant::now().checked_sub(Duration::from_secs(1));
|
||||||
|
let Some(before) = before else { return };
|
||||||
|
a.store(before);
|
||||||
|
let loaded = a.load().unwrap();
|
||||||
|
assert!(loaded >= before);
|
||||||
|
assert!(loaded <= Instant::now());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn interval_stats_display() {
|
||||||
|
assert_eq!(
|
||||||
|
IntervalStats::default().to_string(),
|
||||||
|
"0 pkts, interval min/avg/max -/-/- ms"
|
||||||
|
);
|
||||||
|
let stats = AtomicIntervalStats::new();
|
||||||
|
let t0 = Instant::now();
|
||||||
|
for ms in [0, 100, 400, 500] {
|
||||||
|
stats.record(t0 + Duration::from_millis(ms));
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
stats.snapshot().to_string(),
|
||||||
|
"4 pkts, interval min/avg/max 100/167/300 ms"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn session_stats(last_up: Option<Instant>, last_down: Option<Instant>) -> BfdSessionStats {
|
||||||
|
let rx = AtomicIntervalStats::new();
|
||||||
|
let tx = AtomicIntervalStats::new();
|
||||||
|
let t0 = Instant::now();
|
||||||
|
rx.record(t0);
|
||||||
|
rx.record(t0 + Duration::from_millis(300));
|
||||||
|
tx.record(t0);
|
||||||
|
BfdSessionStats {
|
||||||
|
local_ip: "192.0.2.1".parse().unwrap(),
|
||||||
|
remote_ip: "192.0.2.2".parse().unwrap(),
|
||||||
|
local_discr: BfdDiscriminator(10),
|
||||||
|
remote_discr: BfdDiscriminator(20),
|
||||||
|
state: BfdState::Up,
|
||||||
|
last_diag: BfdDiagnostic::TimeExpired,
|
||||||
|
rx: rx.snapshot(),
|
||||||
|
tx: tx.snapshot(),
|
||||||
|
last_up,
|
||||||
|
last_down,
|
||||||
|
last_change: Instant::now(),
|
||||||
|
detect_time: BfdInterval::from_millis(900),
|
||||||
|
base_interval: BfdInterval::from_secs(1),
|
||||||
|
auth: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn session_stats_display_never() {
|
||||||
|
let out = session_stats(None, None).to_string();
|
||||||
|
let lines: Vec<&str> = out.lines().collect();
|
||||||
|
assert_eq!(lines.len(), 6);
|
||||||
|
assert_eq!(
|
||||||
|
lines[0].split_whitespace().collect::<Vec<_>>(),
|
||||||
|
["192.0.2.2", "Up", "2", "1"]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
lines[1].trim(),
|
||||||
|
"LocalDiscr:10 RemoteDiscr:20 DetectTime: 900000us TxTime: 1000000us Diag:TimeExpired Last: 0s"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
lines[2],
|
||||||
|
" Rx: 2 pkts, interval min/avg/max 300/300/300 ms"
|
||||||
|
);
|
||||||
|
assert_eq!(lines[3], " Tx: 1 pkts, interval min/avg/max -/-/- ms");
|
||||||
|
assert_eq!(lines[4], " Auth: none");
|
||||||
|
assert_eq!(lines[5], " Last Up: never Last Down: never");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn session_stats_display_auth() {
|
||||||
|
let out = session_stats(None, None)
|
||||||
|
.with_auth(Some(AuthStats {
|
||||||
|
auth_type: BfdAuthType::MetKeyedSHA1,
|
||||||
|
key_id: 3,
|
||||||
|
rcv_seq: Some(100),
|
||||||
|
xmit_seq: Some(7),
|
||||||
|
}))
|
||||||
|
.to_string();
|
||||||
|
assert!(
|
||||||
|
out.contains("\n Auth: meticulous-sha1 KeyId:3 RcvSeq:100 XmitSeq:7\n"),
|
||||||
|
"{out}"
|
||||||
|
);
|
||||||
|
let out = session_stats(None, None)
|
||||||
|
.with_auth(Some(AuthStats {
|
||||||
|
auth_type: BfdAuthType::KeyedMD5,
|
||||||
|
key_id: 1,
|
||||||
|
rcv_seq: None,
|
||||||
|
xmit_seq: Some(7),
|
||||||
|
}))
|
||||||
|
.to_string();
|
||||||
|
assert!(
|
||||||
|
out.contains("\n Auth: md5 KeyId:1 RcvSeq:- XmitSeq:7\n"),
|
||||||
|
"{out}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn session_stats_display_last_up_down() {
|
||||||
|
let now = Instant::now();
|
||||||
|
let out = session_stats(Some(now), None).to_string();
|
||||||
|
assert!(out.ends_with("Last Up: 0s ago Last Down: never"), "{out}");
|
||||||
|
let out = session_stats(None, Some(now)).to_string();
|
||||||
|
assert!(out.ends_with("Last Up: never Last Down: 0s ago"), "{out}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn session_stats_with_base_interval() {
|
||||||
|
let s = session_stats(None, None).with_base_interval(BfdInterval::from_millis(300));
|
||||||
|
assert_eq!(s.base_interval, BfdInterval::from_millis(300));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn set_ttl_v4() {
|
||||||
|
let sock = UdpSocket::bind("127.0.0.1:0").await.unwrap();
|
||||||
|
set_ttl_or_hop_limit(&sock, 255).unwrap();
|
||||||
|
assert_eq!(sock.ttl().unwrap(), 255);
|
||||||
|
set_ttl_or_hop_limit(&sock, 64).unwrap();
|
||||||
|
assert_eq!(sock.ttl().unwrap(), 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn set_hop_limit_v6() {
|
||||||
|
let Ok(sock) = UdpSocket::bind("[::1]:0").await else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
set_ttl_or_hop_limit(&sock, 255).unwrap();
|
||||||
|
assert_eq!(getsockopt(&sock, sockopt::Ipv6Ttl).unwrap(), 255);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user