Network.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 ZeroTier Networks LLC
  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. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef _ZT_NETWORK_HPP
  28. #define _ZT_NETWORK_HPP
  29. #include <stdint.h>
  30. #include <string>
  31. #include <set>
  32. #include <map>
  33. #include <vector>
  34. #include <algorithm>
  35. #include <stdexcept>
  36. #include "Constants.hpp"
  37. #include "Utils.hpp"
  38. #include "EthernetTap.hpp"
  39. #include "Address.hpp"
  40. #include "Mutex.hpp"
  41. #include "SharedPtr.hpp"
  42. #include "AtomicCounter.hpp"
  43. #include "MulticastGroup.hpp"
  44. #include "NonCopyable.hpp"
  45. #include "MAC.hpp"
  46. #include "Dictionary.hpp"
  47. #include "Identity.hpp"
  48. #include "InetAddress.hpp"
  49. #include "BandwidthAccount.hpp"
  50. #include "C25519.hpp"
  51. namespace ZeroTier {
  52. class RuntimeEnvironment;
  53. class NodeConfig;
  54. /**
  55. * A virtual LAN
  56. *
  57. * Networks can be open or closed. Each network has an ID whose most
  58. * significant 40 bits are the ZeroTier address of the node that should
  59. * be contacted for network configuration. The least significant 24
  60. * bits are arbitrary, allowing up to 2^24 networks per managing
  61. * node.
  62. *
  63. * Open networks do not track membership. Anyone is allowed to communicate
  64. * over them.
  65. *
  66. * Closed networks track membership by way of timestamped signatures. When
  67. * the network requests its configuration, one of the fields returned is
  68. * a signature for the identity of the peer on the network. This signature
  69. * includes a timestamp. When a peer communicates with other peers on a
  70. * closed network, it periodically (and pre-emptively) propagates this
  71. * signature to the peers with which it is communicating. Peers reject
  72. * packets with an error if no recent signature is on file.
  73. */
  74. class Network : NonCopyable
  75. {
  76. friend class SharedPtr<Network>;
  77. friend class NodeConfig;
  78. public:
  79. /**
  80. * Certificate of network membership
  81. *
  82. * The COM contains a sorted set of three-element tuples called qualifiers.
  83. * These contain an id, a value, and a maximum delta.
  84. *
  85. * The ID is arbitrary and should be assigned using a scheme that makes
  86. * every ID globally unique. ID 0 is reserved for the always-present
  87. * validity timestamp and range, and ID 1 is reserved for the always-present
  88. * network ID. IDs less than 65536 are reserved for future global
  89. * assignment.
  90. *
  91. * The value's meaning is ID-specific and isn't important here. What's
  92. * important is the value and the third member of the tuple: the maximum
  93. * delta. The maximum delta is the maximum difference permitted between
  94. * values for a given ID between certificates for the two certificates to
  95. * themselves agree.
  96. *
  97. * Network membership is checked by checking whether a peer's certificate
  98. * agrees with your own. The timestamp provides the fundamental criterion--
  99. * each member of a private network must constantly obtain new certificates
  100. * often enough to stay within the max delta for this qualifier. But other
  101. * criteria could be added in the future for very special behaviors, things
  102. * like latitude and longitude for instance.
  103. */
  104. class CertificateOfMembership
  105. {
  106. public:
  107. /**
  108. * Certificate type codes, used in serialization
  109. *
  110. * Only one so far, and only one hopefully there shall be for quite some
  111. * time.
  112. */
  113. enum Type
  114. {
  115. COM_UINT64_ED25519 = 1 // tuples of unsigned 64's signed with Ed25519
  116. };
  117. /**
  118. * Reserved COM IDs
  119. *
  120. * IDs below 65536 should be considered reserved for future global
  121. * assignment here.
  122. */
  123. enum ReservedIds
  124. {
  125. COM_RESERVED_ID_TIMESTAMP = 0, // timestamp, max delta defines cert life
  126. COM_RESERVED_ID_NETWORK_ID = 1 // network ID, max delta always 0
  127. };
  128. CertificateOfMembership()
  129. {
  130. memset(_signature.data,0,_signature.size());
  131. }
  132. CertificateOfMembership(const char *s) { fromString(s); }
  133. CertificateOfMembership(const std::string &s) { fromString(s.c_str()); }
  134. /**
  135. * Add or update a qualifier in this certificate
  136. *
  137. * Any signature is invalidated and signedBy is set to null.
  138. *
  139. * @param id Qualifier ID
  140. * @param value Qualifier value
  141. * @param maxDelta Qualifier maximum allowed difference (absolute value of difference)
  142. */
  143. void setQualifier(uint64_t id,uint64_t value,uint64_t maxDelta);
  144. /**
  145. * @return String-serialized representation of this certificate
  146. */
  147. std::string toString() const;
  148. /**
  149. * Set this certificate equal to the hex-serialized string
  150. *
  151. * Invalid strings will result in invalid or undefined certificate
  152. * contents. These will subsequently fail validation and comparison.
  153. *
  154. * @param s String to deserialize
  155. */
  156. void fromString(const char *s);
  157. inline void fromString(const std::string &s) { fromString(s.c_str()); }
  158. /**
  159. * Compare two certificates for parameter agreement
  160. *
  161. * This compares this certificate with the other and returns true if all
  162. * paramters in this cert are present in the other and if they agree to
  163. * within this cert's max delta value for each given parameter.
  164. *
  165. * Tuples present in other but not in this cert are ignored, but any
  166. * tuples present in this cert but not in other result in 'false'.
  167. *
  168. * @param other Cert to compare with
  169. * @return True if certs agree and 'other' may be communicated with
  170. */
  171. bool agreesWith(const CertificateOfMembership &other) const
  172. throw();
  173. /**
  174. * Sign this certificate
  175. *
  176. * @param with Identity to sign with, must include private key
  177. * @return True if signature was successful
  178. */
  179. bool sign(const Identity &with);
  180. /**
  181. * Verify certificate against an identity
  182. *
  183. * @param id Identity to verify against
  184. * @return True if certificate is signed by this identity and verification was successful
  185. */
  186. bool verify(const Identity &id) const;
  187. /**
  188. * @return True if signed
  189. */
  190. inline bool isSigned() const
  191. throw()
  192. {
  193. return (_signedBy);
  194. }
  195. /**
  196. * @return Address that signed this certificate or null address if none
  197. */
  198. inline const Address &signedBy() const
  199. throw()
  200. {
  201. return _signedBy;
  202. }
  203. private:
  204. struct _Qualifier
  205. {
  206. _Qualifier() throw() {}
  207. _Qualifier(uint64_t i,uint64_t v,uint64_t m) throw() :
  208. id(i),
  209. value(v),
  210. maxDelta(m) {}
  211. uint64_t id;
  212. uint64_t value;
  213. uint64_t maxDelta;
  214. inline bool operator==(const _Qualifier &q) const throw() { return (id == q.id); } // for unique
  215. inline bool operator<(const _Qualifier &q) const throw() { return (id < q.id); } // for sort
  216. };
  217. std::vector<_Qualifier> _qualifiers; // sorted by id and unique
  218. Address _signedBy;
  219. C25519::Signature _signature;
  220. };
  221. /**
  222. * Preload and rates of accrual for multicast group bandwidth limits
  223. *
  224. * Key is multicast group in lower case hex format: MAC (without :s) /
  225. * ADI (hex). Value is preload, maximum balance, and rate of accrual in
  226. * hex.
  227. */
  228. class MulticastRates : private Dictionary
  229. {
  230. public:
  231. /**
  232. * Preload and accrual parameter tuple
  233. */
  234. struct Rate
  235. {
  236. Rate() {}
  237. Rate(uint32_t pl,uint32_t maxb,uint32_t acc)
  238. {
  239. preload = pl;
  240. maxBalance = maxb;
  241. accrual = acc;
  242. }
  243. uint32_t preload;
  244. uint32_t maxBalance;
  245. uint32_t accrual;
  246. };
  247. MulticastRates() {}
  248. MulticastRates(const char *s) : Dictionary(s) {}
  249. MulticastRates(const std::string &s) : Dictionary(s) {}
  250. inline std::string toString() const { return Dictionary::toString(); }
  251. /**
  252. * A very minimal default rate, fast enough for ARP
  253. */
  254. static const Rate GLOBAL_DEFAULT_RATE;
  255. /**
  256. * @return Default rate, or GLOBAL_DEFAULT_RATE if not specified
  257. */
  258. inline Rate defaultRate() const
  259. {
  260. Rate r;
  261. const_iterator dfl(find("*"));
  262. if (dfl == end())
  263. return GLOBAL_DEFAULT_RATE;
  264. return _toRate(dfl->second);
  265. }
  266. /**
  267. * Get the rate for a given multicast group
  268. *
  269. * @param mg Multicast group
  270. * @return Rate or default() rate if not specified
  271. */
  272. inline Rate get(const MulticastGroup &mg) const
  273. {
  274. const_iterator r(find(mg.toString()));
  275. if (r == end())
  276. return defaultRate();
  277. return _toRate(r->second);
  278. }
  279. private:
  280. static inline Rate _toRate(const std::string &s)
  281. {
  282. char tmp[16384];
  283. Utils::scopy(tmp,sizeof(tmp),s.c_str());
  284. Rate r(0,0,0);
  285. char *saveptr = (char *)0;
  286. unsigned int fn = 0;
  287. for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  288. switch(fn++) {
  289. case 0:
  290. r.preload = (uint32_t)Utils::hexStrToULong(f);
  291. break;
  292. case 1:
  293. r.maxBalance = (uint32_t)Utils::hexStrToULong(f);
  294. break;
  295. case 2:
  296. r.accrual = (uint32_t)Utils::hexStrToULong(f);
  297. break;
  298. }
  299. }
  300. return r;
  301. }
  302. };
  303. /**
  304. * A network configuration for a given node
  305. *
  306. * Configuration fields:
  307. *
  308. * nwid=<hex network ID> (required)
  309. * name=short name
  310. * desc=long(er) description
  311. * com=Serialized certificate of membership
  312. * mr=MulticastRates (serialized dictionary)
  313. * md=multicast propagation depth
  314. * mpb=multicast propagation prefix bits (2^mpb packets are sent by origin)
  315. * o=open network? (1 or 0, default false if missing)
  316. * et=ethertype whitelist (comma-delimited list of ethertypes in decimal)
  317. * v4s=IPv4 static assignments / netmasks (comma-delimited)
  318. * v6s=IPv6 static assignments / netmasks (comma-delimited)
  319. *
  320. * Notes:
  321. *
  322. * If zero appears in the 'et' list, the sense is inverted. It becomes an
  323. * ethertype blacklist instead of a whitelist and anything not blacklisted
  324. * is permitted.
  325. */
  326. class Config : private Dictionary
  327. {
  328. public:
  329. Config() {}
  330. Config(const char *s) : Dictionary(s) {}
  331. Config(const std::string &s) : Dictionary(s) {}
  332. inline std::string toString() const { return Dictionary::toString(); }
  333. /**
  334. * @return True if configuration is valid and contains required fields
  335. */
  336. inline operator bool() const throw() { return (find("nwid") != end()); }
  337. /**
  338. * @return Network ID
  339. * @throws std::invalid_argument Network ID field missing
  340. */
  341. inline uint64_t networkId() const
  342. throw(std::invalid_argument)
  343. {
  344. return Utils::hexStrToU64(get("nwid").c_str());
  345. }
  346. /**
  347. * Get this network's short name, or its ID in hex if unspecified
  348. *
  349. * @return Short name of this network (e.g. "earth")
  350. */
  351. inline std::string name() const
  352. {
  353. const_iterator n(find("name"));
  354. if (n == end())
  355. return get("nwid");
  356. return n->second;
  357. }
  358. /**
  359. * @return Long description of network or empty string if not present
  360. */
  361. inline std::string desc() const
  362. {
  363. return get("desc",std::string());
  364. }
  365. /**
  366. * @return Certificate of membership for this network, or empty cert if none
  367. */
  368. inline CertificateOfMembership certificateOfMembership() const
  369. {
  370. const_iterator cm(find("com"));
  371. if (cm == end())
  372. return CertificateOfMembership();
  373. else return CertificateOfMembership(cm->second);
  374. }
  375. /**
  376. * @return Multicast rates for this network
  377. */
  378. inline MulticastRates multicastRates() const
  379. {
  380. const_iterator mr(find("mr"));
  381. if (mr == end())
  382. return MulticastRates();
  383. else return MulticastRates(mr->second);
  384. }
  385. /**
  386. * @return Number of bits in propagation prefix for this network
  387. */
  388. inline unsigned int multicastPrefixBits() const
  389. {
  390. const_iterator mpb(find("mpb"));
  391. if (mpb == end())
  392. return ZT_DEFAULT_MULTICAST_PREFIX_BITS;
  393. unsigned int tmp = Utils::hexStrToUInt(mpb->second.c_str());
  394. if (tmp)
  395. return tmp;
  396. else return ZT_DEFAULT_MULTICAST_PREFIX_BITS;
  397. }
  398. /**
  399. * @return Maximum multicast propagation depth for this network
  400. */
  401. inline unsigned int multicastDepth() const
  402. {
  403. const_iterator md(find("md"));
  404. if (md == end())
  405. return ZT_DEFAULT_MULTICAST_DEPTH;
  406. unsigned int tmp = Utils::hexStrToUInt(md->second.c_str());
  407. if (tmp)
  408. return tmp;
  409. else return ZT_DEFAULT_MULTICAST_DEPTH;
  410. }
  411. /**
  412. * @return True if this is an open non-access-controlled network
  413. */
  414. inline bool isOpen() const
  415. {
  416. const_iterator o(find("o"));
  417. if (o == end())
  418. return false;
  419. else if (!o->second.length())
  420. return false;
  421. else return (o->second[0] == '1');
  422. }
  423. /**
  424. * @return Network ethertype whitelist
  425. */
  426. inline std::set<unsigned int> etherTypes() const
  427. {
  428. char tmp[16384];
  429. char *saveptr = (char *)0;
  430. std::set<unsigned int> et;
  431. if (!Utils::scopy(tmp,sizeof(tmp),get("et","").c_str()))
  432. return et; // sanity check, packet can't really be that big
  433. for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  434. unsigned int t = Utils::hexStrToUInt(f);
  435. if (t)
  436. et.insert(t);
  437. }
  438. return et;
  439. }
  440. /**
  441. * @return All static addresses / netmasks, IPv4 or IPv6
  442. */
  443. inline std::set<InetAddress> staticAddresses() const
  444. {
  445. std::set<InetAddress> sa;
  446. std::vector<std::string> ips(Utils::split(get("v4s","").c_str(),",","",""));
  447. for(std::vector<std::string>::const_iterator i(ips.begin());i!=ips.end();++i)
  448. sa.insert(InetAddress(*i));
  449. ips = Utils::split(get("v6s","").c_str(),",","","");
  450. for(std::vector<std::string>::const_iterator i(ips.begin());i!=ips.end();++i)
  451. sa.insert(InetAddress(*i));
  452. return sa;
  453. }
  454. };
  455. /**
  456. * Status for networks
  457. */
  458. enum Status
  459. {
  460. NETWORK_WAITING_FOR_FIRST_AUTOCONF,
  461. NETWORK_OK,
  462. NETWORK_ACCESS_DENIED
  463. };
  464. /**
  465. * @param s Status
  466. * @return String description
  467. */
  468. static const char *statusString(const Status s)
  469. throw();
  470. private:
  471. // Only NodeConfig can create, only SharedPtr can delete
  472. // Actual construction happens in newInstance()
  473. Network()
  474. throw() :
  475. _tap((EthernetTap *)0)
  476. {
  477. }
  478. ~Network();
  479. /**
  480. * Create a new Network instance and restore any saved state
  481. *
  482. * If there is no saved state, a dummy .conf is created on disk to remember
  483. * this network across restarts.
  484. *
  485. * @param renv Runtime environment
  486. * @param id Network ID
  487. * @return Reference counted pointer to new network
  488. * @throws std::runtime_error Unable to create tap device or other fatal error
  489. */
  490. static SharedPtr<Network> newInstance(const RuntimeEnvironment *renv,uint64_t id)
  491. throw(std::runtime_error);
  492. /**
  493. * Causes all persistent disk presence to be erased on delete
  494. */
  495. inline void destroyOnDelete()
  496. throw()
  497. {
  498. _destroyOnDelete = true;
  499. }
  500. public:
  501. /**
  502. * @return Network ID
  503. */
  504. inline uint64_t id() const throw() { return _id; }
  505. /**
  506. * @return Ethernet tap
  507. */
  508. inline EthernetTap &tap() throw() { return *_tap; }
  509. /**
  510. * @return Address of network's controlling node
  511. */
  512. inline Address controller() throw() { return Address(_id >> 24); }
  513. /**
  514. * @return Network ID in hexadecimal form
  515. */
  516. inline std::string idString()
  517. {
  518. char buf[64];
  519. Utils::snprintf(buf,sizeof(buf),"%.16llx",(unsigned long long)_id);
  520. return std::string(buf);
  521. }
  522. /**
  523. * @return True if network is open (no membership required)
  524. */
  525. inline bool isOpen() const
  526. throw()
  527. {
  528. Mutex::Lock _l(_lock);
  529. return _isOpen;
  530. }
  531. /**
  532. * Update multicast groups for this network's tap
  533. *
  534. * @return True if internal multicast group set has changed
  535. */
  536. inline bool updateMulticastGroups()
  537. {
  538. Mutex::Lock _l(_lock);
  539. return _tap->updateMulticastGroups(_multicastGroups);
  540. }
  541. /**
  542. * @return Latest set of multicast groups for this network's tap
  543. */
  544. inline std::set<MulticastGroup> multicastGroups() const
  545. {
  546. Mutex::Lock _l(_lock);
  547. return _multicastGroups;
  548. }
  549. /**
  550. * Set or update this network's configuration
  551. *
  552. * This is called by PacketDecoder when an update comes over the wire, or
  553. * internally when an old config is reloaded from disk.
  554. *
  555. * @param conf Configuration in key/value dictionary form
  556. */
  557. void setConfiguration(const Config &conf);
  558. /**
  559. * Causes this network to request an updated configuration from its master node now
  560. */
  561. void requestConfiguration();
  562. /**
  563. * Add or update a peer's membership certificate
  564. *
  565. * The certificate must already have been validated via signature checking.
  566. *
  567. * @param peer Peer that owns certificate
  568. * @param cert Certificate itself
  569. */
  570. void addMembershipCertificate(const Address &peer,const CertificateOfMembership &cert);
  571. /**
  572. * @param peer Peer address to check
  573. * @return True if peer is allowed to communicate on this network
  574. */
  575. bool isAllowed(const Address &peer) const;
  576. /**
  577. * Perform cleanup and possibly save state
  578. */
  579. void clean();
  580. /**
  581. * @return Time of last updated configuration or 0 if none
  582. */
  583. inline uint64_t lastConfigUpdate() const
  584. throw()
  585. {
  586. return _lastConfigUpdate;
  587. }
  588. /**
  589. * @return Status of this network
  590. */
  591. Status status() const;
  592. /**
  593. * Determine whether frames of a given ethernet type are allowed on this network
  594. *
  595. * @param etherType Ethernet frame type
  596. * @return True if network permits this type
  597. */
  598. inline bool permitsEtherType(unsigned int etherType) const
  599. throw()
  600. {
  601. if (!etherType)
  602. return false;
  603. else if (etherType > 65535)
  604. return false;
  605. else if ((_etWhitelist[0] & 1)) // if type 0 is in the whitelist, sense is inverted from whitelist to blacklist
  606. return ((_etWhitelist[etherType / 8] & (unsigned char)(1 << (etherType & 7))) == 0);
  607. else return ((_etWhitelist[etherType / 8] & (unsigned char)(1 << (etherType & 7))) != 0);
  608. }
  609. /**
  610. * Update multicast balance for an address and multicast group, return whether packet is allowed
  611. *
  612. * @param a Address that wants to send/relay packet
  613. * @param mg Multicast group
  614. * @param bytes Size of packet
  615. * @return True if packet is within budget
  616. */
  617. inline bool updateAndCheckMulticastBalance(const Address &a,const MulticastGroup &mg,unsigned int bytes)
  618. {
  619. Mutex::Lock _l(_lock);
  620. std::pair<Address,MulticastGroup> k(a,mg);
  621. std::map< std::pair<Address,MulticastGroup>,BandwidthAccount >::iterator bal(_multicastRateAccounts.find(k));
  622. if (bal == _multicastRateAccounts.end()) {
  623. MulticastRates::Rate r(_mcRates.get(mg));
  624. bal = _multicastRateAccounts.insert(std::pair< std::pair<Address,MulticastGroup>,BandwidthAccount >(k,BandwidthAccount(r.preload,r.maxBalance,r.accrual))).first;
  625. }
  626. return bal->second.deduct(bytes);
  627. //bool tmp = bal->second.deduct(bytes);
  628. //printf("%s: BAL: %u\n",mg.toString().c_str(),(unsigned int)bal->second.balance());
  629. //return tmp;
  630. }
  631. /**
  632. * @return True if this network allows bridging
  633. */
  634. inline bool permitsBridging() const
  635. throw()
  636. {
  637. return false; // TODO: bridging not implemented yet
  638. }
  639. /**
  640. * @return Bits in multicast restriciton prefix
  641. */
  642. inline unsigned int multicastPrefixBits() const
  643. throw()
  644. {
  645. return _multicastPrefixBits;
  646. }
  647. /**
  648. * @return Max depth (TTL) for a multicast frame
  649. */
  650. inline unsigned int multicastDepth() const
  651. throw()
  652. {
  653. return _multicastDepth;
  654. }
  655. private:
  656. static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data);
  657. void _restoreState();
  658. const RuntimeEnvironment *_r;
  659. // Multicast bandwidth accounting for peers on this network
  660. std::map< std::pair<Address,MulticastGroup>,BandwidthAccount > _multicastRateAccounts;
  661. // Tap and tap multicast memberships for this node on this network
  662. EthernetTap *_tap;
  663. std::set<MulticastGroup> _multicastGroups;
  664. // Membership certificates supplied by other peers on this network
  665. std::map<Address,CertificateOfMembership> _membershipCertificates;
  666. // Configuration from network master node
  667. Config _configuration;
  668. CertificateOfMembership _myCertificate; // memoized from _configuration
  669. MulticastRates _mcRates; // memoized from _configuration
  670. std::set<InetAddress> _staticAddresses; // memoized from _configuration
  671. bool _isOpen; // memoized from _configuration
  672. unsigned int _multicastPrefixBits; // memoized from _configuration
  673. unsigned int _multicastDepth; // memoized from _configuration
  674. // Ethertype whitelist bit field, set from config, for really fast lookup
  675. unsigned char _etWhitelist[65536 / 8];
  676. uint64_t _id;
  677. volatile uint64_t _lastConfigUpdate;
  678. volatile bool _destroyOnDelete;
  679. volatile bool _ready;
  680. Mutex _lock;
  681. AtomicCounter __refCount;
  682. };
  683. } // naemspace ZeroTier
  684. #endif