From 038476c41204e2fb5c82934beefbd50d8d28c4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Fr=C3=BChwirth?= Date: Tue, 24 Nov 2015 22:56:02 +0100 Subject: [PATCH] Fix for GitHub issue #253. Make 'ip' detection more robust (some distros don't ship the binary in /sbin or /usr/sbin). Add error handling for cases where an ip add/remove fails. --- osdep/LinuxEthernetTap.cpp | 11 +++++------ service/OneService.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/osdep/LinuxEthernetTap.cpp b/osdep/LinuxEthernetTap.cpp index 73eb0cc57..f250abd3c 100644 --- a/osdep/LinuxEthernetTap.cpp +++ b/osdep/LinuxEthernetTap.cpp @@ -210,8 +210,8 @@ static bool ___removeIp(const std::string &_dev,const InetAddress &ip) long cpid = (long)vfork(); if (cpid == 0) { OSUtils::redirectUnixOutputs("/dev/null",(const char *)0); - ::execl("/sbin/ip","/sbin/ip","addr","del",ip.toString().c_str(),"dev",_dev.c_str(),(const char *)0); - ::execl("/usr/sbin/ip","/usr/sbin/ip","addr","del",ip.toString().c_str(),"dev",_dev.c_str(),(const char *)0); + setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1); + ::execlp("ip","ip","addr","del",ip.toString().c_str(),"dev",_dev.c_str(),(const char *)0); ::_exit(-1); } else { int exitcode = -1; @@ -238,12 +238,11 @@ bool LinuxEthernetTap::addIp(const InetAddress &ip) long cpid = (long)vfork(); if (cpid == 0) { OSUtils::redirectUnixOutputs("/dev/null",(const char *)0); + setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1); if (ip.isV4()) { - ::execl("/sbin/ip","/sbin/ip","addr","add",ip.toString().c_str(),"broadcast",ip.broadcast().toIpString().c_str(),"dev",_dev.c_str(),(const char *)0); - ::execl("/usr/sbin/ip","/usr/sbin/ip","addr","add",ip.toString().c_str(),"broadcast",ip.broadcast().toIpString().c_str(),"dev",_dev.c_str(),(const char *)0); + ::execlp("ip","ip","addr","add",ip.toString().c_str(),"broadcast",ip.broadcast().toIpString().c_str(),"dev",_dev.c_str(),(const char *)0); } else { - ::execl("/sbin/ip","/sbin/ip","addr","add",ip.toString().c_str(),"dev",_dev.c_str(),(const char *)0); - ::execl("/usr/sbin/ip","/usr/sbin/ip","addr","add",ip.toString().c_str(),"dev",_dev.c_str(),(const char *)0); + ::execlp("ip","ip","addr","add",ip.toString().c_str(),"dev",_dev.c_str(),(const char *)0); } ::_exit(-1); } else if (cpid > 0) { diff --git a/service/OneService.cpp b/service/OneService.cpp index a912c8306..8e21fc5fe 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -1147,11 +1147,13 @@ public: newAssignedIps.erase(std::unique(newAssignedIps.begin(),newAssignedIps.end()),newAssignedIps.end()); for(std::vector::iterator ip(newAssignedIps.begin());ip!=newAssignedIps.end();++ip) { if (!std::binary_search(assignedIps.begin(),assignedIps.end(),*ip)) - t->second->addIp(*ip); + if (!t->second->addIp(*ip)) + fprintf(stderr,"ERROR: unable to add ip address %s"ZT_EOL_S, ip->toString().c_str()); } for(std::vector::iterator ip(assignedIps.begin());ip!=assignedIps.end();++ip) { if (!std::binary_search(newAssignedIps.begin(),newAssignedIps.end(),*ip)) - t->second->removeIp(*ip); + if (!t->second->removeIp(*ip)) + fprintf(stderr,"ERROR: unable to remove ip address %s"ZT_EOL_S, ip->toString().c_str()); } assignedIps.swap(newAssignedIps); } else {