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