mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-02 19:26:41 +00:00
More work on adding testnet and user-mode capabilities for local network simulation.
This commit is contained in:
parent
2a58c3fb98
commit
67aa23530b
33
main.cpp
33
main.cpp
@ -75,6 +75,9 @@
|
|||||||
#include "control/NodeControlClient.hpp"
|
#include "control/NodeControlClient.hpp"
|
||||||
#include "control/NodeControlService.hpp"
|
#include "control/NodeControlService.hpp"
|
||||||
|
|
||||||
|
#include "testnet/TestEthernetTapFactory.hpp"
|
||||||
|
#include "testnet/TestRoutingTable.hpp"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
#include "osnet/WindowsEthernetTapFactory.hpp"
|
#include "osnet/WindowsEthernetTapFactory.hpp"
|
||||||
#include "osnet/WindowsRoutingTable.hpp"
|
#include "osnet/WindowsRoutingTable.hpp"
|
||||||
@ -564,6 +567,8 @@ static void printHelp(const char *cn,FILE *out)
|
|||||||
fprintf(out," -v - Show version"ZT_EOL_S);
|
fprintf(out," -v - Show version"ZT_EOL_S);
|
||||||
fprintf(out," -p<port> - Port for UDP (default: 9993)"ZT_EOL_S);
|
fprintf(out," -p<port> - Port for UDP (default: 9993)"ZT_EOL_S);
|
||||||
fprintf(out," -t<port> - Port for TCP (default: disabled)"ZT_EOL_S);
|
fprintf(out," -t<port> - Port for TCP (default: disabled)"ZT_EOL_S);
|
||||||
|
fprintf(out," -T<path> - Override root topology, do not authenticate or update"ZT_EOL_S);
|
||||||
|
fprintf(out," -u - Do not require root, use dummy tap device"ZT_EOL_S);
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S);
|
fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S);
|
||||||
#endif
|
#endif
|
||||||
@ -619,6 +624,8 @@ int main(int argc,char **argv)
|
|||||||
unsigned int udpPort = ZT_DEFAULT_UDP_PORT;
|
unsigned int udpPort = ZT_DEFAULT_UDP_PORT;
|
||||||
unsigned int tcpPort = 0;
|
unsigned int tcpPort = 0;
|
||||||
|
|
||||||
|
std::string overrideRootTopology;
|
||||||
|
bool userMode = false;
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
bool runAsDaemon = false;
|
bool runAsDaemon = false;
|
||||||
#endif
|
#endif
|
||||||
@ -652,6 +659,20 @@ int main(int argc,char **argv)
|
|||||||
runAsDaemon = true;
|
runAsDaemon = true;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case 'T':
|
||||||
|
if (argv[i][2]) {
|
||||||
|
if (!Utils::readFile(argv[i] + 2,overrideRootTopology)) {
|
||||||
|
fprintf(stderr,"%s: cannot read root topology from %s"ZT_EOL_S,argv[0],argv[i] + 2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printHelp(argv[0],stdout);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
userMode = true;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("%s"ZT_EOL_S,Node::versionString());
|
printf("%s"ZT_EOL_S,Node::versionString());
|
||||||
return 0;
|
return 0;
|
||||||
@ -728,7 +749,7 @@ int main(int argc,char **argv)
|
|||||||
homeDir = ZT_DEFAULTS.defaultHomePath.c_str();
|
homeDir = ZT_DEFAULTS.defaultHomePath.c_str();
|
||||||
|
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
if (getuid() != 0) {
|
if ((!userMode)&&(getuid() != 0)) {
|
||||||
fprintf(stderr,"%s: must be run as root (uid 0)\n",argv[0]);
|
fprintf(stderr,"%s: must be run as root (uid 0)\n",argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -758,17 +779,18 @@ int main(int argc,char **argv)
|
|||||||
#endif // __UNIX_LIKE__
|
#endif // __UNIX_LIKE__
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
_winPokeAHole();
|
|
||||||
if (winRunFromCommandLine) {
|
if (winRunFromCommandLine) {
|
||||||
// Running in "interactive" mode (mostly for debugging)
|
// Running in "interactive" mode (mostly for debugging)
|
||||||
if (IsCurrentUserLocalAdministrator() != TRUE) {
|
if ((!userMode)&&(IsCurrentUserLocalAdministrator() != TRUE)) {
|
||||||
fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
|
fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
_winPokeAHole();
|
||||||
SetConsoleCtrlHandler(&_winConsoleCtrlHandler,TRUE);
|
SetConsoleCtrlHandler(&_winConsoleCtrlHandler,TRUE);
|
||||||
// continues on to ordinary command line execution code below...
|
// continues on to ordinary command line execution code below...
|
||||||
} else {
|
} else {
|
||||||
// Running from service manager
|
// Running from service manager
|
||||||
|
_winPokeAHole();
|
||||||
ZeroTierOneService zt1Service;
|
ZeroTierOneService zt1Service;
|
||||||
if (CServiceBase::Run(zt1Service) == TRUE) {
|
if (CServiceBase::Run(zt1Service) == TRUE) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -791,8 +813,13 @@ int main(int argc,char **argv)
|
|||||||
// succeed unless something is wrong with the filesystem.
|
// succeed unless something is wrong with the filesystem.
|
||||||
std::string authToken(NodeControlClient::getAuthToken((std::string(homeDir) + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),true));
|
std::string authToken(NodeControlClient::getAuthToken((std::string(homeDir) + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),true));
|
||||||
|
|
||||||
|
if (userMode) {
|
||||||
|
tapFactory = new TestEthernetTapFactory();
|
||||||
|
routingTable = new TestRoutingTable();
|
||||||
|
} else {
|
||||||
tapFactory = ZTCreatePlatformEthernetTapFactory;
|
tapFactory = ZTCreatePlatformEthernetTapFactory;
|
||||||
routingTable = ZTCreatePlatformRoutingTable;
|
routingTable = ZTCreatePlatformRoutingTable;
|
||||||
|
}
|
||||||
|
|
||||||
node = new Node(homeDir,tapFactory,routingTable,udpPort,tcpPort,needsReset);
|
node = new Node(homeDir,tapFactory,routingTable,udpPort,tcpPort,needsReset);
|
||||||
controlService = new NodeControlService(node,authToken.c_str());
|
controlService = new NodeControlService(node,authToken.c_str());
|
||||||
|
@ -28,15 +28,15 @@
|
|||||||
#ifndef ZT_CONDITION_HPP
|
#ifndef ZT_CONDITION_HPP
|
||||||
#define ZT_CONDITION_HPP
|
#define ZT_CONDITION_HPP
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "../node/NonCopyable.hpp"
|
#include "NonCopyable.hpp"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "../node/Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ private:
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "../node/Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
@ -152,6 +152,21 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups) = 0;
|
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject a packet as if it was sent by the host, if supported
|
||||||
|
*
|
||||||
|
* This is for testing and is typically not supported by real TAP devices.
|
||||||
|
* It's implemented by TestEthernetTap in testnet.
|
||||||
|
*
|
||||||
|
* @param from Source MAC
|
||||||
|
* @param to Destination MAC
|
||||||
|
* @param etherType Ethernet frame type
|
||||||
|
* @param data Packet data
|
||||||
|
* @param len Packet length
|
||||||
|
* @return False if not supported or packet too large
|
||||||
|
*/
|
||||||
|
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char *_implName;
|
const char *_implName;
|
||||||
MAC _mac;
|
MAC _mac;
|
||||||
|
@ -93,6 +93,7 @@ struct _NodeImpl
|
|||||||
volatile bool running;
|
volatile bool running;
|
||||||
volatile bool resynchronize;
|
volatile bool resynchronize;
|
||||||
volatile bool disableRootTopologyUpdates;
|
volatile bool disableRootTopologyUpdates;
|
||||||
|
std::string overrideRootTopology;
|
||||||
|
|
||||||
// This function performs final node tear-down
|
// This function performs final node tear-down
|
||||||
inline Node::ReasonForTermination terminate()
|
inline Node::ReasonForTermination terminate()
|
||||||
@ -223,8 +224,8 @@ Node::Node(
|
|||||||
RoutingTable *rt,
|
RoutingTable *rt,
|
||||||
unsigned int udpPort,
|
unsigned int udpPort,
|
||||||
unsigned int tcpPort,
|
unsigned int tcpPort,
|
||||||
bool resetIdentity)
|
bool resetIdentity,
|
||||||
throw() :
|
const char *overrideRootTopology) throw() :
|
||||||
_impl(new _NodeImpl)
|
_impl(new _NodeImpl)
|
||||||
{
|
{
|
||||||
_NodeImpl *impl = (_NodeImpl *)_impl;
|
_NodeImpl *impl = (_NodeImpl *)_impl;
|
||||||
@ -260,7 +261,13 @@ Node::Node(
|
|||||||
impl->started = false;
|
impl->started = false;
|
||||||
impl->running = false;
|
impl->running = false;
|
||||||
impl->resynchronize = false;
|
impl->resynchronize = false;
|
||||||
|
|
||||||
|
if (overrideRootTopology) {
|
||||||
|
impl->disableRootTopologyUpdates = true;
|
||||||
|
impl->overrideRootTopology = overrideRootTopology;
|
||||||
|
} else {
|
||||||
impl->disableRootTopologyUpdates = false;
|
impl->disableRootTopologyUpdates = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::~Node()
|
Node::~Node()
|
||||||
@ -403,7 +410,7 @@ Node::ReasonForTermination Node::run()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize root topology from defaults or root-toplogy file in home path on disk
|
// Initialize root topology from defaults or root-toplogy file in home path on disk
|
||||||
{
|
if (impl->overrideRootTopology.length() == 0) {
|
||||||
std::string rootTopologyPath(RR->homePath + ZT_PATH_SEPARATOR_S + "root-topology");
|
std::string rootTopologyPath(RR->homePath + ZT_PATH_SEPARATOR_S + "root-topology");
|
||||||
std::string rootTopology;
|
std::string rootTopology;
|
||||||
if (!Utils::readFile(rootTopologyPath.c_str(),rootTopology))
|
if (!Utils::readFile(rootTopologyPath.c_str(),rootTopology))
|
||||||
@ -427,6 +434,14 @@ Node::ReasonForTermination Node::run()
|
|||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"invalid root-topology format");
|
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"invalid root-topology format");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Dictionary rt(impl->overrideRootTopology);
|
||||||
|
RR->topology->setSupernodes(Dictionary(rt.get("supernodes","")));
|
||||||
|
impl->disableRootTopologyUpdates = true;
|
||||||
|
} catch ( ... ) {
|
||||||
|
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"invalid root-topology format");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (std::bad_alloc &exc) {
|
} catch (std::bad_alloc &exc) {
|
||||||
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"memory allocation failure");
|
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"memory allocation failure");
|
||||||
|
@ -88,6 +88,7 @@ public:
|
|||||||
* @param udpPort UDP port or 0 to disable
|
* @param udpPort UDP port or 0 to disable
|
||||||
* @param tcpPort TCP port or 0 to disable
|
* @param tcpPort TCP port or 0 to disable
|
||||||
* @param resetIdentity If true, delete identity before starting and regenerate
|
* @param resetIdentity If true, delete identity before starting and regenerate
|
||||||
|
* @param overrideRootTopology Override root topology with this dictionary (in string serialized format) and do not update (default: NULL for none)
|
||||||
*/
|
*/
|
||||||
Node(
|
Node(
|
||||||
const char *hp,
|
const char *hp,
|
||||||
@ -95,7 +96,8 @@ public:
|
|||||||
RoutingTable *rt,
|
RoutingTable *rt,
|
||||||
unsigned int udpPort,
|
unsigned int udpPort,
|
||||||
unsigned int tcpPort,
|
unsigned int tcpPort,
|
||||||
bool resetIdentity) throw();
|
bool resetIdentity,
|
||||||
|
const char *overrideRootTopology = (const char *)0) throw();
|
||||||
|
|
||||||
~Node();
|
~Node();
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@ OBJS=\
|
|||||||
control/NodeControlClient.o \
|
control/NodeControlClient.o \
|
||||||
control/NodeControlService.o \
|
control/NodeControlService.o \
|
||||||
ext/lz4/lz4.o \
|
ext/lz4/lz4.o \
|
||||||
|
testnet/TestEthernetTap.o \
|
||||||
|
testnet/TestEthernetTapFactory.o \
|
||||||
|
testnet/TestRoutingTable.o \
|
||||||
node/C25519.o \
|
node/C25519.o \
|
||||||
node/CertificateOfMembership.o \
|
node/CertificateOfMembership.o \
|
||||||
node/Defaults.o \
|
node/Defaults.o \
|
||||||
|
@ -361,6 +361,11 @@ bool LinuxEthernetTap::updateMulticastGroups(std::set<MulticastGroup> &groups)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LinuxEthernetTap::injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void LinuxEthernetTap::threadMain()
|
void LinuxEthernetTap::threadMain()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,7 @@ public:
|
|||||||
virtual std::string deviceName() const;
|
virtual std::string deviceName() const;
|
||||||
virtual void setFriendlyName(const char *friendlyName);
|
virtual void setFriendlyName(const char *friendlyName);
|
||||||
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
||||||
|
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
@ -576,6 +576,11 @@ bool OSXEthernetTap::updateMulticastGroups(std::set<MulticastGroup> &groups)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSXEthernetTap::injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void OSXEthernetTap::threadMain()
|
void OSXEthernetTap::threadMain()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
virtual std::string deviceName() const;
|
virtual std::string deviceName() const;
|
||||||
virtual void setFriendlyName(const char *friendlyName);
|
virtual void setFriendlyName(const char *friendlyName);
|
||||||
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
||||||
|
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
@ -527,6 +527,11 @@ bool WindowsEthernetTap::updateMulticastGroups(std::set<MulticastGroup> &groups)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WindowsEthernetTap::injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void WindowsEthernetTap::threadMain()
|
void WindowsEthernetTap::threadMain()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
|
@ -71,6 +71,7 @@ public:
|
|||||||
virtual std::string deviceName() const;
|
virtual std::string deviceName() const;
|
||||||
virtual void setFriendlyName(const char *friendlyName);
|
virtual void setFriendlyName(const char *friendlyName);
|
||||||
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
||||||
|
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
inline const NET_LUID &luid() const { return _deviceLuid; }
|
inline const NET_LUID &luid() const { return _deviceLuid; }
|
||||||
inline const GUID &guid() const { return _deviceGuid; }
|
inline const GUID &guid() const { return _deviceGuid; }
|
||||||
|
@ -27,10 +27,23 @@
|
|||||||
|
|
||||||
#include "TestEthernetTap.hpp"
|
#include "TestEthernetTap.hpp"
|
||||||
#include "TestEthernetTapFactory.hpp"
|
#include "TestEthernetTapFactory.hpp"
|
||||||
|
|
||||||
|
#include "../node/Constants.hpp"
|
||||||
#include "../node/Utils.hpp"
|
#include "../node/Utils.hpp"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
#include <process.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
static Mutex printLock;
|
||||||
|
|
||||||
TestEthernetTap::TestEthernetTap(
|
TestEthernetTap::TestEthernetTap(
|
||||||
TestEthernetTapFactory *parent,
|
TestEthernetTapFactory *parent,
|
||||||
const MAC &mac,
|
const MAC &mac,
|
||||||
@ -47,9 +60,19 @@ TestEthernetTap::TestEthernetTap(
|
|||||||
_arg(arg),
|
_arg(arg),
|
||||||
_enabled(true)
|
_enabled(true)
|
||||||
{
|
{
|
||||||
|
static volatile unsigned int testTapCounter = 0;
|
||||||
|
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%.16llx",(unsigned long long)nwid);
|
int pid = 0;
|
||||||
|
#ifdef __UNIX_LIKE__
|
||||||
|
pid = (int)getpid();
|
||||||
|
#endif
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
pid = (int)_getpid();
|
||||||
|
#endif
|
||||||
|
Utils::snprintf(tmp,sizeof(tmp),"test%dtap%d",pid,testTapCounter++);
|
||||||
_dev = tmp;
|
_dev = tmp;
|
||||||
|
|
||||||
_thread = Thread::start(this);
|
_thread = Thread::start(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +80,7 @@ TestEthernetTap::~TestEthernetTap()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_pq_m);
|
Mutex::Lock _l(_pq_m);
|
||||||
_pq.push(TestFrame()); // 0-length frame = exit
|
_pq.push(TestFrame()); // 0 length frame = exit
|
||||||
}
|
}
|
||||||
_pq_c.signal();
|
_pq_c.signal();
|
||||||
Thread::join(_thread);
|
Thread::join(_thread);
|
||||||
@ -90,9 +113,9 @@ std::set<InetAddress> TestEthernetTap::ips() const
|
|||||||
|
|
||||||
void TestEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
void TestEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
static Mutex printLock;
|
|
||||||
Mutex::Lock _l(printLock);
|
Mutex::Lock _l(printLock);
|
||||||
fprintf(stderr,"%s << %s %.4x %s"ZT_EOL_S,to.toString().c_str(),from.toString().c_str(),etherType,std::string((const char *)data,len).c_str());
|
fprintf(stdout,"[%s] %s << %s %.4x %s"ZT_EOL_S,_dev.c_str(),to.toString().c_str(),from.toString().c_str(),etherType,std::string((const char *)data,len).c_str());
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TestEthernetTap::deviceName() const
|
std::string TestEthernetTap::deviceName() const
|
||||||
@ -109,6 +132,26 @@ bool TestEthernetTap::updateMulticastGroups(std::set<MulticastGroup> &groups)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TestEthernetTap::injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
|
{
|
||||||
|
if ((len == 0)||(len > 2800))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_pq_m);
|
||||||
|
_pq.push(TestFrame(from,to,data,etherType & 0xffff,len));
|
||||||
|
}
|
||||||
|
_pq_c.signal();
|
||||||
|
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(printLock);
|
||||||
|
fprintf(stdout,"[%s] %s >> %s %.4x %s"ZT_EOL_S,_dev.c_str(),from.toString().c_str(),to.toString().c_str(),etherType,std::string((const char *)data,len).c_str());
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void TestEthernetTap::threadMain()
|
void TestEthernetTap::threadMain()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
@ -126,7 +169,7 @@ void TestEthernetTap::threadMain()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((tf.len > 0)&&(_enabled))
|
if ((tf.len > 0)&&(_enabled))
|
||||||
_handler(_arg,tf.from,tf.to,ZT_TEST_ETHERNET_ETHERTYPE,Buffer<4096>(tf.data,tf.len));
|
_handler(_arg,tf.from,tf.to,tf.etherType,Buffer<4096>(tf.data,tf.len));
|
||||||
|
|
||||||
_pq_c.wait();
|
_pq_c.wait();
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,13 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "../node/Constants.hpp"
|
||||||
|
#include "../node/EthernetTap.hpp"
|
||||||
#include "../node/AtomicCounter.hpp"
|
#include "../node/AtomicCounter.hpp"
|
||||||
#include "../node/SharedPtr.hpp"
|
#include "../node/SharedPtr.hpp"
|
||||||
#include "../node/EthernetTap.hpp"
|
|
||||||
#include "../node/Thread.hpp"
|
#include "../node/Thread.hpp"
|
||||||
#include "../node/Mutex.hpp"
|
#include "../node/Mutex.hpp"
|
||||||
#include "Condition.hpp"
|
#include "../node/Condition.hpp"
|
||||||
|
|
||||||
// Ethernet frame type to use on fake testnet
|
|
||||||
#define ZT_TEST_ETHERNET_ETHERTYPE 0xdead
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
@ -57,16 +55,18 @@ class TestEthernetTap : public EthernetTap
|
|||||||
private:
|
private:
|
||||||
struct TestFrame
|
struct TestFrame
|
||||||
{
|
{
|
||||||
TestFrame() : len(0) {}
|
TestFrame() : etherType(0),len(0) {}
|
||||||
TestFrame(const MAC &f,const MAC &t,const void *d,unsigned int l) :
|
TestFrame(const MAC &f,const MAC &t,const void *d,unsigned int et,unsigned int l) :
|
||||||
from(f),
|
from(f),
|
||||||
to(t),
|
to(t),
|
||||||
|
etherType(et),
|
||||||
len(l)
|
len(l)
|
||||||
{
|
{
|
||||||
memcpy(data,d,l);
|
memcpy(data,d,l);
|
||||||
}
|
}
|
||||||
MAC from;
|
MAC from;
|
||||||
MAC to;
|
MAC to;
|
||||||
|
unsigned int etherType;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
char data[4096];
|
char data[4096];
|
||||||
};
|
};
|
||||||
@ -94,21 +94,11 @@ public:
|
|||||||
virtual std::string deviceName() const;
|
virtual std::string deviceName() const;
|
||||||
virtual void setFriendlyName(const char *friendlyName);
|
virtual void setFriendlyName(const char *friendlyName);
|
||||||
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
||||||
|
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
|
||||||
inline void sendFromHost(const MAC &from,const MAC &to,const void *data,unsigned int len)
|
|
||||||
{
|
|
||||||
if (!len)
|
|
||||||
return;
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(_pq_m);
|
|
||||||
_pq.push(TestFrame(from,to,data,len));
|
|
||||||
}
|
|
||||||
_pq_c.signal();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestEthernetTapFactory *_parent;
|
TestEthernetTapFactory *_parent;
|
||||||
|
|
||||||
|
@ -37,11 +37,10 @@
|
|||||||
#include "../node/Mutex.hpp"
|
#include "../node/Mutex.hpp"
|
||||||
#include "../node/MAC.hpp"
|
#include "../node/MAC.hpp"
|
||||||
#include "../node/CMWC4096.hpp"
|
#include "../node/CMWC4096.hpp"
|
||||||
|
#include "TestEthernetTap.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
class TestEthernetTap;
|
|
||||||
|
|
||||||
class TestEthernetTapFactory : public EthernetTapFactory
|
class TestEthernetTapFactory : public EthernetTapFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
50
testnet/TestRoutingTable.cpp
Normal file
50
testnet/TestRoutingTable.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* ZeroTier One - Global Peer to Peer Ethernet
|
||||||
|
* Copyright (C) 2011-2014 ZeroTier Networks LLC
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* --
|
||||||
|
*
|
||||||
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||||
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
*
|
||||||
|
* If you would like to embed ZeroTier into a commercial application or
|
||||||
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||||
|
* LLC. Start here: http://www.zerotier.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TestRoutingTable.hpp"
|
||||||
|
|
||||||
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
TestRoutingTable::TestRoutingTable()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TestRoutingTable::~TestRoutingTable()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<RoutingTable::Entry> TestRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const
|
||||||
|
{
|
||||||
|
return std::vector<RoutingTable::Entry>();
|
||||||
|
}
|
||||||
|
|
||||||
|
RoutingTable::Entry TestRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric)
|
||||||
|
{
|
||||||
|
return RoutingTable::Entry();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ZeroTier
|
50
testnet/TestRoutingTable.hpp
Normal file
50
testnet/TestRoutingTable.hpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* ZeroTier One - Global Peer to Peer Ethernet
|
||||||
|
* Copyright (C) 2011-2014 ZeroTier Networks LLC
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* --
|
||||||
|
*
|
||||||
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||||
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
*
|
||||||
|
* If you would like to embed ZeroTier into a commercial application or
|
||||||
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||||
|
* LLC. Start here: http://www.zerotier.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZT_TESTROUTINGTABLE_HPP
|
||||||
|
#define ZT_TESTROUTINGTABLE_HPP
|
||||||
|
|
||||||
|
#include "../node/RoutingTable.hpp"
|
||||||
|
|
||||||
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy routing table -- right now this just does nothing
|
||||||
|
*/
|
||||||
|
class TestRoutingTable : public RoutingTable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestRoutingTable();
|
||||||
|
virtual ~TestRoutingTable();
|
||||||
|
|
||||||
|
virtual std::vector<RoutingTable::Entry> get(bool includeLinkLocal = false,bool includeLoopback = false) const;
|
||||||
|
virtual RoutingTable::Entry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ZeroTier
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user