mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-19 03:06:26 +00:00
Yank RuntimeEnvironment from SysEnv.
This commit is contained in:
parent
d6a346ca6e
commit
4e85213473
@ -447,7 +447,7 @@ Node::ReasonForTermination Node::run()
|
|||||||
_r->sw = new Switch(_r);
|
_r->sw = new Switch(_r);
|
||||||
_r->demarc = new Demarc(_r);
|
_r->demarc = new Demarc(_r);
|
||||||
_r->topology = new Topology(_r,Utils::fileExists((_r->homePath + ZT_PATH_SEPARATOR_S + "iddb.d").c_str()));
|
_r->topology = new Topology(_r,Utils::fileExists((_r->homePath + ZT_PATH_SEPARATOR_S + "iddb.d").c_str()));
|
||||||
_r->sysEnv = new SysEnv(_r);
|
_r->sysEnv = new SysEnv();
|
||||||
try {
|
try {
|
||||||
_r->nc = new NodeConfig(_r,configAuthToken.c_str(),impl->controlPort);
|
_r->nc = new NodeConfig(_r,configAuthToken.c_str(),impl->controlPort);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
@ -513,7 +513,7 @@ Node::ReasonForTermination Node::run()
|
|||||||
uint64_t lastPingCheck = 0;
|
uint64_t lastPingCheck = 0;
|
||||||
uint64_t lastClean = Utils::now(); // don't need to do this immediately
|
uint64_t lastClean = Utils::now(); // don't need to do this immediately
|
||||||
uint64_t lastNetworkFingerprintCheck = 0;
|
uint64_t lastNetworkFingerprintCheck = 0;
|
||||||
uint64_t networkConfigurationFingerprint = _r->sysEnv->getNetworkConfigurationFingerprint();
|
uint64_t networkConfigurationFingerprint = _r->sysEnv->getNetworkConfigurationFingerprint(_r->nc->networkTapDeviceNames());
|
||||||
uint64_t lastMulticastCheck = 0;
|
uint64_t lastMulticastCheck = 0;
|
||||||
long lastDelayDelta = 0;
|
long lastDelayDelta = 0;
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ Node::ReasonForTermination Node::run()
|
|||||||
// If our network environment looks like it changed, also set resynchronize flag.
|
// If our network environment looks like it changed, also set resynchronize flag.
|
||||||
if ((resynchronize)||((now - lastNetworkFingerprintCheck) >= ZT_NETWORK_FINGERPRINT_CHECK_DELAY)) {
|
if ((resynchronize)||((now - lastNetworkFingerprintCheck) >= ZT_NETWORK_FINGERPRINT_CHECK_DELAY)) {
|
||||||
lastNetworkFingerprintCheck = now;
|
lastNetworkFingerprintCheck = now;
|
||||||
uint64_t fp = _r->sysEnv->getNetworkConfigurationFingerprint();
|
uint64_t fp = _r->sysEnv->getNetworkConfigurationFingerprint(_r->nc->networkTapDeviceNames());
|
||||||
if (fp != networkConfigurationFingerprint) {
|
if (fp != networkConfigurationFingerprint) {
|
||||||
LOG("netconf fingerprint change: %.16llx != %.16llx, resyncing with network",networkConfigurationFingerprint,fp);
|
LOG("netconf fingerprint change: %.16llx != %.16llx, resyncing with network",networkConfigurationFingerprint,fp);
|
||||||
networkConfigurationFingerprint = fp;
|
networkConfigurationFingerprint = fp;
|
||||||
|
@ -62,8 +62,7 @@
|
|||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
SysEnv::SysEnv(const RuntimeEnvironment *renv) :
|
SysEnv::SysEnv()
|
||||||
_r(renv)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +72,7 @@ SysEnv::~SysEnv()
|
|||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
uint64_t SysEnv::getNetworkConfigurationFingerprint(const std::set<std::string> &ignoreDevices)
|
||||||
{
|
{
|
||||||
int mib[6];
|
int mib[6];
|
||||||
size_t needed;
|
size_t needed;
|
||||||
@ -82,7 +81,8 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||||||
// Right now this just scans for changes in default routes. This is not
|
// Right now this just scans for changes in default routes. This is not
|
||||||
// totally robust -- it will miss cases where we switch from one 10.0.0.0/24
|
// totally robust -- it will miss cases where we switch from one 10.0.0.0/24
|
||||||
// network with gateway .1 to another -- but most of the time it'll pick
|
// network with gateway .1 to another -- but most of the time it'll pick
|
||||||
// up shifts in connectivity.
|
// up shifts in connectivity. Combined with sleep/wake detection this seems
|
||||||
|
// pretty solid so far on Mac for detecting when you change locations.
|
||||||
|
|
||||||
mib[0] = CTL_NET;
|
mib[0] = CTL_NET;
|
||||||
mib[1] = PF_ROUTE;
|
mib[1] = PF_ROUTE;
|
||||||
@ -139,15 +139,13 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||||||
|
|
||||||
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
|
||||||
|
|
||||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
uint64_t SysEnv::getNetworkConfigurationFingerprint(const std::set<std::string> &ignoreDevices)
|
||||||
{
|
{
|
||||||
char buf[16384];
|
char buf[16384];
|
||||||
uint64_t fingerprint = 5381; // djb2 hash algorithm is used below
|
uint64_t fingerprint = 5381; // djb2 hash algorithm is used below
|
||||||
char *t1,*t2;
|
char *t1,*t2;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::set<std::string> tapDevs(_r->nc->networkTapDeviceNames());
|
|
||||||
|
|
||||||
// Include default IPv4 route if available
|
// Include default IPv4 route if available
|
||||||
int fd = open("/proc/net/route",O_RDONLY);
|
int fd = open("/proc/net/route",O_RDONLY);
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
@ -159,7 +157,7 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||||||
int fno = 0;
|
int fno = 0;
|
||||||
for(char *field=strtok_r(line," \t",&t2);(field);field=strtok_r((char *)0," \t",&t2)) {
|
for(char *field=strtok_r(line," \t",&t2);(field);field=strtok_r((char *)0," \t",&t2)) {
|
||||||
if (fno == 0) { // device name
|
if (fno == 0) { // device name
|
||||||
if ((tapDevs.count(std::string(field)))||(!strcmp(field,"lo")))
|
if ((ignoreDevices.count(std::string(field)))||(!strcmp(field,"lo")))
|
||||||
break;
|
break;
|
||||||
} else if ((fno == 1)||(fno == 2)) { // destination, gateway
|
} else if ((fno == 1)||(fno == 2)) { // destination, gateway
|
||||||
if (strlen(field) == 8) { // ignore header junk, use only hex route info
|
if (strlen(field) == 8) { // ignore header junk, use only hex route info
|
||||||
@ -198,7 +196,7 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((v6ip)&&(devname)) {
|
if ((v6ip)&&(devname)) {
|
||||||
if ((!(tapDevs.count(std::string(devname))))&&(strcmp(devname,"lo"))) {
|
if ((!(ignoreDevices.count(std::string(devname))))&&(strcmp(devname,"lo"))) {
|
||||||
while (*v6ip)
|
while (*v6ip)
|
||||||
fingerprint = ((fingerprint << 5) + fingerprint) + (uint64_t)*(v6ip++);
|
fingerprint = ((fingerprint << 5) + fingerprint) + (uint64_t)*(v6ip++);
|
||||||
}
|
}
|
||||||
@ -215,7 +213,7 @@ uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
|||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
uint64_t SysEnv::getNetworkConfigurationFingerprint()
|
uint64_t SysEnv::getNetworkConfigurationFingerprint(const std::set<std::string> &ignoreDevices)
|
||||||
{
|
{
|
||||||
// TODO: windows version
|
// TODO: windows version
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include "NonCopyable.hpp"
|
#include "NonCopyable.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
@ -42,16 +44,16 @@ class RuntimeEnvironment;
|
|||||||
class SysEnv : NonCopyable
|
class SysEnv : NonCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SysEnv(const RuntimeEnvironment *renv);
|
SysEnv();
|
||||||
~SysEnv();
|
~SysEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This computes a CRC-type code from gathered information about your network settings
|
||||||
|
*
|
||||||
|
* @param ignoreDevices Ignore these local network devices by OS-specific name (e.g. our taps)
|
||||||
* @return Fingerprint of currently running network environment
|
* @return Fingerprint of currently running network environment
|
||||||
*/
|
*/
|
||||||
uint64_t getNetworkConfigurationFingerprint();
|
uint64_t getNetworkConfigurationFingerprint(const std::set<std::string> &ignoreDevices);
|
||||||
|
|
||||||
private:
|
|
||||||
const RuntimeEnvironment *_r;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
Loading…
Reference in New Issue
Block a user