浏览代码

Some tap interface changes and integration into main.cpp for *nix systems.

Adam Ierymenko 11 年之前
父节点
当前提交
92d9ad4a7f
共有 4 个文件被更改,包括 55 次插入3 次删除
  1. 34 3
      main.cpp
  2. 15 0
      node/EthernetTap.hpp
  3. 5 0
      osnet/WindowsEthernetTap.cpp
  4. 1 0
      osnet/WindowsEthernetTap.hpp

+ 34 - 3
main.cpp

@@ -56,6 +56,7 @@
 #endif
 
 #include "node/Constants.hpp"
+
 #include "node/Defaults.hpp"
 #include "node/Utils.hpp"
 #include "node/Node.hpp"
@@ -63,6 +64,33 @@
 #include "node/Identity.hpp"
 #include "node/Thread.hpp"
 #include "node/CertificateOfMembership.hpp"
+#include "node/EthernetTapFactory.hpp"
+#include "node/RoutingTable.hpp"
+
+#ifdef __WINDOWS__
+#include "osnet/WindowsEthernetTapFactory.hpp"
+#include "osnet/WindowsRoutingTable.hpp"
+#define ZTCreatePlatformEthernetTapFactory (new WindowsEthernetTapFactory(homeDir))
+#define ZTCreatePlatformRoutingTable (new WindowsRoutingTable())
+#endif
+
+#ifdef __LINUX__
+#include "osnet/LinuxEthernetTapFactory.hpp"
+#include "osnet/LinuxRoutingTable.hpp"
+#define ZTCreatePlatformEthernetTapFactory (new LinuxEthernetTapFactory())
+#define ZTCreatePlatformRoutingTable (new LinuxRoutingTable())
+#endif
+
+#ifdef __APPLE__
+#include "osnet/OSXEthernetTapFactory.hpp"
+#include "osnet/BSDRoutingTable.hpp"
+#define ZTCreatePlatformEthernetTapFactory (new OSXEthernetTapFactory(homeDir,"tap.kext"))
+#define ZTCreatePlatformRoutingTable (new BSDRoutingTable())
+#endif
+
+#ifndef ZTCreatePlatformEthernetTapFactory
+#error Sorry, this platform has no osnet/ implementation yet. Fork me on GitHub and add one?
+#endif
 
 using namespace ZeroTier;
 
@@ -649,7 +677,7 @@ int main(int argc,char **argv)
 			fclose(pf);
 		}
 	}
-#endif
+#endif // __UNIX_LIKE__
 
 #ifdef __WINDOWS__
 	if (winRunFromCommandLine) {
@@ -670,12 +698,15 @@ int main(int argc,char **argv)
 			return 1;
 		}
 	}
-#endif
+#endif // __WINDOWS__
 
 	int exitCode = 0;
 	bool needsReset = false;
 	try {
-		node = new Node(homeDir,udpPort,tcpPort,needsReset);
+		EthernetTapFactory *tapFactory = ZTCreatePlatformEthernetTapFactory;
+		RoutingTable *routingTable = ZTCreatePlatformRoutingTable;
+
+		node = new Node(homeDir,tapFactory,routingTable,udpPort,tcpPort,needsReset);
 		switch(node->run()) {
 #ifdef __WINDOWS__
 			case Node::NODE_RESTART_FOR_UPGRADE: {

+ 15 - 0
node/EthernetTap.hpp

@@ -196,6 +196,21 @@ public:
 	 */
 	virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups) = 0;
 
+	/**
+	 * Should this tap device get a pseudo-default-route?
+	 *
+	 * Some platforms (cough Windows) want all "real" network devices to have a
+	 * routing table entry for default, even if it's got a high metric and is
+	 * never used and goes nowhere. If this returns true, the underlying node
+	 * code will use RoutingTable to create one if no default route is
+	 * otherwise defined.
+	 *
+	 * Base class default returns false. Override to return true if needed.
+	 *
+	 * @return True if pseudo-default-route should always exist
+	 */
+	virtual bool createPseudoDefaultRoute() const { return false; }
+
 protected:
 	const char *_implName;
 	MAC _mac;

+ 5 - 0
osnet/WindowsEthernetTap.cpp

@@ -516,6 +516,11 @@ bool WindowsEthernetTap::updateMulticastGroups(std::set<MulticastGroup> &groups)
 	return changed;
 }
 
+bool WindowsEthernetTap::createPseudoDefaultRoute() const
+{
+	return true;
+}
+
 void WindowsEthernetTap::threadMain()
 	throw()
 {

+ 1 - 0
osnet/WindowsEthernetTap.hpp

@@ -71,6 +71,7 @@ public:
 	virtual std::string deviceName() const;
 	virtual void setFriendlyName(const char *friendlyName);
 	virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
+	virtual bool createPseudoDefaultRoute() const;
 
 	inline const NET_LUID &luid() const { return _deviceLuid; }
 	inline const GUID &guid() const { return _deviceGuid; }