diff --git a/README.md b/README.md index a5ec5f8..0bfcd65 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,71 @@ link. For example, if reflectors A and B want to link, both configs must use the same name (e.g. `[TRUNK_AB]`). A connection from a peer whose section name does not match any local section will be rejected. +### 5. Routable prefixes — hierarchical and non-full-mesh topologies (optional) + +In a standard full mesh every pair of reflectors has a direct trunk link, so +each reflector can reach any TG via `REMOTE_PREFIX` alone. Some deployments +cannot or should not use a full mesh: + +- A **regional leaf** with a single uplink to a national backbone has no + direct path to sibling regions — it needs a default route via the parent. +- A **transit backbone** node between two meshes may carry traffic for prefix + groups it does not own and that are not adjacent in `REMOTE_PREFIX`. + +`ROUTABLE_PREFIXES` (per `[TRUNK_x]` section, comma-separated) declares +additional TG prefixes that are reachable *via* this peer beyond what +`REMOTE_PREFIX` already covers. + +**Explicit prefixes** (e.g. `263`) extend the mesh-wide prefix set so the +reflector will accept those TGs inbound and transit them onward toward the +owner via the existing gateway fanout (`shouldRelayInbound`). Each intermediate +hop along a chain must declare the same routable prefix on the appropriate trunk +— there is no automatic propagation. + +**`*` wildcard** acts as a default route for a single-uplink regional leaf: local +clients can reach any TG via that uplink, and the return audio is accepted back. +`*` is never relayed between trunks (loop-safe) and is not added to the +mesh-wide prefix set, so it is invisible to gateway forwarding. A `*` is a +zero-length, lowest-precedence match — it never overrides a real prefix. A +startup `WARNING` is logged when `*` is set on a reflector that has more than +one trunk, since that topology is outside the intended single-uplink leaf +pattern. + +**Blacklist precedence:** `BLACKLIST_TGS` is evaluated before any routable +logic — a blacklisted TG is never forwarded, accepted, or advertised as +interest, regardless of `ROUTABLE_PREFIXES`. + +**Ownership caveat:** do not set a routable prefix that is a longer +decimal-string match of a TG this reflector itself owns — the +longest-prefix-match ownership check would then incorrectly route that TG +away from the local owner. Keep routable prefixes pointed at TGs owned by +other reflectors (the same discipline that already applies to `REMOTE_PREFIX`). + +Example — three-hop chain where `leaf` (prefix `240`) needs to reach TG `2630xx` +owned by `far` (prefix `263`), transiting through `natl` (prefix `262`): + +```ini +# On leaf — default route via the only uplink +[TRUNK_LEAF_NATL] +HOST=natl.example.com +SECRET=secret_leaf_natl +REMOTE_PREFIX=262 +ROUTABLE_PREFIXES=* + +# On natl — explicit transit toward 263 via the natlde link +[TRUNK_NATL_NATLDE] +HOST=natlde.example.com +SECRET=secret_natl_natlde +REMOTE_PREFIX=262 +ROUTABLE_PREFIXES=263 + +# On natlde — native REMOTE_PREFIX=263 already covers the last hop +[TRUNK_NATLDE_FAR] +HOST=far.example.com +SECRET=secret_natlde_far +REMOTE_PREFIX=263 +``` + ### Network requirements **Trunk links** require **mutual reachability**: each reflector both listens for diff --git a/docs/PEER_PROTOCOL.md b/docs/PEER_PROTOCOL.md index 8eeb80b..9bb90b4 100644 --- a/docs/PEER_PROTOCOL.md +++ b/docs/PEER_PROTOCOL.md @@ -188,6 +188,62 @@ active QSO the fanout stays live indefinitely; on a TG that has been silent for ~10 minutes, the first PTT from a non-owner's client re-arms the fanout before the owner starts forwarding that TG back out. +### Routable Prefixes (`ROUTABLE_PREFIXES`) + +Standard prefix routing requires either a direct `REMOTE_PREFIX` match or full-mesh +connectivity. `ROUTABLE_PREFIXES` (per `[TRUNK_x]` section, comma-separated) adds +two complementary capabilities for hierarchical and non-full-mesh topologies. + +**Explicit prefixes** (e.g. `263`) are injected into `m_all_prefixes` at startup +alongside `LOCAL_PREFIX` and all `REMOTE_PREFIX` values. From that point they +participate in longest-prefix-match just like native prefixes: + +- **Send / interest gate (`isSharedTG`).** When evaluating whether to forward a local + talker event or audio frame on a given trunk link, `isSharedTG` performs a + longest-prefix-match against the remote peer's combined prefix set (its + `REMOTE_PREFIX` plus its `ROUTABLE_PREFIXES`). A TG that matches a routable + prefix on that link is forwarded toward the peer as if it matched `REMOTE_PREFIX`. +- **Interest advertisement (`MsgPeerTgInterest`, type 129).** The same `isSharedTG` + gate controls which TGs are advertised in interest messages, so a routable TG's + interest reaches the next hop toward the owner without a PTT. +- **Inbound accept gate.** On the receive side, `hasPrefixRoute(tg)` is true whenever + `m_all_prefixes` holds a prefix that matches the TG — including routable prefixes. + Combined with `isOwnedTG`, this covers accepting transit traffic for TGs this + reflector neither owns nor has as a direct `REMOTE_PREFIX`. +- **Transit (`shouldRelayInbound` / `hasPrefixRoute`).** Because the routable prefix + is in `m_all_prefixes`, `hasPrefixRoute(tg)` returns true and + `shouldRelayInbound` triggers the gateway fanout arm, re-forwarding the frame via + `onLocal*` toward the actual owner. Each intermediate hop in a chain must + declare the same routable prefix on its appropriate trunk; the declaration does + not propagate automatically. + +**`*` wildcard** is a zero-length default-route match. It is treated as the +lowest-precedence prefix — a real prefix always wins — and is **never** added to +`m_all_prefixes`. As a result: + +- `isSharedTG` admits any TG via a `*`-configured link for local-client forwarding + and interest advertisement. +- `hasPrefixRoute` is **not** set for `*`-matched TGs, so `shouldRelayInbound` does + not trigger the gateway arm. Wildcard-routed frames are delivered locally but + never transited between trunks. +- The **return leg** to a `*`-leaf relies on peer interest: because `*` matches every + TG in the send/interest gate, the leaf advertises interest in the TG toward the + parent (`MsgPeerTgInterest`), and the parent's `isPeerInterestedTG` carries the + return audio back without needing any routable entry on the parent side. + +A startup `WARNING` is emitted when `*` is set on a reflector with more than one +trunk, as that is outside the intended single-uplink leaf pattern and may produce +unexpected fanout behaviour. + +**Blacklist precedence.** `BLACKLIST_TGS` is evaluated before any routable prefix +logic. A blacklisted TG is dropped before `isSharedTG`, `hasPrefixRoute`, or +interest advertisement are consulted. + +**Ownership caveat.** A routable prefix must not be a longer decimal-string match +of a TG the local reflector owns: `isSharedTG` (and `hasPrefixRoute`) would then +route that TG away from the local owner. Keep routable prefixes pointed at TGs +owned by other reflectors — the same discipline that governs `REMOTE_PREFIX`. + ### Cluster TGs Cluster TGs bypass prefix routing entirely. A TG listed in `CLUSTER_TGS` is diff --git a/src/svxlink/reflector/svxreflector.conf.in b/src/svxlink/reflector/svxreflector.conf.in index c4c55a9..faa178f 100644 --- a/src/svxlink/reflector/svxreflector.conf.in +++ b/src/svxlink/reflector/svxreflector.conf.in @@ -129,6 +129,17 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py # Optional bidirectional TG remap (peer_tg:local_tg, comma-separated). # Mapped TGs bypass the prefix routing check on this link. #TG_MAP=1:2624123,2:2624124 +# Optional additional prefixes routable VIA this peer, on top of REMOTE_PREFIX. +# Use on a regional leaf's single uplink as "*" (default route to the parent), +# or on a backbone trunk as explicit prefixes to enable multi-hop transit to a +# sibling reflector (e.g. reach 263 via the 262 peer). "*" is never relayed +# between trunks (loop-safe) and only affects this node's local clients; +# explicit prefixes transit toward the owner and must be declared on each hop. +# Keep routable prefixes pointed at TGs owned by OTHER reflectors (do not let a +# routable prefix be a longer match of a TG this reflector owns). +# BLACKLIST_TGS still vetoes regardless of routable settings. +#ROUTABLE_PREFIXES=263 # backbone transit toward 263 +#ROUTABLE_PREFIXES=* # regional leaf default route via this uplink ############################################################################### # Twin (HA-pair) link — see docs/TWIN_PROTOCOL.md diff --git a/tests/TESTS.md b/tests/TESTS.md index 30b6753..57613c9 100644 --- a/tests/TESTS.md +++ b/tests/TESTS.md @@ -12,6 +12,8 @@ The integration tests verify the trunk protocol, satellite links, twin (HA-pair) A separate harness (`run_redis_tests.sh`) runs `test_redis.py` (13 tests) against a single-reflector + Redis stack. See [Redis Integration Tests](#redis-integration-tests) below. +A separate harness runs `test_routable.py` (2 tests) against a dedicated routable-prefix topology. See [Routable Prefixes](#routable-prefixes) below. + **Requirements:** Docker, Docker Compose, Python 3.7+ (stdlib only, no pip packages). ## Running @@ -131,6 +133,7 @@ Internal port for `[TWIN]` is always 5304; satellite is 5303. | `docker-compose.test.yml` | Generated compose file (do not edit manually) | | `topology_redis.py` | Topology for the Redis test harness (single reflector + Redis). | | `generate_redis_configs.py` | Generates `configs-redis/*.conf` and `docker-compose.redis.yml`. | +| `test_routable.py` | Routable-prefix tests (2 cases): explicit multi-hop transit (forward + return) and `*` wildcard with blacklist veto. Runs on a dedicated compose stack generated from `topology_routable.py`. | | `test_redis.py` | Redis-backed config-store tests (13 cases): users, trunk filters, live-state hashes, outage/resync, import idempotence, peer-node mirroring + sanitization, dynamic trunk add/remove. | | `run_redis_tests.sh` | Redis test orchestrator with `up`/`test`/`down`/`all` subcommands. | | `configs-redis/` | Generated Redis-harness configs (do not edit manually) | @@ -264,6 +267,15 @@ each filter independently of the other trunk fixtures. | 46 | Inbound heartbeat timeout — no crash | A non-paired trunk link whose inbound socket is closed on heartbeat timeout must not abort the process on the next send (e.g. a `MsgPeerTgInterest`) | | 47 | Inbound recovers after timeout | After the reflector times out and drops a silent inbound peer, the same peer can reconnect its inbound leg | +### Routable Prefixes + +Run separately via `test_routable.py` against a dedicated topology. + +| # | Test | What it verifies | +|---|------|-----------------| +| R1 | Explicit transit forward + return | A client on a leaf reflector activates a TG owned by a far reflector two hops away; audio traverses both transit hops (explicit `ROUTABLE_PREFIXES` on each intermediate trunk) and the return audio reaches the leaf via peer interest | +| R2 | `*` wildcard + blacklist veto | A client on a `*`-configured leaf reaches a remote TG via its single uplink; a TG listed in `BLACKLIST_TGS` on the same link is dropped regardless of the wildcard, confirming blacklist-before-routable evaluation order | + ### Twin Protocol (HA-pair) Run separately on the twin topology (`test_twin.py`). See `docs/TWIN_PROTOCOL.md` for the protocol.