Compare commits

...
Author SHA1 Message Date
travisladuke 164a33a24f some temporary code to make sure it works 2025-07-11 11:29:56 -07:00
travisladuke d271b270fc Add macOs defaultRoute function 2025-07-11 10:15:31 -07:00
3 changed files with 60 additions and 8 deletions

No files matched your search

+10 -8
View File
@@ -8,14 +8,16 @@
namespace ZeroTier {
class MacDNSHelper {
public:
static void setDNS(uint64_t nwid, const char* domain, const std::vector<InetAddress>& servers);
static void removeDNS(uint64_t nwid);
static bool addIps4(uint64_t nwid, const MAC mac, const char* dev, const std::vector<InetAddress>& addrs);
static bool addIps6(uint64_t nwid, const MAC mac, const char* dev, const std::vector<InetAddress>& addrs);
static bool removeIps4(uint64_t nwid);
static bool removeIps6(uint64_t nwid);
class MacDNSHelper
{
public:
static void setDNS(uint64_t nwid, const char *domain, const std::vector<InetAddress> &servers);
static void removeDNS(uint64_t nwid);
static bool addIps4(uint64_t nwid, const MAC mac, const char *dev, const std::vector<InetAddress> &addrs);
static bool addIps6(uint64_t nwid, const MAC mac, const char *dev, const std::vector<InetAddress> &addrs);
static bool removeIps4(uint64_t nwid);
static bool removeIps6(uint64_t nwid);
static bool getDefaultRoute(char *buf);
};
} // namespace ZeroTier
+35
View File
@@ -343,5 +343,40 @@ bool MacDNSHelper::removeIps4(uint64_t nwid)
return res;
}
bool MacDNSHelper::getDefaultRoute(char *buf) {
SCDynamicStoreRef ds = SCDynamicStoreCreate(NULL, CFSTR("ZeroTierOne"), NULL, NULL);
CFPropertyListRef propertyList = SCDynamicStoreCopyValue(ds, CFSTR("State:/Network/Global/IPv4"));
if (!propertyList && CFGetTypeID(propertyList) != CFDictionaryGetTypeID()) {
if (propertyList != NULL) {CFRelease(propertyList);}
CFRelease(ds);
return false;
}
CFDictionaryRef dict = (CFDictionaryRef)propertyList;
CFTypeRef routerObject = CFDictionaryGetValue(dict, CFSTR("Router"));
if (!routerObject && CFGetTypeID(routerObject) != CFStringGetTypeID()) {
if (propertyList != NULL) {CFRelease(propertyList);}
CFRelease(ds);
return false;
}
CFStringRef router = (CFStringRef)routerObject;
CFIndex length = CFStringGetLength(router);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
CFStringGetCString(router, buf, maxSize, kCFStringEncodingUTF8);
if (propertyList != NULL) {CFRelease(propertyList);}
CFRelease(ds);
return true;
}
}
+15
View File
@@ -873,6 +873,8 @@ class OneServiceImpl : public OneService {
// Last potential sleep/wake event
uint64_t _lastRestart;
char _lastDefaultGateway[255] = {};
bool gatewayChanged = false;
// Deadline for the next background task service function
volatile int64_t _nextBackgroundTaskDeadline;
@@ -1286,6 +1288,19 @@ class OneServiceImpl : public OneService {
syncManagedStuff(n->second, false, true, false);
}
}
#ifdef __APPLE__
char buf[255];
MacDNSHelper::getDefaultRoute(buf);
if (strlen(_lastDefaultGateway) != 0 && strcmp(_lastDefaultGateway, buf) != 0) {
gatewayChanged = true;
// fprintf(stderr, "gw changed %i\n prev %s new %s", gatewayChanged, _lastDefaultGateway, buf);
// TODO do something to send full hello to roots here
} else {
gatewayChanged = false;
}
strcpy(_lastDefaultGateway, buf);
#endif
}
// Run background task processor in core if it's time to do so