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

This commit is contained in:
Adam Ierymenko 2014-08-06 16:24:30 -07:00
parent 8a804b5257
commit 92d9ad4a7f
4 changed files with 55 additions and 3 deletions

View File

@ -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: {

View File

@ -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;

View File

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

View File

@ -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; }