Trace.hpp 6.2 KB

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