Trace.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #include "Trace.hpp"
  27. #include "RuntimeEnvironment.hpp"
  28. #include "Switch.hpp"
  29. #include "Node.hpp"
  30. #include "Utils.hpp"
  31. #include "Dictionary.hpp"
  32. #include "CertificateOfMembership.hpp"
  33. #include "CertificateOfOwnership.hpp"
  34. #include "CertificateOfRepresentation.hpp"
  35. #include "Tag.hpp"
  36. #include "Capability.hpp"
  37. #include "Revocation.hpp"
  38. namespace ZeroTier {
  39. void Trace::resettingPathsInScope(void *const tPtr,const Address &reporter,const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,const InetAddress::IpScope scope)
  40. {
  41. char tmp[128];
  42. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  43. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__RESETTING_PATHS_IN_SCOPE_S);
  44. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,reporter);
  45. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,reporterPhysicalAddress.toString(tmp));
  46. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_PHYADDR,myPhysicalAddress.toString(tmp));
  47. d.add(ZT_REMOTE_TRACE_FIELD__IP_SCOPE,(uint64_t)scope);
  48. _send(tPtr,d,0);
  49. }
  50. void Trace::txTimedOut(void *const tPtr,const Address &destination)
  51. {
  52. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  53. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__TX_TIMED_OUT_S);
  54. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,destination);
  55. _send(tPtr,d,0);
  56. }
  57. void Trace::peerConfirmingUnknownPath(void *const tPtr,const uint64_t networkId,Peer &peer,const SharedPtr<Path> &path,const uint64_t packetId,const Packet::Verb verb)
  58. {
  59. char tmp[128];
  60. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  61. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PEER_CONFIRMING_UNKNOWN_PATH_S);
  62. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  63. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_VERB,(uint64_t)verb);
  64. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,networkId);
  65. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,peer.address());
  66. if (path) {
  67. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  68. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  69. }
  70. _send(tPtr,d,networkId);
  71. }
  72. void Trace::peerLearnedNewPath(void *const tPtr,const uint64_t networkId,Peer &peer,const SharedPtr<Path> &oldPath,const SharedPtr<Path> &newPath,const uint64_t packetId)
  73. {
  74. char tmp[128];
  75. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  76. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PEER_LEARNED_NEW_PATH_S);
  77. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  78. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,networkId);
  79. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,peer.address());
  80. if (oldPath) {
  81. d.add(ZT_REMOTE_TRACE_FIELD__OLD_REMOTE_PHYADDR,oldPath->address().toString(tmp));
  82. }
  83. if (newPath) {
  84. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,newPath->address().toString(tmp));
  85. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,newPath->localSocket());
  86. }
  87. _send(tPtr,d,networkId);
  88. }
  89. void Trace::peerRedirected(void *const tPtr,const uint64_t networkId,Peer &peer,const SharedPtr<Path> &oldPath,const SharedPtr<Path> &newPath)
  90. {
  91. char tmp[128];
  92. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  93. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PEER_REDIRECTED_S);
  94. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,networkId);
  95. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,peer.address());
  96. if (oldPath) {
  97. d.add(ZT_REMOTE_TRACE_FIELD__OLD_REMOTE_PHYADDR,oldPath->address().toString(tmp));
  98. }
  99. if (newPath) {
  100. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,newPath->address().toString(tmp));
  101. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,newPath->localSocket());
  102. }
  103. _send(tPtr,d,networkId);
  104. }
  105. void Trace::outgoingNetworkFrameDropped(void *const tPtr,const SharedPtr<Network> &network,const MAC &sourceMac,const MAC &destMac,const unsigned int etherType,const unsigned int vlanId,const unsigned int frameLen,const char *reason)
  106. {
  107. if (!network) return; // sanity check
  108. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  109. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__OUTGOING_NETWORK_FRAME_DROPPED_S);
  110. d.add(ZT_REMOTE_TRACE_FIELD__SOURCE_MAC,sourceMac.toInt());
  111. d.add(ZT_REMOTE_TRACE_FIELD__DEST_MAC,destMac.toInt());
  112. d.add(ZT_REMOTE_TRACE_FIELD__ETHERTYPE,(uint64_t)etherType);
  113. d.add(ZT_REMOTE_TRACE_FIELD__VLAN_ID,(uint64_t)vlanId);
  114. d.add(ZT_REMOTE_TRACE_FIELD__FRAME_LENGTH,(uint64_t)frameLen);
  115. if (reason)
  116. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  117. _send(tPtr,d,network);
  118. }
  119. void Trace::incomingNetworkAccessDenied(void *const tPtr,const SharedPtr<Network> &network,const SharedPtr<Path> &path,const uint64_t packetId,const unsigned int packetLength,const Address &source,const Packet::Verb verb,bool credentialsRequested)
  120. {
  121. if (!network) return; // sanity check
  122. char tmp[128];
  123. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  124. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__INCOMING_NETWORK_ACCESS_DENIED_S);
  125. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  126. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_VERB,(uint64_t)verb);
  127. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,network->id());
  128. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  129. if (path) {
  130. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  131. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  132. }
  133. }
  134. void Trace::incomingNetworkFrameDropped(void *const tPtr,const SharedPtr<Network> &network,const SharedPtr<Path> &path,const uint64_t packetId,const unsigned int packetLength,const Address &source,const Packet::Verb verb,const MAC &sourceMac,const MAC &destMac)
  135. {
  136. //Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  137. //d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__INCOMING_NETWORK_FRAME_DROPPED_S);
  138. }
  139. void Trace::incomingPacketTrustedPath(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const uint64_t trustedPathId,bool approved)
  140. {
  141. // TODO
  142. }
  143. void Trace::incomingPacketMessageAuthenticationFailure(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const unsigned int hops)
  144. {
  145. char tmp[128];
  146. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  147. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PACKET_MAC_FAILURE_S);
  148. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  149. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_HOPS,(uint64_t)hops);
  150. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  151. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  152. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  153. _send(tPtr,d,0);
  154. }
  155. void Trace::incomingPacketInvalid(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const unsigned int hops,const Packet::Verb verb,const char *reason)
  156. {
  157. char tmp[128];
  158. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  159. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PACKET_INVALID_S);
  160. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  161. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_VERB,(uint64_t)verb);
  162. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  163. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  164. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  165. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_HOPS,(uint64_t)hops);
  166. if (reason)
  167. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  168. _send(tPtr,d,0);
  169. }
  170. void Trace::incomingPacketDroppedHELLO(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const char *reason)
  171. {
  172. char tmp[128];
  173. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  174. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PACKET_INVALID_S);
  175. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  176. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  177. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  178. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  179. if (reason)
  180. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  181. _send(tPtr,d,0);
  182. }
  183. void Trace::networkConfigRequestSent(void *const tPtr,const Network &network,const Address &controller)
  184. {
  185. }
  186. void Trace::networkFilter(
  187. void *const tPtr,
  188. const Network &network,
  189. const RuleResultLog &primaryRuleSetLog,
  190. const RuleResultLog *const matchingCapabilityRuleSetLog,
  191. const Capability *const matchingCapability,
  192. const Address &ztSource,
  193. const Address &ztDest,
  194. const MAC &macSource,
  195. const MAC &macDest,
  196. const uint8_t *const frameData,
  197. const unsigned int frameLen,
  198. const unsigned int etherType,
  199. const unsigned int vlanId,
  200. const bool noTee,
  201. const bool inbound,
  202. const int accept)
  203. {
  204. //char tmp[128];
  205. //Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  206. //_send(tPtr,d,network.id());
  207. }
  208. void Trace::credentialRejected(void *const tPtr,const CertificateOfMembership &c,const char *reason)
  209. {
  210. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  211. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  212. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  213. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  214. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  215. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  216. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  217. if (reason)
  218. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  219. _send(tPtr,d,0);
  220. }
  221. void Trace::credentialRejected(void *const tPtr,const CertificateOfOwnership &c,const char *reason)
  222. {
  223. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  224. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  225. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  226. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  227. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  228. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  229. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  230. if (reason)
  231. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  232. _send(tPtr,d,0);
  233. }
  234. void Trace::credentialRejected(void *const tPtr,const CertificateOfRepresentation &c,const char *reason)
  235. {
  236. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  237. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  238. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  239. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  240. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  241. if (reason)
  242. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  243. _send(tPtr,d,0);
  244. }
  245. void Trace::credentialRejected(void *const tPtr,const Capability &c,const char *reason)
  246. {
  247. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  248. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  249. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  250. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  251. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  252. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  253. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  254. if (reason)
  255. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  256. _send(tPtr,d,0);
  257. }
  258. void Trace::credentialRejected(void *const tPtr,const Tag &c,const char *reason)
  259. {
  260. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  261. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  262. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  263. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  264. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  265. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  266. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  267. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_INFO,(uint64_t)c.value());
  268. if (reason)
  269. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  270. _send(tPtr,d,0);
  271. }
  272. void Trace::credentialRejected(void *const tPtr,const Revocation &c,const char *reason)
  273. {
  274. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  275. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  276. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  277. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  278. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  279. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_REVOCATION_TARGET,c.target());
  280. if (reason)
  281. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  282. _send(tPtr,d,0);
  283. }
  284. void Trace::credentialAccepted(void *const tPtr,const CertificateOfMembership &c)
  285. {
  286. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  287. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  288. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  289. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  290. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  291. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  292. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  293. _send(tPtr,d,0);
  294. }
  295. void Trace::credentialAccepted(void *const tPtr,const CertificateOfOwnership &c)
  296. {
  297. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  298. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  299. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  300. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  301. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  302. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  303. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  304. _send(tPtr,d,0);
  305. }
  306. void Trace::credentialAccepted(void *const tPtr,const CertificateOfRepresentation &c)
  307. {
  308. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  309. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  310. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  311. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  312. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  313. _send(tPtr,d,0);
  314. }
  315. void Trace::credentialAccepted(void *const tPtr,const Capability &c)
  316. {
  317. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  318. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  319. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  320. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  321. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  322. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  323. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  324. _send(tPtr,d,0);
  325. }
  326. void Trace::credentialAccepted(void *const tPtr,const Tag &c)
  327. {
  328. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  329. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  330. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  331. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  332. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  333. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  334. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  335. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_INFO,(uint64_t)c.value());
  336. _send(tPtr,d,0);
  337. }
  338. void Trace::credentialAccepted(void *const tPtr,const Revocation &c)
  339. {
  340. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  341. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  342. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  343. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  344. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  345. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_REVOCATION_TARGET,c.target());
  346. _send(tPtr,d,0);
  347. }
  348. void Trace::_send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d)
  349. {
  350. #ifdef ZT_TRACE
  351. unsigned int i = 0;
  352. while (i < (unsigned int)(sizeof(_traceMsgBuf) - 1)) {
  353. const char c = d.data()[i];
  354. if (c == 0) {
  355. break;
  356. } else if (c == '\n') {
  357. _traceMsgBuf[i++] = ' ';
  358. } else if ((c >= 32)&&(c <= 126)) {
  359. _traceMsgBuf[i++] = c;
  360. } else {
  361. if ((i + 3) < (unsigned int)(sizeof(_traceMsgBuf) - 1)) {
  362. _traceMsgBuf[i++] = '\\';
  363. Utils::hex((uint8_t)c,_traceMsgBuf + i);
  364. }
  365. }
  366. }
  367. _traceMsgBuf[i] = (char)0;
  368. //printf("%s\n",_traceMsgBuf);
  369. RR->node->postEvent(tPtr,ZT_EVENT_TRACE,_traceMsgBuf);
  370. #endif
  371. const Address rtt(RR->node->remoteTraceTarget());
  372. if (rtt) {
  373. Packet outp(rtt,RR->identity.address(),Packet::VERB_REMOTE_TRACE);
  374. outp.appendCString(d.data());
  375. outp.compress();
  376. RR->sw->send(tPtr,outp,true);
  377. }
  378. }
  379. void Trace::_send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d,const uint64_t networkId)
  380. {
  381. _send(tPtr,d);
  382. if (networkId) {
  383. const SharedPtr<Network> network(RR->node->network(networkId));
  384. if ((network)&&(network->config().remoteTraceTarget)) {
  385. Packet outp(network->config().remoteTraceTarget,RR->identity.address(),Packet::VERB_REMOTE_TRACE);
  386. outp.appendCString(d.data());
  387. outp.compress();
  388. RR->sw->send(tPtr,outp,true);
  389. }
  390. }
  391. }
  392. void Trace::_send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d,const SharedPtr<Network> &network)
  393. {
  394. _send(tPtr,d);
  395. if ((network)&&(network->config().remoteTraceTarget)) {
  396. Packet outp(network->config().remoteTraceTarget,RR->identity.address(),Packet::VERB_REMOTE_TRACE);
  397. outp.appendCString(d.data());
  398. outp.compress();
  399. RR->sw->send(tPtr,outp,true);
  400. }
  401. }
  402. } // namespace ZeroTier