InetAddress.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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_INETADDRESS_HPP
  27. #define ZT_INETADDRESS_HPP
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stdint.h>
  31. #include "Constants.hpp"
  32. #include "../include/ZeroTierOne.h"
  33. #include "Utils.hpp"
  34. #include "MAC.hpp"
  35. #include "Buffer.hpp"
  36. namespace ZeroTier {
  37. /**
  38. * Maximum integer value of enum IpScope
  39. */
  40. #define ZT_INETADDRESS_MAX_SCOPE 7
  41. /**
  42. * Extends sockaddr_storage with friendly C++ methods
  43. *
  44. * This is basically a "mixin" for sockaddr_storage. It adds methods and
  45. * operators, but does not modify the structure. This can be cast to/from
  46. * sockaddr_storage and used interchangeably. DO NOT change this by e.g.
  47. * adding non-static fields, since much code depends on this identity.
  48. */
  49. struct InetAddress : public sockaddr_storage
  50. {
  51. /**
  52. * Loopback IPv4 address (no port)
  53. */
  54. static const InetAddress LO4;
  55. /**
  56. * Loopback IPV6 address (no port)
  57. */
  58. static const InetAddress LO6;
  59. /**
  60. * IP address scope
  61. *
  62. * Note that these values are in ascending order of path preference and
  63. * MUST remain that way or Path must be changed to reflect. Also be sure
  64. * to change ZT_INETADDRESS_MAX_SCOPE if the max changes.
  65. */
  66. enum IpScope
  67. {
  68. IP_SCOPE_NONE = 0, // NULL or not an IP address
  69. IP_SCOPE_MULTICAST = 1, // 224.0.0.0 and other V4/V6 multicast IPs
  70. IP_SCOPE_LOOPBACK = 2, // 127.0.0.1, ::1, etc.
  71. IP_SCOPE_PSEUDOPRIVATE = 3, // 28.x.x.x, etc. -- unofficially unrouted IPv4 blocks often "bogarted"
  72. IP_SCOPE_GLOBAL = 4, // globally routable IP address (all others)
  73. IP_SCOPE_LINK_LOCAL = 5, // 169.254.x.x, IPv6 LL
  74. IP_SCOPE_SHARED = 6, // 100.64.0.0/10, shared space for e.g. carrier-grade NAT
  75. IP_SCOPE_PRIVATE = 7 // 10.x.x.x, 192.168.x.x, etc.
  76. };
  77. InetAddress() { memset(this,0,sizeof(InetAddress)); }
  78. InetAddress(const InetAddress &a) { memcpy(this,&a,sizeof(InetAddress)); }
  79. InetAddress(const InetAddress *a) { memcpy(this,a,sizeof(InetAddress)); }
  80. InetAddress(const struct sockaddr_storage &ss) { *this = ss; }
  81. InetAddress(const struct sockaddr_storage *ss) { *this = ss; }
  82. InetAddress(const struct sockaddr &sa) { *this = sa; }
  83. InetAddress(const struct sockaddr *sa) { *this = sa; }
  84. InetAddress(const struct sockaddr_in &sa) { *this = sa; }
  85. InetAddress(const struct sockaddr_in *sa) { *this = sa; }
  86. InetAddress(const struct sockaddr_in6 &sa) { *this = sa; }
  87. InetAddress(const struct sockaddr_in6 *sa) { *this = sa; }
  88. InetAddress(const void *ipBytes,unsigned int ipLen,unsigned int port) { this->set(ipBytes,ipLen,port); }
  89. InetAddress(const uint32_t ipv4,unsigned int port) { this->set(&ipv4,4,port); }
  90. InetAddress(const char *ipSlashPort) { this->fromString(ipSlashPort); }
  91. inline InetAddress &operator=(const InetAddress &a)
  92. {
  93. if (&a != this)
  94. memcpy(this,&a,sizeof(InetAddress));
  95. return *this;
  96. }
  97. inline InetAddress &operator=(const InetAddress *a)
  98. {
  99. if (a != this)
  100. memcpy(this,a,sizeof(InetAddress));
  101. return *this;
  102. }
  103. inline InetAddress &operator=(const struct sockaddr_storage &ss)
  104. {
  105. if (reinterpret_cast<const InetAddress *>(&ss) != this)
  106. memcpy(this,&ss,sizeof(InetAddress));
  107. return *this;
  108. }
  109. inline InetAddress &operator=(const struct sockaddr_storage *ss)
  110. {
  111. if (reinterpret_cast<const InetAddress *>(ss) != this)
  112. memcpy(this,ss,sizeof(InetAddress));
  113. return *this;
  114. }
  115. inline InetAddress &operator=(const struct sockaddr_in &sa)
  116. {
  117. if (reinterpret_cast<const InetAddress *>(&sa) != this) {
  118. memset(this,0,sizeof(InetAddress));
  119. memcpy(this,&sa,sizeof(struct sockaddr_in));
  120. }
  121. return *this;
  122. }
  123. inline InetAddress &operator=(const struct sockaddr_in *sa)
  124. {
  125. if (reinterpret_cast<const InetAddress *>(sa) != this) {
  126. memset(this,0,sizeof(InetAddress));
  127. memcpy(this,sa,sizeof(struct sockaddr_in));
  128. }
  129. return *this;
  130. }
  131. inline InetAddress &operator=(const struct sockaddr_in6 &sa)
  132. {
  133. if (reinterpret_cast<const InetAddress *>(&sa) != this) {
  134. memset(this,0,sizeof(InetAddress));
  135. memcpy(this,&sa,sizeof(struct sockaddr_in6));
  136. }
  137. return *this;
  138. }
  139. inline InetAddress &operator=(const struct sockaddr_in6 *sa)
  140. {
  141. if (reinterpret_cast<const InetAddress *>(sa) != this) {
  142. memset(this,0,sizeof(InetAddress));
  143. memcpy(this,sa,sizeof(struct sockaddr_in6));
  144. }
  145. return *this;
  146. }
  147. inline InetAddress &operator=(const struct sockaddr &sa)
  148. {
  149. if (reinterpret_cast<const InetAddress *>(&sa) != this) {
  150. memset(this,0,sizeof(InetAddress));
  151. switch(sa.sa_family) {
  152. case AF_INET:
  153. memcpy(this,&sa,sizeof(struct sockaddr_in));
  154. break;
  155. case AF_INET6:
  156. memcpy(this,&sa,sizeof(struct sockaddr_in6));
  157. break;
  158. }
  159. }
  160. return *this;
  161. }
  162. inline InetAddress &operator=(const struct sockaddr *sa)
  163. {
  164. if (reinterpret_cast<const InetAddress *>(sa) != this) {
  165. memset(this,0,sizeof(InetAddress));
  166. switch(sa->sa_family) {
  167. case AF_INET:
  168. memcpy(this,sa,sizeof(struct sockaddr_in));
  169. break;
  170. case AF_INET6:
  171. memcpy(this,sa,sizeof(struct sockaddr_in6));
  172. break;
  173. }
  174. }
  175. return *this;
  176. }
  177. /**
  178. * @return IP scope classification (e.g. loopback, link-local, private, global)
  179. */
  180. IpScope ipScope() const;
  181. /**
  182. * Set from a raw IP and port number
  183. *
  184. * @param ipBytes Bytes of IP address in network byte order
  185. * @param ipLen Length of IP address: 4 or 16
  186. * @param port Port number or 0 for none
  187. */
  188. void set(const void *ipBytes,unsigned int ipLen,unsigned int port);
  189. /**
  190. * Set the port component
  191. *
  192. * @param port Port, 0 to 65535
  193. */
  194. inline void setPort(unsigned int port)
  195. {
  196. switch(ss_family) {
  197. case AF_INET:
  198. reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton((uint16_t)port);
  199. break;
  200. case AF_INET6:
  201. reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_port = Utils::hton((uint16_t)port);
  202. break;
  203. }
  204. }
  205. /**
  206. * @return True if this network/netmask route describes a default route (e.g. 0.0.0.0/0)
  207. */
  208. inline bool isDefaultRoute() const
  209. {
  210. switch(ss_family) {
  211. case AF_INET:
  212. return ( (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == 0) && (reinterpret_cast<const struct sockaddr_in *>(this)->sin_port == 0) );
  213. case AF_INET6:
  214. const uint8_t *ipb = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
  215. for(int i=0;i<16;++i) {
  216. if (ipb[i])
  217. return false;
  218. }
  219. return (reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port == 0);
  220. }
  221. return false;
  222. }
  223. /**
  224. * @return ASCII IP/port format representation
  225. */
  226. char *toString(char buf[64]) const;
  227. /**
  228. * @return IP portion only, in ASCII string format
  229. */
  230. char *toIpString(char buf[64]) const;
  231. /**
  232. * @param ipSlashPort IP/port (port is optional, will be 0 if not included)
  233. * @return True if address appeared to be valid
  234. */
  235. bool fromString(const char *ipSlashPort);
  236. /**
  237. * @return Port or 0 if no port component defined
  238. */
  239. inline unsigned int port() const
  240. {
  241. switch(ss_family) {
  242. case AF_INET: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in *>(this)->sin_port));
  243. case AF_INET6: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port));
  244. default: return 0;
  245. }
  246. }
  247. /**
  248. * Alias for port()
  249. *
  250. * This just aliases port() to make code more readable when netmask bits
  251. * are stuffed there, as they are in Network, EthernetTap, and a few other
  252. * spots.
  253. *
  254. * @return Netmask bits
  255. */
  256. inline unsigned int netmaskBits() const { return port(); }
  257. /**
  258. * @return True if netmask bits is valid for the address type
  259. */
  260. inline bool netmaskBitsValid() const
  261. {
  262. const unsigned int n = port();
  263. switch(ss_family) {
  264. case AF_INET: return (n <= 32);
  265. case AF_INET6: return (n <= 128);
  266. }
  267. return false;
  268. }
  269. /**
  270. * Alias for port()
  271. *
  272. * This just aliases port() because for gateways we use this field to
  273. * store the gateway metric.
  274. *
  275. * @return Gateway metric
  276. */
  277. inline unsigned int metric() const { return port(); }
  278. /**
  279. * Construct a full netmask as an InetAddress
  280. *
  281. * @return Netmask such as 255.255.255.0 if this address is /24 (port field will be unchanged)
  282. */
  283. InetAddress netmask() const;
  284. /**
  285. * Constructs a broadcast address from a network/netmask address
  286. *
  287. * This is only valid for IPv4 and will return a NULL InetAddress for other
  288. * address families.
  289. *
  290. * @return Broadcast address (only IP portion is meaningful)
  291. */
  292. InetAddress broadcast() const;
  293. /**
  294. * Return the network -- a.k.a. the IP ANDed with the netmask
  295. *
  296. * @return Network e.g. 10.0.1.0/24 from 10.0.1.200/24
  297. */
  298. InetAddress network() const;
  299. /**
  300. * Test whether this IPv6 prefix matches the prefix of a given IPv6 address
  301. *
  302. * @param addr Address to check
  303. * @return True if this IPv6 prefix matches the prefix of a given IPv6 address
  304. */
  305. bool isEqualPrefix(const InetAddress &addr) const;
  306. /**
  307. * Test whether this IP/netmask contains this address
  308. *
  309. * @param addr Address to check
  310. * @return True if this IP/netmask (route) contains this address
  311. */
  312. bool containsAddress(const InetAddress &addr) const;
  313. /**
  314. * @return True if this is an IPv4 address
  315. */
  316. inline bool isV4() const { return (ss_family == AF_INET); }
  317. /**
  318. * @return True if this is an IPv6 address
  319. */
  320. inline bool isV6() const { return (ss_family == AF_INET6); }
  321. /**
  322. * @return pointer to raw address bytes or NULL if not available
  323. */
  324. inline const void *rawIpData() const
  325. {
  326. switch(ss_family) {
  327. case AF_INET: return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
  328. case AF_INET6: return (const void *)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
  329. default: return 0;
  330. }
  331. }
  332. /**
  333. * @return InetAddress containing only the IP portion of this address and a zero port, or NULL if not IPv4 or IPv6
  334. */
  335. inline InetAddress ipOnly() const
  336. {
  337. InetAddress r;
  338. switch(ss_family) {
  339. case AF_INET:
  340. r.ss_family = AF_INET;
  341. reinterpret_cast<struct sockaddr_in *>(&r)->sin_addr.s_addr = reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr;
  342. break;
  343. case AF_INET6:
  344. r.ss_family = AF_INET6;
  345. memcpy(reinterpret_cast<struct sockaddr_in6 *>(&r)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,16);
  346. break;
  347. }
  348. return r;
  349. }
  350. /**
  351. * Performs an IP-only comparison or, if that is impossible, a memcmp()
  352. *
  353. * @param a InetAddress to compare again
  354. * @return True if only IP portions are equal (false for non-IP or null addresses)
  355. */
  356. inline bool ipsEqual(const InetAddress &a) const
  357. {
  358. if (ss_family == a.ss_family) {
  359. if (ss_family == AF_INET)
  360. return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr);
  361. if (ss_family == AF_INET6)
  362. return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,16) == 0);
  363. return (memcmp(this,&a,sizeof(InetAddress)) == 0);
  364. }
  365. return false;
  366. }
  367. inline unsigned long hashCode() const
  368. {
  369. if (ss_family == AF_INET) {
  370. return ((unsigned long)reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr + (unsigned long)reinterpret_cast<const struct sockaddr_in *>(this)->sin_port);
  371. } else if (ss_family == AF_INET6) {
  372. unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
  373. const uint8_t *a = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
  374. for(long i=0;i<16;++i)
  375. reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
  376. return tmp;
  377. } else {
  378. unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
  379. const uint8_t *a = reinterpret_cast<const uint8_t *>(this);
  380. for(long i=0;i<(long)sizeof(InetAddress);++i)
  381. reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
  382. return tmp;
  383. }
  384. }
  385. /**
  386. * Set to null/zero
  387. */
  388. inline void zero() { memset(this,0,sizeof(InetAddress)); }
  389. /**
  390. * Check whether this is a network/route rather than an IP assignment
  391. *
  392. * A network is an IP/netmask where everything after the netmask is
  393. * zero e.g. 10.0.0.0/8.
  394. *
  395. * @return True if everything after netmask bits is zero
  396. */
  397. bool isNetwork() const;
  398. /**
  399. * @return 14-bit (0-16383) hash of this IP's first 24 or 48 bits (for V4 or V6) for rate limiting code, or 0 if non-IP
  400. */
  401. inline unsigned long rateGateHash() const
  402. {
  403. unsigned long h = 0;
  404. switch(ss_family) {
  405. case AF_INET:
  406. h = (Utils::ntoh((uint32_t)reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr) & 0xffffff00) >> 8;
  407. h ^= (h >> 14);
  408. break;
  409. case AF_INET6: {
  410. const uint8_t *ip = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
  411. h = ((unsigned long)ip[0]); h <<= 1;
  412. h += ((unsigned long)ip[1]); h <<= 1;
  413. h += ((unsigned long)ip[2]); h <<= 1;
  414. h += ((unsigned long)ip[3]); h <<= 1;
  415. h += ((unsigned long)ip[4]); h <<= 1;
  416. h += ((unsigned long)ip[5]);
  417. } break;
  418. }
  419. return (h & 0x3fff);
  420. }
  421. /**
  422. * @return True if address family is non-zero
  423. */
  424. inline operator bool() const { return (ss_family != 0); }
  425. template<unsigned int C>
  426. inline void serialize(Buffer<C> &b) const
  427. {
  428. // This is used in the protocol and must be the same as describe in places
  429. // like VERB_HELLO in Packet.hpp.
  430. switch(ss_family) {
  431. case AF_INET:
  432. b.append((uint8_t)0x04);
  433. b.append(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr),4);
  434. b.append((uint16_t)port()); // just in case sin_port != uint16_t
  435. return;
  436. case AF_INET6:
  437. b.append((uint8_t)0x06);
  438. b.append(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,16);
  439. b.append((uint16_t)port()); // just in case sin_port != uint16_t
  440. return;
  441. default:
  442. b.append((uint8_t)0);
  443. return;
  444. }
  445. }
  446. template<unsigned int C>
  447. inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
  448. {
  449. memset(this,0,sizeof(InetAddress));
  450. unsigned int p = startAt;
  451. switch(b[p++]) {
  452. case 0:
  453. return 1;
  454. case 0x01:
  455. // TODO: Ethernet address (but accept for forward compatibility)
  456. return 7;
  457. case 0x02:
  458. // TODO: Bluetooth address (but accept for forward compatibility)
  459. return 7;
  460. case 0x03:
  461. // TODO: Other address types (but accept for forward compatibility)
  462. // These could be extended/optional things like AF_UNIX, LTE Direct, shared memory, etc.
  463. return (unsigned int)(b.template at<uint16_t>(p) + 3); // other addresses begin with 16-bit non-inclusive length
  464. case 0x04:
  465. ss_family = AF_INET;
  466. memcpy(&(reinterpret_cast<struct sockaddr_in *>(this)->sin_addr.s_addr),b.field(p,4),4); p += 4;
  467. reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p)); p += 2;
  468. break;
  469. case 0x06:
  470. ss_family = AF_INET6;
  471. memcpy(reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,b.field(p,16),16); p += 16;
  472. reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p)); p += 2;
  473. break;
  474. default:
  475. throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING;
  476. }
  477. return (p - startAt);
  478. }
  479. bool operator==(const InetAddress &a) const;
  480. bool operator<(const InetAddress &a) const;
  481. inline bool operator!=(const InetAddress &a) const { return !(*this == a); }
  482. inline bool operator>(const InetAddress &a) const { return (a < *this); }
  483. inline bool operator<=(const InetAddress &a) const { return !(a < *this); }
  484. inline bool operator>=(const InetAddress &a) const { return !(*this < a); }
  485. /**
  486. * @param mac MAC address seed
  487. * @return IPv6 link-local address
  488. */
  489. static InetAddress makeIpv6LinkLocal(const MAC &mac);
  490. /**
  491. * Compute private IPv6 unicast address from network ID and ZeroTier address
  492. *
  493. * This generates a private unicast IPv6 address that is mostly compliant
  494. * with the letter of RFC4193 and certainly compliant in spirit.
  495. *
  496. * RFC4193 specifies a format of:
  497. *
  498. * | 7 bits |1| 40 bits | 16 bits | 64 bits |
  499. * | Prefix |L| Global ID | Subnet ID | Interface ID |
  500. *
  501. * The 'L' bit is set to 1, yielding an address beginning with 0xfd. Then
  502. * the network ID is filled into the global ID, subnet ID, and first byte
  503. * of the "interface ID" field. Since the first 40 bits of the network ID
  504. * is the unique ZeroTier address of its controller, this makes a very
  505. * good random global ID. Since network IDs have 24 more bits, we let it
  506. * overflow into the interface ID.
  507. *
  508. * After that we pad with two bytes: 0x99, 0x93, namely the default ZeroTier
  509. * port in hex.
  510. *
  511. * Finally we fill the remaining 40 bits of the interface ID field with
  512. * the 40-bit unique ZeroTier device ID of the network member.
  513. *
  514. * This yields a valid RFC4193 address with a random global ID, a
  515. * meaningful subnet ID, and a unique interface ID, all mappable back onto
  516. * ZeroTier space.
  517. *
  518. * This in turn could allow us, on networks numbered this way, to emulate
  519. * IPv6 NDP and eliminate all multicast. This could be beneficial for
  520. * small devices and huge networks, e.g. IoT applications.
  521. *
  522. * The returned address is given an odd prefix length of /88, since within
  523. * a given network only the last 40 bits (device ID) are variable. This
  524. * is a bit unusual but as far as we know should not cause any problems with
  525. * any non-braindead IPv6 stack.
  526. *
  527. * @param nwid 64-bit network ID
  528. * @param zeroTierAddress 40-bit device address (in least significant 40 bits, highest 24 bits ignored)
  529. * @return IPv6 private unicast address with /88 netmask
  530. */
  531. static InetAddress makeIpv6rfc4193(uint64_t nwid,uint64_t zeroTierAddress);
  532. /**
  533. * Compute a private IPv6 "6plane" unicast address from network ID and ZeroTier address
  534. */
  535. static InetAddress makeIpv66plane(uint64_t nwid,uint64_t zeroTierAddress);
  536. };
  537. } // namespace ZeroTier
  538. #endif