Bridge routing table - GitHub issue #68

This commit is contained in:
Adam Ierymenko 2014-06-10 17:18:59 -07:00
parent 6f831d5370
commit d44e1349d8
3 changed files with 69 additions and 3 deletions

View file

@ -333,6 +333,31 @@ void Network::threadMain()
}
}
void Network::learnBridgeRoute(const MAC &mac,const Address &addr)
{
Mutex::Lock _l(_lock);
_bridgeRoutes[mac] = addr;
// If _bridgeRoutes exceeds sanity limit, trim worst offenders until below -- denial of service circuit breaker
while (_bridgeRoutes.size() > ZT_MAX_BRIDGE_ROUTES) {
std::map<Address,unsigned long> counts;
Address maxAddr;
unsigned long maxCount = 0;
for(std::map<MAC,Address>::iterator br(_bridgeRoutes.begin());br!=_bridgeRoutes.end();++br) {
unsigned long c = ++counts[br->second];
if (c > maxCount) {
maxCount = c;
maxAddr = br->second;
}
}
for(std::map<MAC,Address>::iterator br(_bridgeRoutes.begin());br!=_bridgeRoutes.end();) {
if (br->second == maxAddr)
_bridgeRoutes.erase(br++);
else ++br;
}
}
}
void Network::_restoreState()
{
if (!_id)