Capability.hpp 16 KB

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