mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 13:24:09 -07:00
(1) Make ZT_ naming convention consistent (get rid of ZT1_), (2) Make local interface a full sockaddr_storage instead of an int identifier, which turns out to be better for multi-homing and other uses.
This commit is contained in:
parent
0e5aac6a11
commit
f69454ec98
29 changed files with 622 additions and 622 deletions
|
@ -161,7 +161,7 @@
|
|||
/**
|
||||
* Default MTU used for Ethernet tap device
|
||||
*/
|
||||
#define ZT_IF_MTU ZT1_MAX_MTU
|
||||
#define ZT_IF_MTU ZT_MAX_MTU
|
||||
|
||||
/**
|
||||
* Maximum number of packet fragments we'll support
|
||||
|
|
|
@ -75,7 +75,7 @@ static inline std::map< Address,Identity > _mkRootTopologyAuth()
|
|||
Defaults::Defaults() :
|
||||
defaultRootTopology((const char *)ZT_DEFAULT_ROOT_TOPOLOGY,ZT_DEFAULT_ROOT_TOPOLOGY_LEN),
|
||||
rootTopologyAuthorities(_mkRootTopologyAuth()),
|
||||
v4Broadcast(((uint32_t)0xffffffff),ZT1_DEFAULT_PORT)
|
||||
v4Broadcast(((uint32_t)0xffffffff),ZT_DEFAULT_PORT)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ bool IncomingPacket::tryDecode(const RuntimeEnvironment *RR)
|
|||
switch(verb()) {
|
||||
//case Packet::VERB_NOP:
|
||||
default: // ignore unknown verbs, but if they pass auth check they are "received"
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),verb(),0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),verb(),0,Packet::VERB_NOP);
|
||||
return true;
|
||||
case Packet::VERB_HELLO: return _doHELLO(RR);
|
||||
case Packet::VERB_ERROR: return _doERROR(RR,peer);
|
||||
|
@ -130,7 +130,7 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
|||
|
||||
case Packet::ERROR_IDENTITY_COLLISION:
|
||||
if (RR->topology->isRoot(peer->identity()))
|
||||
RR->node->postEvent(ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION);
|
||||
RR->node->postEvent(ZT_EVENT_FATAL_ERROR_IDENTITY_COLLISION);
|
||||
break;
|
||||
|
||||
case Packet::ERROR_NEED_MEMBERSHIP_CERTIFICATE: {
|
||||
|
@ -144,7 +144,7 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
|||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE);
|
||||
nconf->com().serialize(outp);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -165,7 +165,7 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
|||
default: break;
|
||||
}
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_ERROR,inRePacketId,inReVerb);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_ERROR,inRePacketId,inReVerb);
|
||||
} catch (std::exception &ex) {
|
||||
TRACE("dropped ERROR from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -224,20 +224,20 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
|
|||
unsigned char key[ZT_PEER_SECRET_KEY_LENGTH];
|
||||
if (RR->identity.agree(id,key,ZT_PEER_SECRET_KEY_LENGTH)) {
|
||||
if (dearmor(key)) { // ensure packet is authentic, otherwise drop
|
||||
RR->node->postEvent(ZT1_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
RR->node->postEvent(ZT_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
TRACE("rejected HELLO from %s(%s): address already claimed",id.address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
Packet outp(id.address(),RR->identity.address(),Packet::VERB_ERROR);
|
||||
outp.append((unsigned char)Packet::VERB_HELLO);
|
||||
outp.append(packetId());
|
||||
outp.append((unsigned char)Packet::ERROR_IDENTITY_COLLISION);
|
||||
outp.armor(key,true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
} else {
|
||||
RR->node->postEvent(ZT1_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
RR->node->postEvent(ZT_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
TRACE("rejected HELLO from %s(%s): packet failed authentication",id.address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
}
|
||||
} else {
|
||||
RR->node->postEvent(ZT1_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
RR->node->postEvent(ZT_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
TRACE("rejected HELLO from %s(%s): key agreement failed",id.address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
|
|||
// Identity is the same as the one we already have -- check packet integrity
|
||||
|
||||
if (!dearmor(peer->key())) {
|
||||
RR->node->postEvent(ZT1_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
RR->node->postEvent(ZT_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
TRACE("rejected HELLO from %s(%s): packet failed authentication",id.address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
|
|||
|
||||
// Check identity proof of work
|
||||
if (!id.locallyValidate()) {
|
||||
RR->node->postEvent(ZT1_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
RR->node->postEvent(ZT_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
TRACE("dropped HELLO from %s(%s): identity invalid",id.address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
|
|||
// Check packet integrity and authentication
|
||||
SharedPtr<Peer> newPeer(new Peer(RR->identity,id));
|
||||
if (!dearmor(newPeer->key())) {
|
||||
RR->node->postEvent(ZT1_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
RR->node->postEvent(ZT_EVENT_AUTHENTICATION_FAILURE,(const void *)&_remoteAddress);
|
||||
TRACE("rejected HELLO from %s(%s): packet failed authentication",id.address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
|
|||
|
||||
// VALID -- continues here
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_HELLO,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_HELLO,0,Packet::VERB_NOP);
|
||||
peer->setRemoteVersion(protoVersion,vMajor,vMinor,vRevision);
|
||||
|
||||
bool trusted = false;
|
||||
|
@ -316,7 +316,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
|
|||
}
|
||||
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
} catch (std::exception &ex) {
|
||||
TRACE("dropped HELLO from %s(%s): %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -436,7 +436,7 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
|
|||
default: break;
|
||||
}
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_OK,inRePacketId,inReVerb);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_OK,inRePacketId,inReVerb);
|
||||
} catch (std::exception &ex) {
|
||||
TRACE("dropped OK from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -456,7 +456,7 @@ bool IncomingPacket::_doWHOIS(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
|||
outp.append(packetId());
|
||||
queried->identity().serialize(outp,false);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
} else {
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_ERROR);
|
||||
outp.append((unsigned char)Packet::VERB_WHOIS);
|
||||
|
@ -464,12 +464,12 @@ bool IncomingPacket::_doWHOIS(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
|||
outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
|
||||
outp.append(payload(),ZT_ADDRESS_LENGTH);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
} else {
|
||||
TRACE("dropped WHOIS from %s(%s): missing or invalid address",source().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
}
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_WHOIS,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_WHOIS,0,Packet::VERB_NOP);
|
||||
} catch ( ... ) {
|
||||
TRACE("dropped WHOIS from %s(%s): unexpected exception",source().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
}
|
||||
|
@ -487,8 +487,8 @@ bool IncomingPacket::_doRENDEZVOUS(const RuntimeEnvironment *RR,const SharedPtr<
|
|||
if ((port > 0)&&((addrlen == 4)||(addrlen == 16))) {
|
||||
InetAddress atAddr(field(ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRESS,addrlen),addrlen,port);
|
||||
TRACE("RENDEZVOUS from %s says %s might be at %s, starting NAT-t",peer->address().toString().c_str(),with.toString().c_str(),atAddr.toString().c_str());
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_RENDEZVOUS,0,Packet::VERB_NOP);
|
||||
RR->sw->rendezvous(withPeer,_localInterfaceId,atAddr);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_RENDEZVOUS,0,Packet::VERB_NOP);
|
||||
RR->sw->rendezvous(withPeer,_localAddress,atAddr);
|
||||
} else {
|
||||
TRACE("dropped corrupt RENDEZVOUS from %s(%s) (bad address or port)",peer->address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ bool IncomingPacket::_doFRAME(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
|||
RR->node->putFrame(network->id(),MAC(peer->address(),network->id()),network->mac(),etherType,0,field(ZT_PROTO_VERB_FRAME_IDX_PAYLOAD,payloadLen),payloadLen);
|
||||
}
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_FRAME,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_FRAME,0,Packet::VERB_NOP);
|
||||
} else {
|
||||
TRACE("dropped FRAME from %s(%s): we are not connected to network %.16llx",source().toString().c_str(),_remoteAddress.toString().c_str(),at<uint64_t>(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID));
|
||||
}
|
||||
|
@ -602,7 +602,7 @@ bool IncomingPacket::_doEXT_FRAME(const RuntimeEnvironment *RR,const SharedPtr<P
|
|||
RR->node->putFrame(network->id(),from,to,etherType,0,field(comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_PAYLOAD,payloadLen),payloadLen);
|
||||
}
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP);
|
||||
} else {
|
||||
TRACE("dropped EXT_FRAME from %s(%s): we are not connected to network %.16llx",source().toString().c_str(),_remoteAddress.toString().c_str(),at<uint64_t>(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID));
|
||||
}
|
||||
|
@ -623,7 +623,7 @@ bool IncomingPacket::_doMULTICAST_LIKE(const RuntimeEnvironment *RR,const Shared
|
|||
for(unsigned int ptr=ZT_PACKET_IDX_PAYLOAD;ptr<size();ptr+=18)
|
||||
RR->mc->add(now,at<uint64_t>(ptr),MulticastGroup(MAC(field(ptr + 8,6),6),at<uint32_t>(ptr + 14)),peer->address());
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP);
|
||||
} catch (std::exception &ex) {
|
||||
TRACE("dropped MULTICAST_LIKE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -647,7 +647,7 @@ bool IncomingPacket::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment
|
|||
}
|
||||
}
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE,0,Packet::VERB_NOP);
|
||||
} catch (std::exception &ex) {
|
||||
TRACE("dropped NETWORK_MEMBERSHIP_CERTIFICATE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -666,7 +666,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
|||
|
||||
const unsigned int h = hops();
|
||||
const uint64_t pid = packetId();
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,h,pid,Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,h,pid,Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP);
|
||||
|
||||
if (RR->localNetworkController) {
|
||||
Dictionary netconf;
|
||||
|
@ -688,7 +688,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
|||
if (outp.size() > ZT_PROTO_MAX_PACKET_LENGTH) {
|
||||
TRACE("NETWORK_CONFIG_REQUEST failed: internal error: netconf size %u is too large",(unsigned int)netconfStr.length());
|
||||
} else {
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -700,7 +700,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
|||
outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
|
||||
outp.append(nwid);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
} break;
|
||||
|
||||
case NetworkController::NETCONF_QUERY_ACCESS_DENIED: {
|
||||
|
@ -710,7 +710,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
|||
outp.append((unsigned char)Packet::ERROR_NETWORK_ACCESS_DENIED_);
|
||||
outp.append(nwid);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
} break;
|
||||
|
||||
case NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR:
|
||||
|
@ -732,7 +732,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
|||
outp.append((unsigned char)Packet::ERROR_UNSUPPORTED_OPERATION);
|
||||
outp.append(nwid);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
} catch (std::exception &exc) {
|
||||
TRACE("dropped NETWORK_CONFIG_REQUEST from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
||||
|
@ -753,7 +753,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REFRESH(const RuntimeEnvironment *RR,cons
|
|||
nw->requestConfiguration();
|
||||
ptr += 8;
|
||||
}
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REFRESH,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REFRESH,0,Packet::VERB_NOP);
|
||||
} catch (std::exception &exc) {
|
||||
TRACE("dropped NETWORK_CONFIG_REFRESH from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -780,11 +780,11 @@ bool IncomingPacket::_doMULTICAST_GATHER(const RuntimeEnvironment *RR,const Shar
|
|||
outp.append((uint32_t)mg.adi());
|
||||
if (RR->mc->gather(peer->address(),nwid,mg,outp,gatherLimit)) {
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
}
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_GATHER,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_GATHER,0,Packet::VERB_NOP);
|
||||
} catch (std::exception &exc) {
|
||||
TRACE("dropped MULTICAST_GATHER from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -871,12 +871,12 @@ bool IncomingPacket::_doMULTICAST_FRAME(const RuntimeEnvironment *RR,const Share
|
|||
outp.append((unsigned char)0x02); // flag 0x02 = contains gather results
|
||||
if (RR->mc->gather(peer->address(),nwid,to,outp,gatherLimit)) {
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
}
|
||||
} // else ignore -- not a member of this network
|
||||
|
||||
peer->received(RR,_localInterfaceId,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_FRAME,0,Packet::VERB_NOP);
|
||||
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_FRAME,0,Packet::VERB_NOP);
|
||||
} catch (std::exception &exc) {
|
||||
TRACE("dropped MULTICAST_FRAME from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
||||
} catch ( ... ) {
|
||||
|
@ -905,14 +905,14 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha
|
|||
InetAddress a(field(ptr,4),4,at<uint16_t>(ptr + 4));
|
||||
if ( ((flags & (0x01 | 0x02)) == 0) && (Path::isAddressValidForPath(a)) ) {
|
||||
TRACE("attempting to contact %s at pushed direct path %s",peer->address().toString().c_str(),a.toString().c_str());
|
||||
peer->attemptToContactAt(RR,_localInterfaceId,a,RR->node->now());
|
||||
peer->attemptToContactAt(RR,_localAddress,a,RR->node->now());
|
||||
}
|
||||
} break;
|
||||
case 6: {
|
||||
InetAddress a(field(ptr,16),16,at<uint16_t>(ptr + 16));
|
||||
if ( ((flags & (0x01 | 0x02)) == 0) && (Path::isAddressValidForPath(a)) ) {
|
||||
TRACE("attempting to contact %s at pushed direct path %s",peer->address().toString().c_str(),a.toString().c_str());
|
||||
peer->attemptToContactAt(RR,_localInterfaceId,a,RR->node->now());
|
||||
peer->attemptToContactAt(RR,_localAddress,a,RR->node->now());
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
@ -934,7 +934,7 @@ void IncomingPacket::_sendErrorNeedCertificate(const RuntimeEnvironment *RR,cons
|
|||
outp.append((unsigned char)Packet::ERROR_NEED_MEMBERSHIP_CERTIFICATE);
|
||||
outp.append(nwid);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localInterfaceId,_remoteAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -72,16 +72,16 @@ public:
|
|||
*
|
||||
* @param data Packet data
|
||||
* @param len Packet length
|
||||
* @param localInterfaceId Local interface ID
|
||||
* @param localAddress Local interface address
|
||||
* @param remoteAddress Address from which packet came
|
||||
* @param now Current time
|
||||
* @throws std::out_of_range Range error processing packet
|
||||
*/
|
||||
IncomingPacket(const void *data,unsigned int len,int localInterfaceId,const InetAddress &remoteAddress,uint64_t now) :
|
||||
IncomingPacket(const void *data,unsigned int len,const InetAddress &localAddress,const InetAddress &remoteAddress,uint64_t now) :
|
||||
Packet(data,len),
|
||||
_receiveTime(now),
|
||||
_localAddress(localAddress),
|
||||
_remoteAddress(remoteAddress),
|
||||
_localInterfaceId(localInterfaceId),
|
||||
__refCount()
|
||||
{
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ private:
|
|||
void _sendErrorNeedCertificate(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer,uint64_t nwid);
|
||||
|
||||
uint64_t _receiveTime;
|
||||
InetAddress _localAddress;
|
||||
InetAddress _remoteAddress;
|
||||
int _localInterfaceId;
|
||||
AtomicCounter __refCount;
|
||||
};
|
||||
|
||||
|
|
|
@ -100,28 +100,28 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t nwid) :
|
|||
}
|
||||
|
||||
if (!_portInitialized) {
|
||||
ZT1_VirtualNetworkConfig ctmp;
|
||||
ZT_VirtualNetworkConfig ctmp;
|
||||
_externalConfig(&ctmp);
|
||||
_portError = RR->node->configureVirtualNetworkPort(_id,ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||
_portError = RR->node->configureVirtualNetworkPort(_id,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||
_portInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Network::~Network()
|
||||
{
|
||||
ZT1_VirtualNetworkConfig ctmp;
|
||||
ZT_VirtualNetworkConfig ctmp;
|
||||
_externalConfig(&ctmp);
|
||||
|
||||
char n[128];
|
||||
if (_destroyed) {
|
||||
RR->node->configureVirtualNetworkPort(_id,ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY,&ctmp);
|
||||
RR->node->configureVirtualNetworkPort(_id,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY,&ctmp);
|
||||
|
||||
Utils::snprintf(n,sizeof(n),"networks.d/%.16llx.conf",_id);
|
||||
RR->node->dataStoreDelete(n);
|
||||
Utils::snprintf(n,sizeof(n),"networks.d/%.16llx.mcerts",_id);
|
||||
RR->node->dataStoreDelete(n);
|
||||
} else {
|
||||
RR->node->configureVirtualNetworkPort(_id,ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN,&ctmp);
|
||||
RR->node->configureVirtualNetworkPort(_id,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN,&ctmp);
|
||||
|
||||
clean();
|
||||
|
||||
|
@ -184,7 +184,7 @@ bool Network::applyConfiguration(const SharedPtr<NetworkConfig> &conf)
|
|||
return false;
|
||||
try {
|
||||
if ((conf->networkId() == _id)&&(conf->issuedTo() == RR->identity.address())) {
|
||||
ZT1_VirtualNetworkConfig ctmp;
|
||||
ZT_VirtualNetworkConfig ctmp;
|
||||
bool portInitialized;
|
||||
{
|
||||
Mutex::Lock _l(_lock);
|
||||
|
@ -195,7 +195,7 @@ bool Network::applyConfiguration(const SharedPtr<NetworkConfig> &conf)
|
|||
portInitialized = _portInitialized;
|
||||
_portInitialized = true;
|
||||
}
|
||||
_portError = RR->node->configureVirtualNetworkPort(_id,(portInitialized) ? ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE : ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||
_portError = RR->node->configureVirtualNetworkPort(_id,(portInitialized) ? ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE : ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||
return true;
|
||||
} else {
|
||||
TRACE("ignored invalid configuration for network %.16llx (configuration contains mismatched network ID or issued-to address)",(unsigned long long)_id);
|
||||
|
@ -431,9 +431,9 @@ void Network::setEnabled(bool enabled)
|
|||
Mutex::Lock _l(_lock);
|
||||
if (_enabled != enabled) {
|
||||
_enabled = enabled;
|
||||
ZT1_VirtualNetworkConfig ctmp;
|
||||
ZT_VirtualNetworkConfig ctmp;
|
||||
_externalConfig(&ctmp);
|
||||
_portError = RR->node->configureVirtualNetworkPort(_id,ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE,&ctmp);
|
||||
_portError = RR->node->configureVirtualNetworkPort(_id,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE,&ctmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,24 +444,24 @@ void Network::destroy()
|
|||
_destroyed = true;
|
||||
}
|
||||
|
||||
ZT1_VirtualNetworkStatus Network::_status() const
|
||||
ZT_VirtualNetworkStatus Network::_status() const
|
||||
{
|
||||
// assumes _lock is locked
|
||||
if (_portError)
|
||||
return ZT1_NETWORK_STATUS_PORT_ERROR;
|
||||
return ZT_NETWORK_STATUS_PORT_ERROR;
|
||||
switch(_netconfFailure) {
|
||||
case NETCONF_FAILURE_ACCESS_DENIED:
|
||||
return ZT1_NETWORK_STATUS_ACCESS_DENIED;
|
||||
return ZT_NETWORK_STATUS_ACCESS_DENIED;
|
||||
case NETCONF_FAILURE_NOT_FOUND:
|
||||
return ZT1_NETWORK_STATUS_NOT_FOUND;
|
||||
return ZT_NETWORK_STATUS_NOT_FOUND;
|
||||
case NETCONF_FAILURE_NONE:
|
||||
return ((_config) ? ZT1_NETWORK_STATUS_OK : ZT1_NETWORK_STATUS_REQUESTING_CONFIGURATION);
|
||||
return ((_config) ? ZT_NETWORK_STATUS_OK : ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION);
|
||||
default:
|
||||
return ZT1_NETWORK_STATUS_PORT_ERROR;
|
||||
return ZT_NETWORK_STATUS_PORT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
void Network::_externalConfig(ZT1_VirtualNetworkConfig *ec) const
|
||||
void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||
{
|
||||
// assumes _lock is locked
|
||||
ec->nwid = _id;
|
||||
|
@ -470,7 +470,7 @@ void Network::_externalConfig(ZT1_VirtualNetworkConfig *ec) const
|
|||
Utils::scopy(ec->name,sizeof(ec->name),_config->name().c_str());
|
||||
else ec->name[0] = (char)0;
|
||||
ec->status = _status();
|
||||
ec->type = (_config) ? (_config->isPrivate() ? ZT1_NETWORK_TYPE_PRIVATE : ZT1_NETWORK_TYPE_PUBLIC) : ZT1_NETWORK_TYPE_PRIVATE;
|
||||
ec->type = (_config) ? (_config->isPrivate() ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC) : ZT_NETWORK_TYPE_PRIVATE;
|
||||
ec->mtu = ZT_IF_MTU;
|
||||
ec->dhcp = 0;
|
||||
ec->bridge = (_config) ? ((_config->allowPassiveBridging() || (std::find(_config->activeBridges().begin(),_config->activeBridges().end(),RR->identity.address()) != _config->activeBridges().end())) ? 1 : 0) : 0;
|
||||
|
@ -479,7 +479,7 @@ void Network::_externalConfig(ZT1_VirtualNetworkConfig *ec) const
|
|||
ec->enabled = (_enabled) ? 1 : 0;
|
||||
ec->netconfRevision = (_config) ? (unsigned long)_config->revision() : 0;
|
||||
|
||||
ec->multicastSubscriptionCount = std::min((unsigned int)_myMulticastGroups.size(),(unsigned int)ZT1_MAX_NETWORK_MULTICAST_SUBSCRIPTIONS);
|
||||
ec->multicastSubscriptionCount = std::min((unsigned int)_myMulticastGroups.size(),(unsigned int)ZT_MAX_NETWORK_MULTICAST_SUBSCRIPTIONS);
|
||||
for(unsigned int i=0;i<ec->multicastSubscriptionCount;++i) {
|
||||
ec->multicastSubscriptions[i].mac = _myMulticastGroups[i].mac().toInt();
|
||||
ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi();
|
||||
|
@ -487,7 +487,7 @@ void Network::_externalConfig(ZT1_VirtualNetworkConfig *ec) const
|
|||
|
||||
if (_config) {
|
||||
ec->assignedAddressCount = (unsigned int)_config->staticIps().size();
|
||||
for(unsigned long i=0;i<ZT1_MAX_ZT_ASSIGNED_ADDRESSES;++i) {
|
||||
for(unsigned long i=0;i<ZT_MAX_ZT_ASSIGNED_ADDRESSES;++i) {
|
||||
if (i < _config->staticIps().size())
|
||||
memcpy(&(ec->assignedAddresses[i]),&(_config->staticIps()[i]),sizeof(struct sockaddr_storage));
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ public:
|
|||
/**
|
||||
* @return Status of this network
|
||||
*/
|
||||
inline ZT1_VirtualNetworkStatus status() const
|
||||
inline ZT_VirtualNetworkStatus status() const
|
||||
{
|
||||
Mutex::Lock _l(_lock);
|
||||
return _status();
|
||||
|
@ -231,7 +231,7 @@ public:
|
|||
/**
|
||||
* @param ec Buffer to fill with externally-visible network configuration
|
||||
*/
|
||||
inline void externalConfig(ZT1_VirtualNetworkConfig *ec) const
|
||||
inline void externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||
{
|
||||
Mutex::Lock _l(_lock);
|
||||
_externalConfig(ec);
|
||||
|
@ -354,8 +354,8 @@ private:
|
|||
uint64_t lastPushed; // when did we last push ours to them?
|
||||
};
|
||||
|
||||
ZT1_VirtualNetworkStatus _status() const;
|
||||
void _externalConfig(ZT1_VirtualNetworkConfig *ec) const; // assumes _lock is locked
|
||||
ZT_VirtualNetworkStatus _status() const;
|
||||
void _externalConfig(ZT_VirtualNetworkConfig *ec) const; // assumes _lock is locked
|
||||
bool _isAllowed(const Address &peer) const;
|
||||
void _announceMulticastGroups();
|
||||
std::vector<MulticastGroup> _allMulticastGroups() const;
|
||||
|
|
|
@ -108,7 +108,7 @@ void NetworkConfig::_fromDictionary(const Dictionary &d)
|
|||
_private = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE,one).c_str()) != 0);
|
||||
_enableBroadcast = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0);
|
||||
_name = d.get(ZT_NETWORKCONFIG_DICT_KEY_NAME);
|
||||
if (_name.length() > ZT1_MAX_NETWORK_SHORT_NAME_LENGTH)
|
||||
if (_name.length() > ZT_MAX_NETWORK_SHORT_NAME_LENGTH)
|
||||
throw std::invalid_argument("network short name too long (max: 255 characters)");
|
||||
|
||||
// In dictionary IPs are split into V4 and V6 addresses, but we don't really
|
||||
|
@ -142,8 +142,8 @@ void NetworkConfig::_fromDictionary(const Dictionary &d)
|
|||
_localRoutes.push_back(addr);
|
||||
else _staticIps.push_back(addr);
|
||||
}
|
||||
if (_localRoutes.size() > ZT1_MAX_ZT_ASSIGNED_ADDRESSES) throw std::invalid_argument("too many ZT-assigned routes");
|
||||
if (_staticIps.size() > ZT1_MAX_ZT_ASSIGNED_ADDRESSES) throw std::invalid_argument("too many ZT-assigned IP addresses");
|
||||
if (_localRoutes.size() > ZT_MAX_ZT_ASSIGNED_ADDRESSES) throw std::invalid_argument("too many ZT-assigned routes");
|
||||
if (_staticIps.size() > ZT_MAX_ZT_ASSIGNED_ADDRESSES) throw std::invalid_argument("too many ZT-assigned IP addresses");
|
||||
std::sort(_localRoutes.begin(),_localRoutes.end());
|
||||
_localRoutes.erase(std::unique(_localRoutes.begin(),_localRoutes.end()),_localRoutes.end());
|
||||
std::sort(_staticIps.begin(),_staticIps.end());
|
||||
|
|
214
node/Node.cpp
214
node/Node.cpp
|
@ -48,6 +48,8 @@
|
|||
#include "SelfAwareness.hpp"
|
||||
#include "Defaults.hpp"
|
||||
|
||||
const struct sockaddr_storage ZT_SOCKADDR_NULL = {0};
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/****************************************************************************/
|
||||
|
@ -57,12 +59,12 @@ namespace ZeroTier {
|
|||
Node::Node(
|
||||
uint64_t now,
|
||||
void *uptr,
|
||||
ZT1_DataStoreGetFunction dataStoreGetFunction,
|
||||
ZT1_DataStorePutFunction dataStorePutFunction,
|
||||
ZT1_WirePacketSendFunction wirePacketSendFunction,
|
||||
ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
||||
ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
||||
ZT1_EventCallback eventCallback,
|
||||
ZT_DataStoreGetFunction dataStoreGetFunction,
|
||||
ZT_DataStorePutFunction dataStorePutFunction,
|
||||
ZT_WirePacketSendFunction wirePacketSendFunction,
|
||||
ZT_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
||||
ZT_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
||||
ZT_EventCallback eventCallback,
|
||||
const char *overrideRootTopology) :
|
||||
_RR(this),
|
||||
RR(&_RR),
|
||||
|
@ -141,7 +143,7 @@ Node::Node(
|
|||
}
|
||||
RR->topology->setRootServers(Dictionary(rt.get("rootservers","")));
|
||||
|
||||
postEvent(ZT1_EVENT_UP);
|
||||
postEvent(ZT_EVENT_UP);
|
||||
}
|
||||
|
||||
Node::~Node()
|
||||
|
@ -155,20 +157,20 @@ Node::~Node()
|
|||
delete RR->sw;
|
||||
}
|
||||
|
||||
ZT1_ResultCode Node::processWirePacket(
|
||||
ZT_ResultCode Node::processWirePacket(
|
||||
uint64_t now,
|
||||
int localInterfaceId,
|
||||
const struct sockaddr_storage *localAddress,
|
||||
const struct sockaddr_storage *remoteAddress,
|
||||
const void *packetData,
|
||||
unsigned int packetLength,
|
||||
volatile uint64_t *nextBackgroundTaskDeadline)
|
||||
{
|
||||
_now = now;
|
||||
RR->sw->onRemotePacket(localInterfaceId,*(reinterpret_cast<const InetAddress *>(remoteAddress)),packetData,packetLength);
|
||||
return ZT1_RESULT_OK;
|
||||
RR->sw->onRemotePacket(*(reinterpret_cast<const InetAddress *>(localAddress)),*(reinterpret_cast<const InetAddress *>(remoteAddress)),packetData,packetLength);
|
||||
return ZT_RESULT_OK;
|
||||
}
|
||||
|
||||
ZT1_ResultCode Node::processVirtualNetworkFrame(
|
||||
ZT_ResultCode Node::processVirtualNetworkFrame(
|
||||
uint64_t now,
|
||||
uint64_t nwid,
|
||||
uint64_t sourceMac,
|
||||
|
@ -183,8 +185,8 @@ ZT1_ResultCode Node::processVirtualNetworkFrame(
|
|||
SharedPtr<Network> nw(this->network(nwid));
|
||||
if (nw) {
|
||||
RR->sw->onLocalEthernet(nw,MAC(sourceMac),MAC(destMac),etherType,vlanId,frameData,frameLength);
|
||||
return ZT1_RESULT_OK;
|
||||
} else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
return ZT_RESULT_OK;
|
||||
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
}
|
||||
|
||||
class _PingPeersThatNeedPing
|
||||
|
@ -228,7 +230,7 @@ private:
|
|||
std::vector<Address> _rootAddresses;
|
||||
};
|
||||
|
||||
ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
|
||||
ZT_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
|
||||
{
|
||||
_now = now;
|
||||
Mutex::Lock bl(_backgroundTasksLock);
|
||||
|
@ -264,7 +266,7 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
|
|||
if (nr->second) {
|
||||
SharedPtr<Peer> rp(RR->topology->getPeer(nr->first));
|
||||
if ((rp)&&(!rp->hasActiveDirectPath(now)))
|
||||
rp->attemptToContactAt(RR,-1,nr->second,now);
|
||||
rp->attemptToContactAt(RR,InetAddress(),nr->second,now);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,9 +278,9 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
|
|||
bool oldOnline = _online;
|
||||
_online = ((now - pfunc.lastReceiveFromUpstream) < ZT_PEER_ACTIVITY_TIMEOUT);
|
||||
if (oldOnline != _online)
|
||||
postEvent(_online ? ZT1_EVENT_ONLINE : ZT1_EVENT_OFFLINE);
|
||||
postEvent(_online ? ZT_EVENT_ONLINE : ZT_EVENT_OFFLINE);
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
} else {
|
||||
timeUntilNextPingCheck -= (unsigned long)timeSinceLastPingCheck;
|
||||
|
@ -291,30 +293,30 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
|
|||
RR->sa->clean(now);
|
||||
RR->mc->clean(now);
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
*nextBackgroundTaskDeadline = now + (uint64_t)std::max(std::min(timeUntilNextPingCheck,RR->sw->doTimerTasks(now)),(unsigned long)ZT_CORE_TIMER_TASK_GRANULARITY);
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return ZT1_RESULT_OK;
|
||||
return ZT_RESULT_OK;
|
||||
}
|
||||
|
||||
ZT1_ResultCode Node::join(uint64_t nwid)
|
||||
ZT_ResultCode Node::join(uint64_t nwid)
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
SharedPtr<Network> nw = _network(nwid);
|
||||
if(!nw)
|
||||
_networks.push_back(std::pair< uint64_t,SharedPtr<Network> >(nwid,SharedPtr<Network>(new Network(RR,nwid))));
|
||||
std::sort(_networks.begin(),_networks.end()); // will sort by nwid since it's the first in a pair<>
|
||||
return ZT1_RESULT_OK;
|
||||
return ZT_RESULT_OK;
|
||||
}
|
||||
|
||||
ZT1_ResultCode Node::leave(uint64_t nwid)
|
||||
ZT_ResultCode Node::leave(uint64_t nwid)
|
||||
{
|
||||
std::vector< std::pair< uint64_t,SharedPtr<Network> > > newn;
|
||||
Mutex::Lock _l(_networks_m);
|
||||
|
@ -324,25 +326,25 @@ ZT1_ResultCode Node::leave(uint64_t nwid)
|
|||
else n->second->destroy();
|
||||
}
|
||||
_networks.swap(newn);
|
||||
return ZT1_RESULT_OK;
|
||||
return ZT_RESULT_OK;
|
||||
}
|
||||
|
||||
ZT1_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
ZT_ResultCode Node::multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
{
|
||||
SharedPtr<Network> nw(this->network(nwid));
|
||||
if (nw) {
|
||||
nw->multicastSubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
|
||||
return ZT1_RESULT_OK;
|
||||
} else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
return ZT_RESULT_OK;
|
||||
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
}
|
||||
|
||||
ZT1_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
ZT_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
{
|
||||
SharedPtr<Network> nw(this->network(nwid));
|
||||
if (nw) {
|
||||
nw->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
|
||||
return ZT1_RESULT_OK;
|
||||
} else return ZT1_RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
return ZT_RESULT_OK;
|
||||
} else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
|
||||
}
|
||||
|
||||
uint64_t Node::address() const
|
||||
|
@ -350,7 +352,7 @@ uint64_t Node::address() const
|
|||
return RR->identity.address().toInt();
|
||||
}
|
||||
|
||||
void Node::status(ZT1_NodeStatus *status) const
|
||||
void Node::status(ZT_NodeStatus *status) const
|
||||
{
|
||||
status->address = RR->identity.address().toInt();
|
||||
status->publicIdentity = RR->publicIdentityStr.c_str();
|
||||
|
@ -358,20 +360,20 @@ void Node::status(ZT1_NodeStatus *status) const
|
|||
status->online = _online ? 1 : 0;
|
||||
}
|
||||
|
||||
ZT1_PeerList *Node::peers() const
|
||||
ZT_PeerList *Node::peers() const
|
||||
{
|
||||
std::vector< std::pair< Address,SharedPtr<Peer> > > peers(RR->topology->allPeers());
|
||||
std::sort(peers.begin(),peers.end());
|
||||
|
||||
char *buf = (char *)::malloc(sizeof(ZT1_PeerList) + (sizeof(ZT1_Peer) * peers.size()));
|
||||
char *buf = (char *)::malloc(sizeof(ZT_PeerList) + (sizeof(ZT_Peer) * peers.size()));
|
||||
if (!buf)
|
||||
return (ZT1_PeerList *)0;
|
||||
ZT1_PeerList *pl = (ZT1_PeerList *)buf;
|
||||
pl->peers = (ZT1_Peer *)(buf + sizeof(ZT1_PeerList));
|
||||
return (ZT_PeerList *)0;
|
||||
ZT_PeerList *pl = (ZT_PeerList *)buf;
|
||||
pl->peers = (ZT_Peer *)(buf + sizeof(ZT_PeerList));
|
||||
|
||||
pl->peerCount = 0;
|
||||
for(std::vector< std::pair< Address,SharedPtr<Peer> > >::iterator pi(peers.begin());pi!=peers.end();++pi) {
|
||||
ZT1_Peer *p = &(pl->peers[pl->peerCount++]);
|
||||
ZT_Peer *p = &(pl->peers[pl->peerCount++]);
|
||||
p->address = pi->second->address().toInt();
|
||||
p->lastUnicastFrame = pi->second->lastUnicastFrame();
|
||||
p->lastMulticastFrame = pi->second->lastMulticastFrame();
|
||||
|
@ -385,7 +387,7 @@ ZT1_PeerList *Node::peers() const
|
|||
p->versionRev = -1;
|
||||
}
|
||||
p->latency = pi->second->latency();
|
||||
p->role = RR->topology->isRoot(pi->second->identity()) ? ZT1_PEER_ROLE_ROOT : ZT1_PEER_ROLE_LEAF;
|
||||
p->role = RR->topology->isRoot(pi->second->identity()) ? ZT_PEER_ROLE_ROOT : ZT_PEER_ROLE_LEAF;
|
||||
|
||||
std::vector<RemotePath> paths(pi->second->paths());
|
||||
RemotePath *bestPath = pi->second->getBestPath(_now);
|
||||
|
@ -404,27 +406,27 @@ ZT1_PeerList *Node::peers() const
|
|||
return pl;
|
||||
}
|
||||
|
||||
ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
||||
ZT_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
SharedPtr<Network> nw = _network(nwid);
|
||||
if(nw) {
|
||||
ZT1_VirtualNetworkConfig *nc = (ZT1_VirtualNetworkConfig *)::malloc(sizeof(ZT1_VirtualNetworkConfig));
|
||||
ZT_VirtualNetworkConfig *nc = (ZT_VirtualNetworkConfig *)::malloc(sizeof(ZT_VirtualNetworkConfig));
|
||||
nw->externalConfig(nc);
|
||||
return nc;
|
||||
}
|
||||
return (ZT1_VirtualNetworkConfig *)0;
|
||||
return (ZT_VirtualNetworkConfig *)0;
|
||||
}
|
||||
|
||||
ZT1_VirtualNetworkList *Node::networks() const
|
||||
ZT_VirtualNetworkList *Node::networks() const
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
|
||||
char *buf = (char *)::malloc(sizeof(ZT1_VirtualNetworkList) + (sizeof(ZT1_VirtualNetworkConfig) * _networks.size()));
|
||||
char *buf = (char *)::malloc(sizeof(ZT_VirtualNetworkList) + (sizeof(ZT_VirtualNetworkConfig) * _networks.size()));
|
||||
if (!buf)
|
||||
return (ZT1_VirtualNetworkList *)0;
|
||||
ZT1_VirtualNetworkList *nl = (ZT1_VirtualNetworkList *)buf;
|
||||
nl->networks = (ZT1_VirtualNetworkConfig *)(buf + sizeof(ZT1_VirtualNetworkList));
|
||||
return (ZT_VirtualNetworkList *)0;
|
||||
ZT_VirtualNetworkList *nl = (ZT_VirtualNetworkList *)buf;
|
||||
nl->networks = (ZT_VirtualNetworkConfig *)(buf + sizeof(ZT_VirtualNetworkList));
|
||||
|
||||
nl->networkCount = 0;
|
||||
for(std::vector< std::pair< uint64_t,SharedPtr<Network> > >::const_iterator n(_networks.begin());n!=_networks.end();++n)
|
||||
|
@ -439,7 +441,7 @@ void Node::freeQueryResult(void *qr)
|
|||
::free(qr);
|
||||
}
|
||||
|
||||
int Node::addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT1_LocalInterfaceAddressTrust trust)
|
||||
int Node::addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT_LocalInterfaceAddressTrust trust)
|
||||
{
|
||||
if (Path::isAddressValidForPath(*(reinterpret_cast<const InetAddress *>(addr)))) {
|
||||
Mutex::Lock _l(_directPaths_m);
|
||||
|
@ -472,7 +474,7 @@ std::string Node::dataStoreGet(const char *name)
|
|||
std::string r;
|
||||
unsigned long olen = 0;
|
||||
do {
|
||||
long n = _dataStoreGetFunction(reinterpret_cast<ZT1_Node *>(this),_uPtr,name,buf,sizeof(buf),(unsigned long)r.length(),&olen);
|
||||
long n = _dataStoreGetFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,name,buf,sizeof(buf),(unsigned long)r.length(),&olen);
|
||||
if (n <= 0)
|
||||
return std::string();
|
||||
r.append(buf,n);
|
||||
|
@ -486,7 +488,7 @@ void Node::postNewerVersionIfNewer(unsigned int major,unsigned int minor,unsigne
|
|||
_newestVersionSeen[0] = major;
|
||||
_newestVersionSeen[1] = minor;
|
||||
_newestVersionSeen[2] = rev;
|
||||
this->postEvent(ZT1_EVENT_SAW_MORE_RECENT_VERSION,(const void *)_newestVersionSeen);
|
||||
this->postEvent(ZT_EVENT_SAW_MORE_RECENT_VERSION,(const void *)_newestVersionSeen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,7 +521,7 @@ void Node::postTrace(const char *module,unsigned int line,const char *fmt,...)
|
|||
tmp2[sizeof(tmp2)-1] = (char)0;
|
||||
|
||||
Utils::snprintf(tmp1,sizeof(tmp1),"[%s] %s:%u %s",nowstr,module,line,tmp2);
|
||||
postEvent(ZT1_EVENT_TRACE,tmp1);
|
||||
postEvent(ZT_EVENT_TRACE,tmp1);
|
||||
}
|
||||
#endif // ZT_TRACE
|
||||
|
||||
|
@ -539,59 +541,59 @@ uint64_t Node::prng()
|
|||
|
||||
extern "C" {
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_new(
|
||||
ZT1_Node **node,
|
||||
enum ZT_ResultCode ZT_Node_new(
|
||||
ZT_Node **node,
|
||||
void *uptr,
|
||||
uint64_t now,
|
||||
ZT1_DataStoreGetFunction dataStoreGetFunction,
|
||||
ZT1_DataStorePutFunction dataStorePutFunction,
|
||||
ZT1_WirePacketSendFunction wirePacketSendFunction,
|
||||
ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
||||
ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
||||
ZT1_EventCallback eventCallback,
|
||||
ZT_DataStoreGetFunction dataStoreGetFunction,
|
||||
ZT_DataStorePutFunction dataStorePutFunction,
|
||||
ZT_WirePacketSendFunction wirePacketSendFunction,
|
||||
ZT_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
||||
ZT_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
||||
ZT_EventCallback eventCallback,
|
||||
const char *overrideRootTopology)
|
||||
{
|
||||
*node = (ZT1_Node *)0;
|
||||
*node = (ZT_Node *)0;
|
||||
try {
|
||||
*node = reinterpret_cast<ZT1_Node *>(new ZeroTier::Node(now,uptr,dataStoreGetFunction,dataStorePutFunction,wirePacketSendFunction,virtualNetworkFrameFunction,virtualNetworkConfigFunction,eventCallback,overrideRootTopology));
|
||||
return ZT1_RESULT_OK;
|
||||
*node = reinterpret_cast<ZT_Node *>(new ZeroTier::Node(now,uptr,dataStoreGetFunction,dataStorePutFunction,wirePacketSendFunction,virtualNetworkFrameFunction,virtualNetworkConfigFunction,eventCallback,overrideRootTopology));
|
||||
return ZT_RESULT_OK;
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch (std::runtime_error &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
|
||||
return ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
void ZT1_Node_delete(ZT1_Node *node)
|
||||
void ZT_Node_delete(ZT_Node *node)
|
||||
{
|
||||
try {
|
||||
delete (reinterpret_cast<ZeroTier::Node *>(node));
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_processWirePacket(
|
||||
ZT1_Node *node,
|
||||
enum ZT_ResultCode ZT_Node_processWirePacket(
|
||||
ZT_Node *node,
|
||||
uint64_t now,
|
||||
int localInterfaceId,
|
||||
const struct sockaddr_storage *localAddress,
|
||||
const struct sockaddr_storage *remoteAddress,
|
||||
const void *packetData,
|
||||
unsigned int packetLength,
|
||||
volatile uint64_t *nextBackgroundTaskDeadline)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(now,localInterfaceId,remoteAddress,packetData,packetLength,nextBackgroundTaskDeadline);
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(now,localAddress,remoteAddress,packetData,packetLength,nextBackgroundTaskDeadline);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
reinterpret_cast<ZeroTier::Node *>(node)->postEvent(ZT1_EVENT_INVALID_PACKET,(const void *)remoteAddress);
|
||||
return ZT1_RESULT_OK;
|
||||
reinterpret_cast<ZeroTier::Node *>(node)->postEvent(ZT_EVENT_INVALID_PACKET,(const void *)remoteAddress);
|
||||
return ZT_RESULT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_processVirtualNetworkFrame(
|
||||
ZT1_Node *node,
|
||||
enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
|
||||
ZT_Node *node,
|
||||
uint64_t now,
|
||||
uint64_t nwid,
|
||||
uint64_t sourceMac,
|
||||
|
@ -605,121 +607,121 @@ enum ZT1_ResultCode ZT1_Node_processVirtualNetworkFrame(
|
|||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(now,nwid,sourceMac,destMac,etherType,vlanId,frameData,frameLength,nextBackgroundTaskDeadline);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_processBackgroundTasks(ZT1_Node *node,uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
|
||||
enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node,uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(now,nextBackgroundTaskDeadline);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_join(ZT1_Node *node,uint64_t nwid)
|
||||
enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_leave(ZT1_Node *node,uint64_t nwid)
|
||||
enum ZT_ResultCode ZT_Node_leave(ZT_Node *node,uint64_t nwid)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_multicastSubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(nwid,multicastGroup,multicastAdi);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
enum ZT1_ResultCode ZT1_Node_multicastUnsubscribe(ZT1_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
|
||||
} catch (std::bad_alloc &exc) {
|
||||
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
|
||||
} catch ( ... ) {
|
||||
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
|
||||
return ZT_RESULT_FATAL_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ZT1_Node_address(ZT1_Node *node)
|
||||
uint64_t ZT_Node_address(ZT_Node *node)
|
||||
{
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->address();
|
||||
}
|
||||
|
||||
void ZT1_Node_status(ZT1_Node *node,ZT1_NodeStatus *status)
|
||||
void ZT_Node_status(ZT_Node *node,ZT_NodeStatus *status)
|
||||
{
|
||||
try {
|
||||
reinterpret_cast<ZeroTier::Node *>(node)->status(status);
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
|
||||
ZT1_PeerList *ZT1_Node_peers(ZT1_Node *node)
|
||||
ZT_PeerList *ZT_Node_peers(ZT_Node *node)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->peers();
|
||||
} catch ( ... ) {
|
||||
return (ZT1_PeerList *)0;
|
||||
return (ZT_PeerList *)0;
|
||||
}
|
||||
}
|
||||
|
||||
ZT1_VirtualNetworkConfig *ZT1_Node_networkConfig(ZT1_Node *node,uint64_t nwid)
|
||||
ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node,uint64_t nwid)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
|
||||
} catch ( ... ) {
|
||||
return (ZT1_VirtualNetworkConfig *)0;
|
||||
return (ZT_VirtualNetworkConfig *)0;
|
||||
}
|
||||
}
|
||||
|
||||
ZT1_VirtualNetworkList *ZT1_Node_networks(ZT1_Node *node)
|
||||
ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->networks();
|
||||
} catch ( ... ) {
|
||||
return (ZT1_VirtualNetworkList *)0;
|
||||
return (ZT_VirtualNetworkList *)0;
|
||||
}
|
||||
}
|
||||
|
||||
void ZT1_Node_freeQueryResult(ZT1_Node *node,void *qr)
|
||||
void ZT_Node_freeQueryResult(ZT_Node *node,void *qr)
|
||||
{
|
||||
try {
|
||||
reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
|
||||
void ZT1_Node_setNetconfMaster(ZT1_Node *node,void *networkControllerInstance)
|
||||
void ZT_Node_setNetconfMaster(ZT_Node *node,void *networkControllerInstance)
|
||||
{
|
||||
try {
|
||||
reinterpret_cast<ZeroTier::Node *>(node)->setNetconfMaster(networkControllerInstance);
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
|
||||
int ZT1_Node_addLocalInterfaceAddress(ZT1_Node *node,const struct sockaddr_storage *addr,int metric,ZT1_LocalInterfaceAddressTrust trust)
|
||||
int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr,int metric,ZT_LocalInterfaceAddressTrust trust)
|
||||
{
|
||||
try {
|
||||
return reinterpret_cast<ZeroTier::Node *>(node)->addLocalInterfaceAddress(addr,metric,trust);
|
||||
|
@ -728,21 +730,21 @@ int ZT1_Node_addLocalInterfaceAddress(ZT1_Node *node,const struct sockaddr_stora
|
|||
}
|
||||
}
|
||||
|
||||
void ZT1_Node_clearLocalInterfaceAddresses(ZT1_Node *node)
|
||||
void ZT_Node_clearLocalInterfaceAddresses(ZT_Node *node)
|
||||
{
|
||||
try {
|
||||
reinterpret_cast<ZeroTier::Node *>(node)->clearLocalInterfaceAddresses();
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
|
||||
void ZT1_version(int *major,int *minor,int *revision,unsigned long *featureFlags)
|
||||
void ZT_version(int *major,int *minor,int *revision,unsigned long *featureFlags)
|
||||
{
|
||||
if (major) *major = ZEROTIER_ONE_VERSION_MAJOR;
|
||||
if (minor) *minor = ZEROTIER_ONE_VERSION_MINOR;
|
||||
if (revision) *revision = ZEROTIER_ONE_VERSION_REVISION;
|
||||
if (featureFlags) {
|
||||
*featureFlags = (
|
||||
ZT1_FEATURE_FLAG_THREAD_SAFE
|
||||
ZT_FEATURE_FLAG_THREAD_SAFE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace ZeroTier {
|
|||
/**
|
||||
* Implementation of Node object as defined in CAPI
|
||||
*
|
||||
* The pointer returned by ZT1_Node_new() is an instance of this class.
|
||||
* The pointer returned by ZT_Node_new() is an instance of this class.
|
||||
*/
|
||||
class Node
|
||||
{
|
||||
|
@ -66,26 +66,26 @@ public:
|
|||
Node(
|
||||
uint64_t now,
|
||||
void *uptr,
|
||||
ZT1_DataStoreGetFunction dataStoreGetFunction,
|
||||
ZT1_DataStorePutFunction dataStorePutFunction,
|
||||
ZT1_WirePacketSendFunction wirePacketSendFunction,
|
||||
ZT1_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
||||
ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
||||
ZT1_EventCallback eventCallback,
|
||||
ZT_DataStoreGetFunction dataStoreGetFunction,
|
||||
ZT_DataStorePutFunction dataStorePutFunction,
|
||||
ZT_WirePacketSendFunction wirePacketSendFunction,
|
||||
ZT_VirtualNetworkFrameFunction virtualNetworkFrameFunction,
|
||||
ZT_VirtualNetworkConfigFunction virtualNetworkConfigFunction,
|
||||
ZT_EventCallback eventCallback,
|
||||
const char *overrideRootTopology);
|
||||
|
||||
~Node();
|
||||
|
||||
// Public API Functions ----------------------------------------------------
|
||||
|
||||
ZT1_ResultCode processWirePacket(
|
||||
ZT_ResultCode processWirePacket(
|
||||
uint64_t now,
|
||||
int localInterfaceId,
|
||||
const struct sockaddr_storage *localAddress,
|
||||
const struct sockaddr_storage *remoteAddress,
|
||||
const void *packetData,
|
||||
unsigned int packetLength,
|
||||
volatile uint64_t *nextBackgroundTaskDeadline);
|
||||
ZT1_ResultCode processVirtualNetworkFrame(
|
||||
ZT_ResultCode processVirtualNetworkFrame(
|
||||
uint64_t now,
|
||||
uint64_t nwid,
|
||||
uint64_t sourceMac,
|
||||
|
@ -95,18 +95,18 @@ public:
|
|||
const void *frameData,
|
||||
unsigned int frameLength,
|
||||
volatile uint64_t *nextBackgroundTaskDeadline);
|
||||
ZT1_ResultCode processBackgroundTasks(uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline);
|
||||
ZT1_ResultCode join(uint64_t nwid);
|
||||
ZT1_ResultCode leave(uint64_t nwid);
|
||||
ZT1_ResultCode multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);
|
||||
ZT1_ResultCode multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);
|
||||
ZT_ResultCode processBackgroundTasks(uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline);
|
||||
ZT_ResultCode join(uint64_t nwid);
|
||||
ZT_ResultCode leave(uint64_t nwid);
|
||||
ZT_ResultCode multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);
|
||||
ZT_ResultCode multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);
|
||||
uint64_t address() const;
|
||||
void status(ZT1_NodeStatus *status) const;
|
||||
ZT1_PeerList *peers() const;
|
||||
ZT1_VirtualNetworkConfig *networkConfig(uint64_t nwid) const;
|
||||
ZT1_VirtualNetworkList *networks() const;
|
||||
void status(ZT_NodeStatus *status) const;
|
||||
ZT_PeerList *peers() const;
|
||||
ZT_VirtualNetworkConfig *networkConfig(uint64_t nwid) const;
|
||||
ZT_VirtualNetworkList *networks() const;
|
||||
void freeQueryResult(void *qr);
|
||||
int addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT1_LocalInterfaceAddressTrust trust);
|
||||
int addLocalInterfaceAddress(const struct sockaddr_storage *addr,int metric,ZT_LocalInterfaceAddressTrust trust);
|
||||
void clearLocalInterfaceAddresses();
|
||||
void setNetconfMaster(void *networkControllerInstance);
|
||||
|
||||
|
@ -120,18 +120,18 @@ public:
|
|||
/**
|
||||
* Enqueue a ZeroTier message to be sent
|
||||
*
|
||||
* @param localInterfaceId Local interface ID, -1 for unspecified/random
|
||||
* @param localAddress Local address
|
||||
* @param addr Destination address
|
||||
* @param data Packet data
|
||||
* @param len Packet length
|
||||
* @return True if packet appears to have been sent
|
||||
*/
|
||||
inline bool putPacket(int localInterfaceId,const InetAddress &addr,const void *data,unsigned int len)
|
||||
inline bool putPacket(const InetAddress &localAddress,const InetAddress &addr,const void *data,unsigned int len)
|
||||
{
|
||||
return (_wirePacketSendFunction(
|
||||
reinterpret_cast<ZT1_Node *>(this),
|
||||
reinterpret_cast<ZT_Node *>(this),
|
||||
_uPtr,
|
||||
localInterfaceId,
|
||||
reinterpret_cast<const struct sockaddr_storage *>(&localAddress),
|
||||
reinterpret_cast<const struct sockaddr_storage *>(&addr),
|
||||
data,
|
||||
len) == 0);
|
||||
|
@ -151,7 +151,7 @@ public:
|
|||
inline void putFrame(uint64_t nwid,const MAC &source,const MAC &dest,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len)
|
||||
{
|
||||
_virtualNetworkFrameFunction(
|
||||
reinterpret_cast<ZT1_Node *>(this),
|
||||
reinterpret_cast<ZT_Node *>(this),
|
||||
_uPtr,
|
||||
nwid,
|
||||
source.toInt(),
|
||||
|
@ -187,9 +187,9 @@ public:
|
|||
return _directPaths;
|
||||
}
|
||||
|
||||
inline bool dataStorePut(const char *name,const void *data,unsigned int len,bool secure) { return (_dataStorePutFunction(reinterpret_cast<ZT1_Node *>(this),_uPtr,name,data,len,(int)secure) == 0); }
|
||||
inline bool dataStorePut(const char *name,const void *data,unsigned int len,bool secure) { return (_dataStorePutFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,name,data,len,(int)secure) == 0); }
|
||||
inline bool dataStorePut(const char *name,const std::string &data,bool secure) { return dataStorePut(name,(const void *)data.data(),(unsigned int)data.length(),secure); }
|
||||
inline void dataStoreDelete(const char *name) { _dataStorePutFunction(reinterpret_cast<ZT1_Node *>(this),_uPtr,name,(const void *)0,0,0); }
|
||||
inline void dataStoreDelete(const char *name) { _dataStorePutFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,name,(const void *)0,0,0); }
|
||||
std::string dataStoreGet(const char *name);
|
||||
|
||||
/**
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
* @param ev Event type
|
||||
* @param md Meta-data (default: NULL/none)
|
||||
*/
|
||||
inline void postEvent(ZT1_Event ev,const void *md = (const void *)0) { _eventCallback(reinterpret_cast<ZT1_Node *>(this),_uPtr,ev,md); }
|
||||
inline void postEvent(ZT_Event ev,const void *md = (const void *)0) { _eventCallback(reinterpret_cast<ZT_Node *>(this),_uPtr,ev,md); }
|
||||
|
||||
/**
|
||||
* Update virtual network port configuration
|
||||
|
@ -207,7 +207,7 @@ public:
|
|||
* @param op Configuration operation
|
||||
* @param nc Network configuration
|
||||
*/
|
||||
inline int configureVirtualNetworkPort(uint64_t nwid,ZT1_VirtualNetworkConfigOperation op,const ZT1_VirtualNetworkConfig *nc) { return _virtualNetworkConfigFunction(reinterpret_cast<ZT1_Node *>(this),_uPtr,nwid,op,nc); }
|
||||
inline int configureVirtualNetworkPort(uint64_t nwid,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) { return _virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,nwid,op,nc); }
|
||||
|
||||
/**
|
||||
* @return True if we appear to be online
|
||||
|
@ -244,12 +244,12 @@ private:
|
|||
|
||||
void *_uPtr; // _uptr (lower case) is reserved in Visual Studio :P
|
||||
|
||||
ZT1_DataStoreGetFunction _dataStoreGetFunction;
|
||||
ZT1_DataStorePutFunction _dataStorePutFunction;
|
||||
ZT1_WirePacketSendFunction _wirePacketSendFunction;
|
||||
ZT1_VirtualNetworkFrameFunction _virtualNetworkFrameFunction;
|
||||
ZT1_VirtualNetworkConfigFunction _virtualNetworkConfigFunction;
|
||||
ZT1_EventCallback _eventCallback;
|
||||
ZT_DataStoreGetFunction _dataStoreGetFunction;
|
||||
ZT_DataStorePutFunction _dataStorePutFunction;
|
||||
ZT_WirePacketSendFunction _wirePacketSendFunction;
|
||||
ZT_VirtualNetworkFrameFunction _virtualNetworkFrameFunction;
|
||||
ZT_VirtualNetworkConfigFunction _virtualNetworkConfigFunction;
|
||||
ZT_EventCallback _eventCallback;
|
||||
|
||||
std::vector< std::pair< uint64_t, SharedPtr<Network> > > _networks;
|
||||
Mutex _networks_m;
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
* Nearly all paths will be normal trust. The other levels are for high
|
||||
* performance local SDN use only.
|
||||
*
|
||||
* These values MUST match ZT1_LocalInterfaceAddressTrust in ZeroTierOne.h
|
||||
* These values MUST match ZT_LocalInterfaceAddressTrust in ZeroTierOne.h
|
||||
*/
|
||||
enum Trust
|
||||
{
|
||||
|
|
|
@ -64,7 +64,7 @@ Peer::Peer(const Identity &myIdentity,const Identity &peerIdentity)
|
|||
|
||||
void Peer::received(
|
||||
const RuntimeEnvironment *RR,
|
||||
int localInterfaceId,
|
||||
const InetAddress &localAddr,
|
||||
const InetAddress &remoteAddr,
|
||||
unsigned int hops,
|
||||
uint64_t packetId,
|
||||
|
@ -82,7 +82,7 @@ void Peer::received(
|
|||
{
|
||||
unsigned int np = _numPaths;
|
||||
for(unsigned int p=0;p<np;++p) {
|
||||
if ((_paths[p].address() == remoteAddr)&&(_paths[p].localInterfaceId() == localInterfaceId)) {
|
||||
if ((_paths[p].address() == remoteAddr)&&(_paths[p].localAddress() == localAddr)) {
|
||||
_paths[p].received(now);
|
||||
pathIsConfirmed = true;
|
||||
break;
|
||||
|
@ -93,13 +93,13 @@ void Peer::received(
|
|||
if ((verb == Packet::VERB_OK)&&(inReVerb == Packet::VERB_HELLO)) {
|
||||
// Learn paths if they've been confirmed via a HELLO
|
||||
RemotePath *slot = (RemotePath *)0;
|
||||
if (np < ZT1_MAX_PEER_NETWORK_PATHS) {
|
||||
if (np < ZT_MAX_PEER_NETWORK_PATHS) {
|
||||
// Add new path
|
||||
slot = &(_paths[np++]);
|
||||
} else {
|
||||
// Replace oldest non-fixed path
|
||||
uint64_t slotLRmin = 0xffffffffffffffffULL;
|
||||
for(unsigned int p=0;p<ZT1_MAX_PEER_NETWORK_PATHS;++p) {
|
||||
for(unsigned int p=0;p<ZT_MAX_PEER_NETWORK_PATHS;++p) {
|
||||
if ((!_paths[p].fixed())&&(_paths[p].lastReceived() <= slotLRmin)) {
|
||||
slotLRmin = _paths[p].lastReceived();
|
||||
slot = &(_paths[p]);
|
||||
|
@ -107,7 +107,7 @@ void Peer::received(
|
|||
}
|
||||
}
|
||||
if (slot) {
|
||||
*slot = RemotePath(localInterfaceId,remoteAddr,false);
|
||||
*slot = RemotePath(localAddr,remoteAddr,false);
|
||||
slot->received(now);
|
||||
_numPaths = np;
|
||||
pathIsConfirmed = true;
|
||||
|
@ -120,7 +120,7 @@ void Peer::received(
|
|||
if ((now - _lastPathConfirmationSent) >= ZT_MIN_PATH_CONFIRMATION_INTERVAL) {
|
||||
_lastPathConfirmationSent = now;
|
||||
TRACE("got %s via unknown path %s(%s), confirming...",Packet::verbString(verb),_id.address().toString().c_str(),remoteAddr.toString().c_str());
|
||||
attemptToContactAt(RR,localInterfaceId,remoteAddr,now);
|
||||
attemptToContactAt(RR,localAddr,remoteAddr,now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ void Peer::received(
|
|||
for(std::vector<MulticastGroup>::const_iterator mg(mgs.begin());mg!=mgs.end();++mg) {
|
||||
if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) {
|
||||
outp.armor(_key,true);
|
||||
RR->node->putPacket(localInterfaceId,remoteAddr,outp.data(),outp.size());
|
||||
RR->node->putPacket(localAddr,remoteAddr,outp.data(),outp.size());
|
||||
outp.reset(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ void Peer::received(
|
|||
}
|
||||
if (outp.size() > ZT_PROTO_MIN_PACKET_LENGTH) {
|
||||
outp.armor(_key,true);
|
||||
RR->node->putPacket(localInterfaceId,remoteAddr,outp.data(),outp.size());
|
||||
RR->node->putPacket(localAddr,remoteAddr,outp.data(),outp.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ RemotePath *Peer::getBestPath(uint64_t now)
|
|||
return bestPath;
|
||||
}
|
||||
|
||||
void Peer::attemptToContactAt(const RuntimeEnvironment *RR,int localInterfaceId,const InetAddress &atAddress,uint64_t now)
|
||||
void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &localAddr,const InetAddress &atAddress,uint64_t now)
|
||||
{
|
||||
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_HELLO);
|
||||
outp.append((unsigned char)ZT_PROTO_VERSION);
|
||||
|
@ -209,7 +209,7 @@ void Peer::attemptToContactAt(const RuntimeEnvironment *RR,int localInterfaceId,
|
|||
}
|
||||
|
||||
outp.armor(_key,false); // HELLO is sent in the clear
|
||||
RR->node->putPacket(localInterfaceId,atAddress,outp.data(),outp.size());
|
||||
RR->node->putPacket(localAddr,atAddress,outp.data(),outp.size());
|
||||
}
|
||||
|
||||
void Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now)
|
||||
|
@ -218,12 +218,12 @@ void Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now)
|
|||
if (bestPath) {
|
||||
if ((now - bestPath->lastReceived()) >= ZT_PEER_DIRECT_PING_DELAY) {
|
||||
TRACE("PING %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
|
||||
attemptToContactAt(RR,bestPath->localInterfaceId(),bestPath->address(),now);
|
||||
attemptToContactAt(RR,bestPath->localAddress(),bestPath->address(),now);
|
||||
bestPath->sent(now);
|
||||
} else if (((now - bestPath->lastSend()) >= ZT_NAT_KEEPALIVE_DELAY)&&(!bestPath->reliable())) {
|
||||
_natKeepaliveBuf += (uint32_t)((now * 0x9e3779b1) >> 1); // tumble this around to send constantly varying (meaningless) payloads
|
||||
TRACE("NAT keepalive %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
|
||||
RR->node->putPacket(bestPath->localInterfaceId(),bestPath->address(),&_natKeepaliveBuf,sizeof(_natKeepaliveBuf));
|
||||
RR->node->putPacket(bestPath->localAddress(),bestPath->address(),&_natKeepaliveBuf,sizeof(_natKeepaliveBuf));
|
||||
bestPath->sent(now);
|
||||
}
|
||||
}
|
||||
|
@ -311,13 +311,13 @@ void Peer::addPath(const RemotePath &newp)
|
|||
}
|
||||
|
||||
RemotePath *slot = (RemotePath *)0;
|
||||
if (np < ZT1_MAX_PEER_NETWORK_PATHS) {
|
||||
if (np < ZT_MAX_PEER_NETWORK_PATHS) {
|
||||
// Add new path
|
||||
slot = &(_paths[np++]);
|
||||
} else {
|
||||
// Replace oldest non-fixed path
|
||||
uint64_t slotLRmin = 0xffffffffffffffffULL;
|
||||
for(unsigned int p=0;p<ZT1_MAX_PEER_NETWORK_PATHS;++p) {
|
||||
for(unsigned int p=0;p<ZT_MAX_PEER_NETWORK_PATHS;++p) {
|
||||
if ((!_paths[p].fixed())&&(_paths[p].lastReceived() <= slotLRmin)) {
|
||||
slotLRmin = _paths[p].lastReceived();
|
||||
slot = &(_paths[p]);
|
||||
|
@ -355,7 +355,7 @@ bool Peer::resetWithinScope(const RuntimeEnvironment *RR,InetAddress::IpScope sc
|
|||
while (x < np) {
|
||||
if (_paths[x].address().ipScope() == scope) {
|
||||
if (_paths[x].fixed()) {
|
||||
attemptToContactAt(RR,_paths[x].localInterfaceId(),_paths[x].address(),now);
|
||||
attemptToContactAt(RR,_paths[x].localAddress(),_paths[x].address(),now);
|
||||
_paths[y++] = _paths[x]; // keep fixed paths
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
* and appears to be valid.
|
||||
*
|
||||
* @param RR Runtime environment
|
||||
* @param localInterfaceId Local interface ID or -1 if unspecified
|
||||
* @param localAddr Local address
|
||||
* @param remoteAddr Internet address of sender
|
||||
* @param hops ZeroTier (not IP) hops
|
||||
* @param packetId Packet ID
|
||||
|
@ -115,7 +115,7 @@ public:
|
|||
*/
|
||||
void received(
|
||||
const RuntimeEnvironment *RR,
|
||||
int localInterfaceId,
|
||||
const InetAddress &localAddr,
|
||||
const InetAddress &remoteAddr,
|
||||
unsigned int hops,
|
||||
uint64_t packetId,
|
||||
|
@ -157,11 +157,11 @@ public:
|
|||
* for NAT traversal and path verification.
|
||||
*
|
||||
* @param RR Runtime environment
|
||||
* @param localInterfaceId Local interface ID or -1 for unspecified
|
||||
* @param localAddr Local address
|
||||
* @param atAddress Destination address
|
||||
* @param now Current time
|
||||
*/
|
||||
void attemptToContactAt(const RuntimeEnvironment *RR,int localInterfaceId,const InetAddress &atAddress,uint64_t now);
|
||||
void attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &localAddr,const InetAddress &atAddress,uint64_t now);
|
||||
|
||||
/**
|
||||
* Send pings or keepalives depending on configured timeouts
|
||||
|
@ -417,7 +417,7 @@ private:
|
|||
uint16_t _vMinor;
|
||||
uint16_t _vRevision;
|
||||
Identity _id;
|
||||
RemotePath _paths[ZT1_MAX_PEER_NETWORK_PATHS];
|
||||
RemotePath _paths[ZT_MAX_PEER_NETWORK_PATHS];
|
||||
unsigned int _numPaths;
|
||||
unsigned int _latency;
|
||||
|
||||
|
|
|
@ -53,17 +53,17 @@ public:
|
|||
Path(),
|
||||
_lastSend(0),
|
||||
_lastReceived(0),
|
||||
_localInterfaceId(-1),
|
||||
_localAddress(),
|
||||
_fixed(false) {}
|
||||
|
||||
RemotePath(int localInterfaceId,const InetAddress &addr,bool fixed) :
|
||||
RemotePath(const InetAddress &localAddress,const InetAddress &addr,bool fixed) :
|
||||
Path(addr,0,TRUST_NORMAL),
|
||||
_lastSend(0),
|
||||
_lastReceived(0),
|
||||
_localInterfaceId(localInterfaceId),
|
||||
_localAddress(localAddress),
|
||||
_fixed(fixed) {}
|
||||
|
||||
inline int localInterfaceId() const throw() { return _localInterfaceId; }
|
||||
inline const InetAddress &localAddress() const throw() { return _localAddress; }
|
||||
|
||||
inline uint64_t lastSend() const throw() { return _lastSend; }
|
||||
inline uint64_t lastReceived() const throw() { return _lastReceived; }
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
*/
|
||||
inline bool send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
|
||||
{
|
||||
if (RR->node->putPacket(_localInterfaceId,address(),data,len)) {
|
||||
if (RR->node->putPacket(_localAddress,address(),data,len)) {
|
||||
sent(now);
|
||||
RR->antiRec->logOutgoingZT(data,len);
|
||||
return true;
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
private:
|
||||
uint64_t _lastSend;
|
||||
uint64_t _lastReceived;
|
||||
int _localInterfaceId;
|
||||
InetAddress _localAddress;
|
||||
bool _fixed;
|
||||
};
|
||||
|
||||
|
|
|
@ -78,11 +78,8 @@ Switch::~Switch()
|
|||
{
|
||||
}
|
||||
|
||||
void Switch::onRemotePacket(int localInterfaceId,const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||
void Switch::onRemotePacket(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||
{
|
||||
if (localInterfaceId < 0)
|
||||
localInterfaceId = 0;
|
||||
|
||||
try {
|
||||
if (len == 13) {
|
||||
/* LEGACY: before VERB_PUSH_DIRECT_PATHS, peers used broadcast
|
||||
|
@ -99,14 +96,14 @@ void Switch::onRemotePacket(int localInterfaceId,const InetAddress &fromAddr,con
|
|||
_lastBeaconResponse = now;
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NOP);
|
||||
outp.armor(peer->key(),false);
|
||||
RR->node->putPacket(localInterfaceId,fromAddr,outp.data(),outp.size());
|
||||
RR->node->putPacket(localAddr,fromAddr,outp.data(),outp.size());
|
||||
}
|
||||
}
|
||||
} else if (len > ZT_PROTO_MIN_FRAGMENT_LENGTH) {
|
||||
if (((const unsigned char *)data)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] == ZT_PACKET_FRAGMENT_INDICATOR) {
|
||||
_handleRemotePacketFragment(localInterfaceId,fromAddr,data,len);
|
||||
_handleRemotePacketFragment(localAddr,fromAddr,data,len);
|
||||
} else if (len >= ZT_PROTO_MIN_PACKET_LENGTH) {
|
||||
_handleRemotePacketHead(localInterfaceId,fromAddr,data,len);
|
||||
_handleRemotePacketHead(localAddr,fromAddr,data,len);
|
||||
}
|
||||
}
|
||||
} catch (std::exception &ex) {
|
||||
|
@ -379,14 +376,14 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Switch::rendezvous(const SharedPtr<Peer> &peer,int localInterfaceId,const InetAddress &atAddr)
|
||||
void Switch::rendezvous(const SharedPtr<Peer> &peer,const InetAddress &localAddr,const InetAddress &atAddr)
|
||||
{
|
||||
TRACE("sending NAT-t message to %s(%s)",peer->address().toString().c_str(),atAddr.toString().c_str());
|
||||
const uint64_t now = RR->node->now();
|
||||
peer->attemptToContactAt(RR,localInterfaceId,atAddr,now);
|
||||
peer->attemptToContactAt(RR,localAddr,atAddr,now);
|
||||
{
|
||||
Mutex::Lock _l(_contactQueue_m);
|
||||
_contactQueue.push_back(ContactQueueEntry(peer,now + ZT_NAT_T_TACTICAL_ESCALATION_DELAY,localInterfaceId,atAddr));
|
||||
_contactQueue.push_back(ContactQueueEntry(peer,now + ZT_NAT_T_TACTICAL_ESCALATION_DELAY,localAddr,atAddr));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,14 +453,14 @@ unsigned long Switch::doTimerTasks(uint64_t now)
|
|||
} else {
|
||||
if (qi->strategyIteration == 0) {
|
||||
// First strategy: send packet directly to destination
|
||||
qi->peer->attemptToContactAt(RR,qi->localInterfaceId,qi->inaddr,now);
|
||||
qi->peer->attemptToContactAt(RR,qi->localAddr,qi->inaddr,now);
|
||||
} else if (qi->strategyIteration <= 4) {
|
||||
// Strategies 1-4: try escalating ports for symmetric NATs that remap sequentially
|
||||
InetAddress tmpaddr(qi->inaddr);
|
||||
int p = (int)qi->inaddr.port() + qi->strategyIteration;
|
||||
if (p < 0xffff) {
|
||||
tmpaddr.setPort((unsigned int)p);
|
||||
qi->peer->attemptToContactAt(RR,qi->localInterfaceId,tmpaddr,now);
|
||||
qi->peer->attemptToContactAt(RR,qi->localAddr,tmpaddr,now);
|
||||
} else qi->strategyIteration = 5;
|
||||
} else {
|
||||
// All strategies tried, expire entry
|
||||
|
@ -554,7 +551,7 @@ unsigned long Switch::doTimerTasks(uint64_t now)
|
|||
return nextDelay;
|
||||
}
|
||||
|
||||
void Switch::_handleRemotePacketFragment(int localInterfaceId,const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||
void Switch::_handleRemotePacketFragment(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||
{
|
||||
Packet::Fragment fragment(data,len);
|
||||
Address destination(fragment.destination());
|
||||
|
@ -625,9 +622,9 @@ void Switch::_handleRemotePacketFragment(int localInterfaceId,const InetAddress
|
|||
}
|
||||
}
|
||||
|
||||
void Switch::_handleRemotePacketHead(int localInterfaceId,const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||
void Switch::_handleRemotePacketHead(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||
{
|
||||
SharedPtr<IncomingPacket> packet(new IncomingPacket(data,len,localInterfaceId,fromAddr,RR->node->now()));
|
||||
SharedPtr<IncomingPacket> packet(new IncomingPacket(data,len,localAddr,fromAddr,RR->node->now()));
|
||||
|
||||
Address source(packet->source());
|
||||
Address destination(packet->destination());
|
||||
|
|
|
@ -79,12 +79,12 @@ public:
|
|||
/**
|
||||
* Called when a packet is received from the real network
|
||||
*
|
||||
* @param localInterfaceId Local interface ID or -1 for unspecified
|
||||
* @param localAddr Local interface address
|
||||
* @param fromAddr Internet IP address of origin
|
||||
* @param data Packet data
|
||||
* @param len Packet length
|
||||
*/
|
||||
void onRemotePacket(int localInterfaceId,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||
void onRemotePacket(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||
|
||||
/**
|
||||
* Called when a packet comes from a local Ethernet tap
|
||||
|
@ -141,10 +141,10 @@ public:
|
|||
* Attempt NAT traversal to peer at a given physical address
|
||||
*
|
||||
* @param peer Peer to contact
|
||||
* @param localInterfaceId Local interface ID or -1 if unspecified
|
||||
* @param localAddr Local interface address
|
||||
* @param atAddr Address of peer
|
||||
*/
|
||||
void rendezvous(const SharedPtr<Peer> &peer,int localInterfaceId,const InetAddress &atAddr);
|
||||
void rendezvous(const SharedPtr<Peer> &peer,const InetAddress &localAddr,const InetAddress &atAddr);
|
||||
|
||||
/**
|
||||
* Request WHOIS on a given address
|
||||
|
@ -181,8 +181,8 @@ public:
|
|||
unsigned long doTimerTasks(uint64_t now);
|
||||
|
||||
private:
|
||||
void _handleRemotePacketFragment(int localInterfaceId,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||
void _handleRemotePacketHead(int localInterfaceId,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||
void _handleRemotePacketFragment(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||
void _handleRemotePacketHead(const InetAddress &localAddr,const InetAddress &fromAddr,const void *data,unsigned int len);
|
||||
Address _sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted);
|
||||
bool _trySend(const Packet &packet,bool encrypt,uint64_t nwid);
|
||||
|
||||
|
@ -262,17 +262,17 @@ private:
|
|||
struct ContactQueueEntry
|
||||
{
|
||||
ContactQueueEntry() {}
|
||||
ContactQueueEntry(const SharedPtr<Peer> &p,uint64_t ft,int liid,const InetAddress &a) :
|
||||
ContactQueueEntry(const SharedPtr<Peer> &p,uint64_t ft,const InetAddress &laddr,const InetAddress &a) :
|
||||
peer(p),
|
||||
fireAtTime(ft),
|
||||
inaddr(a),
|
||||
localInterfaceId(liid),
|
||||
localAddr(laddr),
|
||||
strategyIteration(0) {}
|
||||
|
||||
SharedPtr<Peer> peer;
|
||||
uint64_t fireAtTime;
|
||||
InetAddress inaddr;
|
||||
int localInterfaceId;
|
||||
InetAddress localAddr;
|
||||
unsigned int strategyIteration;
|
||||
};
|
||||
std::list<ContactQueueEntry> _contactQueue;
|
||||
|
|
|
@ -62,7 +62,7 @@ void Topology::setRootServers(const std::map< Identity,std::vector<InetAddress>
|
|||
if (!p)
|
||||
p = SharedPtr<Peer>(new Peer(RR->identity,i->first));
|
||||
for(std::vector<InetAddress>::const_iterator j(i->second.begin());j!=i->second.end();++j)
|
||||
p->addPath(RemotePath(0,*j,true));
|
||||
p->addPath(RemotePath(InetAddress(),*j,true));
|
||||
p->use(now);
|
||||
_rootPeers.push_back(p);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue