Trace.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #ifndef ZT_TRACE_HPP
  27. #define ZT_TRACE_HPP
  28. #include <stdio.h>
  29. #include <stdint.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include "../include/ZeroTierOne.h"
  33. #include "Constants.hpp"
  34. #include "SharedPtr.hpp"
  35. #include "Packet.hpp"
  36. #include "Credential.hpp"
  37. #include "InetAddress.hpp"
  38. #include "Dictionary.hpp"
  39. namespace ZeroTier {
  40. class RuntimeEnvironment;
  41. class Address;
  42. class Identity;
  43. class Peer;
  44. class Path;
  45. class Network;
  46. class NetworkConfig;
  47. class MAC;
  48. class CertificateOfMembership;
  49. class CertificateOfOwnership;
  50. class Revocation;
  51. class Tag;
  52. class Capability;
  53. /**
  54. * Remote tracing and trace logging handler
  55. */
  56. class Trace
  57. {
  58. public:
  59. /**
  60. * Filter rule evaluation result log
  61. *
  62. * Each rule in a rule set gets a four-bit log entry. A log entry
  63. * of zero means not evaluated. Otherwise each four-bit log entry
  64. * contains two two-bit values of 01 for 'false' and 10 for 'true'.
  65. * As with four-bit rules an 00 value here means this was not
  66. * evaluated or was not relevant.
  67. */
  68. class RuleResultLog
  69. {
  70. public:
  71. RuleResultLog() {}
  72. inline void log(const unsigned int rn,const uint8_t thisRuleMatches,const uint8_t thisSetMatches)
  73. {
  74. _l[rn >> 1] |= ( ((thisRuleMatches + 1) << 2) | (thisSetMatches + 1) ) << ((rn & 1) << 2);
  75. }
  76. inline void logSkipped(const unsigned int rn,const uint8_t thisSetMatches)
  77. {
  78. _l[rn >> 1] |= (thisSetMatches + 1) << ((rn & 1) << 2);
  79. }
  80. inline void clear()
  81. {
  82. memset(_l,0,sizeof(_l));
  83. }
  84. inline const uint8_t *data() const { return _l; }
  85. inline unsigned int sizeBytes() const { return (ZT_MAX_NETWORK_RULES / 2); }
  86. private:
  87. uint8_t _l[ZT_MAX_NETWORK_RULES / 2];
  88. };
  89. Trace(const RuntimeEnvironment *renv) : RR(renv) {}
  90. void resettingPathsInScope(void *const tPtr,const Address &reporter,const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,const InetAddress::IpScope scope);
  91. void txTimedOut(void *const tPtr,const Address &destination);
  92. void peerConfirmingUnknownPath(void *const tPtr,const uint64_t networkId,Peer &peer,const SharedPtr<Path> &path,const uint64_t packetId,const Packet::Verb verb);
  93. void peerLearnedNewPath(void *const tPtr,const uint64_t networkId,Peer &peer,const SharedPtr<Path> &oldPath,const SharedPtr<Path> &newPath,const uint64_t packetId);
  94. void peerRedirected(void *const tPtr,const uint64_t networkId,Peer &peer,const SharedPtr<Path> &newPath);
  95. void incomingPacketMessageAuthenticationFailure(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const unsigned int hops,const char *reason);
  96. void 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);
  97. void incomingPacketDroppedHELLO(void *const tPtr,const SharedPtr<Path> &path,const uint64_t packetId,const Address &source,const char *reason);
  98. void 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);
  99. void 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);
  100. void 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);
  101. void networkConfigRequestSent(void *const tPtr,const Network &network,const Address &controller);
  102. void networkFilter(
  103. void *const tPtr,
  104. const Network &network,
  105. const RuleResultLog &primaryRuleSetLog,
  106. const RuleResultLog *const matchingCapabilityRuleSetLog,
  107. const Capability *const matchingCapability,
  108. const Address &ztSource,
  109. const Address &ztDest,
  110. const MAC &macSource,
  111. const MAC &macDest,
  112. const uint8_t *const frameData,
  113. const unsigned int frameLen,
  114. const unsigned int etherType,
  115. const unsigned int vlanId,
  116. const bool noTee,
  117. const bool inbound,
  118. const int accept);
  119. void credentialRejected(void *const tPtr,const CertificateOfMembership &c,const char *reason);
  120. void credentialRejected(void *const tPtr,const CertificateOfOwnership &c,const char *reason);
  121. void credentialRejected(void *const tPtr,const Capability &c,const char *reason);
  122. void credentialRejected(void *const tPtr,const Tag &c,const char *reason);
  123. void credentialRejected(void *const tPtr,const Revocation &c,const char *reason);
  124. private:
  125. const RuntimeEnvironment *const RR;
  126. void _send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d);
  127. void _send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d,const uint64_t networkId);
  128. void _send(void *const tPtr,const Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> &d,const Network &network);
  129. #ifdef ZT_TRACE
  130. char _traceMsgBuf[4096];
  131. #endif
  132. };
  133. } // namespace ZeroTier
  134. #endif