From 7cf6589a3b47b0e6544b9f7902a96131fbbaab29 Mon Sep 17 00:00:00 2001 From: Audric Date: Mon, 25 May 2026 20:43:09 +0200 Subject: [PATCH] feat(trunk): apply per-link TG filter to peer node roster on ingest BLACKLIST_TGS / ALLOW_TGS previously gated only audio and active-talker traffic on a trunk link; the full client roster (MsgPeerNodeList) was stored verbatim, so a peer node parked on a filtered TG still appeared in /status.trunks[
].nodes and the MQTT/Redis mirrors. Filter each node-list entry in TrunkLink::handleMsgPeerNodeList using the same composite gate as the audio receive path (isBlacklisted(tg) || isBlacklisted(mapTgIn(tg)) || !isAllowed(tg)), so TG_MAP translation is honoured. Filtered entries are dropped entirely. Safe because m_partner_nodes feeds only statusJson() and onPeerNodeList() (MQTT/Redis) -- no routing depends on it. Adds test_21b_filter_drops_nodes_from_roster and documents the receive-side trim in PEER_PROTOCOL.md and svxreflector.conf.in. --- docs/PEER_PROTOCOL.md | 11 ++++++ src/svxlink/reflector/TrunkLink.cpp | 10 ++++++ src/svxlink/reflector/svxreflector.conf.in | 4 ++- tests/test_trunk.py | 42 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/PEER_PROTOCOL.md b/docs/PEER_PROTOCOL.md index 87abd6a..1987170 100644 --- a/docs/PEER_PROTOCOL.md +++ b/docs/PEER_PROTOCOL.md @@ -545,6 +545,17 @@ or TG change, debounced to 500 ms, and broadcast to every trunk peer. Peers republish it via MQTT under `nodes/` so a central dashboard can see who is connected to each reflector. +On ingest the receiver applies that link's per-trunk TG filter +(`BLACKLIST_TGS` / `ALLOW_TGS`) to every entry, using the same match as the +audio/talker receive gate (`isBlacklisted(tg) || isBlacklisted(mapTgIn(tg)) +|| !isAllowed(tg)`, so `TG_MAP` translation is honoured). A node whose +selected TG is blacklisted or outside `ALLOW_TGS` is dropped from the roster +entirely, so it never appears under `/status.trunks[
].nodes`, MQTT +`nodes/`, or the Redis mirror — a filtered TG's roster is trimmed on +this link just like its audio, even though the full snapshot is sent on the +wire. (Satellite links filter on the *send* side via `SATELLITE_FILTER`; trunk +links have no roster filtering on send, so the trim happens on receive.) + The optional `status_blobs[i]` field carries the source reflector's `m_status["nodes"][callsign]` JSON serialised verbatim — the same rich per-client status that local clients expose (rx/tx config, qth array, diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index faad01d..6363736 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -2044,6 +2044,16 @@ void TrunkLink::handleMsgPeerNodeList(std::istream& is) continue; } e.tg = n.tg; + + // Per-link TG filter: a node whose selected TG is blacklisted or falls + // outside ALLOW_TGS on this link is dropped from the roster entirely, + // mirroring the audio/talker receive gate (handleMsgPeerTalkerStart). + // This keeps filtered TGs out of /status, MQTT and the Redis mirror — + // m_partner_nodes feeds statusJson() and onPeerNodeList() only. + if (isBlacklisted(e.tg) || isBlacklisted(mapTgIn(e.tg)) || !isAllowed(e.tg)) + { + continue; + } e.qth_name = sanitizeText(n.qth_name, 64); // Lat/lon: reject non-finite; drop out-of-range values by zeroing diff --git a/src/svxlink/reflector/svxreflector.conf.in b/src/svxlink/reflector/svxreflector.conf.in index caaa416..c4c55a9 100644 --- a/src/svxlink/reflector/svxreflector.conf.in +++ b/src/svxlink/reflector/svxreflector.conf.in @@ -121,7 +121,9 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py # component for this link, so set it to a stable, broker-friendly name. #PEER_ID=reflector-a # Optional per-trunk TG filters (syntax: exact "26200", prefix "24*", -# range "2427-2438", comma-separated): +# range "2427-2438", comma-separated). These gate audio/talker traffic AND +# trim the peer's node roster shown under /status.trunks[
].nodes +# (and its MQTT/Redis mirror), so a filtered TG never pollutes the roster. #BLACKLIST_TGS=666,777* # never carried in either direction on this link #ALLOW_TGS=24*,2624123 # if set, ONLY these TGs are exchanged # Optional bidirectional TG remap (peer_tg:local_tg, comma-separated). diff --git a/tests/test_trunk.py b/tests/test_trunk.py index 5e252a8..b86de16 100644 --- a/tests/test_trunk.py +++ b/tests/test_trunk.py @@ -1669,6 +1669,48 @@ class TestTrunkIntegration(unittest.TestCase): finally: peer.close() + # ------------------------------------------------------------------ + # Test 21b: per-link TG filter trims the node roster in /status + # ------------------------------------------------------------------ + def test_21b_filter_drops_nodes_from_roster(self): + """A peer-advertised node whose selected TG is blacklisted (or not in + ALLOW_TGS) must NOT appear under /status.trunks[X].nodes — the same + per-link filter that gates audio/active_talkers also trims the roster. + """ + peer = TrunkPeer() + peer.connect(*_trunk(self.PRIMARY)) + peer.handshake(trunk_id="TRUNK_TEST_FILTER", + local_prefix=FILTER_PREFIX, + secret=FILTER_SECRET) + try: + blocked_tg = int(T.TEST_PEER_FILTER["blacklist_tgs"]) # 12345 + allowed_tg = 7100 # matches ALLOW_TGS "7*" + disallowed_tg = 99 # matches neither "7*" nor "1220" + peer.send_node_list([ + ("N0ROK", allowed_tg), + ("N0RBL", blocked_tg), + ("N0RDIS", disallowed_tg), + ]) + + def roster_callsigns(): + status = get_status(*_http(self.PRIMARY)) + nodes = status["trunks"].get( + "TRUNK_TEST_FILTER", {}).get("nodes", []) + return {n.get("callsign") for n in nodes} + + # The allowed-TG node must appear (proves the roster was ingested) + wait_until(lambda: "N0ROK" in roster_callsigns(), + timeout=5.0, interval=0.25, + msg="Allowed-TG node N0ROK missing from trunk roster") + + cs = roster_callsigns() + self.assertNotIn("N0RBL", cs, + f"Blacklisted-TG ({blocked_tg}) node leaked into roster: {cs}") + self.assertNotIn("N0RDIS", cs, + f"Disallowed-TG ({disallowed_tg}) node leaked into roster: {cs}") + finally: + peer.close() + # ------------------------------------------------------------------ # Test 22: TG_MAP remaps incoming TGs # ------------------------------------------------------------------