Support overlapping TG prefixes with longest-prefix-match routing
isSharedTG now finds the longest matching remote prefix and verifies no other prefix in the mesh is more specific. Each TrunkLink receives the full set of all prefixes at startup via setAllPrefixes(). initTrunkLinks is split into two passes: collect all prefixes first, then create links with full knowledge.
This commit is contained in:
1 parent
dda6ac5531
commit
53a9a6fc75
4 files changed
+60
-6
No files matched your search
@@ -1994,14 +1994,16 @@ void Reflector::initTrunkLinks(void)
|
||||
}
|
||||
}
|
||||
|
||||
// First pass: collect all remote prefixes so we can do longest-prefix-match
|
||||
std::vector<std::string> trunk_sections;
|
||||
for (const auto& section : m_cfg->listSections())
|
||||
{
|
||||
if (section.substr(0, 6) != "TRUNK_")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
trunk_sections.push_back(section);
|
||||
|
||||
// Collect remote prefixes for validation
|
||||
std::string remote_prefix_str;
|
||||
m_cfg->getValue(section, "REMOTE_PREFIX", remote_prefix_str);
|
||||
{
|
||||
@@ -2014,10 +2016,15 @@ void Reflector::initTrunkLinks(void)
|
||||
if (!token.empty()) all_prefixes.push_back(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass: create trunk links with full prefix knowledge
|
||||
for (const auto& section : trunk_sections)
|
||||
{
|
||||
auto* link = new TrunkLink(this, *m_cfg, section);
|
||||
if (link->initialize())
|
||||
{
|
||||
link->setAllPrefixes(all_prefixes);
|
||||
m_trunk_links.push_back(link);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -199,13 +199,36 @@ bool TrunkLink::initialize(void)
|
||||
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;
|
||||
for (const auto& prefix : m_remote_prefix)
|
||||
{
|
||||
if (s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0)
|
||||
return true;
|
||||
s.compare(0, prefix.size(), prefix) == 0 &&
|
||||
prefix.size() > best_remote_len)
|
||||
{
|
||||
best_remote_len = prefix.size();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (best_remote_len == 0)
|
||||
{
|
||||
return false; // no remote prefix matches at all
|
||||
}
|
||||
|
||||
// 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.
|
||||
for (const auto& prefix : m_all_prefixes)
|
||||
{
|
||||
if (prefix.size() > best_remote_len &&
|
||||
s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0)
|
||||
{
|
||||
return false; // a longer prefix claims this TG
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* TrunkLink::isSharedTG */
|
||||
|
||||
|
||||
|
||||
@@ -92,6 +92,10 @@ class TrunkLink : public sigc::trackable
|
||||
bool initialize(void);
|
||||
|
||||
bool isSharedTG(uint32_t tg) const;
|
||||
void setAllPrefixes(const std::vector<std::string>& all_prefixes)
|
||||
{
|
||||
m_all_prefixes = all_prefixes;
|
||||
}
|
||||
const std::string& section(void) const { return m_section; }
|
||||
|
||||
Json::Value statusJson(void) const;
|
||||
@@ -128,6 +132,7 @@ class TrunkLink : public sigc::trackable
|
||||
Async::Timer m_heartbeat_timer;
|
||||
unsigned m_hb_tx_cnt;
|
||||
unsigned m_hb_rx_cnt;
|
||||
std::vector<std::string> m_all_prefixes; // all prefixes in the mesh
|
||||
// TGs where we suppressed our local talker to defer to the peer
|
||||
std::set<uint32_t> m_yielded_tgs;
|
||||
// TGs currently held by this specific trunk peer (for scoped cleanup)
|
||||
|
||||
Reference in new issue
Block a user