Forráskód Böngészése

fix memory init issue

and another place where dns data needs to be copied
Grant Limberg 5 éve
szülő
commit
d098a99d09

+ 1 - 0
.gitignore

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

+ 1 - 0
node/DNS.hpp

@@ -43,6 +43,7 @@ public:
     template<unsigned int C>
     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) {
             char *d = (char*)b.data()+p;
             memcpy(dns[i].domain, d, 128);

+ 6 - 0
node/Network.cpp

@@ -586,6 +586,7 @@ Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *u
 
 	if (!_portInitialized) {
 		ZT_VirtualNetworkConfig ctmp;
+		memset(&ctmp, 0, sizeof(ZT_VirtualNetworkConfig));
 		_externalConfig(&ctmp);
 		_portError = RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
 		_portInitialized = true;
@@ -1426,6 +1427,11 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
 		ec->multicastSubscriptions[i].mac = _myMulticastGroups[i].mac().toInt();
 		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)

+ 1 - 0
osdep/EthernetTap.hpp

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

+ 5 - 0
osdep/MacEthernetTap.cpp

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

+ 1 - 0
osdep/MacEthernetTap.hpp

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

+ 5 - 0
osdep/MacKextEthernetTap.cpp

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

+ 2 - 0
osdep/MacKextEthernetTap.hpp

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

+ 25 - 4
service/OneService.cpp

@@ -501,6 +501,7 @@ public:
 			settings.allowManaged = true;
 			settings.allowGlobal = false;
 			settings.allowDefault = false;
+			memset(&config, 0, sizeof(ZT_VirtualNetworkConfig));
 		}
 
 		std::shared_ptr<EthernetTap> tap;
@@ -831,7 +832,7 @@ public:
 						Mutex::Lock _l(_nets_m);
 						for(std::map<uint64_t,NetworkState>::iterator n(_nets.begin());n!=_nets.end();++n) {
 							if (n->second.tap)
-								syncManagedStuff(n->second,false,true);
+								syncManagedStuff(n->second,false,true,false);
 						}
 					}
 				}
@@ -1117,7 +1118,7 @@ public:
 		}
 
 		if (n->second.tap)
-			syncManagedStuff(n->second,true,true);
+			syncManagedStuff(n->second,true,true,true);
 
 		return true;
 	}
@@ -1864,7 +1865,7 @@ public:
 	}
 
 	// 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];
 
@@ -1984,6 +1985,26 @@ public:
 #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);
 					}
 #endif
-					syncManagedStuff(n,true,true);
+					syncManagedStuff(n,true,true,true);
 					n.tap->setMtu(nwc->mtu);
 				} else {
 					_nets.erase(nwid);