Capability.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #ifndef ZT_CAPABILITY_HPP
  9. #define ZT_CAPABILITY_HPP
  10. #include "../include/ZeroTierOne.h"
  11. #include "Address.hpp"
  12. #include "Buffer.hpp"
  13. #include "Constants.hpp"
  14. #include "Credential.hpp"
  15. #include "ECC.hpp"
  16. #include "Identity.hpp"
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. namespace ZeroTier {
  21. class RuntimeEnvironment;
  22. /**
  23. * A set of grouped and signed network flow rules
  24. *
  25. * On the sending side the sender does the following for each packet:
  26. *
  27. * (1) Evaluates its capabilities in ascending order of ID to determine
  28. * which capability allows it to transmit this packet.
  29. * (2) If it has not done so lately, it then sends this capability to the
  30. * receiving peer ("presents" it).
  31. * (3) The sender then sends the packet.
  32. *
  33. * On the receiving side the receiver evaluates the capabilities presented
  34. * by the sender. If any valid un-expired capability allows this packet it
  35. * is accepted.
  36. *
  37. * Note that this is after evaluation of network scope rules and only if
  38. * network scope rules do not deliver an explicit match.
  39. *
  40. * Capabilities support a chain of custody. This is currently unused but
  41. * in the future would allow the publication of capabilities that can be
  42. * handed off between nodes. Limited transferability of capabilities is
  43. * a feature of true capability based security.
  44. */
  45. class Capability : public Credential {
  46. public:
  47. static inline Credential::Type credentialType()
  48. {
  49. return Credential::CREDENTIAL_TYPE_CAPABILITY;
  50. }
  51. Capability() : _nwid(0), _ts(0), _id(0), _maxCustodyChainLength(0), _ruleCount(0)
  52. {
  53. memset(_rules, 0, sizeof(_rules));
  54. memset(_custody, 0, sizeof(_custody));
  55. }
  56. /**
  57. * @param id Capability ID
  58. * @param nwid Network ID
  59. * @param ts Timestamp (at controller)
  60. * @param mccl Maximum custody chain length (1 to create non-transferable capability)
  61. * @param rules Network flow rules for this capability
  62. * @param ruleCount Number of flow rules
  63. */
  64. Capability(uint32_t id, uint64_t nwid, int64_t ts, unsigned int mccl, const ZT_VirtualNetworkRule* rules, unsigned int ruleCount)
  65. : _nwid(nwid)
  66. , _ts(ts)
  67. , _id(id)
  68. , _maxCustodyChainLength((mccl > 0) ? ((mccl < ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH) ? mccl : (unsigned int)ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH) : 1)
  69. , _ruleCount((ruleCount < ZT_MAX_CAPABILITY_RULES) ? ruleCount : ZT_MAX_CAPABILITY_RULES)
  70. {
  71. if (_ruleCount > 0) {
  72. memcpy(_rules, rules, sizeof(ZT_VirtualNetworkRule) * _ruleCount);
  73. }
  74. }
  75. /**
  76. * @return Rules -- see ruleCount() for size of array
  77. */
  78. inline const ZT_VirtualNetworkRule* rules() const
  79. {
  80. return _rules;
  81. }
  82. /**
  83. * @return Number of rules in rules()
  84. */
  85. inline unsigned int ruleCount() const
  86. {
  87. return _ruleCount;
  88. }
  89. /**
  90. * @return ID and evaluation order of this capability in network
  91. */
  92. inline uint32_t id() const
  93. {
  94. return _id;
  95. }
  96. /**
  97. * @return Network ID for which this capability was issued
  98. */
  99. inline uint64_t networkId() const
  100. {
  101. return _nwid;
  102. }
  103. /**
  104. * @return Timestamp
  105. */
  106. inline int64_t timestamp() const
  107. {
  108. return _ts;
  109. }
  110. /**
  111. * @return Last 'to' address in chain of custody
  112. */
  113. inline Address issuedTo() const
  114. {
  115. Address i2;
  116. for (unsigned int i = 0; i < ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH; ++i) {
  117. if (! _custody[i].to) {
  118. return i2;
  119. }
  120. else {
  121. i2 = _custody[i].to;
  122. }
  123. }
  124. return i2;
  125. }
  126. /**
  127. * Sign this capability and add signature to its chain of custody
  128. *
  129. * If this returns false, this object should be considered to be
  130. * in an undefined state and should be discarded. False can be returned
  131. * if there is no more room for signatures (max chain length reached)
  132. * or if the 'from' identity does not include a secret key to allow
  133. * it to sign anything.
  134. *
  135. * @param from Signing identity (must have secret)
  136. * @param to Recipient of this signature
  137. * @return True if signature successful and chain of custody appended
  138. */
  139. inline bool sign(const Identity& from, const Address& to)
  140. {
  141. try {
  142. for (unsigned int i = 0; ((i < _maxCustodyChainLength) && (i < ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH)); ++i) {
  143. if (! (_custody[i].to)) {
  144. Buffer<(sizeof(Capability) * 2)> tmp;
  145. this->serialize(tmp, true);
  146. _custody[i].to = to;
  147. _custody[i].from = from.address();
  148. _custody[i].signature = from.sign(tmp.data(), tmp.size());
  149. return true;
  150. }
  151. }
  152. }
  153. catch (...) {
  154. }
  155. return false;
  156. }
  157. /**
  158. * Verify this capability's chain of custody and signatures
  159. *
  160. * @param RR Runtime environment to provide for peer lookup, etc.
  161. * @return 0 == OK, 1 == waiting for WHOIS, -1 == BAD signature or chain
  162. */
  163. int verify(const RuntimeEnvironment* RR, void* tPtr) const;
  164. template <unsigned int C> static inline void serializeRules(Buffer<C>& b, const ZT_VirtualNetworkRule* rules, unsigned int ruleCount)
  165. {
  166. for (unsigned int i = 0; i < ruleCount; ++i) {
  167. // Each rule consists of its 8-bit type followed by the size of that type's
  168. // field followed by field data. The inclusion of the size will allow non-supported
  169. // rules to be ignored but still parsed.
  170. b.append((uint8_t)rules[i].t);
  171. switch ((ZT_VirtualNetworkRuleType)(rules[i].t & 0x3f)) {
  172. default:
  173. b.append((uint8_t)0);
  174. break;
  175. case ZT_NETWORK_RULE_ACTION_TEE:
  176. case ZT_NETWORK_RULE_ACTION_WATCH:
  177. case ZT_NETWORK_RULE_ACTION_REDIRECT:
  178. b.append((uint8_t)14);
  179. b.append((uint64_t)rules[i].v.fwd.address);
  180. b.append((uint32_t)rules[i].v.fwd.flags);
  181. b.append((uint16_t)rules[i].v.fwd.length); // unused for redirect
  182. break;
  183. case ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS:
  184. case ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS:
  185. b.append((uint8_t)5);
  186. Address(rules[i].v.zt).appendTo(b);
  187. break;
  188. case ZT_NETWORK_RULE_MATCH_VLAN_ID:
  189. b.append((uint8_t)2);
  190. b.append((uint16_t)rules[i].v.vlanId);
  191. break;
  192. case ZT_NETWORK_RULE_MATCH_VLAN_PCP:
  193. b.append((uint8_t)1);
  194. b.append((uint8_t)rules[i].v.vlanPcp);
  195. break;
  196. case ZT_NETWORK_RULE_MATCH_VLAN_DEI:
  197. b.append((uint8_t)1);
  198. b.append((uint8_t)rules[i].v.vlanDei);
  199. break;
  200. case ZT_NETWORK_RULE_MATCH_MAC_SOURCE:
  201. case ZT_NETWORK_RULE_MATCH_MAC_DEST:
  202. b.append((uint8_t)6);
  203. b.append(rules[i].v.mac, 6);
  204. break;
  205. case ZT_NETWORK_RULE_MATCH_IPV4_SOURCE:
  206. case ZT_NETWORK_RULE_MATCH_IPV4_DEST:
  207. b.append((uint8_t)5);
  208. b.append(&(rules[i].v.ipv4.ip), 4);
  209. b.append((uint8_t)rules[i].v.ipv4.mask);
  210. break;
  211. case ZT_NETWORK_RULE_MATCH_IPV6_SOURCE:
  212. case ZT_NETWORK_RULE_MATCH_IPV6_DEST:
  213. b.append((uint8_t)17);
  214. b.append(rules[i].v.ipv6.ip, 16);
  215. b.append((uint8_t)rules[i].v.ipv6.mask);
  216. break;
  217. case ZT_NETWORK_RULE_MATCH_IP_TOS:
  218. b.append((uint8_t)3);
  219. b.append((uint8_t)rules[i].v.ipTos.mask);
  220. b.append((uint8_t)rules[i].v.ipTos.value[0]);
  221. b.append((uint8_t)rules[i].v.ipTos.value[1]);
  222. break;
  223. case ZT_NETWORK_RULE_MATCH_IP_PROTOCOL:
  224. b.append((uint8_t)1);
  225. b.append((uint8_t)rules[i].v.ipProtocol);
  226. break;
  227. case ZT_NETWORK_RULE_MATCH_ETHERTYPE:
  228. b.append((uint8_t)2);
  229. b.append((uint16_t)rules[i].v.etherType);
  230. break;
  231. case ZT_NETWORK_RULE_MATCH_ICMP:
  232. b.append((uint8_t)3);
  233. b.append((uint8_t)rules[i].v.icmp.type);
  234. b.append((uint8_t)rules[i].v.icmp.code);
  235. b.append((uint8_t)rules[i].v.icmp.flags);
  236. break;
  237. case ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE:
  238. case ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE:
  239. b.append((uint8_t)4);
  240. b.append((uint16_t)rules[i].v.port[0]);
  241. b.append((uint16_t)rules[i].v.port[1]);
  242. break;
  243. case ZT_NETWORK_RULE_MATCH_CHARACTERISTICS:
  244. b.append((uint8_t)8);
  245. b.append((uint64_t)rules[i].v.characteristics);
  246. break;
  247. case ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE:
  248. b.append((uint8_t)4);
  249. b.append((uint16_t)rules[i].v.frameSize[0]);
  250. b.append((uint16_t)rules[i].v.frameSize[1]);
  251. break;
  252. case ZT_NETWORK_RULE_MATCH_RANDOM:
  253. b.append((uint8_t)4);
  254. b.append((uint32_t)rules[i].v.randomProbability);
  255. break;
  256. case ZT_NETWORK_RULE_MATCH_TAGS_DIFFERENCE:
  257. case ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_AND:
  258. case ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_OR:
  259. case ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_XOR:
  260. case ZT_NETWORK_RULE_MATCH_TAGS_EQUAL:
  261. case ZT_NETWORK_RULE_MATCH_TAG_SENDER:
  262. case ZT_NETWORK_RULE_MATCH_TAG_RECEIVER:
  263. b.append((uint8_t)8);
  264. b.append((uint32_t)rules[i].v.tag.id);
  265. b.append((uint32_t)rules[i].v.tag.value);
  266. break;
  267. case ZT_NETWORK_RULE_MATCH_INTEGER_RANGE:
  268. b.append((uint8_t)19);
  269. b.append((uint64_t)rules[i].v.intRange.start);
  270. b.append((uint64_t)(rules[i].v.intRange.start + (uint64_t)rules[i].v.intRange.end)); // more future-proof
  271. b.append((uint16_t)rules[i].v.intRange.idx);
  272. b.append((uint8_t)rules[i].v.intRange.format);
  273. break;
  274. }
  275. }
  276. }
  277. template <unsigned int C> static inline void deserializeRules(const Buffer<C>& b, unsigned int& p, ZT_VirtualNetworkRule* rules, unsigned int& ruleCount, const unsigned int maxRuleCount)
  278. {
  279. while ((ruleCount < maxRuleCount) && (p < b.size())) {
  280. rules[ruleCount].t = (uint8_t)b[p++];
  281. const unsigned int fieldLen = (unsigned int)b[p++];
  282. switch ((ZT_VirtualNetworkRuleType)(rules[ruleCount].t & 0x3f)) {
  283. default:
  284. break;
  285. case ZT_NETWORK_RULE_ACTION_TEE:
  286. case ZT_NETWORK_RULE_ACTION_WATCH:
  287. case ZT_NETWORK_RULE_ACTION_REDIRECT:
  288. rules[ruleCount].v.fwd.address = b.template at<uint64_t>(p);
  289. rules[ruleCount].v.fwd.flags = b.template at<uint32_t>(p + 8);
  290. rules[ruleCount].v.fwd.length = b.template at<uint16_t>(p + 12);
  291. break;
  292. case ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS:
  293. case ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS:
  294. rules[ruleCount].v.zt = Address(b.field(p, ZT_ADDRESS_LENGTH), ZT_ADDRESS_LENGTH).toInt();
  295. break;
  296. case ZT_NETWORK_RULE_MATCH_VLAN_ID:
  297. rules[ruleCount].v.vlanId = b.template at<uint16_t>(p);
  298. break;
  299. case ZT_NETWORK_RULE_MATCH_VLAN_PCP:
  300. rules[ruleCount].v.vlanPcp = (uint8_t)b[p];
  301. break;
  302. case ZT_NETWORK_RULE_MATCH_VLAN_DEI:
  303. rules[ruleCount].v.vlanDei = (uint8_t)b[p];
  304. break;
  305. case ZT_NETWORK_RULE_MATCH_MAC_SOURCE:
  306. case ZT_NETWORK_RULE_MATCH_MAC_DEST:
  307. memcpy(rules[ruleCount].v.mac, b.field(p, 6), 6);
  308. break;
  309. case ZT_NETWORK_RULE_MATCH_IPV4_SOURCE:
  310. case ZT_NETWORK_RULE_MATCH_IPV4_DEST:
  311. memcpy(&(rules[ruleCount].v.ipv4.ip), b.field(p, 4), 4);
  312. rules[ruleCount].v.ipv4.mask = (uint8_t)b[p + 4];
  313. break;
  314. case ZT_NETWORK_RULE_MATCH_IPV6_SOURCE:
  315. case ZT_NETWORK_RULE_MATCH_IPV6_DEST:
  316. memcpy(rules[ruleCount].v.ipv6.ip, b.field(p, 16), 16);
  317. rules[ruleCount].v.ipv6.mask = (uint8_t)b[p + 16];
  318. break;
  319. case ZT_NETWORK_RULE_MATCH_IP_TOS:
  320. rules[ruleCount].v.ipTos.mask = (uint8_t)b[p];
  321. rules[ruleCount].v.ipTos.value[0] = (uint8_t)b[p + 1];
  322. rules[ruleCount].v.ipTos.value[1] = (uint8_t)b[p + 2];
  323. break;
  324. case ZT_NETWORK_RULE_MATCH_IP_PROTOCOL:
  325. rules[ruleCount].v.ipProtocol = (uint8_t)b[p];
  326. break;
  327. case ZT_NETWORK_RULE_MATCH_ETHERTYPE:
  328. rules[ruleCount].v.etherType = b.template at<uint16_t>(p);
  329. break;
  330. case ZT_NETWORK_RULE_MATCH_ICMP:
  331. rules[ruleCount].v.icmp.type = (uint8_t)b[p];
  332. rules[ruleCount].v.icmp.code = (uint8_t)b[p + 1];
  333. rules[ruleCount].v.icmp.flags = (uint8_t)b[p + 2];
  334. break;
  335. case ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE:
  336. case ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE:
  337. rules[ruleCount].v.port[0] = b.template at<uint16_t>(p);
  338. rules[ruleCount].v.port[1] = b.template at<uint16_t>(p + 2);
  339. break;
  340. case ZT_NETWORK_RULE_MATCH_CHARACTERISTICS:
  341. rules[ruleCount].v.characteristics = b.template at<uint64_t>(p);
  342. break;
  343. case ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE:
  344. rules[ruleCount].v.frameSize[0] = b.template at<uint16_t>(p);
  345. rules[ruleCount].v.frameSize[1] = b.template at<uint16_t>(p + 2);
  346. break;
  347. case ZT_NETWORK_RULE_MATCH_RANDOM:
  348. rules[ruleCount].v.randomProbability = b.template at<uint32_t>(p);
  349. break;
  350. case ZT_NETWORK_RULE_MATCH_TAGS_DIFFERENCE:
  351. case ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_AND:
  352. case ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_OR:
  353. case ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_XOR:
  354. case ZT_NETWORK_RULE_MATCH_TAGS_EQUAL:
  355. case ZT_NETWORK_RULE_MATCH_TAG_SENDER:
  356. case ZT_NETWORK_RULE_MATCH_TAG_RECEIVER:
  357. rules[ruleCount].v.tag.id = b.template at<uint32_t>(p);
  358. rules[ruleCount].v.tag.value = b.template at<uint32_t>(p + 4);
  359. break;
  360. case ZT_NETWORK_RULE_MATCH_INTEGER_RANGE:
  361. rules[ruleCount].v.intRange.start = b.template at<uint64_t>(p);
  362. rules[ruleCount].v.intRange.end = (uint32_t)(b.template at<uint64_t>(p + 8) - rules[ruleCount].v.intRange.start);
  363. rules[ruleCount].v.intRange.idx = b.template at<uint16_t>(p + 16);
  364. rules[ruleCount].v.intRange.format = (uint8_t)b[p + 18];
  365. break;
  366. }
  367. p += fieldLen;
  368. ++ruleCount;
  369. }
  370. }
  371. template <unsigned int C> inline void serialize(Buffer<C>& b, const bool forSign = false) const
  372. {
  373. if (forSign) {
  374. b.append((uint64_t)0x7f7f7f7f7f7f7f7fULL);
  375. }
  376. // These are the same between Tag and Capability
  377. b.append(_nwid);
  378. b.append(_ts);
  379. b.append(_id);
  380. b.append((uint16_t)_ruleCount);
  381. serializeRules(b, _rules, _ruleCount);
  382. b.append((uint8_t)_maxCustodyChainLength);
  383. if (! forSign) {
  384. for (unsigned int i = 0;; ++i) {
  385. if ((i < _maxCustodyChainLength) && (i < ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH) && (_custody[i].to)) {
  386. _custody[i].to.appendTo(b);
  387. _custody[i].from.appendTo(b);
  388. b.append((uint8_t)1); // 1 == Ed25519 signature
  389. b.append((uint16_t)ZT_ECC_SIGNATURE_LEN); // length of signature
  390. b.append(_custody[i].signature.data, ZT_ECC_SIGNATURE_LEN);
  391. }
  392. else {
  393. b.append((unsigned char)0, ZT_ADDRESS_LENGTH); // zero 'to' terminates chain
  394. break;
  395. }
  396. }
  397. }
  398. // This is the size of any additional fields, currently 0.
  399. b.append((uint16_t)0);
  400. if (forSign) {
  401. b.append((uint64_t)0x7f7f7f7f7f7f7f7fULL);
  402. }
  403. }
  404. template <unsigned int C> inline unsigned int deserialize(const Buffer<C>& b, unsigned int startAt = 0)
  405. {
  406. *this = Capability();
  407. unsigned int p = startAt;
  408. _nwid = b.template at<uint64_t>(p);
  409. p += 8;
  410. _ts = b.template at<uint64_t>(p);
  411. p += 8;
  412. _id = b.template at<uint32_t>(p);
  413. p += 4;
  414. const unsigned int rc = b.template at<uint16_t>(p);
  415. p += 2;
  416. if (rc > ZT_MAX_CAPABILITY_RULES) {
  417. throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
  418. }
  419. deserializeRules(b, p, _rules, _ruleCount, rc);
  420. _maxCustodyChainLength = (unsigned int)b[p++];
  421. if ((_maxCustodyChainLength < 1) || (_maxCustodyChainLength > ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH)) {
  422. throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
  423. }
  424. for (unsigned int i = 0;; ++i) {
  425. const Address to(b.field(p, ZT_ADDRESS_LENGTH), ZT_ADDRESS_LENGTH);
  426. p += ZT_ADDRESS_LENGTH;
  427. if (! to) {
  428. break;
  429. }
  430. if ((i >= _maxCustodyChainLength) || (i >= ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH)) {
  431. throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
  432. }
  433. _custody[i].to = to;
  434. _custody[i].from.setTo(b.field(p, ZT_ADDRESS_LENGTH), ZT_ADDRESS_LENGTH);
  435. p += ZT_ADDRESS_LENGTH;
  436. if (b[p++] == 1) {
  437. if (b.template at<uint16_t>(p) != ZT_ECC_SIGNATURE_LEN) {
  438. throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN;
  439. }
  440. p += 2;
  441. memcpy(_custody[i].signature.data, b.field(p, ZT_ECC_SIGNATURE_LEN), ZT_ECC_SIGNATURE_LEN);
  442. p += ZT_ECC_SIGNATURE_LEN;
  443. }
  444. else {
  445. p += 2 + b.template at<uint16_t>(p);
  446. }
  447. }
  448. p += 2 + b.template at<uint16_t>(p);
  449. if (p > b.size()) {
  450. throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
  451. }
  452. return (p - startAt);
  453. }
  454. // Provides natural sort order by ID
  455. inline bool operator<(const Capability& c) const
  456. {
  457. return (_id < c._id);
  458. }
  459. inline bool operator==(const Capability& c) const
  460. {
  461. return (memcmp(this, &c, sizeof(Capability)) == 0);
  462. }
  463. inline bool operator!=(const Capability& c) const
  464. {
  465. return (memcmp(this, &c, sizeof(Capability)) != 0);
  466. }
  467. private:
  468. uint64_t _nwid;
  469. int64_t _ts;
  470. uint32_t _id;
  471. unsigned int _maxCustodyChainLength;
  472. unsigned int _ruleCount;
  473. ZT_VirtualNetworkRule _rules[ZT_MAX_CAPABILITY_RULES];
  474. struct {
  475. Address to;
  476. Address from;
  477. ECC::Signature signature;
  478. } _custody[ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH];
  479. };
  480. } // namespace ZeroTier
  481. #endif