IncomingPacket.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #include "Constants.hpp"
  14. #include "RuntimeEnvironment.hpp"
  15. #include "IncomingPacket.hpp"
  16. #include "Topology.hpp"
  17. #include "Switch.hpp"
  18. #include "Peer.hpp"
  19. #include "NetworkController.hpp"
  20. #include "SelfAwareness.hpp"
  21. #include "Salsa20.hpp"
  22. #include "Node.hpp"
  23. #include "CertificateOfMembership.hpp"
  24. #include "Capability.hpp"
  25. #include "Tag.hpp"
  26. #include "Revocation.hpp"
  27. #include "Trace.hpp"
  28. #include <cstring>
  29. #include <cstdlib>
  30. #include <list>
  31. namespace ZeroTier {
  32. namespace {
  33. void _sendErrorNeedCredentials(IncomingPacket &pkt,const RuntimeEnvironment *RR,void *tPtr,const SharedPtr<Peer> &peer,const uint64_t nwid,const SharedPtr<Path> &path)
  34. {
  35. Packet outp(pkt.source(),RR->identity.address(),Packet::VERB_ERROR);
  36. outp.append((uint8_t)pkt.verb());
  37. outp.append(pkt.packetId());
  38. outp.append((uint8_t)Packet::ERROR_NEED_MEMBERSHIP_CERTIFICATE);
  39. outp.append(nwid);
  40. outp.armor(peer->key(),true);
  41. path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now());
  42. }
  43. ZT_ALWAYS_INLINE bool _doHELLO(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const bool alreadyAuthenticated,const SharedPtr<Path> &path)
  44. {
  45. const int64_t now = RR->node->now();
  46. const uint64_t pid = pkt.packetId();
  47. const Address fromAddress(pkt.source());
  48. const unsigned int protoVersion = pkt[ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION];
  49. const unsigned int vMajor = pkt[ZT_PROTO_VERB_HELLO_IDX_MAJOR_VERSION];
  50. const unsigned int vMinor = pkt[ZT_PROTO_VERB_HELLO_IDX_MINOR_VERSION];
  51. const unsigned int vRevision = pkt.at<uint16_t>(ZT_PROTO_VERB_HELLO_IDX_REVISION);
  52. const int64_t timestamp = pkt.at<int64_t>(ZT_PROTO_VERB_HELLO_IDX_TIMESTAMP);
  53. Identity id;
  54. unsigned int ptr = ZT_PROTO_VERB_HELLO_IDX_IDENTITY + id.deserialize(pkt,ZT_PROTO_VERB_HELLO_IDX_IDENTITY);
  55. if (protoVersion < ZT_PROTO_VERSION_MIN) {
  56. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_PEER_TOO_OLD);
  57. return true;
  58. }
  59. if (fromAddress != id.address()) {
  60. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MALFORMED_PACKET);
  61. return true;
  62. }
  63. SharedPtr<Peer> peer(RR->topology->get(tPtr,id.address()));
  64. if (peer) {
  65. // We already have an identity with this address -- check for collisions
  66. if (!alreadyAuthenticated) {
  67. if (peer->identity() != id) {
  68. // Identity is different from the one we already have -- address collision
  69. // Check rate limits
  70. if (!RR->node->rateGateIdentityVerification(now,path->address()))
  71. return true;
  72. uint8_t key[ZT_PEER_SECRET_KEY_LENGTH];
  73. if (RR->identity.agree(id,key)) {
  74. if (pkt.dearmor(key)) { // ensure packet is authentic, otherwise drop
  75. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MALFORMED_PACKET);
  76. // TODO: we handle identity collisions differently now
  77. } else {
  78. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MAC_FAILED);
  79. }
  80. } else {
  81. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MALFORMED_PACKET);
  82. }
  83. return true;
  84. } else {
  85. // Identity is the same as the one we already have -- check packet integrity
  86. if (!pkt.dearmor(peer->key())) {
  87. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MAC_FAILED);
  88. return true;
  89. }
  90. // Continue at // VALID
  91. }
  92. } // else if alreadyAuthenticated then continue at // VALID
  93. } else {
  94. // We don't already have an identity with this address -- validate and learn it
  95. // Sanity check: this basically can't happen
  96. if (alreadyAuthenticated) {
  97. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_UNSPECIFIED);
  98. return true;
  99. }
  100. // Check rate limits
  101. if (!RR->node->rateGateIdentityVerification(now,path->address())) {
  102. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_RATE_LIMIT_EXCEEDED);
  103. return true;
  104. }
  105. // Check packet integrity and MAC (this is faster than locallyValidate() so do it first to filter out total crap)
  106. SharedPtr<Peer> newPeer(new Peer(RR));
  107. if (!newPeer->init(RR->identity,id)) {
  108. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_UNSPECIFIED);
  109. return true;
  110. }
  111. if (!pkt.dearmor(newPeer->key())) {
  112. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MAC_FAILED);
  113. return true;
  114. }
  115. // Check that identity's address is valid as per the derivation function
  116. if (!id.locallyValidate()) {
  117. RR->t->incomingPacketDropped(tPtr,pid,0,id,path->address(),pkt.hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_INVALID_OBJECT);
  118. return true;
  119. }
  120. peer = RR->topology->add(tPtr,newPeer);
  121. // Continue at // VALID
  122. }
  123. // VALID -- if we made it here, packet passed identity and authenticity checks!
  124. // Get address to which this packet was sent to learn our external surface address if packet was direct.
  125. if (pkt.hops() == 0) {
  126. InetAddress externalSurfaceAddress;
  127. if (ptr < pkt.size()) {
  128. ptr += externalSurfaceAddress.deserialize(pkt,ptr);
  129. if ((externalSurfaceAddress)&&(pkt.hops() == 0))
  130. RR->sa->iam(tPtr,id,path->localSocket(),path->address(),externalSurfaceAddress,RR->topology->isRoot(id),now);
  131. }
  132. }
  133. // Send OK(HELLO) with an echo of the packet's timestamp and some of the same
  134. // information about us: version, sent-to address, etc.
  135. Packet outp(id.address(),RR->identity.address(),Packet::VERB_OK);
  136. outp.append((unsigned char)Packet::VERB_HELLO);
  137. outp.append((uint64_t)pid);
  138. outp.append((uint64_t)timestamp);
  139. outp.append((unsigned char)ZT_PROTO_VERSION);
  140. outp.append((unsigned char)ZEROTIER_ONE_VERSION_MAJOR);
  141. outp.append((unsigned char)ZEROTIER_ONE_VERSION_MINOR);
  142. outp.append((uint16_t)ZEROTIER_ONE_VERSION_REVISION);
  143. path->address().serialize(outp);
  144. outp.armor(peer->key(),true);
  145. path->send(RR,tPtr,outp.data(),outp.size(),now);
  146. peer->setRemoteVersion(protoVersion,vMajor,vMinor,vRevision); // important for this to go first so received() knows the version
  147. peer->received(tPtr,path,pkt.hops(),pid,pkt.payloadLength(),Packet::VERB_HELLO,0,Packet::VERB_NOP,0);
  148. return true;
  149. }
  150. ZT_ALWAYS_INLINE bool _doERROR(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  151. {
  152. const Packet::Verb inReVerb = (Packet::Verb)pkt[ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB];
  153. const uint64_t inRePacketId = pkt.at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_IN_RE_PACKET_ID);
  154. const Packet::ErrorCode errorCode = (Packet::ErrorCode)pkt[ZT_PROTO_VERB_ERROR_IDX_ERROR_CODE];
  155. uint64_t networkId = 0;
  156. /* Security note: we do not gate doERROR() with expectingReplyTo() to
  157. * avoid having to log every outgoing packet ID. Instead we put the
  158. * logic to determine whether we should consider an ERROR in each
  159. * error handler. In most cases these are only trusted in specific
  160. * circumstances. */
  161. switch(errorCode) {
  162. case Packet::ERROR_OBJ_NOT_FOUND:
  163. // Object not found, currently only meaningful from network controllers.
  164. if (inReVerb == Packet::VERB_NETWORK_CONFIG_REQUEST) {
  165. networkId = pkt.at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD);
  166. const SharedPtr<Network> network(RR->node->network(networkId));
  167. if ((network)&&(network->controller() == peer->address()))
  168. network->setNotFound();
  169. }
  170. break;
  171. case Packet::ERROR_UNSUPPORTED_OPERATION:
  172. // This can be sent in response to any operation, though right now we only
  173. // consider it meaningful from network controllers. This would indicate
  174. // that the queried node does not support acting as a controller.
  175. if (inReVerb == Packet::VERB_NETWORK_CONFIG_REQUEST) {
  176. networkId = pkt.at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD);
  177. const SharedPtr<Network> network(RR->node->network(networkId));
  178. if ((network)&&(network->controller() == peer->address()))
  179. network->setNotFound();
  180. }
  181. break;
  182. case Packet::ERROR_NEED_MEMBERSHIP_CERTIFICATE: {
  183. // Peers can send this to ask for a cert for a network.
  184. networkId = pkt.at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD);
  185. const SharedPtr<Network> network(RR->node->network(networkId));
  186. const int64_t now = RR->node->now();
  187. if ((network)&&(network->config().com))
  188. network->pushCredentialsNow(tPtr,peer->address(),now);
  189. } break;
  190. case Packet::ERROR_NETWORK_ACCESS_DENIED_: {
  191. // Network controller: network access denied.
  192. networkId = pkt.at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD);
  193. const SharedPtr<Network> network(RR->node->network(networkId));
  194. if ((network)&&(network->controller() == peer->address()))
  195. network->setAccessDenied();
  196. } break;
  197. default: break;
  198. }
  199. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_ERROR,inRePacketId,inReVerb,networkId);
  200. return true;
  201. }
  202. ZT_ALWAYS_INLINE bool _doOK(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  203. {
  204. const Packet::Verb inReVerb = (Packet::Verb)pkt[ZT_PROTO_VERB_OK_IDX_IN_RE_VERB];
  205. const uint64_t inRePacketId = pkt.at<uint64_t>(ZT_PROTO_VERB_OK_IDX_IN_RE_PACKET_ID);
  206. uint64_t networkId = 0;
  207. if (!RR->node->expectingReplyTo(inRePacketId))
  208. return true;
  209. switch(inReVerb) {
  210. case Packet::VERB_HELLO: {
  211. const uint64_t latency = RR->node->now() - pkt.at<uint64_t>(ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP);
  212. const unsigned int vProto = pkt[ZT_PROTO_VERB_HELLO__OK__IDX_PROTOCOL_VERSION];
  213. const unsigned int vMajor = pkt[ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION];
  214. const unsigned int vMinor = pkt[ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION];
  215. const unsigned int vRevision = pkt.at<uint16_t>(ZT_PROTO_VERB_HELLO__OK__IDX_REVISION);
  216. if (vProto < ZT_PROTO_VERSION_MIN)
  217. return true;
  218. if (pkt.hops() == 0) {
  219. if ((ZT_PROTO_VERB_HELLO__OK__IDX_REVISION + 2) < pkt.size()) {
  220. InetAddress externalSurfaceAddress;
  221. externalSurfaceAddress.deserialize(pkt,ZT_PROTO_VERB_HELLO__OK__IDX_REVISION + 2);
  222. if (externalSurfaceAddress)
  223. RR->sa->iam(tPtr,peer->identity(),path->localSocket(),path->address(),externalSurfaceAddress,RR->topology->isRoot(peer->identity()),RR->node->now());
  224. }
  225. }
  226. peer->updateLatency((unsigned int)latency);
  227. peer->setRemoteVersion(vProto,vMajor,vMinor,vRevision);
  228. } break;
  229. case Packet::VERB_WHOIS:
  230. if (RR->topology->isRoot(peer->identity())) {
  231. unsigned int p = ZT_PROTO_VERB_WHOIS__OK__IDX_IDENTITY;
  232. while (p < pkt.size()) {
  233. try {
  234. Identity id;
  235. p += id.deserialize(pkt,p);
  236. if (id) {
  237. SharedPtr<Peer> ptmp(RR->topology->add(tPtr,SharedPtr<Peer>(new Peer(RR))));
  238. ptmp->init(RR->identity,id);
  239. RR->sw->doAnythingWaitingForPeer(tPtr,ptmp);
  240. }
  241. } catch ( ... ) {
  242. break;
  243. }
  244. }
  245. }
  246. break;
  247. case Packet::VERB_NETWORK_CONFIG_REQUEST: {
  248. networkId = pkt.at<uint64_t>(ZT_PROTO_VERB_OK_IDX_PAYLOAD);
  249. const SharedPtr<Network> network(RR->node->network(networkId));
  250. if (network)
  251. network->handleConfigChunk(tPtr,pkt.packetId(),pkt.source(),pkt,ZT_PROTO_VERB_OK_IDX_PAYLOAD);
  252. } break;
  253. case Packet::VERB_MULTICAST_GATHER: {
  254. } break;
  255. default: break;
  256. }
  257. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_OK,inRePacketId,inReVerb,networkId);
  258. return true;
  259. }
  260. ZT_ALWAYS_INLINE bool _doWHOIS(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  261. {
  262. if (!peer->rateGateInboundWhoisRequest(RR->node->now()))
  263. return true;
  264. Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
  265. outp.append((unsigned char)Packet::VERB_WHOIS);
  266. outp.append(pkt.packetId());
  267. unsigned int count = 0;
  268. unsigned int ptr = ZT_PACKET_IDX_PAYLOAD;
  269. while ((ptr + ZT_ADDRESS_LENGTH) <= pkt.size()) {
  270. const Address addr(pkt.field(ptr,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
  271. ptr += ZT_ADDRESS_LENGTH;
  272. const SharedPtr<Peer> ptmp(RR->topology->get(tPtr,addr));
  273. if (ptmp) {
  274. ptmp->identity().serialize(outp,false);
  275. ++count;
  276. } else {
  277. // Request unknown WHOIS from upstream from us (if we have one)
  278. RR->sw->requestWhois(tPtr,RR->node->now(),addr);
  279. }
  280. }
  281. if (count > 0) {
  282. outp.armor(peer->key(),true);
  283. path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now());
  284. }
  285. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_WHOIS,0,Packet::VERB_NOP,0);
  286. return true;
  287. }
  288. ZT_ALWAYS_INLINE bool _doRENDEZVOUS(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  289. {
  290. if (RR->topology->isRoot(peer->identity())) {
  291. uint16_t junk = (uint16_t)Utils::random();
  292. const Address with(pkt.field(ZT_PROTO_VERB_RENDEZVOUS_IDX_ZTADDRESS,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
  293. const SharedPtr<Peer> rendezvousWith(RR->topology->get(tPtr,with));
  294. if (rendezvousWith) {
  295. const unsigned int port = pkt.at<uint16_t>(ZT_PROTO_VERB_RENDEZVOUS_IDX_PORT);
  296. const unsigned int addrlen = pkt[ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRLEN];
  297. if ((port > 0)&&((addrlen == 4)||(addrlen == 16))) {
  298. InetAddress atAddr(pkt.field(ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRESS,addrlen),addrlen,port);
  299. if (rendezvousWith->shouldTryPath(tPtr,RR->node->now(),peer,atAddr)) {
  300. if (atAddr.isV4())
  301. RR->node->putPacket(tPtr,path->localSocket(),atAddr,&junk,2,2); // IPv4 "firewall opener" hack
  302. rendezvousWith->sendHELLO(tPtr,path->localSocket(),atAddr,RR->node->now());
  303. RR->t->tryingNewPath(tPtr,rendezvousWith->identity(),atAddr,path->address(),pkt.packetId(),Packet::VERB_RENDEZVOUS,peer->address(),peer->identity().hash(),ZT_TRACE_TRYING_NEW_PATH_REASON_RENDEZVOUS);
  304. }
  305. }
  306. }
  307. }
  308. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_RENDEZVOUS,0,Packet::VERB_NOP,0);
  309. return true;
  310. }
  311. ZT_ALWAYS_INLINE bool _doFRAME(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  312. {
  313. const uint64_t nwid = pkt.at<uint64_t>(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID);
  314. const SharedPtr<Network> network(RR->node->network(nwid));
  315. if (network) {
  316. if (network->gate(tPtr,peer)) {
  317. if (pkt.size() > ZT_PROTO_VERB_FRAME_IDX_PAYLOAD) {
  318. const unsigned int etherType = pkt.at<uint16_t>(ZT_PROTO_VERB_FRAME_IDX_ETHERTYPE);
  319. const MAC sourceMac(peer->address(),nwid);
  320. const unsigned int frameLen = pkt.size() - ZT_PROTO_VERB_FRAME_IDX_PAYLOAD;
  321. const uint8_t *const frameData = reinterpret_cast<const uint8_t *>(pkt.data()) + ZT_PROTO_VERB_FRAME_IDX_PAYLOAD;
  322. if (network->filterIncomingPacket(tPtr,peer,RR->identity.address(),sourceMac,network->mac(),frameData,frameLen,etherType,0) > 0)
  323. RR->node->putFrame(tPtr,nwid,network->userPtr(),sourceMac,network->mac(),etherType,0,(const void *)frameData,frameLen);
  324. }
  325. } else {
  326. RR->t->incomingNetworkFrameDropped(tPtr,nwid,MAC(),MAC(),peer->identity(),path->address(),pkt.hops(),0,nullptr,Packet::VERB_FRAME,true,ZT_TRACE_FRAME_DROP_REASON_PERMISSION_DENIED);
  327. _sendErrorNeedCredentials(pkt,RR,tPtr,peer,nwid,path);
  328. return false;
  329. }
  330. }
  331. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_FRAME,0,Packet::VERB_NOP,nwid);
  332. return true;
  333. }
  334. ZT_ALWAYS_INLINE bool _doEXT_FRAME(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  335. {
  336. const uint64_t nwid = pkt.at<uint64_t>(ZT_PROTO_VERB_EXT_FRAME_IDX_NETWORK_ID);
  337. const SharedPtr<Network> network(RR->node->network(nwid));
  338. if (network) {
  339. const unsigned int flags = pkt[ZT_PROTO_VERB_EXT_FRAME_IDX_FLAGS];
  340. unsigned int comLen = 0;
  341. if ((flags & 0x01) != 0) { // inline COM with EXT_FRAME is deprecated but still used with old peers
  342. CertificateOfMembership com;
  343. comLen = com.deserialize(pkt,ZT_PROTO_VERB_EXT_FRAME_IDX_COM);
  344. if (com)
  345. network->addCredential(tPtr,peer->identity(),com);
  346. }
  347. if (!network->gate(tPtr,peer)) {
  348. RR->t->incomingNetworkFrameDropped(tPtr,nwid,MAC(),MAC(),peer->identity(),path->address(),pkt.hops(),0,nullptr,Packet::VERB_EXT_FRAME,true,ZT_TRACE_FRAME_DROP_REASON_PERMISSION_DENIED);
  349. _sendErrorNeedCredentials(pkt,RR,tPtr,peer,nwid,path);
  350. return false;
  351. }
  352. if (pkt.size() > ZT_PROTO_VERB_EXT_FRAME_IDX_PAYLOAD) {
  353. const unsigned int etherType = pkt.at<uint16_t>(comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_ETHERTYPE);
  354. const MAC to(pkt.field(comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_TO,ZT_PROTO_VERB_EXT_FRAME_LEN_TO),ZT_PROTO_VERB_EXT_FRAME_LEN_TO);
  355. const MAC from(pkt.field(comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_FROM,ZT_PROTO_VERB_EXT_FRAME_LEN_FROM),ZT_PROTO_VERB_EXT_FRAME_LEN_FROM);
  356. const unsigned int frameLen = pkt.size() - (comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_PAYLOAD);
  357. const uint8_t *const frameData = (const uint8_t *)pkt.field(comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_PAYLOAD,frameLen);
  358. if ((!from)||(from == network->mac())) {
  359. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP,nwid);
  360. return true;
  361. }
  362. switch (network->filterIncomingPacket(tPtr,peer,RR->identity.address(),from,to,frameData,frameLen,etherType,0)) {
  363. case 1:
  364. if (from != MAC(peer->address(),nwid)) {
  365. if (network->config().permitsBridging(peer->address())) {
  366. network->learnBridgeRoute(from,peer->address());
  367. } else {
  368. RR->t->incomingNetworkFrameDropped(tPtr,nwid,from,to,peer->identity(),path->address(),pkt.hops(),(uint16_t)frameLen,frameData,Packet::VERB_EXT_FRAME,true,ZT_TRACE_FRAME_DROP_REASON_BRIDGING_NOT_ALLOWED_REMOTE);
  369. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP,nwid);
  370. return true;
  371. }
  372. } else if (to != network->mac()) {
  373. if (to.isMulticast()) {
  374. if (network->config().multicastLimit == 0) {
  375. RR->t->incomingNetworkFrameDropped(tPtr,nwid,from,to,peer->identity(),path->address(),pkt.hops(),(uint16_t)frameLen,frameData,Packet::VERB_EXT_FRAME,true,ZT_TRACE_FRAME_DROP_REASON_MULTICAST_DISABLED);
  376. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP,nwid);
  377. return true;
  378. }
  379. } else if (!network->config().permitsBridging(RR->identity.address())) {
  380. RR->t->incomingNetworkFrameDropped(tPtr,nwid,from,to,peer->identity(),path->address(),pkt.hops(),(uint16_t)frameLen,frameData,Packet::VERB_EXT_FRAME,true,ZT_TRACE_FRAME_DROP_REASON_BRIDGING_NOT_ALLOWED_LOCAL);
  381. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP,nwid);
  382. return true;
  383. }
  384. }
  385. // fall through -- 2 means accept regardless of bridging checks or other restrictions
  386. case 2:
  387. RR->node->putFrame(tPtr,nwid,network->userPtr(),from,to,etherType,0,(const void *)frameData,frameLen);
  388. break;
  389. }
  390. }
  391. if ((flags & 0x10U) != 0) { // ACK requested
  392. Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
  393. outp.append((uint8_t)Packet::VERB_EXT_FRAME);
  394. outp.append((uint64_t)pkt.packetId());
  395. outp.append((uint64_t)nwid);
  396. outp.armor(peer->key(),true);
  397. path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now());
  398. }
  399. }
  400. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP,nwid);
  401. return true;
  402. }
  403. ZT_ALWAYS_INLINE bool _doECHO(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  404. {
  405. if (!peer->rateGateEchoRequest(RR->node->now()))
  406. return true;
  407. const uint64_t pid = pkt.packetId();
  408. Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
  409. outp.append((unsigned char)Packet::VERB_ECHO);
  410. outp.append((uint64_t)pid);
  411. if (pkt.size() > ZT_PACKET_IDX_PAYLOAD)
  412. outp.append(reinterpret_cast<const unsigned char *>(pkt.data()) + ZT_PACKET_IDX_PAYLOAD,pkt.size() - ZT_PACKET_IDX_PAYLOAD);
  413. outp.armor(peer->key(),true);
  414. path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now());
  415. peer->received(tPtr,path,pkt.hops(),pid,pkt.payloadLength(),Packet::VERB_ECHO,0,Packet::VERB_NOP,0);
  416. return true;
  417. }
  418. ZT_ALWAYS_INLINE bool _doNETWORK_CREDENTIALS(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  419. {
  420. CertificateOfMembership com;
  421. Capability cap;
  422. Tag tag;
  423. Revocation revocation;
  424. CertificateOfOwnership coo;
  425. SharedPtr<Network> network;
  426. unsigned int p = ZT_PACKET_IDX_PAYLOAD;
  427. while ((p < pkt.size())&&(pkt[p] != 0)) {
  428. p += com.deserialize(pkt,p);
  429. if (com) {
  430. network = RR->node->network(com.networkId());
  431. if (network) {
  432. if (network->addCredential(tPtr,peer->identity(),com) == Membership::ADD_DEFERRED_FOR_WHOIS)
  433. return false;
  434. }
  435. }
  436. }
  437. ++p; // skip trailing 0 after COMs if present
  438. if (p < pkt.size()) { // older ZeroTier versions do not send capabilities, tags, or revocations
  439. const unsigned int numCapabilities = pkt.at<uint16_t>(p); p += 2;
  440. for(unsigned int i=0;i<numCapabilities;++i) {
  441. p += cap.deserialize(pkt,p);
  442. if ((!network)||(network->id() != cap.networkId()))
  443. network = RR->node->network(cap.networkId());
  444. if (network) {
  445. if (network->addCredential(tPtr,peer->identity(),cap) == Membership::ADD_DEFERRED_FOR_WHOIS)
  446. return false;
  447. }
  448. }
  449. if (p >= pkt.size()) return true;
  450. const unsigned int numTags = pkt.at<uint16_t>(p); p += 2;
  451. for(unsigned int i=0;i<numTags;++i) {
  452. p += tag.deserialize(pkt,p);
  453. if ((!network)||(network->id() != tag.networkId()))
  454. network = RR->node->network(tag.networkId());
  455. if (network) {
  456. if (network->addCredential(tPtr,peer->identity(),tag) == Membership::ADD_DEFERRED_FOR_WHOIS)
  457. return false;
  458. }
  459. }
  460. if (p >= pkt.size()) return true;
  461. const unsigned int numRevocations = pkt.at<uint16_t>(p); p += 2;
  462. for(unsigned int i=0;i<numRevocations;++i) {
  463. p += revocation.deserialize(pkt,p);
  464. if ((!network)||(network->id() != revocation.networkId()))
  465. network = RR->node->network(revocation.networkId());
  466. if (network) {
  467. if (network->addCredential(tPtr,peer->identity(),revocation) == Membership::ADD_DEFERRED_FOR_WHOIS)
  468. return false;
  469. }
  470. }
  471. if (p >= pkt.size()) return true;
  472. const unsigned int numCoos = pkt.at<uint16_t>(p); p += 2;
  473. for(unsigned int i=0;i<numCoos;++i) {
  474. p += coo.deserialize(pkt,p);
  475. if ((!network)||(network->id() != coo.networkId()))
  476. network = RR->node->network(coo.networkId());
  477. if (network) {
  478. if (network->addCredential(tPtr,peer->identity(),coo) == Membership::ADD_DEFERRED_FOR_WHOIS)
  479. return false;
  480. }
  481. }
  482. }
  483. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_NETWORK_CREDENTIALS,0,Packet::VERB_NOP,(network) ? network->id() : 0);
  484. return true;
  485. }
  486. ZT_ALWAYS_INLINE bool _doNETWORK_CONFIG_REQUEST(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  487. {
  488. const uint64_t nwid = pkt.at<uint64_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID);
  489. const unsigned int hopCount = pkt.hops();
  490. const uint64_t requestPacketId = pkt.packetId();
  491. if (RR->localNetworkController) {
  492. const unsigned int metaDataLength = (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN <= pkt.size()) ? pkt.at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN) : 0;
  493. const char *metaDataBytes = (metaDataLength != 0) ? (const char *)pkt.field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength) : (const char *)0;
  494. const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> metaData(metaDataBytes,metaDataLength);
  495. RR->localNetworkController->request(nwid,(hopCount > 0) ? InetAddress() : path->address(),requestPacketId,peer->identity(),metaData);
  496. } else {
  497. Packet outp(peer->address(),RR->identity.address(),Packet::VERB_ERROR);
  498. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  499. outp.append(requestPacketId);
  500. outp.append((unsigned char)Packet::ERROR_UNSUPPORTED_OPERATION);
  501. outp.append(nwid);
  502. outp.armor(peer->key(),true);
  503. path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now());
  504. }
  505. peer->received(tPtr,path,hopCount,requestPacketId,pkt.payloadLength(),Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP,nwid);
  506. return true;
  507. }
  508. ZT_ALWAYS_INLINE bool _doNETWORK_CONFIG(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  509. {
  510. const SharedPtr<Network> network(RR->node->network(pkt.at<uint64_t>(ZT_PACKET_IDX_PAYLOAD)));
  511. if (network) {
  512. const uint64_t configUpdateId = network->handleConfigChunk(tPtr,pkt.packetId(),pkt.source(),pkt,ZT_PACKET_IDX_PAYLOAD);
  513. if (configUpdateId) {
  514. Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
  515. outp.append((uint8_t)Packet::VERB_ECHO);
  516. outp.append((uint64_t)pkt.packetId());
  517. outp.append((uint64_t)network->id());
  518. outp.append((uint64_t)configUpdateId);
  519. outp.armor(peer->key(),true);
  520. path->send(RR,tPtr,outp.data(),outp.size(),RR->node->now());
  521. }
  522. }
  523. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_NETWORK_CONFIG,0,Packet::VERB_NOP,(network) ? network->id() : 0);
  524. return true;
  525. }
  526. ZT_ALWAYS_INLINE bool _doMULTICAST_GATHER(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  527. {
  528. const uint64_t nwid = pkt.at<uint64_t>(ZT_PROTO_VERB_MULTICAST_GATHER_IDX_NETWORK_ID);
  529. const unsigned int flags = pkt[ZT_PROTO_VERB_MULTICAST_GATHER_IDX_FLAGS];
  530. const MulticastGroup mg(MAC(pkt.field(ZT_PROTO_VERB_MULTICAST_GATHER_IDX_MAC,6),6),pkt.at<uint32_t>(ZT_PROTO_VERB_MULTICAST_GATHER_IDX_ADI));
  531. const unsigned int gatherLimit = pkt.at<uint32_t>(ZT_PROTO_VERB_MULTICAST_GATHER_IDX_GATHER_LIMIT);
  532. const SharedPtr<Network> network(RR->node->network(nwid));
  533. // LEGACY: older versions would send this
  534. if ((flags & 0x01U) != 0) {
  535. try {
  536. CertificateOfMembership com;
  537. com.deserialize(pkt,ZT_PROTO_VERB_MULTICAST_GATHER_IDX_COM);
  538. if ((com)&&(network))
  539. network->addCredential(tPtr,peer->identity(),com);
  540. } catch ( ... ) {} // discard invalid COMs
  541. }
  542. if (network) {
  543. if (!network->gate(tPtr,peer)) {
  544. _sendErrorNeedCredentials(pkt,RR,tPtr,peer,nwid,path);
  545. return false;
  546. }
  547. }
  548. const int64_t now = RR->node->now();
  549. if (gatherLimit) {
  550. // TODO
  551. /*
  552. Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
  553. outp.append((unsigned char)Packet::VERB_MULTICAST_GATHER);
  554. outp.append(packetId());
  555. outp.append(nwid);
  556. mg.mac().appendTo(outp);
  557. outp.append((uint32_t)mg.adi());
  558. const unsigned int gatheredLocally = RR->mc->gather(peer->address(),nwid,mg,outp,gatherLimit);
  559. if (gatheredLocally > 0) {
  560. outp.armor(peer->key(),true);
  561. _path->send(RR,tPtr,outp.data(),outp.size(),now);
  562. }
  563. */
  564. }
  565. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_MULTICAST_GATHER,0,Packet::VERB_NOP,nwid);
  566. return true;
  567. }
  568. volatile uint16_t junk = 0;
  569. ZT_ALWAYS_INLINE bool _doPUSH_DIRECT_PATHS(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  570. {
  571. const int64_t now = RR->node->now();
  572. if (peer->rateGateInboundPushDirectPaths(now)) {
  573. uint8_t countPerScope[ZT_INETADDRESS_MAX_SCOPE+1][2]; // [][0] is v4, [][1] is v6
  574. memset(countPerScope,0,sizeof(countPerScope));
  575. unsigned int count = pkt.at<uint16_t>(ZT_PACKET_IDX_PAYLOAD);
  576. unsigned int ptr = ZT_PACKET_IDX_PAYLOAD + 2;
  577. while (count--) {
  578. /* unsigned int flags = (*this)[ptr++]; */ ++ptr;
  579. unsigned int extLen = pkt.at<uint16_t>(ptr); ptr += 2;
  580. ptr += extLen; // unused right now
  581. unsigned int addrType = pkt[ptr++];
  582. unsigned int addrLen = pkt[ptr++];
  583. switch(addrType) {
  584. case 4: {
  585. const InetAddress a(pkt.field(ptr,4),4,pkt.at<uint16_t>(ptr + 4));
  586. if (peer->shouldTryPath(tPtr,now,peer,a)) {
  587. if (++countPerScope[(int)a.ipScope()][0] <= ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY) {
  588. RR->node->putPacket(tPtr,path->localSocket(),a,(const void *)&junk,sizeof(junk),2); // IPv4 "firewall opener"
  589. ++junk;
  590. peer->sendHELLO(tPtr,-1,a,now);
  591. RR->t->tryingNewPath(tPtr,peer->identity(),a,path->address(),pkt.packetId(),Packet::VERB_PUSH_DIRECT_PATHS,peer->address(),peer->identity().hash(),ZT_TRACE_TRYING_NEW_PATH_REASON_RECEIVED_PUSH_DIRECT_PATHS);
  592. }
  593. }
  594. } break;
  595. case 6: {
  596. const InetAddress a(pkt.field(ptr,16),16,pkt.at<uint16_t>(ptr + 16));
  597. if (peer->shouldTryPath(tPtr,now,peer,a)) {
  598. if (++countPerScope[(int)a.ipScope()][1] <= ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY) {
  599. peer->sendHELLO(tPtr,-1,a,now);
  600. RR->t->tryingNewPath(tPtr,peer->identity(),a,path->address(),pkt.packetId(),Packet::VERB_PUSH_DIRECT_PATHS,peer->address(),peer->identity().hash(),ZT_TRACE_TRYING_NEW_PATH_REASON_RECEIVED_PUSH_DIRECT_PATHS);
  601. }
  602. }
  603. } break;
  604. }
  605. ptr += addrLen;
  606. }
  607. }
  608. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_PUSH_DIRECT_PATHS,0,Packet::VERB_NOP,0);
  609. return true;
  610. }
  611. ZT_ALWAYS_INLINE bool _doUSER_MESSAGE(IncomingPacket &pkt,const RuntimeEnvironment *const RR,void *const tPtr,const SharedPtr<Peer> &peer,const SharedPtr<Path> &path)
  612. {
  613. if (likely(pkt.size() >= (ZT_PACKET_IDX_PAYLOAD + 8))) {
  614. ZT_UserMessage um;
  615. um.id = (const ZT_Identity *)(&(peer->identity()));
  616. um.typeId = pkt.at<uint64_t>(ZT_PACKET_IDX_PAYLOAD);
  617. um.data = reinterpret_cast<const void *>(reinterpret_cast<const uint8_t *>(pkt.data()) + ZT_PACKET_IDX_PAYLOAD + 8);
  618. um.length = pkt.size() - (ZT_PACKET_IDX_PAYLOAD + 8);
  619. RR->node->postEvent(tPtr,ZT_EVENT_USER_MESSAGE,reinterpret_cast<const void *>(&um));
  620. }
  621. peer->received(tPtr,path,pkt.hops(),pkt.packetId(),pkt.payloadLength(),Packet::VERB_USER_MESSAGE,0,Packet::VERB_NOP,0);
  622. return true;
  623. }
  624. //////////////////////////////////////////////////////////////////////////////
  625. } // anonymous namespace
  626. bool IncomingPacket::tryDecode(const RuntimeEnvironment *RR,void *tPtr)
  627. {
  628. const Address sourceAddress(source());
  629. const SharedPtr<Peer> peer(RR->topology->get(tPtr,sourceAddress));
  630. try {
  631. // Check for trusted paths or unencrypted HELLOs (HELLO is the only packet sent in the clear)
  632. const unsigned int c = cipher();
  633. bool trusted = false;
  634. if (c == ZT_PROTO_CIPHER_SUITE__NONE) {
  635. // If this is marked as a packet via a trusted path, check source address and path ID.
  636. // Obviously if no trusted paths are configured this always returns false and such
  637. // packets are dropped on the floor.
  638. const uint64_t tpid = trustedPathId();
  639. if (RR->topology->shouldInboundPathBeTrusted(_path->address(),tpid)) {
  640. trusted = true;
  641. } else {
  642. if (peer)
  643. RR->t->incomingPacketDropped(tPtr,packetId(),0,peer->identity(),_path->address(),hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MAC_FAILED);
  644. return true;
  645. }
  646. } else if ((c == ZT_PROTO_CIPHER_SUITE__POLY1305_NONE)&&(verb() == Packet::VERB_HELLO)) {
  647. // Only HELLO is allowed in the clear, but will still have a MAC
  648. return _doHELLO(*this,RR,tPtr,false,_path);
  649. }
  650. if (!peer) {
  651. RR->sw->requestWhois(tPtr,RR->node->now(),sourceAddress);
  652. return false;
  653. }
  654. if (!trusted) {
  655. if (!dearmor(peer->key())) {
  656. RR->t->incomingPacketDropped(tPtr,packetId(),0,peer->identity(),_path->address(),hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_MAC_FAILED);
  657. return true;
  658. }
  659. }
  660. if (!uncompress()) {
  661. RR->t->incomingPacketDropped(tPtr,packetId(),0,peer->identity(),_path->address(),hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_INVALID_COMPRESSED_DATA);
  662. return true;
  663. }
  664. const Packet::Verb v = verb();
  665. bool r = true;
  666. switch(v) {
  667. default: // ignore unknown verbs, but if they pass auth check they are "received" and considered NOPs by peer->receive()
  668. RR->t->incomingPacketDropped(tPtr,packetId(),0,peer->identity(),_path->address(),hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_UNRECOGNIZED_VERB);
  669. // fall through
  670. case Packet::VERB_NOP:
  671. peer->received(tPtr,_path,hops(),packetId(),payloadLength(),v,0,Packet::VERB_NOP,0);
  672. break;
  673. case Packet::VERB_HELLO: r = _doHELLO(*this,RR,tPtr,true,_path); break;
  674. case Packet::VERB_ERROR: r = _doERROR(*this,RR,tPtr,peer,_path); break;
  675. case Packet::VERB_OK: r = _doOK(*this,RR,tPtr,peer,_path); break;
  676. case Packet::VERB_WHOIS: r = _doWHOIS(*this,RR,tPtr,peer,_path); break;
  677. case Packet::VERB_RENDEZVOUS: r = _doRENDEZVOUS(*this,RR,tPtr,peer,_path); break;
  678. case Packet::VERB_FRAME: r = _doFRAME(*this,RR,tPtr,peer,_path); break;
  679. case Packet::VERB_EXT_FRAME: r = _doEXT_FRAME(*this,RR,tPtr,peer,_path); break;
  680. case Packet::VERB_ECHO: r = _doECHO(*this,RR,tPtr,peer,_path); break;
  681. case Packet::VERB_NETWORK_CREDENTIALS: r = _doNETWORK_CREDENTIALS(*this,RR,tPtr,peer,_path); break;
  682. case Packet::VERB_NETWORK_CONFIG_REQUEST: r = _doNETWORK_CONFIG_REQUEST(*this,RR,tPtr,peer,_path); break;
  683. case Packet::VERB_NETWORK_CONFIG: r = _doNETWORK_CONFIG(*this,RR,tPtr,peer,_path); break;
  684. case Packet::VERB_MULTICAST_GATHER: r = _doMULTICAST_GATHER(*this,RR,tPtr,peer,_path); break;
  685. case Packet::VERB_PUSH_DIRECT_PATHS: r = _doPUSH_DIRECT_PATHS(*this,RR,tPtr,peer,_path); break;
  686. case Packet::VERB_USER_MESSAGE: r = _doUSER_MESSAGE(*this,RR,tPtr,peer,_path); break;
  687. }
  688. return r;
  689. } catch (int ztExcCode) {
  690. } catch ( ... ) {}
  691. if (peer)
  692. RR->t->incomingPacketDropped(tPtr,packetId(),0,peer->identity(),_path->address(),hops(),Packet::VERB_HELLO,ZT_TRACE_PACKET_DROP_REASON_UNSPECIFIED);
  693. return true;
  694. }
  695. } // namespace ZeroTier