summaryrefslogtreecommitdiff
path: root/zerotierone/osdep/LinuxEthernetTap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zerotierone/osdep/LinuxEthernetTap.cpp')
-rw-r--r--zerotierone/osdep/LinuxEthernetTap.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/zerotierone/osdep/LinuxEthernetTap.cpp b/zerotierone/osdep/LinuxEthernetTap.cpp
index c66b7a3..e336bb6 100644
--- a/zerotierone/osdep/LinuxEthernetTap.cpp
+++ b/zerotierone/osdep/LinuxEthernetTap.cpp
@@ -95,12 +95,12 @@ LinuxEthernetTap::LinuxEthernetTap(
// Try to recall our last device name, or pick an unused one if that fails.
bool recalledDevice = false;
std::string devmapbuf;
- Dictionary devmap;
+ Dictionary<8194> devmap;
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
- devmap.fromString(devmapbuf);
- std::string desiredDevice(devmap.get(nwids,""));
- if (desiredDevice.length() > 2) {
- Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),desiredDevice.c_str());
+ devmap.load(devmapbuf.c_str());
+ char desiredDevice[128];
+ if (devmap.get(nwids,desiredDevice,sizeof(desiredDevice)) > 0) {
+ Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),desiredDevice);
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
recalledDevice = (stat(procpath,&sbuf) != 0);
}
@@ -172,17 +172,18 @@ LinuxEthernetTap::LinuxEthernetTap(
// Set close-on-exec so that devices cannot persist if we fork/exec for update
::fcntl(_fd,F_SETFD,fcntl(_fd,F_GETFD) | FD_CLOEXEC);
- ::pipe(_shutdownSignalPipe);
+ (void)::pipe(_shutdownSignalPipe);
- devmap[nwids] = _dev;
- OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
+ devmap.erase(nwids);
+ devmap.add(nwids,_dev.c_str());
+ OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),(const void *)devmap.data(),devmap.sizeBytes());
_thread = Thread::start(this);
}
LinuxEthernetTap::~LinuxEthernetTap()
{
- ::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
+ (void)::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
Thread::join(_thread);
::close(_fd);
::close(_shutdownSignalPipe[0]);
@@ -253,7 +254,7 @@ bool LinuxEthernetTap::removeIp(const InetAddress &ip)
if (!ip)
return true;
std::vector<InetAddress> allIps(ips());
- if (!std::binary_search(allIps.begin(),allIps.end(),ip)) {
+ if (std::find(allIps.begin(),allIps.end(),ip) != allIps.end()) {
if (___removeIp(_dev,ip))
return true;
}
@@ -293,7 +294,7 @@ std::vector<InetAddress> LinuxEthernetTap::ips() const
freeifaddrs(ifa);
std::sort(r.begin(),r.end());
- std::unique(r.begin(),r.end());
+ r.erase(std::unique(r.begin(),r.end()),r.end());
return r;
}
@@ -307,7 +308,7 @@ void LinuxEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,
*((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType);
memcpy(putBuf + 14,data,len);
len += 14;
- ::write(_fd,putBuf,len);
+ (void)::write(_fd,putBuf,len);
}
}
@@ -355,7 +356,7 @@ void LinuxEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,st
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
std::sort(newGroups.begin(),newGroups.end());
- std::unique(newGroups.begin(),newGroups.end());
+ newGroups.erase(std::unique(newGroups.begin(),newGroups.end()),newGroups.end());
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))