mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
A few more fixes, ready to integrate main payload.
This commit is contained in:
parent
bf4cab5f2f
commit
b9d4b42f93
2 changed files with 38 additions and 13 deletions
|
@ -27,6 +27,9 @@
|
||||||
|
|
||||||
#ifdef ZT_ENABLE_NETCON
|
#ifdef ZT_ENABLE_NETCON
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "NetconEthernetTap.hpp"
|
#include "NetconEthernetTap.hpp"
|
||||||
|
|
||||||
#include "../node/Utils.hpp"
|
#include "../node/Utils.hpp"
|
||||||
|
@ -44,15 +47,12 @@ NetconEthernetTap::NetconEthernetTap(
|
||||||
const char *friendlyName,
|
const char *friendlyName,
|
||||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
||||||
void *arg) :
|
void *arg) :
|
||||||
_phy(new Phy<NetconEthernetTap *>(this,false,true)),
|
_phy(this,false,true),
|
||||||
_unixListenSocket((PhySocket *)0),
|
_unixListenSocket((PhySocket *)0),
|
||||||
_handler(handler),
|
_handler(handler),
|
||||||
_arg(arg),
|
_arg(arg),
|
||||||
_nwid(nwid),
|
_nwid(nwid),
|
||||||
_thread(),
|
|
||||||
_homePath(homePath),
|
_homePath(homePath),
|
||||||
_dev(),
|
|
||||||
_multicastGroups(),
|
|
||||||
_mtu(mtu),
|
_mtu(mtu),
|
||||||
_enabled(true),
|
_enabled(true),
|
||||||
_run(true)
|
_run(true)
|
||||||
|
@ -61,7 +61,7 @@ NetconEthernetTap::NetconEthernetTap(
|
||||||
Utils::snprintf(sockPath,sizeof(sockPath),"/tmp/.ztnc_%.16llx",(unsigned long long)nwid);
|
Utils::snprintf(sockPath,sizeof(sockPath),"/tmp/.ztnc_%.16llx",(unsigned long long)nwid);
|
||||||
_dev = sockPath;
|
_dev = sockPath;
|
||||||
|
|
||||||
_unixListenSocket = _phy->unixListen(sockPath,(void *)this);
|
_unixListenSocket = _phy.unixListen(sockPath,(void *)this);
|
||||||
if (!_unixListenSocket)
|
if (!_unixListenSocket)
|
||||||
throw std::runtime_error(std::string("unable to bind to ")+sockPath);
|
throw std::runtime_error(std::string("unable to bind to ")+sockPath);
|
||||||
|
|
||||||
|
@ -71,11 +71,10 @@ NetconEthernetTap::NetconEthernetTap(
|
||||||
NetconEthernetTap::~NetconEthernetTap()
|
NetconEthernetTap::~NetconEthernetTap()
|
||||||
{
|
{
|
||||||
_run = false;
|
_run = false;
|
||||||
_phy->whack();
|
_phy.whack();
|
||||||
_phy->whack();
|
_phy.whack();
|
||||||
Thread::join(_thread);
|
Thread::join(_thread);
|
||||||
_phy->close(_unixListenSocket,false);
|
_phy.close(_unixListenSocket,false);
|
||||||
delete _phy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetconEthernetTap::setEnabled(bool en)
|
void NetconEthernetTap::setEnabled(bool en)
|
||||||
|
@ -90,14 +89,32 @@ bool NetconEthernetTap::enabled() const
|
||||||
|
|
||||||
bool NetconEthernetTap::addIp(const InetAddress &ip)
|
bool NetconEthernetTap::addIp(const InetAddress &ip)
|
||||||
{
|
{
|
||||||
|
Mutex::Lock _l(_ips_m);
|
||||||
|
if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
|
||||||
|
_ips.push_back(ip);
|
||||||
|
std::sort(_ips.begin(),_ips.end());
|
||||||
|
|
||||||
|
// TODO: alloc IP in LWIP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetconEthernetTap::removeIp(const InetAddress &ip)
|
bool NetconEthernetTap::removeIp(const InetAddress &ip)
|
||||||
{
|
{
|
||||||
|
Mutex::Lock _l(_ips_m);
|
||||||
|
std::vector<InetAddress> i(std::find(_ips.begin(),_ips.end(),ip));
|
||||||
|
if (i == _ips.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_ips.erase(i);
|
||||||
|
// TODO: dealloc IP from LWIP
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<InetAddress> NetconEthernetTap::ips() const
|
std::vector<InetAddress> NetconEthernetTap::ips() const
|
||||||
{
|
{
|
||||||
|
Mutex::Lock _l(_ips_m);
|
||||||
|
return _ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
|
@ -117,6 +134,7 @@ void NetconEthernetTap::setFriendlyName(const char *friendlyName)
|
||||||
|
|
||||||
void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
||||||
{
|
{
|
||||||
|
// TODO: get multicast subscriptions from LWIP
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetconEthernetTap::threadMain()
|
void NetconEthernetTap::threadMain()
|
||||||
|
@ -127,13 +145,13 @@ void NetconEthernetTap::threadMain()
|
||||||
|
|
||||||
// TODO: compute timeout from LWIP stuff
|
// TODO: compute timeout from LWIP stuff
|
||||||
|
|
||||||
_phy->poll(pollTimeout);
|
_phy.poll(pollTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: cleanup -- destroy LWIP state, kill any clients, unload .so, etc.
|
// TODO: cleanup -- destroy LWIP state, kill any clients, unload .so, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unused
|
// Unused -- no UDP or TCP from this thread/Phy<>
|
||||||
void NetconEthernetTap::phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *from,void *data,unsigned long len) {}
|
void NetconEthernetTap::phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *from,void *data,unsigned long len) {}
|
||||||
void NetconEthernetTap::phyOnTcpConnect(PhySocket *sock,void **uptr,bool success) {}
|
void NetconEthernetTap::phyOnTcpConnect(PhySocket *sock,void **uptr,bool success) {}
|
||||||
void NetconEthernetTap::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from) {}
|
void NetconEthernetTap::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from) {}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "../node/Constants.hpp"
|
#include "../node/Constants.hpp"
|
||||||
#include "../node/MulticastGroup.hpp"
|
#include "../node/MulticastGroup.hpp"
|
||||||
#include "../node/Mutex.hpp"
|
#include "../node/Mutex.hpp"
|
||||||
|
#include "../node/InetAddress.hpp"
|
||||||
#include "../osdep/Thread.hpp"
|
#include "../osdep/Thread.hpp"
|
||||||
#include "../osdep/Phy.hpp"
|
#include "../osdep/Phy.hpp"
|
||||||
|
|
||||||
|
@ -95,14 +96,20 @@ private:
|
||||||
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
||||||
void *_arg;
|
void *_arg;
|
||||||
|
|
||||||
Phy<NetconEthernetTap *> *_phy;
|
Phy<NetconEthernetTap *> _phy;
|
||||||
PhySocket *_unixListenSocket;
|
PhySocket *_unixListenSocket;
|
||||||
|
|
||||||
uint64_t _nwid;
|
uint64_t _nwid;
|
||||||
Thread _thread;
|
Thread _thread;
|
||||||
std::string _homePath;
|
std::string _homePath;
|
||||||
std::string _dev; // path to Unix domain socket
|
std::string _dev; // path to Unix domain socket
|
||||||
std::vector<MulticastGroup> _multicastGroups;
|
|
||||||
|
std::vector<MulticastGroup> _lastMulticastGroupList;
|
||||||
|
Mutex _lastMulticastGroupList_m;
|
||||||
|
|
||||||
|
std::vector<InetAddress> _ips;
|
||||||
|
Mutex _ips_m;
|
||||||
|
|
||||||
unsigned int _mtu;
|
unsigned int _mtu;
|
||||||
volatile bool _enabled;
|
volatile bool _enabled;
|
||||||
volatile bool _run;
|
volatile bool _run;
|
||||||
|
|
Loading…
Add table
Reference in a new issue