Require matching trunk section names and cap audio debug at 500 frames

Trunk link matching now requires the peer's hello ID (section name) to
match the local [TRUNK_x] section name. Both sides of a trunk link must
use the same section name, agreed upon by both sysops. This replaces
the previous matching by secret+prefix only.

BREAKING CHANGE: existing deployments must rename their [TRUNK_x]
sections so both sides use the same name for each link.

Also cap TRUNK_DEBUG audio frame logging at 500 frames per trunk link
to prevent excessive log output during sustained transmissions.
This commit is contained in:
Audric committed 2026-04-05 18:22:04 +02:00
1 parent 638d3c527e
commit 05c4c88ff3
6 files changed
+59 -20

No files matched your search

+23 -10
View File
@@ -2198,21 +2198,32 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
safe_id.resize(64); safe_id.resize(64);
} }
// Find the matching TrunkLink by verifying the shared secret AND matching // Find the matching TrunkLink by section name, shared secret, and prefix.
// the peer's declared prefix against our configured REMOTE_PREFIX. // Both sides must use the same [TRUNK_x] section name — sysops agree on a
// This allows multiple trunk sections to share the same secret safely. // shared link name. The peer's hello ID is its section name.
TrunkLink* matched_link = nullptr; TrunkLink* matched_link = nullptr;
for (auto* link : m_trunk_links) for (auto* link : m_trunk_links)
{ {
// Section name must match (case-sensitive)
if (msg.id() != link->section())
{
continue;
}
if (!msg.verify(link->secret())) if (!msg.verify(link->secret()))
{ {
if (m_trunk_debug) if (m_trunk_debug)
{ {
std::cout << "TRUNK [DEBUG]: peer '" << safe_id std::cout << "TRUNK [DEBUG]: peer '" << safe_id
<< "' HMAC mismatch against " << link->section() << "' section matches " << link->section()
<< std::endl; << " but HMAC mismatch" << std::endl;
} }
continue; std::cerr << "*** ERROR: TRUNK inbound: peer '" << safe_id
<< "' section matches " << link->section()
<< " but authentication failed (wrong secret)"
<< std::endl;
con->disconnect();
return;
} }
// Check if the peer's local_prefix matches this link's remote_prefix. // Check if the peer's local_prefix matches this link's remote_prefix.
@@ -2239,7 +2250,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
matched_link = link; matched_link = link;
break; break;
} }
else if (m_trunk_debug) else
{ {
std::string exp_str, peer_str; std::string exp_str, peer_str;
for (const auto& p : sorted_expected) for (const auto& p : sorted_expected)
@@ -2252,17 +2263,19 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
if (!peer_str.empty()) peer_str += ","; if (!peer_str.empty()) peer_str += ",";
peer_str += p; peer_str += p;
} }
std::cout << "TRUNK [DEBUG]: peer '" << safe_id std::cerr << "*** ERROR: TRUNK inbound: peer '" << safe_id
<< "' secret OK for " << link->section() << "' section matches " << link->section()
<< " but prefix mismatch: expected=[" << exp_str << " but prefix mismatch: expected=[" << exp_str
<< "] got=[" << peer_str << "]" << std::endl; << "] got=[" << peer_str << "]" << std::endl;
con->disconnect();
return;
} }
} }
if (matched_link == nullptr) if (matched_link == nullptr)
{ {
std::cerr << "*** ERROR: TRUNK inbound: peer '" << safe_id std::cerr << "*** ERROR: TRUNK inbound: peer '" << safe_id
<< "' failed authentication (no matching secret/prefix)" << "' no matching section name"
<< std::endl; << std::endl;
con->disconnect(); con->disconnect();
return; return;
+19 -2
View File
@@ -563,8 +563,25 @@ void TrunkLink::onFrameReceived(FramedTcpConnection* con,
if (m_debug && header.type() != MsgTrunkHeartbeat::TYPE) if (m_debug && header.type() != MsgTrunkHeartbeat::TYPE)
{ {
cout << m_section << " [DEBUG]: rx " << (is_inbound ? "IB" : "OB") if (header.type() == MsgTrunkAudio::TYPE ||
<< " type=" << header.type() << " len=" << data.size() << endl; header.type() == MsgTrunkFlush::TYPE)
{
if (m_debug_frame_cnt < 500)
{
cout << m_section << " [DEBUG]: rx " << (is_inbound ? "IB" : "OB")
<< " type=" << header.type() << " len=" << data.size() << endl;
if (++m_debug_frame_cnt == 500)
{
cout << m_section << " [DEBUG]: audio frame log limit reached (500)"
<< " — suppressing further audio/flush debug" << endl;
}
}
}
else
{
cout << m_section << " [DEBUG]: rx " << (is_inbound ? "IB" : "OB")
<< " type=" << header.type() << " len=" << data.size() << endl;
}
} }
switch (header.type()) switch (header.type())
+1
View File
@@ -141,6 +141,7 @@ class TrunkLink : public sigc::trackable
Async::Config& m_cfg; Async::Config& m_cfg;
std::string m_section; std::string m_section;
bool m_debug = false; bool m_debug = false;
unsigned m_debug_frame_cnt = 0;
std::string m_peer_host; std::string m_peer_host;
uint16_t m_peer_port; uint16_t m_peer_port;
std::string m_secret; std::string m_secret;
+1 -1
View File
@@ -47,7 +47,7 @@ def generate_reflector_conf(name: str) -> str:
# Trunk sections for each peer reflector # Trunk sections for each peer reflector
for peer_name in sorted(peers): for peer_name in sorted(peers):
peer = peers[peer_name] peer = peers[peer_name]
section = T.trunk_section_name(peer_name) section = T.trunk_section_name(name, peer_name)
secret = T.trunk_secret(name, peer_name) secret = T.trunk_secret(name, peer_name)
lines += [ lines += [
"", "",
+5 -5
View File
@@ -210,7 +210,7 @@ class TrunkPeer:
self.sock = socket.create_connection((host, port), timeout=timeout) self.sock = socket.create_connection((host, port), timeout=timeout)
self.sock.settimeout(timeout) self.sock.settimeout(timeout)
def handshake(self, trunk_id: str = "TEST_PEER", local_prefix: str = TEST_PREFIX, def handshake(self, trunk_id: str = "TRUNK_TEST", local_prefix: str = TEST_PREFIX,
priority: int = None, secret: str = TEST_SECRET): priority: int = None, secret: str = TEST_SECRET):
if priority is None: if priority is None:
priority = struct.unpack("!I", os.urandom(4))[0] priority = struct.unpack("!I", os.urandom(4))[0]
@@ -552,7 +552,7 @@ class TestTrunkIntegration(unittest.TestCase):
for peer in REFLECTOR_NAMES: for peer in REFLECTOR_NAMES:
if peer != name: if peer != name:
wait_for_trunk_connected( wait_for_trunk_connected(
*_http(name), T.trunk_section_name(peer), timeout=30.0) *_http(name), T.trunk_section_name(name, peer), timeout=30.0)
labels = "\u2194".join(n.upper() for n in REFLECTOR_NAMES) labels = "\u2194".join(n.upper() for n in REFLECTOR_NAMES)
sys.stderr.write(f"\r\033[K {G}\u2714{RST} Mesh connected ({labels})\n") sys.stderr.write(f"\r\033[K {G}\u2714{RST} Mesh connected ({labels})\n")
sys.stderr.write(f"\033[2m{'─' * 50}\033[0m\n") sys.stderr.write(f"\033[2m{'─' * 50}\033[0m\n")
@@ -584,7 +584,7 @@ class TestTrunkIntegration(unittest.TestCase):
for peer in REFLECTOR_NAMES: for peer in REFLECTOR_NAMES:
if peer == name: if peer == name:
continue continue
section = T.trunk_section_name(peer) section = T.trunk_section_name(name, peer)
self.assertTrue( self.assertTrue(
status["trunks"][section]["connected"], status["trunks"][section]["connected"],
f"{section} not connected on reflector-{name}") f"{section} not connected on reflector-{name}")
@@ -694,10 +694,10 @@ class TestTrunkIntegration(unittest.TestCase):
# Verify NOT propagated to other peers (no trunk-to-trunk forwarding) # Verify NOT propagated to other peers (no trunk-to-trunk forwarding)
time.sleep(1.0) time.sleep(1.0)
primary_section = T.trunk_section_name(self.PRIMARY)
for name in REFLECTOR_NAMES: for name in REFLECTOR_NAMES:
if name == self.PRIMARY: if name == self.PRIMARY:
continue continue
primary_section = T.trunk_section_name(name, self.PRIMARY)
status = get_status(*_http(name)) status = get_status(*_http(name))
talkers = status["trunks"].get(primary_section, {}).get("active_talkers", {}) talkers = status["trunks"].get(primary_section, {}).get("active_talkers", {})
for tg in T.CLUSTER_TGS: for tg in T.CLUSTER_TGS:
@@ -777,7 +777,7 @@ class TestTrunkIntegration(unittest.TestCase):
receiver = TrunkPeer() receiver = TrunkPeer()
receiver.connect(*_trunk(self.PRIMARY)) receiver.connect(*_trunk(self.PRIMARY))
rx_type, rx_fields = receiver.handshake( rx_type, rx_fields = receiver.handshake(
trunk_id="TEST_RX", local_prefix=TEST_RX_PREFIX, trunk_id="TRUNK_TEST_RX", local_prefix=TEST_RX_PREFIX,
secret=TEST_RX_SECRET) secret=TEST_RX_SECRET)
self.assertEqual(rx_type, MSG_TRUNK_HELLO) self.assertEqual(rx_type, MSG_TRUNK_HELLO)
+10 -2
View File
@@ -98,5 +98,13 @@ def service_name(name: str) -> str:
def mapped_satellite_port(name: str) -> int: def mapped_satellite_port(name: str) -> int:
return REFLECTORS[name]["trunk_port_base"] + 303 return REFLECTORS[name]["trunk_port_base"] + 303
def trunk_section_name(peer_name: str) -> str: def trunk_section_name(name_a: str, name_b: str = "") -> str:
return f"TRUNK_{peer_name.upper()}" """Shared trunk section name for a link between two reflectors.
Both sides must use the same section name. Convention: sorted pair.
If only one name given (legacy), returns TRUNK_<NAME> for test harness use.
"""
if not name_b:
return f"TRUNK_{name_a.upper()}"
pair = tuple(sorted([name_a, name_b]))
return f"TRUNK_{pair[0].upper()}_{pair[1].upper()}"