update stats APIs to use TimePoint vs Duration correctly
[folly.git] / folly / IPAddressV6.cpp
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <folly/IPAddressV6.h>
18
19 #include <ostream>
20 #include <string>
21
22 #include <folly/Format.h>
23 #include <folly/IPAddress.h>
24 #include <folly/IPAddressV4.h>
25 #include <folly/MacAddress.h>
26 #include <folly/detail/IPAddressSource.h>
27
28 using std::ostream;
29 using std::string;
30
31 namespace folly {
32
33 // public static const
34 const uint32_t IPAddressV6::PREFIX_TEREDO = 0x20010000;
35 const uint32_t IPAddressV6::PREFIX_6TO4 = 0x2002;
36
37 // free functions
38 size_t hash_value(const IPAddressV6& addr) {
39   return addr.hash();
40 }
41 ostream& operator<<(ostream& os, const IPAddressV6& addr) {
42   os << addr.str();
43   return os;
44 }
45 void toAppend(IPAddressV6 addr, string* result) {
46   result->append(addr.str());
47 }
48 void toAppend(IPAddressV6 addr, fbstring* result) {
49   result->append(addr.str());
50 }
51
52 bool IPAddressV6::validate(StringPiece ip) {
53   if (ip.size() > 0 && ip.front() == '[' && ip.back() == ']') {
54     ip = ip.subpiece(1, ip.size() - 2);
55   }
56
57   constexpr size_t kStrMaxLen = INET6_ADDRSTRLEN;
58   std::array<char, kStrMaxLen + 1> ip_cstr;
59   const size_t len = std::min(ip.size(), kStrMaxLen);
60   std::memcpy(ip_cstr.data(), ip.data(), len);
61   ip_cstr[len] = 0;
62   struct in6_addr addr;
63   return 1 == inet_pton(AF_INET6, ip_cstr.data(), &addr);
64 }
65
66 // public default constructor
67 IPAddressV6::IPAddressV6() {
68 }
69
70 // public string constructor
71 IPAddressV6::IPAddressV6(StringPiece addr) {
72   auto ip = addr.str();
73
74   // Allow addresses surrounded in brackets
75   if (ip.size() < 2) {
76     throw IPAddressFormatException(
77         to<std::string>("Invalid IPv6 address '", ip, "': address too short"));
78   }
79   if (ip.front() == '[' && ip.back() == ']') {
80     ip = ip.substr(1, ip.size() - 2);
81   }
82
83   struct addrinfo* result;
84   struct addrinfo hints;
85   memset(&hints, 0, sizeof(hints));
86   hints.ai_family = AF_INET6;
87   hints.ai_socktype = SOCK_STREAM;
88   hints.ai_flags = AI_NUMERICHOST;
89   if (!getaddrinfo(ip.c_str(), nullptr, &hints, &result)) {
90     struct sockaddr_in6* ipAddr = (struct sockaddr_in6*)result->ai_addr;
91     addr_.in6Addr_ = ipAddr->sin6_addr;
92     scope_ = ipAddr->sin6_scope_id;
93     freeaddrinfo(result);
94   } else {
95     throw IPAddressFormatException(
96         to<std::string>("Invalid IPv6 address '", ip, "'"));
97   }
98 }
99
100 // in6_addr constructor
101 IPAddressV6::IPAddressV6(const in6_addr& src)
102   : addr_(src)
103 {
104 }
105
106 // sockaddr_in6 constructor
107 IPAddressV6::IPAddressV6(const sockaddr_in6& src)
108   : addr_(src.sin6_addr)
109   , scope_(src.sin6_scope_id)
110 {
111 }
112
113 // ByteArray16 constructor
114 IPAddressV6::IPAddressV6(const ByteArray16& src)
115   : addr_(src)
116 {
117 }
118
119 // link-local constructor
120 IPAddressV6::IPAddressV6(LinkLocalTag, MacAddress mac)
121   : addr_(mac) {
122 }
123
124 IPAddressV6::AddressStorage::AddressStorage(MacAddress mac) {
125   // The link-local address uses modified EUI-64 format,
126   // See RFC 4291 sections 2.5.1, 2.5.6, and Appendix A
127   const auto* macBytes = mac.bytes();
128   memcpy(&bytes_.front(), "\xfe\x80\x00\x00\x00\x00\x00\x00", 8);
129   bytes_[8] = macBytes[0] ^ 0x02;
130   bytes_[9] = macBytes[1];
131   bytes_[10] = macBytes[2];
132   bytes_[11] = 0xff;
133   bytes_[12] = 0xfe;
134   bytes_[13] = macBytes[3];
135   bytes_[14] = macBytes[4];
136   bytes_[15] = macBytes[5];
137 }
138
139 void IPAddressV6::setFromBinary(ByteRange bytes) {
140   if (bytes.size() != 16) {
141     throw IPAddressFormatException(to<std::string>(
142         "Invalid IPv6 binary data: length must ",
143         "be 16 bytes, got ",
144         bytes.size()));
145   }
146   memcpy(&addr_.in6Addr_.s6_addr, bytes.data(), sizeof(in6_addr));
147   scope_ = 0;
148 }
149
150 // public
151 IPAddressV4 IPAddressV6::createIPv4() const {
152   if (!isIPv4Mapped()) {
153     throw IPAddressFormatException("addr is not v4-to-v6-mapped");
154   }
155   const unsigned char* by = bytes();
156   return IPAddressV4(detail::Bytes::mkAddress4(&by[12]));
157 }
158
159 // convert two uint8_t bytes into a uint16_t as hibyte.lobyte
160 static inline uint16_t unpack(uint8_t lobyte, uint8_t hibyte) {
161   return ((uint16_t)hibyte << 8) | (uint16_t)lobyte;
162 }
163
164 // given a src string, unpack count*2 bytes into dest
165 // dest must have as much storage as count
166 static inline void unpackInto(const unsigned char* src,
167                               uint16_t* dest,
168                               size_t count) {
169   for (size_t i = 0, hi = 1, lo = 0; i < count; i++) {
170     dest[i] = unpack(src[hi], src[lo]);
171     hi += 2;
172     lo += 2;
173   }
174 }
175
176 // public
177 IPAddressV4 IPAddressV6::getIPv4For6To4() const {
178   if (!is6To4()) {
179     throw IPAddressV6::TypeError(format(
180             "Invalid IP '{}': not a 6to4 address", str()).str());
181   }
182   // convert 16x8 bytes into first 4x16 bytes
183   uint16_t ints[4] = {0,0,0,0};
184   unpackInto(bytes(), ints, 4);
185   // repack into 4x8
186   union {
187     unsigned char bytes[4];
188     in_addr addr;
189   } ipv4;
190   ipv4.bytes[0] = (uint8_t)((ints[1] & 0xFF00) >> 8);
191   ipv4.bytes[1] = (uint8_t)(ints[1] & 0x00FF);
192   ipv4.bytes[2] = (uint8_t)((ints[2] & 0xFF00) >> 8);
193   ipv4.bytes[3] = (uint8_t)(ints[2] & 0x00FF);
194   return IPAddressV4(ipv4.addr);
195 }
196
197 // public
198 bool IPAddressV6::isIPv4Mapped() const {
199   // v4 mapped addresses have their first 10 bytes set to 0, the next 2 bytes
200   // set to 255 (0xff);
201   const unsigned char* by = bytes();
202
203   // check if first 10 bytes are 0
204   for (int i = 0; i < 10; i++) {
205     if (by[i] != 0x00) {
206       return false;
207     }
208   }
209   // check if bytes 11 and 12 are 255
210   if (by[10] == 0xff && by[11] == 0xff) {
211     return true;
212   }
213   return false;
214 }
215
216 // public
217 IPAddressV6::Type IPAddressV6::type() const {
218   // convert 16x8 bytes into first 2x16 bytes
219   uint16_t ints[2] = {0,0};
220   unpackInto(bytes(), ints, 2);
221
222   if ((((uint32_t)ints[0] << 16) | ints[1]) == IPAddressV6::PREFIX_TEREDO) {
223     return Type::TEREDO;
224   }
225
226   if ((uint32_t)ints[0] == IPAddressV6::PREFIX_6TO4) {
227     return Type::T6TO4;
228   }
229
230   return Type::NORMAL;
231 }
232
233 // public
234 string IPAddressV6::toJson() const {
235   return format(
236       "{{family:'AF_INET6', addr:'{}', hash:{}}}", str(), hash()).str();
237 }
238
239 // public
240 size_t IPAddressV6::hash() const {
241   if (isIPv4Mapped()) {
242     /* An IPAddress containing this object would be equal (i.e. operator==)
243        to an IPAddress containing the corresponding IPv4.
244        So we must make sure that the hash values are the same as well */
245     return IPAddress::createIPv4(*this).hash();
246   }
247
248   static const uint64_t seed = AF_INET6;
249   uint64_t hash1 = 0, hash2 = 0;
250   hash::SpookyHashV2::Hash128(&addr_, 16, &hash1, &hash2);
251   return hash::hash_combine(seed, hash1, hash2);
252 }
253
254 // public
255 bool IPAddressV6::inSubnet(StringPiece cidrNetwork) const {
256   auto subnetInfo = IPAddress::createNetwork(cidrNetwork);
257   auto addr = subnetInfo.first;
258   if (!addr.isV6()) {
259     throw IPAddressFormatException(to<std::string>(
260         "Address '", addr.toJson(), "' ", "is not a V6 address"));
261   }
262   return inSubnetWithMask(addr.asV6(), fetchMask(subnetInfo.second));
263 }
264
265 // public
266 bool IPAddressV6::inSubnetWithMask(const IPAddressV6& subnet,
267                                    const ByteArray16& cidrMask) const {
268   const ByteArray16 mask = detail::Bytes::mask(toByteArray(), cidrMask);
269   const ByteArray16 subMask = detail::Bytes::mask(subnet.toByteArray(),
270                                                   cidrMask);
271   return (mask == subMask);
272 }
273
274 // public
275 bool IPAddressV6::isLoopback() const {
276   // Check if v4 mapped is loopback
277   if (isIPv4Mapped() && createIPv4().isLoopback()) {
278     return true;
279   }
280   auto socka = toSockAddr();
281   return IN6_IS_ADDR_LOOPBACK(&socka.sin6_addr);
282 }
283
284 bool IPAddressV6::isRoutable() const {
285   return
286     // 2000::/3 is the only assigned global unicast block
287     inBinarySubnet({{0x20, 0x00}}, 3) ||
288     // ffxe::/16 are global scope multicast addresses,
289     // which are eligible to be routed over the internet
290     (isMulticast() && getMulticastScope() == 0xe);
291 }
292
293 bool IPAddressV6::isLinkLocalBroadcast() const {
294   static const IPAddressV6 kLinkLocalBroadcast("ff02::1");
295   return *this == kLinkLocalBroadcast;
296 }
297
298 // public
299 bool IPAddressV6::isPrivate() const {
300   // Check if mapped is private
301   if (isIPv4Mapped() && createIPv4().isPrivate()) {
302     return true;
303   }
304   return isLoopback() || inBinarySubnet({{0xfc, 0x00}}, 7);
305 }
306
307 // public
308 bool IPAddressV6::isLinkLocal() const {
309   return inBinarySubnet({{0xfe, 0x80}}, 10);
310 }
311
312 bool IPAddressV6::isMulticast() const {
313   return addr_.bytes_[0] == 0xff;
314 }
315
316 uint8_t IPAddressV6::getMulticastFlags() const {
317   DCHECK(isMulticast());
318   return ((addr_.bytes_[1] >> 4) & 0xf);
319 }
320
321 uint8_t IPAddressV6::getMulticastScope() const {
322   DCHECK(isMulticast());
323   return (addr_.bytes_[1] & 0xf);
324 }
325
326 IPAddressV6 IPAddressV6::getSolicitedNodeAddress() const {
327   // Solicted node addresses must be constructed from unicast (or anycast)
328   // addresses
329   DCHECK(!isMulticast());
330
331   uint8_t bytes[16] = { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332                         0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00 };
333   bytes[13] = addr_.bytes_[13];
334   bytes[14] = addr_.bytes_[14];
335   bytes[15] = addr_.bytes_[15];
336   return IPAddressV6::fromBinary(ByteRange(bytes, 16));
337 }
338
339 // public
340 IPAddressV6 IPAddressV6::mask(size_t numBits) const {
341   static const auto bits = bitCount();
342   if (numBits > bits) {
343     throw IPAddressFormatException(
344         to<std::string>("numBits(", numBits, ") > bitCount(", bits, ")"));
345   }
346   ByteArray16 ba = detail::Bytes::mask(fetchMask(numBits), addr_.bytes_);
347   return IPAddressV6(ba);
348 }
349
350 // public
351 string IPAddressV6::str() const {
352   char buffer[INET6_ADDRSTRLEN] = {0};
353   sockaddr_in6 sock = toSockAddr();
354   if (!getnameinfo(
355         (sockaddr*)&sock, sizeof(sock),
356         buffer, INET6_ADDRSTRLEN,
357         nullptr, 0, NI_NUMERICHOST)) {
358     string ip(buffer);
359     return ip;
360   } else {
361     throw IPAddressFormatException(to<std::string>(
362         "Invalid address with hex ",
363         "'",
364         detail::Bytes::toHex(bytes(), 16),
365         "'"));
366   }
367 }
368
369 // public
370 string IPAddressV6::toFullyQualified() const {
371   return detail::fastIpv6ToString(addr_.in6Addr_);
372 }
373
374 // public
375 uint8_t IPAddressV6::getNthMSByte(size_t byteIndex) const {
376   const auto highestIndex = byteCount() - 1;
377   if (byteIndex > highestIndex) {
378     throw std::invalid_argument(to<string>("Byte index must be <= ",
379         to<string>(highestIndex), " for addresses of type :",
380         detail::familyNameStr(AF_INET6)));
381   }
382   return bytes()[byteIndex];
383 }
384
385 // protected
386 const ByteArray16 IPAddressV6::fetchMask(size_t numBits) {
387   static const uint8_t bits = bitCount();
388   if (numBits > bits) {
389     throw IPAddressFormatException("IPv6 addresses are 128 bits.");
390   }
391   // masks_ is backed by an array so is zero indexed
392   return masks_[numBits];
393 }
394
395 // public static
396 CIDRNetworkV6 IPAddressV6::longestCommonPrefix(
397     const CIDRNetworkV6& one,
398     const CIDRNetworkV6& two) {
399   auto prefix = detail::Bytes::longestCommonPrefix(
400       one.first.addr_.bytes_, one.second, two.first.addr_.bytes_, two.second);
401   return {IPAddressV6(prefix.first), prefix.second};
402 }
403
404 // protected
405 bool IPAddressV6::inBinarySubnet(const std::array<uint8_t, 2> addr,
406                                  size_t numBits) const {
407   auto masked = mask(numBits);
408   return (std::memcmp(addr.data(), masked.bytes(), 2) == 0);
409 }
410
411 // static private
412 const std::array<ByteArray16, 129> IPAddressV6::masks_ = {{
413 /* /0   */ {{ 0x00,0x00,0x00,0x00,
414              0x00,0x00,0x00,0x00,
415              0x00,0x00,0x00,0x00,
416              0x00,0x00,0x00,0x00 }},
417 /* /1   */ {{ 0x80,0x00,0x00,0x00,
418              0x00,0x00,0x00,0x00,
419              0x00,0x00,0x00,0x00,
420              0x00,0x00,0x00,0x00 }},
421 /* /2   */ {{ 0xc0,0x00,0x00,0x00,
422              0x00,0x00,0x00,0x00,
423              0x00,0x00,0x00,0x00,
424              0x00,0x00,0x00,0x00 }},
425 /* /3   */ {{ 0xe0,0x00,0x00,0x00,
426              0x00,0x00,0x00,0x00,
427              0x00,0x00,0x00,0x00,
428              0x00,0x00,0x00,0x00 }},
429 /* /4   */ {{ 0xf0,0x00,0x00,0x00,
430              0x00,0x00,0x00,0x00,
431              0x00,0x00,0x00,0x00,
432              0x00,0x00,0x00,0x00 }},
433 /* /5   */ {{ 0xf8,0x00,0x00,0x00,
434              0x00,0x00,0x00,0x00,
435              0x00,0x00,0x00,0x00,
436              0x00,0x00,0x00,0x00 }},
437 /* /6   */ {{ 0xfc,0x00,0x00,0x00,
438              0x00,0x00,0x00,0x00,
439              0x00,0x00,0x00,0x00,
440              0x00,0x00,0x00,0x00 }},
441 /* /7   */ {{ 0xfe,0x00,0x00,0x00,
442              0x00,0x00,0x00,0x00,
443              0x00,0x00,0x00,0x00,
444              0x00,0x00,0x00,0x00 }},
445 /* /8   */ {{ 0xff,0x00,0x00,0x00,
446              0x00,0x00,0x00,0x00,
447              0x00,0x00,0x00,0x00,
448              0x00,0x00,0x00,0x00 }},
449 /* /9   */ {{ 0xff,0x80,0x00,0x00,
450              0x00,0x00,0x00,0x00,
451              0x00,0x00,0x00,0x00,
452              0x00,0x00,0x00,0x00 }},
453 /* /10  */ {{ 0xff,0xc0,0x00,0x00,
454              0x00,0x00,0x00,0x00,
455              0x00,0x00,0x00,0x00,
456              0x00,0x00,0x00,0x00 }},
457 /* /11  */ {{ 0xff,0xe0,0x00,0x00,
458              0x00,0x00,0x00,0x00,
459              0x00,0x00,0x00,0x00,
460              0x00,0x00,0x00,0x00 }},
461 /* /12  */ {{ 0xff,0xf0,0x00,0x00,
462              0x00,0x00,0x00,0x00,
463              0x00,0x00,0x00,0x00,
464              0x00,0x00,0x00,0x00 }},
465 /* /13  */ {{ 0xff,0xf8,0x00,0x00,
466              0x00,0x00,0x00,0x00,
467              0x00,0x00,0x00,0x00,
468              0x00,0x00,0x00,0x00 }},
469 /* /14  */ {{ 0xff,0xfc,0x00,0x00,
470              0x00,0x00,0x00,0x00,
471              0x00,0x00,0x00,0x00,
472              0x00,0x00,0x00,0x00 }},
473 /* /15  */ {{ 0xff,0xfe,0x00,0x00,
474              0x00,0x00,0x00,0x00,
475              0x00,0x00,0x00,0x00,
476              0x00,0x00,0x00,0x00 }},
477 /* /16  */ {{ 0xff,0xff,0x00,0x00,
478              0x00,0x00,0x00,0x00,
479              0x00,0x00,0x00,0x00,
480              0x00,0x00,0x00,0x00 }},
481 /* /17  */ {{ 0xff,0xff,0x80,0x00,
482              0x00,0x00,0x00,0x00,
483              0x00,0x00,0x00,0x00,
484              0x00,0x00,0x00,0x00 }},
485 /* /18  */ {{ 0xff,0xff,0xc0,0x00,
486              0x00,0x00,0x00,0x00,
487              0x00,0x00,0x00,0x00,
488              0x00,0x00,0x00,0x00 }},
489 /* /19  */ {{ 0xff,0xff,0xe0,0x00,
490              0x00,0x00,0x00,0x00,
491              0x00,0x00,0x00,0x00,
492              0x00,0x00,0x00,0x00 }},
493 /* /20  */ {{ 0xff,0xff,0xf0,0x00,
494              0x00,0x00,0x00,0x00,
495              0x00,0x00,0x00,0x00,
496              0x00,0x00,0x00,0x00 }},
497 /* /21  */ {{ 0xff,0xff,0xf8,0x00,
498              0x00,0x00,0x00,0x00,
499              0x00,0x00,0x00,0x00,
500              0x00,0x00,0x00,0x00 }},
501 /* /22  */ {{ 0xff,0xff,0xfc,0x00,
502              0x00,0x00,0x00,0x00,
503              0x00,0x00,0x00,0x00,
504              0x00,0x00,0x00,0x00 }},
505 /* /23  */ {{ 0xff,0xff,0xfe,0x00,
506              0x00,0x00,0x00,0x00,
507              0x00,0x00,0x00,0x00,
508              0x00,0x00,0x00,0x00 }},
509 /* /24  */ {{ 0xff,0xff,0xff,0x00,
510              0x00,0x00,0x00,0x00,
511              0x00,0x00,0x00,0x00,
512              0x00,0x00,0x00,0x00 }},
513 /* /25  */ {{ 0xff,0xff,0xff,0x80,
514              0x00,0x00,0x00,0x00,
515              0x00,0x00,0x00,0x00,
516              0x00,0x00,0x00,0x00 }},
517 /* /26  */ {{ 0xff,0xff,0xff,0xc0,
518              0x00,0x00,0x00,0x00,
519              0x00,0x00,0x00,0x00,
520              0x00,0x00,0x00,0x00 }},
521 /* /27  */ {{ 0xff,0xff,0xff,0xe0,
522              0x00,0x00,0x00,0x00,
523              0x00,0x00,0x00,0x00,
524              0x00,0x00,0x00,0x00 }},
525 /* /28  */ {{ 0xff,0xff,0xff,0xf0,
526              0x00,0x00,0x00,0x00,
527              0x00,0x00,0x00,0x00,
528              0x00,0x00,0x00,0x00 }},
529 /* /29  */ {{ 0xff,0xff,0xff,0xf8,
530              0x00,0x00,0x00,0x00,
531              0x00,0x00,0x00,0x00,
532              0x00,0x00,0x00,0x00 }},
533 /* /30  */ {{ 0xff,0xff,0xff,0xfc,
534              0x00,0x00,0x00,0x00,
535              0x00,0x00,0x00,0x00,
536              0x00,0x00,0x00,0x00 }},
537 /* /31  */ {{ 0xff,0xff,0xff,0xfe,
538              0x00,0x00,0x00,0x00,
539              0x00,0x00,0x00,0x00,
540              0x00,0x00,0x00,0x00 }},
541 /* /32  */ {{ 0xff,0xff,0xff,0xff,
542              0x00,0x00,0x00,0x00,
543              0x00,0x00,0x00,0x00,
544              0x00,0x00,0x00,0x00 }},
545 /* /33  */ {{ 0xff,0xff,0xff,0xff,
546              0x80,0x00,0x00,0x00,
547              0x00,0x00,0x00,0x00,
548              0x00,0x00,0x00,0x00 }},
549 /* /34  */ {{ 0xff,0xff,0xff,0xff,
550              0xc0,0x00,0x00,0x00,
551              0x00,0x00,0x00,0x00,
552              0x00,0x00,0x00,0x00 }},
553 /* /35  */ {{ 0xff,0xff,0xff,0xff,
554              0xe0,0x00,0x00,0x00,
555              0x00,0x00,0x00,0x00,
556              0x00,0x00,0x00,0x00 }},
557 /* /36  */ {{ 0xff,0xff,0xff,0xff,
558              0xf0,0x00,0x00,0x00,
559              0x00,0x00,0x00,0x00,
560              0x00,0x00,0x00,0x00 }},
561 /* /37  */ {{ 0xff,0xff,0xff,0xff,
562              0xf8,0x00,0x00,0x00,
563              0x00,0x00,0x00,0x00,
564              0x00,0x00,0x00,0x00 }},
565 /* /38  */ {{ 0xff,0xff,0xff,0xff,
566              0xfc,0x00,0x00,0x00,
567              0x00,0x00,0x00,0x00,
568              0x00,0x00,0x00,0x00 }},
569 /* /39  */ {{ 0xff,0xff,0xff,0xff,
570              0xfe,0x00,0x00,0x00,
571              0x00,0x00,0x00,0x00,
572              0x00,0x00,0x00,0x00 }},
573 /* /40  */ {{ 0xff,0xff,0xff,0xff,
574              0xff,0x00,0x00,0x00,
575              0x00,0x00,0x00,0x00,
576              0x00,0x00,0x00,0x00 }},
577 /* /41  */ {{ 0xff,0xff,0xff,0xff,
578              0xff,0x80,0x00,0x00,
579              0x00,0x00,0x00,0x00,
580              0x00,0x00,0x00,0x00 }},
581 /* /42  */ {{ 0xff,0xff,0xff,0xff,
582              0xff,0xc0,0x00,0x00,
583              0x00,0x00,0x00,0x00,
584              0x00,0x00,0x00,0x00 }},
585 /* /43  */ {{ 0xff,0xff,0xff,0xff,
586              0xff,0xe0,0x00,0x00,
587              0x00,0x00,0x00,0x00,
588              0x00,0x00,0x00,0x00 }},
589 /* /44  */ {{ 0xff,0xff,0xff,0xff,
590              0xff,0xf0,0x00,0x00,
591              0x00,0x00,0x00,0x00,
592              0x00,0x00,0x00,0x00 }},
593 /* /45  */ {{ 0xff,0xff,0xff,0xff,
594              0xff,0xf8,0x00,0x00,
595              0x00,0x00,0x00,0x00,
596              0x00,0x00,0x00,0x00 }},
597 /* /46  */ {{ 0xff,0xff,0xff,0xff,
598              0xff,0xfc,0x00,0x00,
599              0x00,0x00,0x00,0x00,
600              0x00,0x00,0x00,0x00 }},
601 /* /47  */ {{ 0xff,0xff,0xff,0xff,
602              0xff,0xfe,0x00,0x00,
603              0x00,0x00,0x00,0x00,
604              0x00,0x00,0x00,0x00 }},
605 /* /48  */ {{ 0xff,0xff,0xff,0xff,
606              0xff,0xff,0x00,0x00,
607              0x00,0x00,0x00,0x00,
608              0x00,0x00,0x00,0x00 }},
609 /* /49  */ {{ 0xff,0xff,0xff,0xff,
610              0xff,0xff,0x80,0x00,
611              0x00,0x00,0x00,0x00,
612              0x00,0x00,0x00,0x00 }},
613 /* /50  */ {{ 0xff,0xff,0xff,0xff,
614              0xff,0xff,0xc0,0x00,
615              0x00,0x00,0x00,0x00,
616              0x00,0x00,0x00,0x00 }},
617 /* /51  */ {{ 0xff,0xff,0xff,0xff,
618              0xff,0xff,0xe0,0x00,
619              0x00,0x00,0x00,0x00,
620              0x00,0x00,0x00,0x00 }},
621 /* /52  */ {{ 0xff,0xff,0xff,0xff,
622              0xff,0xff,0xf0,0x00,
623              0x00,0x00,0x00,0x00,
624              0x00,0x00,0x00,0x00 }},
625 /* /53  */ {{ 0xff,0xff,0xff,0xff,
626              0xff,0xff,0xf8,0x00,
627              0x00,0x00,0x00,0x00,
628              0x00,0x00,0x00,0x00 }},
629 /* /54  */ {{ 0xff,0xff,0xff,0xff,
630              0xff,0xff,0xfc,0x00,
631              0x00,0x00,0x00,0x00,
632              0x00,0x00,0x00,0x00 }},
633 /* /55  */ {{ 0xff,0xff,0xff,0xff,
634              0xff,0xff,0xfe,0x00,
635              0x00,0x00,0x00,0x00,
636              0x00,0x00,0x00,0x00 }},
637 /* /56  */ {{ 0xff,0xff,0xff,0xff,
638              0xff,0xff,0xff,0x00,
639              0x00,0x00,0x00,0x00,
640              0x00,0x00,0x00,0x00 }},
641 /* /57  */ {{ 0xff,0xff,0xff,0xff,
642              0xff,0xff,0xff,0x80,
643              0x00,0x00,0x00,0x00,
644              0x00,0x00,0x00,0x00 }},
645 /* /58  */ {{ 0xff,0xff,0xff,0xff,
646              0xff,0xff,0xff,0xc0,
647              0x00,0x00,0x00,0x00,
648              0x00,0x00,0x00,0x00 }},
649 /* /59  */ {{ 0xff,0xff,0xff,0xff,
650              0xff,0xff,0xff,0xe0,
651              0x00,0x00,0x00,0x00,
652              0x00,0x00,0x00,0x00 }},
653 /* /60  */ {{ 0xff,0xff,0xff,0xff,
654              0xff,0xff,0xff,0xf0,
655              0x00,0x00,0x00,0x00,
656              0x00,0x00,0x00,0x00 }},
657 /* /61  */ {{ 0xff,0xff,0xff,0xff,
658              0xff,0xff,0xff,0xf8,
659              0x00,0x00,0x00,0x00,
660              0x00,0x00,0x00,0x00 }},
661 /* /62  */ {{ 0xff,0xff,0xff,0xff,
662              0xff,0xff,0xff,0xfc,
663              0x00,0x00,0x00,0x00,
664              0x00,0x00,0x00,0x00 }},
665 /* /63  */ {{ 0xff,0xff,0xff,0xff,
666              0xff,0xff,0xff,0xfe,
667              0x00,0x00,0x00,0x00,
668              0x00,0x00,0x00,0x00 }},
669 /* /64  */ {{ 0xff,0xff,0xff,0xff,
670              0xff,0xff,0xff,0xff,
671              0x00,0x00,0x00,0x00,
672              0x00,0x00,0x00,0x00 }},
673 /* /65  */ {{ 0xff,0xff,0xff,0xff,
674              0xff,0xff,0xff,0xff,
675              0x80,0x00,0x00,0x00,
676              0x00,0x00,0x00,0x00 }},
677 /* /66  */ {{ 0xff,0xff,0xff,0xff,
678              0xff,0xff,0xff,0xff,
679              0xc0,0x00,0x00,0x00,
680              0x00,0x00,0x00,0x00 }},
681 /* /67  */ {{ 0xff,0xff,0xff,0xff,
682              0xff,0xff,0xff,0xff,
683              0xe0,0x00,0x00,0x00,
684              0x00,0x00,0x00,0x00 }},
685 /* /68  */ {{ 0xff,0xff,0xff,0xff,
686              0xff,0xff,0xff,0xff,
687              0xf0,0x00,0x00,0x00,
688              0x00,0x00,0x00,0x00 }},
689 /* /69  */ {{ 0xff,0xff,0xff,0xff,
690              0xff,0xff,0xff,0xff,
691              0xf8,0x00,0x00,0x00,
692              0x00,0x00,0x00,0x00 }},
693 /* /70  */ {{ 0xff,0xff,0xff,0xff,
694              0xff,0xff,0xff,0xff,
695              0xfc,0x00,0x00,0x00,
696              0x00,0x00,0x00,0x00 }},
697 /* /71  */ {{ 0xff,0xff,0xff,0xff,
698              0xff,0xff,0xff,0xff,
699              0xfe,0x00,0x00,0x00,
700              0x00,0x00,0x00,0x00 }},
701 /* /72  */ {{ 0xff,0xff,0xff,0xff,
702              0xff,0xff,0xff,0xff,
703              0xff,0x00,0x00,0x00,
704              0x00,0x00,0x00,0x00 }},
705 /* /73  */ {{ 0xff,0xff,0xff,0xff,
706              0xff,0xff,0xff,0xff,
707              0xff,0x80,0x00,0x00,
708              0x00,0x00,0x00,0x00 }},
709 /* /74  */ {{ 0xff,0xff,0xff,0xff,
710              0xff,0xff,0xff,0xff,
711              0xff,0xc0,0x00,0x00,
712              0x00,0x00,0x00,0x00 }},
713 /* /75  */ {{ 0xff,0xff,0xff,0xff,
714              0xff,0xff,0xff,0xff,
715              0xff,0xe0,0x00,0x00,
716              0x00,0x00,0x00,0x00 }},
717 /* /76  */ {{ 0xff,0xff,0xff,0xff,
718              0xff,0xff,0xff,0xff,
719              0xff,0xf0,0x00,0x00,
720              0x00,0x00,0x00,0x00 }},
721 /* /77  */ {{ 0xff,0xff,0xff,0xff,
722              0xff,0xff,0xff,0xff,
723              0xff,0xf8,0x00,0x00,
724              0x00,0x00,0x00,0x00 }},
725 /* /78  */ {{ 0xff,0xff,0xff,0xff,
726              0xff,0xff,0xff,0xff,
727              0xff,0xfc,0x00,0x00,
728              0x00,0x00,0x00,0x00 }},
729 /* /79  */ {{ 0xff,0xff,0xff,0xff,
730              0xff,0xff,0xff,0xff,
731              0xff,0xfe,0x00,0x00,
732              0x00,0x00,0x00,0x00 }},
733 /* /80  */ {{ 0xff,0xff,0xff,0xff,
734              0xff,0xff,0xff,0xff,
735              0xff,0xff,0x00,0x00,
736              0x00,0x00,0x00,0x00 }},
737 /* /81  */ {{ 0xff,0xff,0xff,0xff,
738              0xff,0xff,0xff,0xff,
739              0xff,0xff,0x80,0x00,
740              0x00,0x00,0x00,0x00 }},
741 /* /82  */ {{ 0xff,0xff,0xff,0xff,
742              0xff,0xff,0xff,0xff,
743              0xff,0xff,0xc0,0x00,
744              0x00,0x00,0x00,0x00 }},
745 /* /83  */ {{ 0xff,0xff,0xff,0xff,
746              0xff,0xff,0xff,0xff,
747              0xff,0xff,0xe0,0x00,
748              0x00,0x00,0x00,0x00 }},
749 /* /84  */ {{ 0xff,0xff,0xff,0xff,
750              0xff,0xff,0xff,0xff,
751              0xff,0xff,0xf0,0x00,
752              0x00,0x00,0x00,0x00 }},
753 /* /85  */ {{ 0xff,0xff,0xff,0xff,
754              0xff,0xff,0xff,0xff,
755              0xff,0xff,0xf8,0x00,
756              0x00,0x00,0x00,0x00 }},
757 /* /86  */ {{ 0xff,0xff,0xff,0xff,
758              0xff,0xff,0xff,0xff,
759              0xff,0xff,0xfc,0x00,
760              0x00,0x00,0x00,0x00 }},
761 /* /87  */ {{ 0xff,0xff,0xff,0xff,
762              0xff,0xff,0xff,0xff,
763              0xff,0xff,0xfe,0x00,
764              0x00,0x00,0x00,0x00 }},
765 /* /88  */ {{ 0xff,0xff,0xff,0xff,
766              0xff,0xff,0xff,0xff,
767              0xff,0xff,0xff,0x00,
768              0x00,0x00,0x00,0x00 }},
769 /* /89  */ {{ 0xff,0xff,0xff,0xff,
770              0xff,0xff,0xff,0xff,
771              0xff,0xff,0xff,0x80,
772              0x00,0x00,0x00,0x00 }},
773 /* /90  */ {{ 0xff,0xff,0xff,0xff,
774              0xff,0xff,0xff,0xff,
775              0xff,0xff,0xff,0xc0,
776              0x00,0x00,0x00,0x00 }},
777 /* /91  */ {{ 0xff,0xff,0xff,0xff,
778              0xff,0xff,0xff,0xff,
779              0xff,0xff,0xff,0xe0,
780              0x00,0x00,0x00,0x00 }},
781 /* /92  */ {{ 0xff,0xff,0xff,0xff,
782              0xff,0xff,0xff,0xff,
783              0xff,0xff,0xff,0xf0,
784              0x00,0x00,0x00,0x00 }},
785 /* /93  */ {{ 0xff,0xff,0xff,0xff,
786              0xff,0xff,0xff,0xff,
787              0xff,0xff,0xff,0xf8,
788              0x00,0x00,0x00,0x00 }},
789 /* /94  */ {{ 0xff,0xff,0xff,0xff,
790              0xff,0xff,0xff,0xff,
791              0xff,0xff,0xff,0xfc,
792              0x00,0x00,0x00,0x00 }},
793 /* /95  */ {{ 0xff,0xff,0xff,0xff,
794              0xff,0xff,0xff,0xff,
795              0xff,0xff,0xff,0xfe,
796              0x00,0x00,0x00,0x00 }},
797 /* /96  */ {{ 0xff,0xff,0xff,0xff,
798              0xff,0xff,0xff,0xff,
799              0xff,0xff,0xff,0xff,
800              0x00,0x00,0x00,0x00 }},
801 /* /97  */ {{ 0xff,0xff,0xff,0xff,
802              0xff,0xff,0xff,0xff,
803              0xff,0xff,0xff,0xff,
804              0x80,0x00,0x00,0x00 }},
805 /* /98  */ {{ 0xff,0xff,0xff,0xff,
806              0xff,0xff,0xff,0xff,
807              0xff,0xff,0xff,0xff,
808              0xc0,0x00,0x00,0x00 }},
809 /* /99  */ {{ 0xff,0xff,0xff,0xff,
810              0xff,0xff,0xff,0xff,
811              0xff,0xff,0xff,0xff,
812              0xe0,0x00,0x00,0x00 }},
813 /* /100 */ {{ 0xff,0xff,0xff,0xff,
814              0xff,0xff,0xff,0xff,
815              0xff,0xff,0xff,0xff,
816              0xf0,0x00,0x00,0x00 }},
817 /* /101 */ {{ 0xff,0xff,0xff,0xff,
818              0xff,0xff,0xff,0xff,
819              0xff,0xff,0xff,0xff,
820              0xf8,0x00,0x00,0x00 }},
821 /* /102 */ {{ 0xff,0xff,0xff,0xff,
822              0xff,0xff,0xff,0xff,
823              0xff,0xff,0xff,0xff,
824              0xfc,0x00,0x00,0x00 }},
825 /* /103 */ {{ 0xff,0xff,0xff,0xff,
826              0xff,0xff,0xff,0xff,
827              0xff,0xff,0xff,0xff,
828              0xfe,0x00,0x00,0x00 }},
829 /* /104 */ {{ 0xff,0xff,0xff,0xff,
830              0xff,0xff,0xff,0xff,
831              0xff,0xff,0xff,0xff,
832              0xff,0x00,0x00,0x00 }},
833 /* /105 */ {{ 0xff,0xff,0xff,0xff,
834              0xff,0xff,0xff,0xff,
835              0xff,0xff,0xff,0xff,
836              0xff,0x80,0x00,0x00 }},
837 /* /106 */ {{ 0xff,0xff,0xff,0xff,
838              0xff,0xff,0xff,0xff,
839              0xff,0xff,0xff,0xff,
840              0xff,0xc0,0x00,0x00 }},
841 /* /107 */ {{ 0xff,0xff,0xff,0xff,
842              0xff,0xff,0xff,0xff,
843              0xff,0xff,0xff,0xff,
844              0xff,0xe0,0x00,0x00 }},
845 /* /108 */ {{ 0xff,0xff,0xff,0xff,
846              0xff,0xff,0xff,0xff,
847              0xff,0xff,0xff,0xff,
848              0xff,0xf0,0x00,0x00 }},
849 /* /109 */ {{ 0xff,0xff,0xff,0xff,
850              0xff,0xff,0xff,0xff,
851              0xff,0xff,0xff,0xff,
852              0xff,0xf8,0x00,0x00 }},
853 /* /110 */ {{ 0xff,0xff,0xff,0xff,
854              0xff,0xff,0xff,0xff,
855              0xff,0xff,0xff,0xff,
856              0xff,0xfc,0x00,0x00 }},
857 /* /111 */ {{ 0xff,0xff,0xff,0xff,
858              0xff,0xff,0xff,0xff,
859              0xff,0xff,0xff,0xff,
860              0xff,0xfe,0x00,0x00 }},
861 /* /112 */ {{ 0xff,0xff,0xff,0xff,
862              0xff,0xff,0xff,0xff,
863              0xff,0xff,0xff,0xff,
864              0xff,0xff,0x00,0x00 }},
865 /* /113 */ {{ 0xff,0xff,0xff,0xff,
866              0xff,0xff,0xff,0xff,
867              0xff,0xff,0xff,0xff,
868              0xff,0xff,0x80,0x00 }},
869 /* /114 */ {{ 0xff,0xff,0xff,0xff,
870              0xff,0xff,0xff,0xff,
871              0xff,0xff,0xff,0xff,
872              0xff,0xff,0xc0,0x00 }},
873 /* /115 */ {{ 0xff,0xff,0xff,0xff,
874              0xff,0xff,0xff,0xff,
875              0xff,0xff,0xff,0xff,
876              0xff,0xff,0xe0,0x00 }},
877 /* /116 */ {{ 0xff,0xff,0xff,0xff,
878              0xff,0xff,0xff,0xff,
879              0xff,0xff,0xff,0xff,
880              0xff,0xff,0xf0,0x00 }},
881 /* /117 */ {{ 0xff,0xff,0xff,0xff,
882              0xff,0xff,0xff,0xff,
883              0xff,0xff,0xff,0xff,
884              0xff,0xff,0xf8,0x00 }},
885 /* /118 */ {{ 0xff,0xff,0xff,0xff,
886              0xff,0xff,0xff,0xff,
887              0xff,0xff,0xff,0xff,
888              0xff,0xff,0xfc,0x00 }},
889 /* /119 */ {{ 0xff,0xff,0xff,0xff,
890              0xff,0xff,0xff,0xff,
891              0xff,0xff,0xff,0xff,
892              0xff,0xff,0xfe,0x00 }},
893 /* /120 */ {{ 0xff,0xff,0xff,0xff,
894              0xff,0xff,0xff,0xff,
895              0xff,0xff,0xff,0xff,
896              0xff,0xff,0xff,0x00 }},
897 /* /121 */ {{ 0xff,0xff,0xff,0xff,
898              0xff,0xff,0xff,0xff,
899              0xff,0xff,0xff,0xff,
900              0xff,0xff,0xff,0x80 }},
901 /* /122 */ {{ 0xff,0xff,0xff,0xff,
902              0xff,0xff,0xff,0xff,
903              0xff,0xff,0xff,0xff,
904              0xff,0xff,0xff,0xc0 }},
905 /* /123 */ {{ 0xff,0xff,0xff,0xff,
906              0xff,0xff,0xff,0xff,
907              0xff,0xff,0xff,0xff,
908              0xff,0xff,0xff,0xe0 }},
909 /* /124 */ {{ 0xff,0xff,0xff,0xff,
910              0xff,0xff,0xff,0xff,
911              0xff,0xff,0xff,0xff,
912              0xff,0xff,0xff,0xf0 }},
913 /* /125 */ {{ 0xff,0xff,0xff,0xff,
914              0xff,0xff,0xff,0xff,
915              0xff,0xff,0xff,0xff,
916              0xff,0xff,0xff,0xf8 }},
917 /* /126 */ {{ 0xff,0xff,0xff,0xff,
918              0xff,0xff,0xff,0xff,
919              0xff,0xff,0xff,0xff,
920              0xff,0xff,0xff,0xfc }},
921 /* /127 */ {{ 0xff,0xff,0xff,0xff,
922              0xff,0xff,0xff,0xff,
923              0xff,0xff,0xff,0xff,
924              0xff,0xff,0xff,0xfe }},
925 /* /128 */ {{ 0xff,0xff,0xff,0xff,
926              0xff,0xff,0xff,0xff,
927              0xff,0xff,0xff,0xff,
928              0xff,0xff,0xff,0xff }},
929 }};
930
931 } // folly