From 1e1d477957ab06239155e8e469d17b53b34122ab Mon Sep 17 00:00:00 2001 From: Audric Date: Mon, 15 Jun 2026 16:57:10 +0200 Subject: [PATCH] feat(trunk): routable prefixes feed isSharedTG send/interest gate (* = zero-length) --- src/svxlink/reflector/TrunkLink.cpp | 35 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index 7bc1bf3..f5774f2 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -456,34 +456,47 @@ bool TrunkLink::isSharedTG(uint32_t tg) const { const std::string s = std::to_string(tg); - // Find the best (longest) matching remote prefix for this peer - size_t best_remote_len = 0; + // Best (longest) prefix THIS link claims: an owned remote prefix or an + // explicit routable prefix. The "*" wildcard is a zero-length candidate + // (lowest precedence), considered only when no real prefix matches. + size_t best_link_len = 0; + bool matched = false; for (const auto& prefix : m_remote_prefix) { if (s.size() >= prefix.size() && s.compare(0, prefix.size(), prefix) == 0 && - prefix.size() > best_remote_len) + prefix.size() > best_link_len) { - best_remote_len = prefix.size(); + best_link_len = prefix.size(); + matched = true; } } - if (best_remote_len == 0) + for (const auto& prefix : m_routable_prefixes) { - return false; // no remote prefix matches at all + if (s.size() >= prefix.size() && + s.compare(0, prefix.size(), prefix) == 0 && + prefix.size() > best_link_len) + { + best_link_len = prefix.size(); + matched = true; + } + } + if (!matched) + { + if (!m_routable_wildcard) return false; + best_link_len = 0; // wildcard: zero-length, any real prefix beats it } - // Check if any prefix in the mesh is a longer match — if so, that other - // reflector is more specific and this TG doesn't belong to this peer. + // A longer prefix anywhere in the mesh is more specific — not ours. for (const auto& prefix : m_all_prefixes) { - if (prefix.size() > best_remote_len && + if (prefix.size() > best_link_len && s.size() >= prefix.size() && s.compare(0, prefix.size(), prefix) == 0) { - return false; // a longer prefix claims this TG + return false; } } - return true; } /* TrunkLink::isSharedTG */