mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-30 14:04:23 +00:00
Use network user ptr in lookup for Ethernet frame handling to eliminate map lookup.
This commit is contained in:
parent
83ef98a9dc
commit
d6f0f1a82a
@ -981,7 +981,7 @@ typedef int (*ZT_VirtualNetworkConfigFunction)(
|
|||||||
ZT_Node *, /* Node */
|
ZT_Node *, /* Node */
|
||||||
void *, /* User ptr */
|
void *, /* User ptr */
|
||||||
uint64_t, /* Network ID */
|
uint64_t, /* Network ID */
|
||||||
void *, /* Network user ptr (set w/join) */
|
void **, /* Modifiable network user PTR */
|
||||||
enum ZT_VirtualNetworkConfigOperation, /* Config operation */
|
enum ZT_VirtualNetworkConfigOperation, /* Config operation */
|
||||||
const ZT_VirtualNetworkConfig *); /* Network configuration */
|
const ZT_VirtualNetworkConfig *); /* Network configuration */
|
||||||
|
|
||||||
@ -996,7 +996,7 @@ typedef void (*ZT_VirtualNetworkFrameFunction)(
|
|||||||
ZT_Node *, /* Node */
|
ZT_Node *, /* Node */
|
||||||
void *, /* User ptr */
|
void *, /* User ptr */
|
||||||
uint64_t, /* Network ID */
|
uint64_t, /* Network ID */
|
||||||
void *, /* Network user PTR (set w/join) */
|
void **, /* Modifiable network user PTR */
|
||||||
uint64_t, /* Source MAC */
|
uint64_t, /* Source MAC */
|
||||||
uint64_t, /* Destination MAC */
|
uint64_t, /* Destination MAC */
|
||||||
unsigned int, /* Ethernet type */
|
unsigned int, /* Ethernet type */
|
||||||
@ -1247,10 +1247,10 @@ enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node,uint64_t now,vol
|
|||||||
*
|
*
|
||||||
* @param node Node instance
|
* @param node Node instance
|
||||||
* @param nwid 64-bit ZeroTier network ID
|
* @param nwid 64-bit ZeroTier network ID
|
||||||
* @param uptr An arbitrary pointer to associate with this network
|
* @param uptr An arbitrary pointer to associate with this network (default: NULL)
|
||||||
* @return OK (0) or error code if a fatal error condition has occurred
|
* @return OK (0) or error code if a fatal error condition has occurred
|
||||||
*/
|
*/
|
||||||
enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid,void *uptr);
|
enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid,void *uptr = (void *)0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leave a network
|
* Leave a network
|
||||||
|
@ -89,7 +89,7 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t nwid,void *uptr) :
|
|||||||
if (!_portInitialized) {
|
if (!_portInitialized) {
|
||||||
ZT_VirtualNetworkConfig ctmp;
|
ZT_VirtualNetworkConfig ctmp;
|
||||||
_externalConfig(&ctmp);
|
_externalConfig(&ctmp);
|
||||||
_portError = RR->node->configureVirtualNetworkPort(_id,_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
_portError = RR->node->configureVirtualNetworkPort(_id,&_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||||
_portInitialized = true;
|
_portInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,11 +101,11 @@ Network::~Network()
|
|||||||
|
|
||||||
char n[128];
|
char n[128];
|
||||||
if (_destroyed) {
|
if (_destroyed) {
|
||||||
RR->node->configureVirtualNetworkPort(_id,_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY,&ctmp);
|
RR->node->configureVirtualNetworkPort(_id,&_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY,&ctmp);
|
||||||
Utils::snprintf(n,sizeof(n),"networks.d/%.16llx.conf",_id);
|
Utils::snprintf(n,sizeof(n),"networks.d/%.16llx.conf",_id);
|
||||||
RR->node->dataStoreDelete(n);
|
RR->node->dataStoreDelete(n);
|
||||||
} else {
|
} else {
|
||||||
RR->node->configureVirtualNetworkPort(_id,_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN,&ctmp);
|
RR->node->configureVirtualNetworkPort(_id,&_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN,&ctmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ bool Network::applyConfiguration(const SharedPtr<NetworkConfig> &conf)
|
|||||||
portInitialized = _portInitialized;
|
portInitialized = _portInitialized;
|
||||||
_portInitialized = true;
|
_portInitialized = true;
|
||||||
}
|
}
|
||||||
_portError = RR->node->configureVirtualNetworkPort(_id,_uptr,(portInitialized) ? ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE : ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
_portError = RR->node->configureVirtualNetworkPort(_id,&_uptr,(portInitialized) ? ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE : ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
TRACE("ignored invalid configuration for network %.16llx (configuration contains mismatched network ID or issued-to address)",(unsigned long long)_id);
|
TRACE("ignored invalid configuration for network %.16llx (configuration contains mismatched network ID or issued-to address)",(unsigned long long)_id);
|
||||||
@ -332,7 +332,7 @@ void Network::setEnabled(bool enabled)
|
|||||||
_enabled = enabled;
|
_enabled = enabled;
|
||||||
ZT_VirtualNetworkConfig ctmp;
|
ZT_VirtualNetworkConfig ctmp;
|
||||||
_externalConfig(&ctmp);
|
_externalConfig(&ctmp);
|
||||||
_portError = RR->node->configureVirtualNetworkPort(_id,_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE,&ctmp);
|
_portError = RR->node->configureVirtualNetworkPort(_id,&_uptr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE,&ctmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,9 +333,9 @@ public:
|
|||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return User ptr
|
* @return Pointer to user PTR (modifiable user ptr used in API)
|
||||||
*/
|
*/
|
||||||
inline void *userPtr() const throw() { return _uptr; }
|
inline void **userPtr() throw() { return &_uptr; }
|
||||||
|
|
||||||
inline bool operator==(const Network &n) const throw() { return (_id == n._id); }
|
inline bool operator==(const Network &n) const throw() { return (_id == n._id); }
|
||||||
inline bool operator!=(const Network &n) const throw() { return (_id != n._id); }
|
inline bool operator!=(const Network &n) const throw() { return (_id != n._id); }
|
||||||
|
@ -177,7 +177,7 @@ public:
|
|||||||
* @param data Frame data
|
* @param data Frame data
|
||||||
* @param len Frame length
|
* @param len Frame length
|
||||||
*/
|
*/
|
||||||
inline void putFrame(uint64_t nwid,void *nuptr,const MAC &source,const MAC &dest,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
inline void putFrame(uint64_t nwid,void **nuptr,const MAC &source,const MAC &dest,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
_virtualNetworkFrameFunction(
|
_virtualNetworkFrameFunction(
|
||||||
reinterpret_cast<ZT_Node *>(this),
|
reinterpret_cast<ZT_Node *>(this),
|
||||||
@ -255,7 +255,7 @@ public:
|
|||||||
* @param op Configuration operation
|
* @param op Configuration operation
|
||||||
* @param nc Network configuration
|
* @param nc Network configuration
|
||||||
*/
|
*/
|
||||||
inline int configureVirtualNetworkPort(uint64_t nwid,void *nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) { return _virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,nwid,nuptr,op,nc); }
|
inline int configureVirtualNetworkPort(uint64_t nwid,void **nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) { return _virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,nwid,nuptr,op,nc); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return True if we appear to be online
|
* @return True if we appear to be online
|
||||||
|
@ -391,12 +391,12 @@ static std::string _trimString(const std::string &s)
|
|||||||
|
|
||||||
class OneServiceImpl;
|
class OneServiceImpl;
|
||||||
|
|
||||||
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,void *nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf);
|
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,void **nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf);
|
||||||
static void SnodeEventCallback(ZT_Node *node,void *uptr,enum ZT_Event event,const void *metaData);
|
static void SnodeEventCallback(ZT_Node *node,void *uptr,enum ZT_Event event,const void *metaData);
|
||||||
static long SnodeDataStoreGetFunction(ZT_Node *node,void *uptr,const char *name,void *buf,unsigned long bufSize,unsigned long readIndex,unsigned long *totalSize);
|
static long SnodeDataStoreGetFunction(ZT_Node *node,void *uptr,const char *name,void *buf,unsigned long bufSize,unsigned long readIndex,unsigned long *totalSize);
|
||||||
static int SnodeDataStorePutFunction(ZT_Node *node,void *uptr,const char *name,const void *data,unsigned long len,int secure);
|
static int SnodeDataStorePutFunction(ZT_Node *node,void *uptr,const char *name,const void *data,unsigned long len,int secure);
|
||||||
static int SnodeWirePacketSendFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *addr,const void *data,unsigned int len,unsigned int ttl);
|
static int SnodeWirePacketSendFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *addr,const void *data,unsigned int len,unsigned int ttl);
|
||||||
static void SnodeVirtualNetworkFrameFunction(ZT_Node *node,void *uptr,uint64_t nwid,void *nuptr,uint64_t sourceMac,uint64_t destMac,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len);
|
static void SnodeVirtualNetworkFrameFunction(ZT_Node *node,void *uptr,uint64_t nwid,void **nuptr,uint64_t sourceMac,uint64_t destMac,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len);
|
||||||
static int SnodePathCheckFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *remoteAddr);
|
static int SnodePathCheckFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *remoteAddr);
|
||||||
|
|
||||||
#ifdef ZT_ENABLE_CLUSTER
|
#ifdef ZT_ENABLE_CLUSTER
|
||||||
@ -1131,7 +1131,7 @@ public:
|
|||||||
inline void phyOnUnixData(PhySocket *sock,void **uptr,void *data,unsigned long len) {}
|
inline void phyOnUnixData(PhySocket *sock,void **uptr,void *data,unsigned long len) {}
|
||||||
inline void phyOnUnixWritable(PhySocket *sock,void **uptr) {}
|
inline void phyOnUnixWritable(PhySocket *sock,void **uptr) {}
|
||||||
|
|
||||||
inline int nodeVirtualNetworkConfigFunction(uint64_t nwid,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwc)
|
inline int nodeVirtualNetworkConfigFunction(uint64_t nwid,void **nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwc)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_taps_m);
|
Mutex::Lock _l(_taps_m);
|
||||||
std::map< uint64_t,EthernetTap * >::iterator t(_taps.find(nwid));
|
std::map< uint64_t,EthernetTap * >::iterator t(_taps.find(nwid));
|
||||||
@ -1150,6 +1150,7 @@ public:
|
|||||||
friendlyName,
|
friendlyName,
|
||||||
StapFrameHandler,
|
StapFrameHandler,
|
||||||
(void *)this))).first;
|
(void *)this))).first;
|
||||||
|
*nuptr = (void *)t->second;
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
FILE *tapFailLog = fopen((_homePath + ZT_PATH_SEPARATOR_S"port_error_log.txt").c_str(),"a");
|
FILE *tapFailLog = fopen((_homePath + ZT_PATH_SEPARATOR_S"port_error_log.txt").c_str(),"a");
|
||||||
@ -1197,6 +1198,7 @@ public:
|
|||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
std::string winInstanceId(t->second->instanceId());
|
std::string winInstanceId(t->second->instanceId());
|
||||||
#endif
|
#endif
|
||||||
|
*nuptr = (void *)0;
|
||||||
delete t->second;
|
delete t->second;
|
||||||
_taps.erase(t);
|
_taps.erase(t);
|
||||||
_tapAssignedIps.erase(nwid);
|
_tapAssignedIps.erase(nwid);
|
||||||
@ -1387,12 +1389,12 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void nodeVirtualNetworkFrameFunction(uint64_t nwid,uint64_t sourceMac,uint64_t destMac,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
inline void nodeVirtualNetworkFrameFunction(uint64_t nwid,void **nuptr,uint64_t sourceMac,uint64_t destMac,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_taps_m);
|
EthernetTap *tap = reinterpret_cast<EthernetTap *>(*nuptr);
|
||||||
std::map< uint64_t,EthernetTap * >::const_iterator t(_taps.find(nwid));
|
if (!tap)
|
||||||
if (t != _taps.end())
|
return;
|
||||||
t->second->put(MAC(sourceMac),MAC(destMac),etherType,data,len);
|
tap->put(MAC(sourceMac),MAC(destMac),etherType,data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int nodePathCheckFunction(const struct sockaddr_storage *localAddr,const struct sockaddr_storage *remoteAddr)
|
inline int nodePathCheckFunction(const struct sockaddr_storage *localAddr,const struct sockaddr_storage *remoteAddr)
|
||||||
@ -1533,8 +1535,8 @@ public:
|
|||||||
Mutex _run_m;
|
Mutex _run_m;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,void *nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf)
|
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,void **nuptr,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf)
|
||||||
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodeVirtualNetworkConfigFunction(nwid,op,nwconf); }
|
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodeVirtualNetworkConfigFunction(nwid,nuptr,op,nwconf); }
|
||||||
static void SnodeEventCallback(ZT_Node *node,void *uptr,enum ZT_Event event,const void *metaData)
|
static void SnodeEventCallback(ZT_Node *node,void *uptr,enum ZT_Event event,const void *metaData)
|
||||||
{ reinterpret_cast<OneServiceImpl *>(uptr)->nodeEventCallback(event,metaData); }
|
{ reinterpret_cast<OneServiceImpl *>(uptr)->nodeEventCallback(event,metaData); }
|
||||||
static long SnodeDataStoreGetFunction(ZT_Node *node,void *uptr,const char *name,void *buf,unsigned long bufSize,unsigned long readIndex,unsigned long *totalSize)
|
static long SnodeDataStoreGetFunction(ZT_Node *node,void *uptr,const char *name,void *buf,unsigned long bufSize,unsigned long readIndex,unsigned long *totalSize)
|
||||||
@ -1543,8 +1545,8 @@ static int SnodeDataStorePutFunction(ZT_Node *node,void *uptr,const char *name,c
|
|||||||
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodeDataStorePutFunction(name,data,len,secure); }
|
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodeDataStorePutFunction(name,data,len,secure); }
|
||||||
static int SnodeWirePacketSendFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *addr,const void *data,unsigned int len,unsigned int ttl)
|
static int SnodeWirePacketSendFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *addr,const void *data,unsigned int len,unsigned int ttl)
|
||||||
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodeWirePacketSendFunction(localAddr,addr,data,len,ttl); }
|
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodeWirePacketSendFunction(localAddr,addr,data,len,ttl); }
|
||||||
static void SnodeVirtualNetworkFrameFunction(ZT_Node *node,void *uptr,uint64_t nwid,void *nuptr,uint64_t sourceMac,uint64_t destMac,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
static void SnodeVirtualNetworkFrameFunction(ZT_Node *node,void *uptr,uint64_t nwid,void **nuptr,uint64_t sourceMac,uint64_t destMac,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
||||||
{ reinterpret_cast<OneServiceImpl *>(uptr)->nodeVirtualNetworkFrameFunction(nwid,sourceMac,destMac,etherType,vlanId,data,len); }
|
{ reinterpret_cast<OneServiceImpl *>(uptr)->nodeVirtualNetworkFrameFunction(nwid,nuptr,sourceMac,destMac,etherType,vlanId,data,len); }
|
||||||
static int SnodePathCheckFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *remoteAddr)
|
static int SnodePathCheckFunction(ZT_Node *node,void *uptr,const struct sockaddr_storage *localAddr,const struct sockaddr_storage *remoteAddr)
|
||||||
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodePathCheckFunction(localAddr,remoteAddr); }
|
{ return reinterpret_cast<OneServiceImpl *>(uptr)->nodePathCheckFunction(localAddr,remoteAddr); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user