feat(trunk): apply per-link TG filter to monitoredTGs in peer roster

The roster trim added in 7cf6589 dropped a peer node entirely when its
*selected* TG was filtered, but a kept node (selected on a permitted TG)
still carried its full monitoredTGs list verbatim in the status blob, so
blacklisted / non-ALLOW_TGS TGs it was only monitoring leaked into
/status.trunks[<section>].nodes[*].monitoredTGs and the MQTT/Redis mirrors.

Filter each entry's monitoredTGs array in TrunkLink::handleMsgPeerNodeList
with the same composite gate as the selected TG and the audio receive path
(isBlacklisted(tg) || isBlacklisted(mapTgIn(tg)) || !isAllowed(tg)), so
TG_MAP translation is honoured and the blacklist wins over an allow-prefix.
Non-permitted and malformed (non-uint) entries are dropped; the array may
become empty. Visibility-only: m_partner_nodes feeds statusJson() and
onPeerNodeList() (MQTT/Redis), never routing.

Adds test_21c_filter_trims_monitored_tgs_in_blob and documents the
monitor-list trim in PEER_PROTOCOL.md.
This commit is contained in:
Audric committed 2026-05-27 13:06:23 +02:00
1 parent 7cf6589a3b
commit 88739d160b
3 files changed
+66 -1

No files matched your search

+4 -1
View File
@@ -554,7 +554,10 @@ entirely, so it never appears under `/status.trunks[<section>].nodes`, MQTT
`nodes/<peer_id>`, or the Redis mirror — a filtered TG's roster is trimmed on `nodes/<peer_id>`, 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 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 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.) links have no roster filtering on send, so the trim happens on receive.) The
same gate is then applied to each kept entry's `monitoredTGs` array inside the
status blob (see below), so a node retained because its *selected* TG is
permitted cannot surface filtered TGs it is only monitoring.
The optional `status_blobs[i]` field carries the source reflector's The optional `status_blobs[i]` field carries the source reflector's
`m_status["nodes"][callsign]` JSON serialised verbatim — the same rich `m_status["nodes"][callsign]` JSON serialised verbatim — the same rich
+22
View File
@@ -2073,6 +2073,28 @@ void TrunkLink::handleMsgPeerNodeList(std::istream& is)
} }
e.status = n.status; e.status = n.status;
sanitizeJsonStrings(e.status); sanitizeJsonStrings(e.status);
// Trim non-permitted TGs out of the status blob's monitoredTGs array
// with the same per-link gate as the selected TG above. Otherwise a
// node kept because its *selected* TG is permitted could still surface
// filtered TGs it is only monitoring into /status, MQTT and the Redis
// mirror. Values stay in the peer's wire numbering, matching e.tg.
if (e.status.isMember("monitoredTGs") && e.status["monitoredTGs"].isArray())
{
Json::Value kept(Json::arrayValue);
for (const auto& mt : e.status["monitoredTGs"])
{
if (!mt.isUInt()) continue; // drop malformed entries
const uint32_t tg = mt.asUInt();
if (isBlacklisted(tg) || isBlacklisted(mapTgIn(tg)) || !isAllowed(tg))
{
continue;
}
kept.append(tg);
}
e.status["monitoredTGs"] = kept; // may be empty
}
// Recipient-relative sat_id from the peer. Pass through as-is after // Recipient-relative sat_id from the peer. Pass through as-is after
// bounded sanitisation: empty = "on the peer itself", non-empty = // bounded sanitisation: empty = "on the peer itself", non-empty =
// "on a satellite attached to the peer". // "on a satellite attached to the peer".
+40
View File
@@ -1711,6 +1711,46 @@ class TestTrunkIntegration(unittest.TestCase):
finally: finally:
peer.close() peer.close()
# ------------------------------------------------------------------
# Test 21c: per-link TG filter trims monitoredTGs inside the status blob
# ------------------------------------------------------------------
def test_21c_filter_trims_monitored_tgs_in_blob(self):
"""A node kept because its SELECTED TG is permitted must still have
non-permitted entries trimmed from its status blob's monitoredTGs
array — the same per-link gate that drops whole entries (test_21b)
also scrubs the monitored list so filtered TGs never surface under
/status.trunks[X].nodes[*].monitoredTGs.
"""
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
# monitor list mixes allowed (7*), blacklisted, and disallowed TGs
blob = json.dumps({"monitoredTGs": [7100, blocked_tg, 99, 7205]})
# selected TG 7100 is permitted, so the node itself is kept
peer.send_node_list([("N0RMON", 7100, 0.0, 0.0, "", blob, "")])
def monitored():
status = get_status(*_http(self.PRIMARY))
nodes = status["trunks"].get(
"TRUNK_TEST_FILTER", {}).get("nodes", [])
for n in nodes:
if n.get("callsign") == "N0RMON":
return n.get("monitoredTGs")
return None
wait_until(lambda: monitored() is not None,
timeout=5.0, interval=0.25,
msg="Kept node N0RMON missing from trunk roster")
self.assertEqual(sorted(monitored()), [7100, 7205],
f"monitoredTGs leaked filtered TGs: {monitored()}")
finally:
peer.close()
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Test 22: TG_MAP remaps incoming TGs # Test 22: TG_MAP remaps incoming TGs
# ------------------------------------------------------------------ # ------------------------------------------------------------------