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