IfaceMap add look up index by address, and loopback by index
This commit is contained in:
@@ -837,6 +837,21 @@ uint64_t IfaceMap::index_of(const std::string& name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t IfaceMap::index_of(const SockAddr &addr)
|
||||
{
|
||||
Guard G(lock);
|
||||
|
||||
uint64_t ret = 0u;
|
||||
try_cache(*this, [&ret, this, addr]() {
|
||||
auto it = byAddr.find(addr);
|
||||
bool hit = it!=byAddr.end() && !it->second.second;
|
||||
if(hit)
|
||||
ret = it->second.first->index;
|
||||
return hit;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool IfaceMap::is_iface(const SockAddr& addr)
|
||||
{
|
||||
Guard G(lock);
|
||||
@@ -847,6 +862,19 @@ bool IfaceMap::is_iface(const SockAddr& addr)
|
||||
});
|
||||
}
|
||||
|
||||
bool IfaceMap::is_lo(uint64_t index)
|
||||
{
|
||||
bool is_lo = false;
|
||||
(void)try_cache(*this, [this, &is_lo, index]() {
|
||||
auto ifit(byIndex.find(index));
|
||||
if(ifit!=byIndex.end()) { // hit
|
||||
is_lo = ifit->second.isLO;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return is_lo;
|
||||
}
|
||||
|
||||
bool IfaceMap::is_broadcast(const SockAddr& addr)
|
||||
{
|
||||
Guard G(lock);
|
||||
|
||||
@@ -316,8 +316,12 @@ struct PVXS_API IfaceMap {
|
||||
std::string name_of(const SockAddr& addr);
|
||||
// returns 0 if not found
|
||||
uint64_t index_of(const std::string& name);
|
||||
// lookup interface index by interface address (not broadcast addr)
|
||||
uint64_t index_of(const SockAddr& addr);
|
||||
// is this a valid interface or broadcast address?
|
||||
bool is_iface(const SockAddr& addr);
|
||||
// is this index the/a loopback interface?
|
||||
bool is_lo(uint64_t index);
|
||||
// is this a valid interface or broadcast address?
|
||||
bool is_broadcast(const SockAddr& addr);
|
||||
// look up interface address. useful for IPV4. returns AF_UNSPEC if not found
|
||||
|
||||
Reference in New Issue
Block a user