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