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
@@ -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 */
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user