Trace.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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. }
  118. _send(tPtr,d,network);
  119. }
  120. 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)
  121. {
  122. if (!network) return; // sanity check
  123. char tmp[128];
  124. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  125. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__INCOMING_NETWORK_ACCESS_DENIED_S);
  126. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  127. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_VERB,(uint64_t)verb);
  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. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,network->id());
  134. _send(tPtr,d,network);
  135. }
  136. 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,const char *reason)
  137. {
  138. if (!network) return; // sanity check
  139. char tmp[128];
  140. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  141. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__INCOMING_NETWORK_FRAME_DROPPED_S);
  142. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  143. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_VERB,(uint64_t)verb);
  144. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  145. if (path) {
  146. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  147. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  148. }
  149. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,network->id());
  150. d.add(ZT_REMOTE_TRACE_FIELD__SOURCE_MAC,sourceMac.toInt());
  151. d.add(ZT_REMOTE_TRACE_FIELD__DEST_MAC,destMac.toInt());
  152. if (reason)
  153. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  154. _send(tPtr,d,network);
  155. }
  156. void Trace::incomingPacketTrustedPath(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const uint64_t trustedPathId,bool approved)
  157. {
  158. // TODO
  159. }
  160. void Trace::incomingPacketMessageAuthenticationFailure(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const unsigned int hops)
  161. {
  162. char tmp[128];
  163. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  164. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PACKET_MAC_FAILURE_S);
  165. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  166. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_HOPS,(uint64_t)hops);
  167. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  168. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  169. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  170. _send(tPtr,d,0);
  171. }
  172. 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)
  173. {
  174. char tmp[128];
  175. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  176. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PACKET_INVALID_S);
  177. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  178. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_VERB,(uint64_t)verb);
  179. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  180. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  181. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  182. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_HOPS,(uint64_t)hops);
  183. if (reason)
  184. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  185. _send(tPtr,d,0);
  186. }
  187. void Trace::incomingPacketDroppedHELLO(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const char *reason)
  188. {
  189. char tmp[128];
  190. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  191. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__PACKET_INVALID_S);
  192. d.add(ZT_REMOTE_TRACE_FIELD__PACKET_ID,packetId);
  193. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_ZTADDR,source);
  194. d.add(ZT_REMOTE_TRACE_FIELD__REMOTE_PHYADDR,path->address().toString(tmp));
  195. d.add(ZT_REMOTE_TRACE_FIELD__LOCAL_SOCKET,path->localSocket());
  196. if (reason)
  197. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  198. _send(tPtr,d,0);
  199. }
  200. void Trace::networkConfigRequestSent(void *const tPtr,const Network &network,const Address &controller)
  201. {
  202. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  203. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__NETWORK_CONFIG_REQUEST_SENT_S);
  204. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,network.id());
  205. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_CONTROLLER_ID,controller);
  206. _send(tPtr,d,0);
  207. }
  208. void Trace::networkFilter(
  209. void *const tPtr,
  210. const Network &network,
  211. const RuleResultLog &primaryRuleSetLog,
  212. const RuleResultLog *const matchingCapabilityRuleSetLog,
  213. const Capability *const matchingCapability,
  214. const Address &ztSource,
  215. const Address &ztDest,
  216. const MAC &macSource,
  217. const MAC &macDest,
  218. const uint8_t *const frameData,
  219. const unsigned int frameLen,
  220. const unsigned int etherType,
  221. const unsigned int vlanId,
  222. const bool noTee,
  223. const bool inbound,
  224. const int accept)
  225. {
  226. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  227. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__NETWORK_FILTER_TRACE_S);
  228. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,network.id());
  229. d.add(ZT_REMOTE_TRACE_FIELD__SOURCE_ZTADDR,ztSource);
  230. d.add(ZT_REMOTE_TRACE_FIELD__DEST_ZTADDR,ztDest);
  231. d.add(ZT_REMOTE_TRACE_FIELD__SOURCE_MAC,macSource.toInt());
  232. d.add(ZT_REMOTE_TRACE_FIELD__DEST_MAC,macDest.toInt());
  233. d.add(ZT_REMOTE_TRACE_FIELD__ETHERTYPE,(uint64_t)etherType);
  234. d.add(ZT_REMOTE_TRACE_FIELD__VLAN_ID,(uint64_t)vlanId);
  235. d.add(ZT_REMOTE_TRACE_FIELD__FILTER_FLAG_NOTEE,noTee ? "1" : "0");
  236. d.add(ZT_REMOTE_TRACE_FIELD__FILTER_FLAG_INBOUND,inbound ? "1" : "0");
  237. d.add(ZT_REMOTE_TRACE_FIELD__FILTER_RESULT,(int64_t)accept);
  238. d.add(ZT_REMOTE_TRACE_FIELD__FILTER_BASE_RULE_LOG,(const char *)primaryRuleSetLog.data(),(int)primaryRuleSetLog.sizeBytes());
  239. if (matchingCapabilityRuleSetLog)
  240. d.add(ZT_REMOTE_TRACE_FIELD__FILTER_CAP_RULE_LOG,(const char *)matchingCapabilityRuleSetLog->data(),(int)matchingCapabilityRuleSetLog->sizeBytes());
  241. if (matchingCapability)
  242. d.add(ZT_REMOTE_TRACE_FIELD__FILTER_CAP_ID,(uint64_t)matchingCapability->id());
  243. d.add(ZT_REMOTE_TRACE_FIELD__FRAME_LENGTH,(uint64_t)frameLen);
  244. if (frameLen > 0)
  245. d.add(ZT_REMOTE_TRACE_FIELD__FRAME_DATA,(const char *)frameData,(frameLen > 256) ? (int)256 : (int)frameLen);
  246. _send(tPtr,d,network.id());
  247. }
  248. void Trace::credentialRejected(void *const tPtr,const CertificateOfMembership &c,const char *reason)
  249. {
  250. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  251. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  252. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  253. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  254. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  255. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  256. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  257. if (reason)
  258. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  259. _send(tPtr,d,0);
  260. }
  261. void Trace::credentialRejected(void *const tPtr,const CertificateOfOwnership &c,const char *reason)
  262. {
  263. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  264. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  265. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  266. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  267. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  268. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  269. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  270. if (reason)
  271. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  272. _send(tPtr,d,0);
  273. }
  274. void Trace::credentialRejected(void *const tPtr,const CertificateOfRepresentation &c,const char *reason)
  275. {
  276. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  277. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  278. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  279. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  280. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  281. if (reason)
  282. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  283. _send(tPtr,d,0);
  284. }
  285. void Trace::credentialRejected(void *const tPtr,const Capability &c,const char *reason)
  286. {
  287. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  288. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  289. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  290. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  291. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  292. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  293. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  294. if (reason)
  295. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  296. _send(tPtr,d,0);
  297. }
  298. void Trace::credentialRejected(void *const tPtr,const Tag &c,const char *reason)
  299. {
  300. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  301. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  302. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  303. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  304. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  305. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  306. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  307. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_INFO,(uint64_t)c.value());
  308. if (reason)
  309. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  310. _send(tPtr,d,0);
  311. }
  312. void Trace::credentialRejected(void *const tPtr,const Revocation &c,const char *reason)
  313. {
  314. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  315. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_REJECTED_S);
  316. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  317. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  318. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  319. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_REVOCATION_TARGET,c.target());
  320. if (reason)
  321. d.add(ZT_REMOTE_TRACE_FIELD__REASON,reason);
  322. _send(tPtr,d,0);
  323. }
  324. void Trace::credentialAccepted(void *const tPtr,const CertificateOfMembership &c)
  325. {
  326. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  327. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  328. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  329. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  330. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  331. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  332. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  333. _send(tPtr,d,0);
  334. }
  335. void Trace::credentialAccepted(void *const tPtr,const CertificateOfOwnership &c)
  336. {
  337. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  338. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  339. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  340. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  341. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  342. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  343. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  344. _send(tPtr,d,0);
  345. }
  346. void Trace::credentialAccepted(void *const tPtr,const CertificateOfRepresentation &c)
  347. {
  348. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  349. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  350. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  351. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  352. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  353. _send(tPtr,d,0);
  354. }
  355. void Trace::credentialAccepted(void *const tPtr,const Capability &c)
  356. {
  357. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  358. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  359. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  360. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  361. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  362. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  363. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  364. _send(tPtr,d,0);
  365. }
  366. void Trace::credentialAccepted(void *const tPtr,const Tag &c)
  367. {
  368. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  369. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  370. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  371. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  372. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  373. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TIMESTAMP,c.timestamp());
  374. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ISSUED_TO,c.issuedTo());
  375. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_INFO,(uint64_t)c.value());
  376. _send(tPtr,d,0);
  377. }
  378. void Trace::credentialAccepted(void *const tPtr,const Revocation &c)
  379. {
  380. Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
  381. d.add(ZT_REMOTE_TRACE_FIELD__EVENT,ZT_REMOTE_TRACE_EVENT__CREDENTIAL_ACCEPTED_S);
  382. d.add(ZT_REMOTE_TRACE_FIELD__NETWORK_ID,c.networkId());
  383. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_TYPE,(uint64_t)c.credentialType());
  384. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_ID,(uint64_t)c.id());
  385. d.add(ZT_REMOTE_TRACE_FIELD__CREDENTIAL_REVOCATION_TARGET,c.target());
  386. _send(tPtr,d,0);
  387. }
  388. void Trace::_send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d)
  389. {
  390. #ifdef ZT_TRACE
  391. unsigned int i = 0;
  392. while (i < (unsigned int)(sizeof(_traceMsgBuf) - 1)) {
  393. const char c = d.data()[i];
  394. if (c == 0) {
  395. break;
  396. } else if (c == '\n') {
  397. _traceMsgBuf[i++] = ' ';
  398. } else if ((c >= 32)&&(c <= 126)) {
  399. _traceMsgBuf[i++] = c;
  400. } else {
  401. if ((i + 3) < (unsigned int)(sizeof(_traceMsgBuf) - 1)) {
  402. _traceMsgBuf[i++] = '\\';
  403. Utils::hex((uint8_t)c,_traceMsgBuf + i);
  404. }
  405. }
  406. }
  407. _traceMsgBuf[i] = (char)0;
  408. //printf("%s\n",_traceMsgBuf);
  409. RR->node->postEvent(tPtr,ZT_EVENT_TRACE,_traceMsgBuf);
  410. #endif
  411. const Address rtt(RR->node->remoteTraceTarget());
  412. if (rtt) {
  413. Packet outp(rtt,RR->identity.address(),Packet::VERB_REMOTE_TRACE);
  414. outp.appendCString(d.data());
  415. outp.compress();
  416. RR->sw->send(tPtr,outp,true);
  417. }
  418. }
  419. void Trace::_send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d,const uint64_t networkId)
  420. {
  421. _send(tPtr,d);
  422. if (networkId) {
  423. const SharedPtr<Network> network(RR->node->network(networkId));
  424. if ((network)&&(network->config().remoteTraceTarget)) {
  425. Packet outp(network->config().remoteTraceTarget,RR->identity.address(),Packet::VERB_REMOTE_TRACE);
  426. outp.appendCString(d.data());
  427. outp.compress();
  428. RR->sw->send(tPtr,outp,true);
  429. }
  430. }
  431. }
  432. void Trace::_send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d,const SharedPtr<Network> &network)
  433. {
  434. _send(tPtr,d);
  435. if ((network)&&(network->config().remoteTraceTarget)) {
  436. Packet outp(network->config().remoteTraceTarget,RR->identity.address(),Packet::VERB_REMOTE_TRACE);
  437. outp.appendCString(d.data());
  438. outp.compress();
  439. RR->sw->send(tPtr,outp,true);
  440. }
  441. }
  442. } // namespace ZeroTier