mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-20 09:46:13 +00:00
cache getifaddrs - bsd
This commit is contained in:
parent
259ee610a6
commit
60d2138f30
@ -74,7 +74,8 @@ BSDEthernetTap::BSDEthernetTap(
|
||||
_mtu(mtu),
|
||||
_metric(metric),
|
||||
_fd(0),
|
||||
_enabled(true)
|
||||
_enabled(true),
|
||||
_lastIfAddrsUpdate(0)
|
||||
{
|
||||
static Mutex globalTapCreateLock;
|
||||
char devpath[64],ethaddr[64],mtustr[32],metstr[32],tmpdevname[32];
|
||||
@ -287,6 +288,13 @@ bool BSDEthernetTap::removeIp(const InetAddress &ip)
|
||||
|
||||
std::vector<InetAddress> BSDEthernetTap::ips() const
|
||||
{
|
||||
uint64_t now = OSUtils::now();
|
||||
|
||||
if ((now - _lastIfAddrsUpdate) <= GETIFADDRS_CACHE_TIME) {
|
||||
return _ifaddrs;
|
||||
}
|
||||
_lastIfAddrsUpdate = now;
|
||||
|
||||
struct ifaddrs *ifa = (struct ifaddrs *)0;
|
||||
if (getifaddrs(&ifa))
|
||||
return std::vector<InetAddress>();
|
||||
@ -320,6 +328,8 @@ std::vector<InetAddress> BSDEthernetTap::ips() const
|
||||
std::sort(r.begin(),r.end());
|
||||
std::unique(r.begin(),r.end());
|
||||
|
||||
_ifaddrs = r;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,8 @@ private:
|
||||
int _fd;
|
||||
int _shutdownSignalPipe[2];
|
||||
volatile bool _enabled;
|
||||
mutable std::vector<InetAddress> _ifaddrs;
|
||||
mutable uint64_t _lastIfAddrsUpdate;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
Loading…
x
Reference in New Issue
Block a user