Skip to content

Commit 8d21ae9

Browse files
committed
Merge branch 'dev' of https://github.com/zerotier/zerotierone into dev
2 parents ff8044f + 1b8917a commit 8d21ae9

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

osdep/MacEthernetTap.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,30 @@ MacEthernetTap::MacEthernetTap(
209209
::_exit(-1);
210210
} else {
211211
_agentPid = apid;
212+
213+
// Wait up to 10 seconds for the subprocess to actually create the device. This prevents
214+
// things like routes from being created before the device exists.
215+
for(int waitLoops=0;;++waitLoops) {
216+
struct ifaddrs *ifa = (struct ifaddrs *)0;
217+
if (!getifaddrs(&ifa)) {
218+
struct ifaddrs *p = ifa;
219+
while (p) {
220+
if ((p->ifa_name)&&(!strcmp(devstr, p->ifa_name))) {
221+
waitLoops = -1;
222+
break;
223+
}
224+
p = p->ifa_next;
225+
}
226+
freeifaddrs(ifa);
227+
}
228+
if (waitLoops == -1) {
229+
break;
230+
} else if (waitLoops >= 100) { // 10 seconds
231+
throw std::runtime_error("feth device creation timed out");
232+
}
233+
Thread::sleep(100);
234+
}
212235
}
213-
Thread::sleep(100); // this causes them to come up in a more user-friendly order on launch
214236

215237
_thread = Thread::start(this);
216238
}

osdep/MacEthernetTapAgent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ static void die()
176176
close(s_ndrvfd);
177177
if (s_bpffd >= 0)
178178
close(s_bpffd);
179-
if (s_deviceName[0])
180-
run("/sbin/ifconfig",s_deviceName,"destroy",(char *)0);
181179
if (s_peerDeviceName[0])
182180
run("/sbin/ifconfig",s_peerDeviceName,"destroy",(char *)0);
181+
if (s_deviceName[0])
182+
run("/sbin/ifconfig",s_deviceName,"destroy",(char *)0);
183183
}
184184

185185
static inline void close_inherited_fds()

osdep/ManagedRoute.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ ManagedRoute::ManagedRoute(const InetAddress &target,const InetAddress &via,cons
405405
}
406406

407407
ManagedRoute::~ManagedRoute()
408-
{
409-
this->remove();
410-
}
408+
{}
411409

412410
/* Linux NOTE: for default route override, some Linux distributions will
413411
* require a change to the rp_filter parameter. A value of '1' will prevent

service/OneService.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,7 @@ class OneServiceImpl : public OneService
542542
~NetworkState()
543543
{
544544
this->managedRoutes.clear();
545-
#ifdef __APPLE__
546-
Thread::sleep(10);
547545
this->tap.reset();
548-
#endif
549546
}
550547

551548
std::shared_ptr<EthernetTap> tap;

0 commit comments

Comments
 (0)