mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2026-09-22 15:29:03 -07:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
164a33a24f | ||
|
|
d271b270fc |
No files matched your search
+10
-8
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user