From 3f2b21ce71be81ae960a4a6197555a92158a74e3 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 12 Jul 2016 08:55:57 -0700 Subject: Do not shadow our own route twice on Mac if there is no default route. (Fix for issue found during IPv6 default route override testing.) --- osdep/ManagedRoute.cpp | 4 +++- osdep/ManagedRoute.hpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'osdep') diff --git a/osdep/ManagedRoute.cpp b/osdep/ManagedRoute.cpp index 54990122..88fd944a 100644 --- a/osdep/ManagedRoute.cpp +++ b/osdep/ManagedRoute.cpp @@ -57,6 +57,8 @@ #define ZT_LINUX_IP_COMMAND "/sbin/ip" #define ZT_LINUX_IP_COMMAND_2 "/usr/sbin/ip" +// NOTE: BSD is mostly tested on Apple/Mac but is likely to work on other BSD too + namespace ZeroTier { namespace { @@ -413,7 +415,7 @@ bool ManagedRoute::sync() // Shadow system route if it exists, also delete any obsolete shadows // and replace them with the new state. sync() is called periodically to // allow us to do that if underlying connectivity changes. - if ((_systemVia != newSystemVia)||(!strcmp(_systemDevice,newSystemDevice))) { + if ( ((_systemVia != newSystemVia)||(!strcmp(_systemDevice,newSystemDevice))) && (strcmp(_device,newSystemDevice)) ) { if ((_systemVia)&&(_systemDevice[0])) { _routeCmd("delete",leftt,_systemVia,_systemDevice,(const char *)0); _routeCmd("delete",rightt,_systemVia,_systemDevice,(const char *)0); diff --git a/osdep/ManagedRoute.hpp b/osdep/ManagedRoute.hpp index 5dde12ad..63310f24 100644 --- a/osdep/ManagedRoute.hpp +++ b/osdep/ManagedRoute.hpp @@ -54,8 +54,8 @@ public: * "device name." * * @param target Route target (e.g. 0.0.0.0/0 for default) - * @param via Route next L3 hop or NULL InetAddress if local - * @param device Device name/ID if 'via' is null and route is local, otherwise ignored + * @param via Route next L3 hop or NULL InetAddress if local in which case it will be routed via device + * @param device Name or hex LUID of ZeroTier device (e.g. zt#) * @return True if route was successfully set */ inline bool set(const InetAddress &target,const InetAddress &via,const char *device) -- cgit v1.2.3 From 23391ff9dad8c82858cee8f1bb19ca10bf613bcb Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 12 Jul 2016 09:22:04 -0700 Subject: More OSX IPv6 fixes. --- osdep/ManagedRoute.cpp | 2 +- osdep/OSXEthernetTap.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'osdep') diff --git a/osdep/ManagedRoute.cpp b/osdep/ManagedRoute.cpp index 88fd944a..ae2f8943 100644 --- a/osdep/ManagedRoute.cpp +++ b/osdep/ManagedRoute.cpp @@ -415,7 +415,7 @@ bool ManagedRoute::sync() // Shadow system route if it exists, also delete any obsolete shadows // and replace them with the new state. sync() is called periodically to // allow us to do that if underlying connectivity changes. - if ( ((_systemVia != newSystemVia)||(!strcmp(_systemDevice,newSystemDevice))) && (strcmp(_device,newSystemDevice)) ) { + if ( ((_systemVia != newSystemVia)||(strcmp(_systemDevice,newSystemDevice))) && (strcmp(_device,newSystemDevice)) ) { if ((_systemVia)&&(_systemDevice[0])) { _routeCmd("delete",leftt,_systemVia,_systemDevice,(const char *)0); _routeCmd("delete",rightt,_systemVia,_systemDevice,(const char *)0); diff --git a/osdep/OSXEthernetTap.cpp b/osdep/OSXEthernetTap.cpp index e8c5c1ea..56934c96 100644 --- a/osdep/OSXEthernetTap.cpp +++ b/osdep/OSXEthernetTap.cpp @@ -474,7 +474,7 @@ bool OSXEthernetTap::addIp(const InetAddress &ip) long cpid = (long)vfork(); if (cpid == 0) { - ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.isV4() ? "inet" : "inet6",ip.toString().c_str(),"alias",(const char *)0); + ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),(ip.ss_family == AF_INET6) ? "inet6" : "inet",ip.toString().c_str(),"alias",(const char *)0); ::_exit(-1); } else if (cpid > 0) { int exitcode = -1; @@ -494,7 +494,7 @@ bool OSXEthernetTap::removeIp(const InetAddress &ip) if (*i == ip) { long cpid = (long)vfork(); if (cpid == 0) { - execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0); + execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),(ip.ss_family == AF_INET6) ? "inet6" : "inet",ip.toIpString().c_str(),"-alias",(const char *)0); _exit(-1); } else if (cpid > 0) { int exitcode = -1; -- cgit v1.2.3