From 4b55d69bd61c0429abf3b8145fabc2efeda49470 Mon Sep 17 00:00:00 2001 From: Audric Date: Mon, 15 Jun 2026 16:48:43 +0200 Subject: [PATCH] feat(trunk): parse ROUTABLE_PREFIXES (members + initialize + reload) --- src/svxlink/reflector/TrunkLink.cpp | 49 +++++++++++++++++++++++++++++ src/svxlink/reflector/TrunkLink.h | 5 +++ 2 files changed, 54 insertions(+) diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index d942b8d..7bc1bf3 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -316,6 +316,23 @@ bool TrunkLink::initialize(void) return false; } + // ROUTABLE_PREFIXES — optional additional prefixes (or "*") reachable VIA + // this peer beyond what it owns. "*" is a default route (regional leaves); + // explicit prefixes enable backbone transit. See docs/PEER_PROTOCOL.md. + std::string routable_str; + if (m_cfg.getValue(m_section, "ROUTABLE_PREFIXES", routable_str) + && !routable_str.empty()) + { + for (const auto& p : splitPrefixes(routable_str)) + { + if (p == "*") m_routable_wildcard = true; + else m_routable_prefixes.push_back(p); + } + geulog::info("trunk", m_section, ": Routable prefixes: ", + joinPrefixes(m_routable_prefixes), + (m_routable_wildcard ? " *(default route)" : "")); + } + // PEER_ID — name we advertise in our hello (defaults to section name). // Used by the receiving peer as the MQTT topic component for this link. if (!m_cfg.getValue(m_section, "PEER_ID", m_peer_id_config) @@ -471,6 +488,22 @@ bool TrunkLink::isSharedTG(uint32_t tg) const } /* TrunkLink::isSharedTG */ +bool TrunkLink::matchesRoutable(uint32_t tg) const +{ + if (m_routable_wildcard) return true; + const std::string s = std::to_string(tg); + for (const auto& prefix : m_routable_prefixes) + { + if (s.size() >= prefix.size() && + s.compare(0, prefix.size(), prefix) == 0) + { + return true; + } + } + return false; +} /* TrunkLink::matchesRoutable */ + + bool TrunkLink::isOwnedTG(uint32_t tg) const { const std::string s = std::to_string(tg); @@ -1951,6 +1984,8 @@ void TrunkLink::reloadConfig(void) m_allow_filter = TgFilter{}; m_tg_map_in.clear(); m_tg_map_out.clear(); + m_routable_prefixes.clear(); + m_routable_wildcard = false; RedisStore* rs = m_reflector->redisStore(); @@ -1976,6 +2011,20 @@ void TrunkLink::reloadConfig(void) m_allow_filter = TgFilter::parse(allow_str); } + if (!rs) + { + std::string routable_str; + if (m_cfg.getValue(m_section, "ROUTABLE_PREFIXES", routable_str) + && !routable_str.empty()) + { + for (const auto& p : splitPrefixes(routable_str)) + { + if (p == "*") m_routable_wildcard = true; + else m_routable_prefixes.push_back(p); + } + } + } + if (rs) { auto tgmap = rs->loadTrunkTgMap(m_section); for (auto& kv : tgmap) { diff --git a/src/svxlink/reflector/TrunkLink.h b/src/svxlink/reflector/TrunkLink.h index cfc1cfd..92c8488 100644 --- a/src/svxlink/reflector/TrunkLink.h +++ b/src/svxlink/reflector/TrunkLink.h @@ -101,6 +101,9 @@ class TrunkLink : public sigc::trackable bool initialize(void); bool isSharedTG(uint32_t tg) const; + // True if tg matches an explicit ROUTABLE_PREFIXES entry on this link, + // or the "*" wildcard is set. Per-link; used by the inbound-accept gate. + bool matchesRoutable(uint32_t tg) const; void setAllPrefixes(const std::vector& all_prefixes) { m_all_prefixes = all_prefixes; @@ -206,6 +209,8 @@ class TrunkLink : public sigc::trackable std::string m_peer_id_received; // peer's hello id (set on hello rx) std::vector m_local_prefix; // our authoritative TG prefixes std::vector m_remote_prefix; // peer's authoritative TG prefixes + std::vector m_routable_prefixes; // explicit ROUTABLE_PREFIXES (non-"*") + bool m_routable_wildcard = false; // "*" present uint32_t m_priority; // our tie-break nonce (random, set once) uint32_t m_peer_priority; // peer's nonce, from MsgPeerHello FramedTcpClient m_con; // outbound client connection