NetworkConfig.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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: 2025-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_NETWORKCONFIG_HPP
  14. #define ZT_NETWORKCONFIG_HPP
  15. #include <stdint.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <vector>
  19. #include <stdexcept>
  20. #include <algorithm>
  21. #include "../include/ZeroTierOne.h"
  22. #include "Constants.hpp"
  23. #include "Buffer.hpp"
  24. #include "DNS.hpp"
  25. #include "InetAddress.hpp"
  26. #include "MulticastGroup.hpp"
  27. #include "Address.hpp"
  28. #include "CertificateOfMembership.hpp"
  29. #include "CertificateOfOwnership.hpp"
  30. #include "Capability.hpp"
  31. #include "Tag.hpp"
  32. #include "Dictionary.hpp"
  33. #include "Hashtable.hpp"
  34. #include "Identity.hpp"
  35. #include "Utils.hpp"
  36. #include "Trace.hpp"
  37. /**
  38. * Default time delta for COMs, tags, and capabilities
  39. */
  40. #define ZT_NETWORKCONFIG_DEFAULT_CREDENTIAL_TIME_DFL_MAX_DELTA ((int64_t)(1000 * 60 * 30))
  41. /**
  42. * Maximum time delta for COMs, tags, and capabilities
  43. */
  44. #define ZT_NETWORKCONFIG_DEFAULT_CREDENTIAL_TIME_MAX_MAX_DELTA ((int64_t)(1000 * 60 * 60 * 2))
  45. /**
  46. * Minimum credential TTL and maxDelta for COM timestamps
  47. */
  48. #define ZT_NETWORKCONFIG_DEFAULT_CREDENTIAL_TIME_MIN_MAX_DELTA ((int64_t)(1000 * 60 * 5))
  49. /**
  50. * Flag: enable broadcast
  51. */
  52. #define ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST 0x0000000000000002ULL
  53. /**
  54. * Flag: enable IPv6 NDP emulation for certain V6 address patterns
  55. */
  56. #define ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION 0x0000000000000004ULL
  57. /**
  58. * Flag: result of unrecognized MATCH entries in a rules table: match if set, no-match if clear
  59. */
  60. #define ZT_NETWORKCONFIG_FLAG_RULES_RESULT_OF_UNSUPPORTED_MATCH 0x0000000000000008ULL
  61. /**
  62. * Flag: disable frame compression
  63. */
  64. #define ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION 0x0000000000000010ULL
  65. /**
  66. * Device can bridge to other Ethernet networks and gets unknown recipient multicasts
  67. */
  68. #define ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE 0x0000020000000000ULL
  69. /**
  70. * Anchors are stable devices on this network that can act like roots when none are up
  71. */
  72. #define ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR 0x0000040000000000ULL
  73. /**
  74. * Designated multicast replicators replicate multicast in place of sender-side replication
  75. */
  76. #define ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR 0x0000080000000000ULL
  77. namespace ZeroTier {
  78. // Dictionary capacity needed for max size network config
  79. #define ZT_NETWORKCONFIG_DICT_CAPACITY (4096 + (sizeof(ZT_VirtualNetworkConfig)) + (sizeof(ZT_VirtualNetworkRule) * ZT_MAX_NETWORK_RULES) + (sizeof(Capability) * ZT_MAX_NETWORK_CAPABILITIES) + (sizeof(Tag) * ZT_MAX_NETWORK_TAGS) + (sizeof(CertificateOfOwnership) * ZT_MAX_CERTIFICATES_OF_OWNERSHIP))
  80. // Dictionary capacity needed for max size network meta-data
  81. #define ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY 1024
  82. // Network config version
  83. #define ZT_NETWORKCONFIG_VERSION 7
  84. // Fields for meta-data sent with network config requests
  85. // Network config version
  86. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_VERSION "v"
  87. // Protocol version (see Packet.hpp)
  88. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_PROTOCOL_VERSION "pv"
  89. // Software vendor
  90. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_VENDOR "vend"
  91. // Software major version
  92. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION "majv"
  93. // Software minor version
  94. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION "minv"
  95. // Software revision
  96. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION "revv"
  97. // Rules engine revision
  98. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_RULES_ENGINE_REV "revr"
  99. // Maximum number of rules per network this node can accept
  100. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_RULES "mr"
  101. // Maximum number of capabilities this node can accept
  102. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_CAPABILITIES "mc"
  103. // Maximum number of rules per capability this node can accept
  104. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_CAPABILITY_RULES "mcr"
  105. // Maximum number of tags this node can accept
  106. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_TAGS "mt"
  107. // Network join authorization token (if any)
  108. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_AUTH "a"
  109. // Network configuration meta-data flags
  110. #define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_FLAGS "f"
  111. // These dictionary keys are short so they don't take up much room.
  112. // By convention we use upper case for binary blobs, but it doesn't really matter.
  113. // network config version
  114. #define ZT_NETWORKCONFIG_DICT_KEY_VERSION "v"
  115. // network ID
  116. #define ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID "nwid"
  117. // integer(hex)
  118. #define ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP "ts"
  119. // integer(hex)
  120. #define ZT_NETWORKCONFIG_DICT_KEY_REVISION "r"
  121. // address of member
  122. #define ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO "id"
  123. // remote trace target
  124. #define ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_TARGET "tt"
  125. // remote trace level
  126. #define ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_LEVEL "tl"
  127. // flags(hex)
  128. #define ZT_NETWORKCONFIG_DICT_KEY_FLAGS "f"
  129. // integer(hex)
  130. #define ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT "ml"
  131. // network type (hex)
  132. #define ZT_NETWORKCONFIG_DICT_KEY_TYPE "t"
  133. // text
  134. #define ZT_NETWORKCONFIG_DICT_KEY_NAME "n"
  135. // network MTU
  136. #define ZT_NETWORKCONFIG_DICT_KEY_MTU "mtu"
  137. // credential time max delta in ms
  138. #define ZT_NETWORKCONFIG_DICT_KEY_CREDENTIAL_TIME_MAX_DELTA "ctmd"
  139. // binary serialized certificate of membership
  140. #define ZT_NETWORKCONFIG_DICT_KEY_COM "C"
  141. // specialists (binary array of uint64_t)
  142. #define ZT_NETWORKCONFIG_DICT_KEY_SPECIALISTS "S"
  143. // routes (binary blob)
  144. #define ZT_NETWORKCONFIG_DICT_KEY_ROUTES "RT"
  145. // static IPs (binary blob)
  146. #define ZT_NETWORKCONFIG_DICT_KEY_STATIC_IPS "I"
  147. // rules (binary blob)
  148. #define ZT_NETWORKCONFIG_DICT_KEY_RULES "R"
  149. // capabilities (binary blobs)
  150. #define ZT_NETWORKCONFIG_DICT_KEY_CAPABILITIES "CAP"
  151. // tags (binary blobs)
  152. #define ZT_NETWORKCONFIG_DICT_KEY_TAGS "TAG"
  153. // tags (binary blobs)
  154. #define ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATES_OF_OWNERSHIP "COO"
  155. // dns (binary blobs)
  156. #define ZT_NETWORKCONFIG_DICT_KEY_DNS "DNS"
  157. // sso enabled
  158. #define ZT_NETWORKCONFIG_DICT_KEY_SSO_ENABLED "ssoe"
  159. // so version
  160. #define ZT_NETWORKCONFIG_DICT_KEY_SSO_VERSION "ssov"
  161. // authentication URL
  162. #define ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_URL "aurl"
  163. // authentication expiry
  164. #define ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_EXPIRY_TIME "aexpt"
  165. // oidc issuer URL
  166. #define ZT_NETWORKCONFIG_DICT_KEY_ISSUER_URL "iurl"
  167. // central endpoint
  168. #define ZT_NETWORKCONFIG_DICT_KEY_CENTRAL_ENDPOINT_URL "ssoce"
  169. // nonce
  170. #define ZT_NETWORKCONFIG_DICT_KEY_NONCE "sson"
  171. // state
  172. #define ZT_NETWORKCONFIG_DICT_KEY_STATE "ssos"
  173. // client ID
  174. #define ZT_NETWORKCONFIG_DICT_KEY_CLIENT_ID "ssocid"
  175. // SSO Provider
  176. #define ZT_NETWORKCONFIG_DICT_KEY_SSO_PROVIDER "ssop"
  177. // AuthInfo fields -- used by ncSendError for sso
  178. // AuthInfo Version
  179. #define ZT_AUTHINFO_DICT_KEY_VERSION "aV"
  180. // authentication URL
  181. #define ZT_AUTHINFO_DICT_KEY_AUTHENTICATION_URL "aU"
  182. // issuer URL
  183. #define ZT_AUTHINFO_DICT_KEY_ISSUER_URL "iU"
  184. // Central endpoint URL
  185. #define ZT_AUTHINFO_DICT_KEY_CENTRAL_ENDPOINT_URL "aCU"
  186. // Nonce
  187. #define ZT_AUTHINFO_DICT_KEY_NONCE "aN"
  188. // State
  189. #define ZT_AUTHINFO_DICT_KEY_STATE "aS"
  190. // Client ID
  191. #define ZT_AUTHINFO_DICT_KEY_CLIENT_ID "aCID"
  192. // SSO Provider
  193. #define ZT_AUTHINFO_DICT_KEY_SSO_PROVIDER "aSSOp"
  194. // Legacy fields -- these are obsoleted but are included when older clients query
  195. // boolean (now a flag)
  196. #define ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST_OLD "eb"
  197. // IP/bits[,IP/bits,...]
  198. // Note that IPs that end in all zeroes are routes with no assignment in them.
  199. #define ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC_OLD "v4s"
  200. // IP/bits[,IP/bits,...]
  201. // Note that IPs that end in all zeroes are routes with no assignment in them.
  202. #define ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC_OLD "v6s"
  203. // 0/1
  204. #define ZT_NETWORKCONFIG_DICT_KEY_PRIVATE_OLD "p"
  205. // integer(hex)[,integer(hex),...]
  206. #define ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES_OLD "et"
  207. // string-serialized CertificateOfMembership
  208. #define ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP_OLD "com"
  209. // node[,node,...]
  210. #define ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES_OLD "ab"
  211. // node;IP/port[,node;IP/port]
  212. #define ZT_NETWORKCONFIG_DICT_KEY_RELAYS_OLD "rl"
  213. // End legacy fields
  214. /**
  215. * Network configuration received from network controller nodes
  216. *
  217. * This is a memcpy()'able structure and is safe (in a crash sense) to modify
  218. * without locks.
  219. */
  220. class NetworkConfig
  221. {
  222. public:
  223. NetworkConfig() :
  224. networkId(0),
  225. timestamp(0),
  226. credentialTimeMaxDelta(0),
  227. revision(0),
  228. issuedTo(),
  229. remoteTraceTarget(),
  230. flags(0),
  231. remoteTraceLevel(Trace::LEVEL_NORMAL),
  232. mtu(0),
  233. multicastLimit(0),
  234. specialistCount(0),
  235. routeCount(0),
  236. staticIpCount(0),
  237. ruleCount(0),
  238. capabilityCount(0),
  239. tagCount(0),
  240. certificateOfOwnershipCount(0),
  241. capabilities(),
  242. tags(),
  243. certificatesOfOwnership(),
  244. type(ZT_NETWORK_TYPE_PRIVATE),
  245. dnsCount(0),
  246. ssoEnabled(false),
  247. authenticationURL(),
  248. authenticationExpiryTime(0),
  249. issuerURL(),
  250. centralAuthURL(),
  251. ssoNonce(),
  252. ssoState(),
  253. ssoClientID()
  254. {
  255. name[0] = 0;
  256. memset(specialists, 0, sizeof(uint64_t)*ZT_MAX_NETWORK_SPECIALISTS);
  257. memset(routes, 0, sizeof(ZT_VirtualNetworkRoute)*ZT_MAX_NETWORK_ROUTES);
  258. memset(staticIps, 0, sizeof(InetAddress)*ZT_MAX_ZT_ASSIGNED_ADDRESSES);
  259. memset(rules, 0, sizeof(ZT_VirtualNetworkRule)*ZT_MAX_NETWORK_RULES);
  260. memset(&dns, 0, sizeof(ZT_VirtualNetworkDNS));
  261. memset(authenticationURL, 0, sizeof(authenticationURL));
  262. memset(issuerURL, 0, sizeof(issuerURL));
  263. memset(centralAuthURL, 0, sizeof(centralAuthURL));
  264. memset(ssoNonce, 0, sizeof(ssoNonce));
  265. memset(ssoState, 0, sizeof(ssoState));
  266. memset(ssoClientID, 0, sizeof(ssoClientID));
  267. strncpy(ssoProvider, "default", sizeof(ssoProvider));
  268. }
  269. /**
  270. * Write this network config to a dictionary for transport
  271. *
  272. * @param d Dictionary
  273. * @param includeLegacy If true, include legacy fields for old node versions
  274. * @return True if dictionary was successfully created, false if e.g. overflow
  275. */
  276. bool toDictionary(Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d,bool includeLegacy) const;
  277. /**
  278. * Read this network config from a dictionary
  279. *
  280. * @param d Dictionary (non-const since it might be modified during parse, should not be used after call)
  281. * @return True if dictionary was valid and network config successfully initialized
  282. */
  283. bool fromDictionary(const Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d);
  284. /**
  285. * @return True if broadcast (ff:ff:ff:ff:ff:ff) address should work on this network
  286. */
  287. inline bool enableBroadcast() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); }
  288. /**
  289. * @return True if IPv6 NDP emulation should be allowed for certain "magic" IPv6 address patterns
  290. */
  291. inline bool ndpEmulation() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION) != 0); }
  292. /**
  293. * @return True if frames should not be compressed
  294. */
  295. inline bool disableCompression() const
  296. {
  297. #ifndef ZT_DISABLE_COMPRESSION
  298. return ((this->flags & ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION) != 0);
  299. #else
  300. /* Compression is disabled for libzt builds since it causes non-obvious chaotic
  301. interference with lwIP's TCP congestion algorithm. Compression is also disabled
  302. for some NAS builds due to the usage of low-performance processors in certain
  303. older and budget models. */
  304. return false;
  305. #endif
  306. }
  307. /**
  308. * @return Network type is public (no access control)
  309. */
  310. inline bool isPublic() const { return (this->type == ZT_NETWORK_TYPE_PUBLIC); }
  311. /**
  312. * @return Network type is private (certificate access control)
  313. */
  314. inline bool isPrivate() const { return (this->type == ZT_NETWORK_TYPE_PRIVATE); }
  315. /**
  316. * @return ZeroTier addresses of devices on this network designated as active bridges
  317. */
  318. inline std::vector<Address> activeBridges() const
  319. {
  320. std::vector<Address> r;
  321. for(unsigned int i=0;i<specialistCount;++i) {
  322. if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
  323. r.push_back(Address(specialists[i]));
  324. }
  325. return r;
  326. }
  327. inline unsigned int activeBridges(Address ab[ZT_MAX_NETWORK_SPECIALISTS]) const
  328. {
  329. unsigned int c = 0;
  330. for(unsigned int i=0;i<specialistCount;++i) {
  331. if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
  332. ab[c++] = specialists[i];
  333. }
  334. return c;
  335. }
  336. inline bool isActiveBridge(const Address &a) const
  337. {
  338. for(unsigned int i=0;i<specialistCount;++i) {
  339. if (((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)&&(a == specialists[i]))
  340. return true;
  341. }
  342. return false;
  343. }
  344. inline std::vector<Address> anchors() const
  345. {
  346. std::vector<Address> r;
  347. for(unsigned int i=0;i<specialistCount;++i) {
  348. if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR) != 0)
  349. r.push_back(Address(specialists[i]));
  350. }
  351. return r;
  352. }
  353. inline std::vector<Address> multicastReplicators() const
  354. {
  355. std::vector<Address> r;
  356. for(unsigned int i=0;i<specialistCount;++i) {
  357. if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR) != 0)
  358. r.push_back(Address(specialists[i]));
  359. }
  360. return r;
  361. }
  362. inline unsigned int multicastReplicators(Address mr[ZT_MAX_NETWORK_SPECIALISTS]) const
  363. {
  364. unsigned int c = 0;
  365. for(unsigned int i=0;i<specialistCount;++i) {
  366. if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR) != 0)
  367. mr[c++] = specialists[i];
  368. }
  369. return c;
  370. }
  371. inline bool isMulticastReplicator(const Address &a) const
  372. {
  373. for(unsigned int i=0;i<specialistCount;++i) {
  374. if (((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR) != 0)&&(a == specialists[i]))
  375. return true;
  376. }
  377. return false;
  378. }
  379. inline std::vector<Address> alwaysContactAddresses() const
  380. {
  381. std::vector<Address> r;
  382. for(unsigned int i=0;i<specialistCount;++i) {
  383. if ((specialists[i] & (ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR | ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR)) != 0)
  384. r.push_back(Address(specialists[i]));
  385. }
  386. return r;
  387. }
  388. inline unsigned int alwaysContactAddresses(Address ac[ZT_MAX_NETWORK_SPECIALISTS]) const
  389. {
  390. unsigned int c = 0;
  391. for(unsigned int i=0;i<specialistCount;++i) {
  392. if ((specialists[i] & (ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR | ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR)) != 0)
  393. ac[c++] = specialists[i];
  394. }
  395. return c;
  396. }
  397. inline void alwaysContactAddresses(Hashtable< Address,std::vector<InetAddress> > &a) const
  398. {
  399. for(unsigned int i=0;i<specialistCount;++i) {
  400. if ((specialists[i] & (ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR | ZT_NETWORKCONFIG_SPECIALIST_TYPE_MULTICAST_REPLICATOR)) != 0) {
  401. a[Address(specialists[i])];
  402. }
  403. }
  404. }
  405. /**
  406. * @param fromPeer Peer attempting to bridge other Ethernet peers onto network
  407. * @return True if this network allows bridging
  408. */
  409. inline bool permitsBridging(const Address &fromPeer) const
  410. {
  411. for(unsigned int i=0;i<specialistCount;++i) {
  412. if ((fromPeer == specialists[i])&&((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0))
  413. return true;
  414. }
  415. return false;
  416. }
  417. inline operator bool() const { return (networkId != 0); }
  418. inline bool operator==(const NetworkConfig &nc) const { return (memcmp(this,&nc,sizeof(NetworkConfig)) == 0); }
  419. inline bool operator!=(const NetworkConfig &nc) const { return (!(*this == nc)); }
  420. /**
  421. * Add a specialist or mask flags if already present
  422. *
  423. * This masks the existing flags if the specialist is already here or adds
  424. * it otherwise.
  425. *
  426. * @param a Address of specialist
  427. * @param f Flags (OR of specialist role/type flags)
  428. * @return True if successfully masked or added
  429. */
  430. inline bool addSpecialist(const Address &a,const uint64_t f)
  431. {
  432. const uint64_t aint = a.toInt();
  433. for(unsigned int i=0;i<specialistCount;++i) {
  434. if ((specialists[i] & 0xffffffffffULL) == aint) {
  435. specialists[i] |= f;
  436. return true;
  437. }
  438. }
  439. if (specialistCount < ZT_MAX_NETWORK_SPECIALISTS) {
  440. specialists[specialistCount++] = f | aint;
  441. return true;
  442. }
  443. return false;
  444. }
  445. const Capability *capability(const uint32_t id) const
  446. {
  447. for(unsigned int i=0;i<capabilityCount;++i) {
  448. if (capabilities[i].id() == id)
  449. return &(capabilities[i]);
  450. }
  451. return (Capability *)0;
  452. }
  453. const Tag *tag(const uint32_t id) const
  454. {
  455. for(unsigned int i=0;i<tagCount;++i) {
  456. if (tags[i].id() == id)
  457. return &(tags[i]);
  458. }
  459. return (Tag *)0;
  460. }
  461. /**
  462. * Network ID that this configuration applies to
  463. */
  464. uint64_t networkId;
  465. /**
  466. * Controller-side time of config generation/issue
  467. */
  468. int64_t timestamp;
  469. /**
  470. * Max difference between timestamp and tag/capability timestamp
  471. */
  472. int64_t credentialTimeMaxDelta;
  473. /**
  474. * Controller-side revision counter for this configuration
  475. */
  476. uint64_t revision;
  477. /**
  478. * Address of device to which this config is issued
  479. */
  480. Address issuedTo;
  481. /**
  482. * If non-NULL, remote traces related to this network are sent here
  483. */
  484. Address remoteTraceTarget;
  485. /**
  486. * Flags (64-bit)
  487. */
  488. uint64_t flags;
  489. /**
  490. * Remote trace level
  491. */
  492. Trace::Level remoteTraceLevel;
  493. /**
  494. * Network MTU
  495. */
  496. unsigned int mtu;
  497. /**
  498. * Maximum number of recipients per multicast (not including active bridges)
  499. */
  500. unsigned int multicastLimit;
  501. /**
  502. * Number of specialists
  503. */
  504. unsigned int specialistCount;
  505. /**
  506. * Number of routes
  507. */
  508. unsigned int routeCount;
  509. /**
  510. * Number of ZT-managed static IP assignments
  511. */
  512. unsigned int staticIpCount;
  513. /**
  514. * Number of rule table entries
  515. */
  516. unsigned int ruleCount;
  517. /**
  518. * Number of capabilities
  519. */
  520. unsigned int capabilityCount;
  521. /**
  522. * Number of tags
  523. */
  524. unsigned int tagCount;
  525. /**
  526. * Number of certificates of ownership
  527. */
  528. unsigned int certificateOfOwnershipCount;
  529. /**
  530. * Specialist devices
  531. *
  532. * For each entry the least significant 40 bits are the device's ZeroTier
  533. * address and the most significant 24 bits are flags indicating its role.
  534. */
  535. uint64_t specialists[ZT_MAX_NETWORK_SPECIALISTS];
  536. /**
  537. * Statically defined "pushed" routes (including default gateways)
  538. */
  539. ZT_VirtualNetworkRoute routes[ZT_MAX_NETWORK_ROUTES];
  540. /**
  541. * Static IP assignments
  542. */
  543. InetAddress staticIps[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
  544. /**
  545. * Base network rules
  546. */
  547. ZT_VirtualNetworkRule rules[ZT_MAX_NETWORK_RULES];
  548. /**
  549. * Capabilities for this node on this network, in ascending order of capability ID
  550. */
  551. Capability capabilities[ZT_MAX_NETWORK_CAPABILITIES];
  552. /**
  553. * Tags for this node on this network, in ascending order of tag ID
  554. */
  555. Tag tags[ZT_MAX_NETWORK_TAGS];
  556. /**
  557. * Certificates of ownership for this network member
  558. */
  559. CertificateOfOwnership certificatesOfOwnership[ZT_MAX_CERTIFICATES_OF_OWNERSHIP];
  560. /**
  561. * Network type (currently just public or private)
  562. */
  563. ZT_VirtualNetworkType type;
  564. /**
  565. * Network short name or empty string if not defined
  566. */
  567. char name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
  568. /**
  569. * Certificate of membership (for private networks)
  570. */
  571. CertificateOfMembership com;
  572. /**
  573. * Number of ZT-pushed DNS configurations
  574. */
  575. unsigned int dnsCount;
  576. /**
  577. * ZT pushed DNS configuration
  578. */
  579. ZT_VirtualNetworkDNS dns;
  580. /**
  581. * SSO enabled flag.
  582. */
  583. bool ssoEnabled;
  584. /**
  585. * SSO version
  586. */
  587. uint64_t ssoVersion;
  588. /**
  589. * Authentication URL if authentication is required
  590. */
  591. char authenticationURL[2048];
  592. /**
  593. * Time current authentication expires or 0 if external authentication is disabled
  594. *
  595. * Not used if authVersion >= 1
  596. */
  597. uint64_t authenticationExpiryTime;
  598. /**
  599. * OIDC issuer URL
  600. */
  601. char issuerURL[2048];
  602. /**
  603. * central base URL.
  604. */
  605. char centralAuthURL[2048];
  606. /**
  607. * sso nonce
  608. */
  609. char ssoNonce[128];
  610. /**
  611. * sso state
  612. */
  613. char ssoState[256];
  614. /**
  615. * oidc client id
  616. */
  617. char ssoClientID[256];
  618. /**
  619. * oidc provider
  620. *
  621. * because certain providers require specific scopes to be requested
  622. * and others to be not requested in order to make everything work
  623. * correctly
  624. **/
  625. char ssoProvider[64];
  626. };
  627. } // namespace ZeroTier
  628. #endif