瀏覽代碼

Linux bug fixes, small controller fix.

Adam Ierymenko 9 年之前
父節點
當前提交
37afa876a7
共有 6 個文件被更改,包括 22 次插入19 次删除
  1. 7 5
      controller/SqliteNetworkController.cpp
  2. 1 1
      make-linux.mk
  3. 3 5
      node/NetworkConfig.cpp
  4. 7 6
      osdep/LinuxEthernetTap.cpp
  5. 3 1
      osdep/ManagedRoute.hpp
  6. 1 1
      osdep/Phy.hpp

+ 7 - 5
controller/SqliteNetworkController.cpp

@@ -1769,13 +1769,15 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
 		std::sort(allowedEtherTypes.begin(),allowedEtherTypes.end());
 		std::sort(allowedEtherTypes.begin(),allowedEtherTypes.end());
 		allowedEtherTypes.erase(std::unique(allowedEtherTypes.begin(),allowedEtherTypes.end()),allowedEtherTypes.end());
 		allowedEtherTypes.erase(std::unique(allowedEtherTypes.begin(),allowedEtherTypes.end()),allowedEtherTypes.end());
 
 
-		for(long i=0,k=0;((i<(long)allowedEtherTypes.size())&&(k<ZT_MAX_NETWORK_RULES));++i) {
+		for(long i=0;i<(long)allowedEtherTypes.size();++i) {
+			if ((nc.ruleCount + 2) > ZT_MAX_NETWORK_RULES)
+				break;
 			if (allowedEtherTypes[i] > 0) {
 			if (allowedEtherTypes[i] > 0) {
-				nc.rules[k].t = ZT_NETWORK_RULE_MATCH_ETHERTYPE;
-				nc.rules[k].v.etherType = (uint16_t)allowedEtherTypes[i];
-				++k;
+				nc.rules[nc.ruleCount].t = ZT_NETWORK_RULE_MATCH_ETHERTYPE;
+				nc.rules[nc.ruleCount].v.etherType = (uint16_t)allowedEtherTypes[i];
+				++nc.ruleCount;
 			}
 			}
-			nc.rules[k++].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
+			nc.rules[nc.ruleCount++].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
 		}
 		}
 
 
 		/*
 		/*

+ 1 - 1
make-linux.mk

@@ -107,7 +107,7 @@ else
 	CFLAGS?=-O3 -fstack-protector-strong
 	CFLAGS?=-O3 -fstack-protector-strong
 	CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
 	CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
 	CXXFLAGS?=-O3 -fstack-protector-strong
 	CXXFLAGS?=-O3 -fstack-protector-strong
-	CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
+	CXXFLAGS+=-Wall -Wno-unused-result -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
 	LDFLAGS=-pie -Wl,-z,relro,-z,now
 	LDFLAGS=-pie -Wl,-z,relro,-z,now
 	STRIP?=strip
 	STRIP?=strip
 	STRIP+=--strip-all
 	STRIP+=--strip-all

+ 3 - 5
node/NetworkConfig.cpp

@@ -476,11 +476,9 @@ bool NetworkConfig::fromDictionary(const Dictionary &d)
 			}
 			}
 		}
 		}
 
 
-		/*
-		printf("~~~\n%s\n~~~\n",d.data());
-		dump();
-		printf("~~~\n");
-		*/
+		//printf("~~~\n%s\n~~~\n",d.data());
+		//dump();
+		//printf("~~~\n");
 
 
 		return true;
 		return true;
 	} catch ( ... ) {
 	} catch ( ... ) {

+ 7 - 6
osdep/LinuxEthernetTap.cpp

@@ -97,10 +97,10 @@ LinuxEthernetTap::LinuxEthernetTap(
 	std::string devmapbuf;
 	std::string devmapbuf;
 	Dictionary devmap;
 	Dictionary devmap;
 	if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
 	if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
-		devmap.fromString(devmapbuf);
-		std::string desiredDevice(devmap.get(nwids,""));
-		if (desiredDevice.length() > 2) {
-			Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),desiredDevice.c_str());
+		devmap.load(devmapbuf.c_str());
+		char desiredDevice[128];
+		if (devmap.get(nwids,desiredDevice,sizeof(desiredDevice)) > 0) {
+			Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),desiredDevice);
 			Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
 			Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
 			recalledDevice = (stat(procpath,&sbuf) != 0);
 			recalledDevice = (stat(procpath,&sbuf) != 0);
 		}
 		}
@@ -174,8 +174,9 @@ LinuxEthernetTap::LinuxEthernetTap(
 
 
 	(void)::pipe(_shutdownSignalPipe);
 	(void)::pipe(_shutdownSignalPipe);
 
 
-	devmap[nwids] = _dev;
-	OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
+	devmap.erase(nwids);
+	devmap.add(nwids,_dev.c_str());
+	OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),(const void *)devmap.data(),devmap.sizeBytes());
 
 
 	_thread = Thread::start(this);
 	_thread = Thread::start(this);
 }
 }

+ 3 - 1
osdep/ManagedRoute.hpp

@@ -32,6 +32,7 @@ public:
 
 
 	ManagedRoute(const ManagedRoute &r)
 	ManagedRoute(const ManagedRoute &r)
 	{
 	{
+		_applied = false;
 		*this = r;
 		*this = r;
 	}
 	}
 
 
@@ -40,7 +41,8 @@ public:
 		if ((!_applied)&&(!r._applied)) {
 		if ((!_applied)&&(!r._applied)) {
 			memcpy(this,&r,sizeof(ManagedRoute)); // InetAddress is memcpy'able
 			memcpy(this,&r,sizeof(ManagedRoute)); // InetAddress is memcpy'able
 		} else {
 		} else {
-			throw std::runtime_error("Applied ManagedRoute is non-copyable!");
+			fprintf(stderr,"Applied ManagedRoute isn't copyable!\n");
+			abort();
 		}
 		}
 		return *this;
 		return *this;
 	}
 	}

+ 1 - 1
osdep/Phy.hpp

@@ -871,7 +871,7 @@ public:
 #if defined(_WIN32) || defined(_WIN64)
 #if defined(_WIN32) || defined(_WIN64)
 			::recv(_whackReceiveSocket,tmp,16,0);
 			::recv(_whackReceiveSocket,tmp,16,0);
 #else
 #else
-			(void)(::read(_whackReceiveSocket,tmp,16));
+			::read(_whackReceiveSocket,tmp,16);
 #endif
 #endif
 		}
 		}