fix memory init issue

and another place where dns data needs to be copied
This commit is contained in:
Grant Limberg 2020-07-31 11:42:03 -07:00
parent 6b197e067a
commit d098a99d09
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A
9 changed files with 47 additions and 4 deletions

1
.gitignore vendored
View File

@ -121,3 +121,4 @@ __pycache__
attic/world/*.c25519 attic/world/*.c25519
attic/world/mkworld attic/world/mkworld
workspace/ workspace/
workspace2/

View File

@ -43,6 +43,7 @@ public:
template<unsigned int C> template<unsigned int C>
static inline void deserializeDNS(const Buffer<C> &b, unsigned int &p, ZT_VirtualNetworkDNS *dns, const unsigned int dnsCount) static inline void deserializeDNS(const Buffer<C> &b, unsigned int &p, ZT_VirtualNetworkDNS *dns, const unsigned int dnsCount)
{ {
memset(dns, 0, sizeof(ZT_VirtualNetworkDNS)*ZT_MAX_NETWORK_DNS);
for(unsigned int i = 0; i < dnsCount; ++i) { for(unsigned int i = 0; i < dnsCount; ++i) {
char *d = (char*)b.data()+p; char *d = (char*)b.data()+p;
memcpy(dns[i].domain, d, 128); memcpy(dns[i].domain, d, 128);

View File

@ -586,6 +586,7 @@ Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *u
if (!_portInitialized) { if (!_portInitialized) {
ZT_VirtualNetworkConfig ctmp; ZT_VirtualNetworkConfig ctmp;
memset(&ctmp, 0, sizeof(ZT_VirtualNetworkConfig));
_externalConfig(&ctmp); _externalConfig(&ctmp);
_portError = RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp); _portError = RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
_portInitialized = true; _portInitialized = true;
@ -1426,6 +1427,11 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
ec->multicastSubscriptions[i].mac = _myMulticastGroups[i].mac().toInt(); ec->multicastSubscriptions[i].mac = _myMulticastGroups[i].mac().toInt();
ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi(); ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi();
} }
ec->dnsCount = _config.dnsCount;
if (ec->dnsCount > 0) {
memcpy(&ec->dns, &_config.dns, sizeof(ZT_VirtualNetworkDNS));
}
} }
void Network::_sendUpdatesToMembers(void *tPtr,const MulticastGroup *const newMulticastGroup) void Network::_sendUpdatesToMembers(void *tPtr,const MulticastGroup *const newMulticastGroup)

View File

@ -53,6 +53,7 @@ public:
virtual void setFriendlyName(const char *friendlyName) = 0; virtual void setFriendlyName(const char *friendlyName) = 0;
virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed) = 0; virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed) = 0;
virtual void setMtu(unsigned int mtu) = 0; virtual void setMtu(unsigned int mtu) = 0;
virtual void setDns(const char *domain, const std::vector<InetAddress> &servers) = 0;
}; };
} // namespace ZeroTier } // namespace ZeroTier

View File

@ -452,6 +452,11 @@ void MacEthernetTap::threadMain()
} }
} }
void MacEthernetTap::setDns(const char *domain, const std::vector<InetAddress> &servers)
{
}
} // namespace ZeroTier } // namespace ZeroTier
#endif // __APPLE__ #endif // __APPLE__

View File

@ -56,6 +56,7 @@ public:
virtual void setFriendlyName(const char *friendlyName); virtual void setFriendlyName(const char *friendlyName);
virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed); virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
virtual void setMtu(unsigned int mtu); virtual void setMtu(unsigned int mtu);
virtual void setDns(const char *domain, const std::vector<InetAddress> &servers);
void threadMain() void threadMain()
throw(); throw();

View File

@ -687,4 +687,9 @@ void MacKextEthernetTap::threadMain()
} }
} }
void MacKextEthernetTap::setDns(const char *domain, const std::vector<InetAddress> &servers)
{
}
} // namespace ZeroTier } // namespace ZeroTier

View File

@ -56,6 +56,8 @@ public:
virtual void setFriendlyName(const char *friendlyName); virtual void setFriendlyName(const char *friendlyName);
virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed); virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
virtual void setMtu(unsigned int mtu); virtual void setMtu(unsigned int mtu);
virtual void setDns(const char *domain, const std::vector<InetAddress> &servers);
void threadMain() void threadMain()
throw(); throw();

View File

@ -501,6 +501,7 @@ public:
settings.allowManaged = true; settings.allowManaged = true;
settings.allowGlobal = false; settings.allowGlobal = false;
settings.allowDefault = false; settings.allowDefault = false;
memset(&config, 0, sizeof(ZT_VirtualNetworkConfig));
} }
std::shared_ptr<EthernetTap> tap; std::shared_ptr<EthernetTap> tap;
@ -831,7 +832,7 @@ public:
Mutex::Lock _l(_nets_m); Mutex::Lock _l(_nets_m);
for(std::map<uint64_t,NetworkState>::iterator n(_nets.begin());n!=_nets.end();++n) { for(std::map<uint64_t,NetworkState>::iterator n(_nets.begin());n!=_nets.end();++n) {
if (n->second.tap) if (n->second.tap)
syncManagedStuff(n->second,false,true); syncManagedStuff(n->second,false,true,false);
} }
} }
} }
@ -1117,7 +1118,7 @@ public:
} }
if (n->second.tap) if (n->second.tap)
syncManagedStuff(n->second,true,true); syncManagedStuff(n->second,true,true,true);
return true; return true;
} }
@ -1864,7 +1865,7 @@ public:
} }
// Apply or update managed IPs for a configured network (be sure n.tap exists) // Apply or update managed IPs for a configured network (be sure n.tap exists)
void syncManagedStuff(NetworkState &n,bool syncIps,bool syncRoutes) void syncManagedStuff(NetworkState &n,bool syncIps,bool syncRoutes, bool syncDns)
{ {
char ipbuf[64]; char ipbuf[64];
@ -1984,6 +1985,26 @@ public:
#endif #endif
} }
} }
if (syncDns) {
char buf[128];
if (n.config.dnsCount > ZT_MAX_NETWORK_DNS) {
fprintf(stderr, "ERROR: %d records > max %d. Skipping DNS\n", n.config.dnsCount, ZT_MAX_NETWORK_DNS);
return;
}
fprintf(stderr, "Syncing %d DNS configurations\n", n.config.dnsCount);
for (int i = 0; i < n.config.dnsCount; ++i) {
if (strlen(n.config.dns[i].domain) != 0) {
fprintf(stderr, "Syncing DNS for domain: %s\n", n.config.dns[i].domain);
for (int j = 0; j < ZT_MAX_DNS_SERVERS; ++j) {
InetAddress a(n.config.dns[i].server_addr[j]);
if (a.isV4() || a.isV6()) {
fprintf(stderr, "\t Server %d: %s\n", j+1, a.toIpString(buf));
}
}
}
}
}
} }
// ========================================================================= // =========================================================================
@ -2333,7 +2354,7 @@ public:
Sleep(10); Sleep(10);
} }
#endif #endif
syncManagedStuff(n,true,true); syncManagedStuff(n,true,true,true);
n.tap->setMtu(nwc->mtu); n.tap->setMtu(nwc->mtu);
} else { } else {
_nets.erase(nwid); _nets.erase(nwid);