Move common/network/IPAddress.h and related to folly/
[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   auto asHex = detail::Bytes::toHex(bytes(), 16);
323   uint8_t chunks = asHex.size() / 4;
324   for (int chunk = 1; chunk < chunks; chunk++) {
325     // position changes as new characters are inserted
326     int pos = (chunk*4) + (chunk - 1);
327     asHex.insert(pos, ":");
328   }
329   return asHex;
330 }
331
332 // public
333 uint8_t IPAddressV6::getNthMSByte(size_t byteIndex) const {
334   const auto highestIndex = byteCount() - 1;
335   if (byteIndex > highestIndex) {
336     throw std::invalid_argument(to<string>("Byte index must be <= ",
337         to<string>(highestIndex), " for addresses of type :",
338         detail::familyNameStr(AF_INET6)));
339   }
340   return bytes()[byteIndex];
341 }
342
343 // protected
344 const ByteArray16 IPAddressV6::fetchMask(size_t numBits) {
345   static const uint8_t bits = bitCount();
346   if (numBits > bits) {
347     throw IPAddressFormatException("IPv6 addresses are 128 bits.");
348   }
349   // masks_ is backed by an array so is zero indexed
350   return masks_[numBits];
351 }
352
353 // protected
354 bool IPAddressV6::inBinarySubnet(const std::array<uint8_t, 2> addr,
355                                  size_t numBits) const {
356   const unsigned char* subbytes = mask(numBits).bytes();
357   return (std::memcmp(addr.data(), subbytes, 2) == 0);
358 }
359
360 // static private
361 const std::array<ByteArray16, 129> IPAddressV6::masks_ = {{
362 /* /0   */ {{ 0x00,0x00,0x00,0x00,
363              0x00,0x00,0x00,0x00,
364              0x00,0x00,0x00,0x00,
365              0x00,0x00,0x00,0x00 }},
366 /* /1   */ {{ 0x80,0x00,0x00,0x00,
367              0x00,0x00,0x00,0x00,
368              0x00,0x00,0x00,0x00,
369              0x00,0x00,0x00,0x00 }},
370 /* /2   */ {{ 0xc0,0x00,0x00,0x00,
371              0x00,0x00,0x00,0x00,
372              0x00,0x00,0x00,0x00,
373              0x00,0x00,0x00,0x00 }},
374 /* /3   */ {{ 0xe0,0x00,0x00,0x00,
375              0x00,0x00,0x00,0x00,
376              0x00,0x00,0x00,0x00,
377              0x00,0x00,0x00,0x00 }},
378 /* /4   */ {{ 0xf0,0x00,0x00,0x00,
379              0x00,0x00,0x00,0x00,
380              0x00,0x00,0x00,0x00,
381              0x00,0x00,0x00,0x00 }},
382 /* /5   */ {{ 0xf8,0x00,0x00,0x00,
383              0x00,0x00,0x00,0x00,
384              0x00,0x00,0x00,0x00,
385              0x00,0x00,0x00,0x00 }},
386 /* /6   */ {{ 0xfc,0x00,0x00,0x00,
387              0x00,0x00,0x00,0x00,
388              0x00,0x00,0x00,0x00,
389              0x00,0x00,0x00,0x00 }},
390 /* /7   */ {{ 0xfe,0x00,0x00,0x00,
391              0x00,0x00,0x00,0x00,
392              0x00,0x00,0x00,0x00,
393              0x00,0x00,0x00,0x00 }},
394 /* /8   */ {{ 0xff,0x00,0x00,0x00,
395              0x00,0x00,0x00,0x00,
396              0x00,0x00,0x00,0x00,
397              0x00,0x00,0x00,0x00 }},
398 /* /9   */ {{ 0xff,0x80,0x00,0x00,
399              0x00,0x00,0x00,0x00,
400              0x00,0x00,0x00,0x00,
401              0x00,0x00,0x00,0x00 }},
402 /* /10  */ {{ 0xff,0xc0,0x00,0x00,
403              0x00,0x00,0x00,0x00,
404              0x00,0x00,0x00,0x00,
405              0x00,0x00,0x00,0x00 }},
406 /* /11  */ {{ 0xff,0xe0,0x00,0x00,
407              0x00,0x00,0x00,0x00,
408              0x00,0x00,0x00,0x00,
409              0x00,0x00,0x00,0x00 }},
410 /* /12  */ {{ 0xff,0xf0,0x00,0x00,
411              0x00,0x00,0x00,0x00,
412              0x00,0x00,0x00,0x00,
413              0x00,0x00,0x00,0x00 }},
414 /* /13  */ {{ 0xff,0xf8,0x00,0x00,
415              0x00,0x00,0x00,0x00,
416              0x00,0x00,0x00,0x00,
417              0x00,0x00,0x00,0x00 }},
418 /* /14  */ {{ 0xff,0xfc,0x00,0x00,
419              0x00,0x00,0x00,0x00,
420              0x00,0x00,0x00,0x00,
421              0x00,0x00,0x00,0x00 }},
422 /* /15  */ {{ 0xff,0xfe,0x00,0x00,
423              0x00,0x00,0x00,0x00,
424              0x00,0x00,0x00,0x00,
425              0x00,0x00,0x00,0x00 }},
426 /* /16  */ {{ 0xff,0xff,0x00,0x00,
427              0x00,0x00,0x00,0x00,
428              0x00,0x00,0x00,0x00,
429              0x00,0x00,0x00,0x00 }},
430 /* /17  */ {{ 0xff,0xff,0x80,0x00,
431              0x00,0x00,0x00,0x00,
432              0x00,0x00,0x00,0x00,
433              0x00,0x00,0x00,0x00 }},
434 /* /18  */ {{ 0xff,0xff,0xc0,0x00,
435              0x00,0x00,0x00,0x00,
436              0x00,0x00,0x00,0x00,
437              0x00,0x00,0x00,0x00 }},
438 /* /19  */ {{ 0xff,0xff,0xe0,0x00,
439              0x00,0x00,0x00,0x00,
440              0x00,0x00,0x00,0x00,
441              0x00,0x00,0x00,0x00 }},
442 /* /20  */ {{ 0xff,0xff,0xf0,0x00,
443              0x00,0x00,0x00,0x00,
444              0x00,0x00,0x00,0x00,
445              0x00,0x00,0x00,0x00 }},
446 /* /21  */ {{ 0xff,0xff,0xf8,0x00,
447              0x00,0x00,0x00,0x00,
448              0x00,0x00,0x00,0x00,
449              0x00,0x00,0x00,0x00 }},
450 /* /22  */ {{ 0xff,0xff,0xfc,0x00,
451              0x00,0x00,0x00,0x00,
452              0x00,0x00,0x00,0x00,
453              0x00,0x00,0x00,0x00 }},
454 /* /23  */ {{ 0xff,0xff,0xfe,0x00,
455              0x00,0x00,0x00,0x00,
456              0x00,0x00,0x00,0x00,
457              0x00,0x00,0x00,0x00 }},
458 /* /24  */ {{ 0xff,0xff,0xff,0x00,
459              0x00,0x00,0x00,0x00,
460              0x00,0x00,0x00,0x00,
461              0x00,0x00,0x00,0x00 }},
462 /* /25  */ {{ 0xff,0xff,0xff,0x80,
463              0x00,0x00,0x00,0x00,
464              0x00,0x00,0x00,0x00,
465              0x00,0x00,0x00,0x00 }},
466 /* /26  */ {{ 0xff,0xff,0xff,0xc0,
467              0x00,0x00,0x00,0x00,
468              0x00,0x00,0x00,0x00,
469              0x00,0x00,0x00,0x00 }},
470 /* /27  */ {{ 0xff,0xff,0xff,0xe0,
471              0x00,0x00,0x00,0x00,
472              0x00,0x00,0x00,0x00,
473              0x00,0x00,0x00,0x00 }},
474 /* /28  */ {{ 0xff,0xff,0xff,0xf0,
475              0x00,0x00,0x00,0x00,
476              0x00,0x00,0x00,0x00,
477              0x00,0x00,0x00,0x00 }},
478 /* /29  */ {{ 0xff,0xff,0xff,0xf8,
479              0x00,0x00,0x00,0x00,
480              0x00,0x00,0x00,0x00,
481              0x00,0x00,0x00,0x00 }},
482 /* /30  */ {{ 0xff,0xff,0xff,0xfc,
483              0x00,0x00,0x00,0x00,
484              0x00,0x00,0x00,0x00,
485              0x00,0x00,0x00,0x00 }},
486 /* /31  */ {{ 0xff,0xff,0xff,0xfe,
487              0x00,0x00,0x00,0x00,
488              0x00,0x00,0x00,0x00,
489              0x00,0x00,0x00,0x00 }},
490 /* /32  */ {{ 0xff,0xff,0xff,0xff,
491              0x00,0x00,0x00,0x00,
492              0x00,0x00,0x00,0x00,
493              0x00,0x00,0x00,0x00 }},
494 /* /33  */ {{ 0xff,0xff,0xff,0xff,
495              0x80,0x00,0x00,0x00,
496              0x00,0x00,0x00,0x00,
497              0x00,0x00,0x00,0x00 }},
498 /* /34  */ {{ 0xff,0xff,0xff,0xff,
499              0xc0,0x00,0x00,0x00,
500              0x00,0x00,0x00,0x00,
501              0x00,0x00,0x00,0x00 }},
502 /* /35  */ {{ 0xff,0xff,0xff,0xff,
503              0xe0,0x00,0x00,0x00,
504              0x00,0x00,0x00,0x00,
505              0x00,0x00,0x00,0x00 }},
506 /* /36  */ {{ 0xff,0xff,0xff,0xff,
507              0xf0,0x00,0x00,0x00,
508              0x00,0x00,0x00,0x00,
509              0x00,0x00,0x00,0x00 }},
510 /* /37  */ {{ 0xff,0xff,0xff,0xff,
511              0xf8,0x00,0x00,0x00,
512              0x00,0x00,0x00,0x00,
513              0x00,0x00,0x00,0x00 }},
514 /* /38  */ {{ 0xff,0xff,0xff,0xff,
515              0xfc,0x00,0x00,0x00,
516              0x00,0x00,0x00,0x00,
517              0x00,0x00,0x00,0x00 }},
518 /* /39  */ {{ 0xff,0xff,0xff,0xff,
519              0xfe,0x00,0x00,0x00,
520              0x00,0x00,0x00,0x00,
521              0x00,0x00,0x00,0x00 }},
522 /* /40  */ {{ 0xff,0xff,0xff,0xff,
523              0xff,0x00,0x00,0x00,
524              0x00,0x00,0x00,0x00,
525              0x00,0x00,0x00,0x00 }},
526 /* /41  */ {{ 0xff,0xff,0xff,0xff,
527              0xff,0x80,0x00,0x00,
528              0x00,0x00,0x00,0x00,
529              0x00,0x00,0x00,0x00 }},
530 /* /42  */ {{ 0xff,0xff,0xff,0xff,
531              0xff,0xc0,0x00,0x00,
532              0x00,0x00,0x00,0x00,
533              0x00,0x00,0x00,0x00 }},
534 /* /43  */ {{ 0xff,0xff,0xff,0xff,
535              0xff,0xe0,0x00,0x00,
536              0x00,0x00,0x00,0x00,
537              0x00,0x00,0x00,0x00 }},
538 /* /44  */ {{ 0xff,0xff,0xff,0xff,
539              0xff,0xf0,0x00,0x00,
540              0x00,0x00,0x00,0x00,
541              0x00,0x00,0x00,0x00 }},
542 /* /45  */ {{ 0xff,0xff,0xff,0xff,
543              0xff,0xf8,0x00,0x00,
544              0x00,0x00,0x00,0x00,
545              0x00,0x00,0x00,0x00 }},
546 /* /46  */ {{ 0xff,0xff,0xff,0xff,
547              0xff,0xfc,0x00,0x00,
548              0x00,0x00,0x00,0x00,
549              0x00,0x00,0x00,0x00 }},
550 /* /47  */ {{ 0xff,0xff,0xff,0xff,
551              0xff,0xfe,0x00,0x00,
552              0x00,0x00,0x00,0x00,
553              0x00,0x00,0x00,0x00 }},
554 /* /48  */ {{ 0xff,0xff,0xff,0xff,
555              0xff,0xff,0x00,0x00,
556              0x00,0x00,0x00,0x00,
557              0x00,0x00,0x00,0x00 }},
558 /* /49  */ {{ 0xff,0xff,0xff,0xff,
559              0xff,0xff,0x80,0x00,
560              0x00,0x00,0x00,0x00,
561              0x00,0x00,0x00,0x00 }},
562 /* /50  */ {{ 0xff,0xff,0xff,0xff,
563              0xff,0xff,0xc0,0x00,
564              0x00,0x00,0x00,0x00,
565              0x00,0x00,0x00,0x00 }},
566 /* /51  */ {{ 0xff,0xff,0xff,0xff,
567              0xff,0xff,0xe0,0x00,
568              0x00,0x00,0x00,0x00,
569              0x00,0x00,0x00,0x00 }},
570 /* /52  */ {{ 0xff,0xff,0xff,0xff,
571              0xff,0xff,0xf0,0x00,
572              0x00,0x00,0x00,0x00,
573              0x00,0x00,0x00,0x00 }},
574 /* /53  */ {{ 0xff,0xff,0xff,0xff,
575              0xff,0xff,0xf8,0x00,
576              0x00,0x00,0x00,0x00,
577              0x00,0x00,0x00,0x00 }},
578 /* /54  */ {{ 0xff,0xff,0xff,0xff,
579              0xff,0xff,0xfc,0x00,
580              0x00,0x00,0x00,0x00,
581              0x00,0x00,0x00,0x00 }},
582 /* /55  */ {{ 0xff,0xff,0xff,0xff,
583              0xff,0xff,0xfe,0x00,
584              0x00,0x00,0x00,0x00,
585              0x00,0x00,0x00,0x00 }},
586 /* /56  */ {{ 0xff,0xff,0xff,0xff,
587              0xff,0xff,0xff,0x00,
588              0x00,0x00,0x00,0x00,
589              0x00,0x00,0x00,0x00 }},
590 /* /57  */ {{ 0xff,0xff,0xff,0xff,
591              0xff,0xff,0xff,0x80,
592              0x00,0x00,0x00,0x00,
593              0x00,0x00,0x00,0x00 }},
594 /* /58  */ {{ 0xff,0xff,0xff,0xff,
595              0xff,0xff,0xff,0xc0,
596              0x00,0x00,0x00,0x00,
597              0x00,0x00,0x00,0x00 }},
598 /* /59  */ {{ 0xff,0xff,0xff,0xff,
599              0xff,0xff,0xff,0xe0,
600              0x00,0x00,0x00,0x00,
601              0x00,0x00,0x00,0x00 }},
602 /* /60  */ {{ 0xff,0xff,0xff,0xff,
603              0xff,0xff,0xff,0xf0,
604              0x00,0x00,0x00,0x00,
605              0x00,0x00,0x00,0x00 }},
606 /* /61  */ {{ 0xff,0xff,0xff,0xff,
607              0xff,0xff,0xff,0xf8,
608              0x00,0x00,0x00,0x00,
609              0x00,0x00,0x00,0x00 }},
610 /* /62  */ {{ 0xff,0xff,0xff,0xff,
611              0xff,0xff,0xff,0xfc,
612              0x00,0x00,0x00,0x00,
613              0x00,0x00,0x00,0x00 }},
614 /* /63  */ {{ 0xff,0xff,0xff,0xff,
615              0xff,0xff,0xff,0xfe,
616              0x00,0x00,0x00,0x00,
617              0x00,0x00,0x00,0x00 }},
618 /* /64  */ {{ 0xff,0xff,0xff,0xff,
619              0xff,0xff,0xff,0xff,
620              0x00,0x00,0x00,0x00,
621              0x00,0x00,0x00,0x00 }},
622 /* /65  */ {{ 0xff,0xff,0xff,0xff,
623              0xff,0xff,0xff,0xff,
624              0x80,0x00,0x00,0x00,
625              0x00,0x00,0x00,0x00 }},
626 /* /66  */ {{ 0xff,0xff,0xff,0xff,
627              0xff,0xff,0xff,0xff,
628              0xc0,0x00,0x00,0x00,
629              0x00,0x00,0x00,0x00 }},
630 /* /67  */ {{ 0xff,0xff,0xff,0xff,
631              0xff,0xff,0xff,0xff,
632              0xe0,0x00,0x00,0x00,
633              0x00,0x00,0x00,0x00 }},
634 /* /68  */ {{ 0xff,0xff,0xff,0xff,
635              0xff,0xff,0xff,0xff,
636              0xf0,0x00,0x00,0x00,
637              0x00,0x00,0x00,0x00 }},
638 /* /69  */ {{ 0xff,0xff,0xff,0xff,
639              0xff,0xff,0xff,0xff,
640              0xf8,0x00,0x00,0x00,
641              0x00,0x00,0x00,0x00 }},
642 /* /70  */ {{ 0xff,0xff,0xff,0xff,
643              0xff,0xff,0xff,0xff,
644              0xfc,0x00,0x00,0x00,
645              0x00,0x00,0x00,0x00 }},
646 /* /71  */ {{ 0xff,0xff,0xff,0xff,
647              0xff,0xff,0xff,0xff,
648              0xfe,0x00,0x00,0x00,
649              0x00,0x00,0x00,0x00 }},
650 /* /72  */ {{ 0xff,0xff,0xff,0xff,
651              0xff,0xff,0xff,0xff,
652              0xff,0x00,0x00,0x00,
653              0x00,0x00,0x00,0x00 }},
654 /* /73  */ {{ 0xff,0xff,0xff,0xff,
655              0xff,0xff,0xff,0xff,
656              0xff,0x80,0x00,0x00,
657              0x00,0x00,0x00,0x00 }},
658 /* /74  */ {{ 0xff,0xff,0xff,0xff,
659              0xff,0xff,0xff,0xff,
660              0xff,0xc0,0x00,0x00,
661              0x00,0x00,0x00,0x00 }},
662 /* /75  */ {{ 0xff,0xff,0xff,0xff,
663              0xff,0xff,0xff,0xff,
664              0xff,0xe0,0x00,0x00,
665              0x00,0x00,0x00,0x00 }},
666 /* /76  */ {{ 0xff,0xff,0xff,0xff,
667              0xff,0xff,0xff,0xff,
668              0xff,0xf0,0x00,0x00,
669              0x00,0x00,0x00,0x00 }},
670 /* /77  */ {{ 0xff,0xff,0xff,0xff,
671              0xff,0xff,0xff,0xff,
672              0xff,0xf8,0x00,0x00,
673              0x00,0x00,0x00,0x00 }},
674 /* /78  */ {{ 0xff,0xff,0xff,0xff,
675              0xff,0xff,0xff,0xff,
676              0xff,0xfc,0x00,0x00,
677              0x00,0x00,0x00,0x00 }},
678 /* /79  */ {{ 0xff,0xff,0xff,0xff,
679              0xff,0xff,0xff,0xff,
680              0xff,0xfe,0x00,0x00,
681              0x00,0x00,0x00,0x00 }},
682 /* /80  */ {{ 0xff,0xff,0xff,0xff,
683              0xff,0xff,0xff,0xff,
684              0xff,0xff,0x00,0x00,
685              0x00,0x00,0x00,0x00 }},
686 /* /81  */ {{ 0xff,0xff,0xff,0xff,
687              0xff,0xff,0xff,0xff,
688              0xff,0xff,0x80,0x00,
689              0x00,0x00,0x00,0x00 }},
690 /* /82  */ {{ 0xff,0xff,0xff,0xff,
691              0xff,0xff,0xff,0xff,
692              0xff,0xff,0xc0,0x00,
693              0x00,0x00,0x00,0x00 }},
694 /* /83  */ {{ 0xff,0xff,0xff,0xff,
695              0xff,0xff,0xff,0xff,
696              0xff,0xff,0xe0,0x00,
697              0x00,0x00,0x00,0x00 }},
698 /* /84  */ {{ 0xff,0xff,0xff,0xff,
699              0xff,0xff,0xff,0xff,
700              0xff,0xff,0xf0,0x00,
701              0x00,0x00,0x00,0x00 }},
702 /* /85  */ {{ 0xff,0xff,0xff,0xff,
703              0xff,0xff,0xff,0xff,
704              0xff,0xff,0xf8,0x00,
705              0x00,0x00,0x00,0x00 }},
706 /* /86  */ {{ 0xff,0xff,0xff,0xff,
707              0xff,0xff,0xff,0xff,
708              0xff,0xff,0xfc,0x00,
709              0x00,0x00,0x00,0x00 }},
710 /* /87  */ {{ 0xff,0xff,0xff,0xff,
711              0xff,0xff,0xff,0xff,
712              0xff,0xff,0xfe,0x00,
713              0x00,0x00,0x00,0x00 }},
714 /* /88  */ {{ 0xff,0xff,0xff,0xff,
715              0xff,0xff,0xff,0xff,
716              0xff,0xff,0xff,0x00,
717              0x00,0x00,0x00,0x00 }},
718 /* /89  */ {{ 0xff,0xff,0xff,0xff,
719              0xff,0xff,0xff,0xff,
720              0xff,0xff,0xff,0x80,
721              0x00,0x00,0x00,0x00 }},
722 /* /90  */ {{ 0xff,0xff,0xff,0xff,
723              0xff,0xff,0xff,0xff,
724              0xff,0xff,0xff,0xc0,
725              0x00,0x00,0x00,0x00 }},
726 /* /91  */ {{ 0xff,0xff,0xff,0xff,
727              0xff,0xff,0xff,0xff,
728              0xff,0xff,0xff,0xe0,
729              0x00,0x00,0x00,0x00 }},
730 /* /92  */ {{ 0xff,0xff,0xff,0xff,
731              0xff,0xff,0xff,0xff,
732              0xff,0xff,0xff,0xf0,
733              0x00,0x00,0x00,0x00 }},
734 /* /93  */ {{ 0xff,0xff,0xff,0xff,
735              0xff,0xff,0xff,0xff,
736              0xff,0xff,0xff,0xf8,
737              0x00,0x00,0x00,0x00 }},
738 /* /94  */ {{ 0xff,0xff,0xff,0xff,
739              0xff,0xff,0xff,0xff,
740              0xff,0xff,0xff,0xfc,
741              0x00,0x00,0x00,0x00 }},
742 /* /95  */ {{ 0xff,0xff,0xff,0xff,
743              0xff,0xff,0xff,0xff,
744              0xff,0xff,0xff,0xfe,
745              0x00,0x00,0x00,0x00 }},
746 /* /96  */ {{ 0xff,0xff,0xff,0xff,
747              0xff,0xff,0xff,0xff,
748              0xff,0xff,0xff,0xff,
749              0x00,0x00,0x00,0x00 }},
750 /* /97  */ {{ 0xff,0xff,0xff,0xff,
751              0xff,0xff,0xff,0xff,
752              0xff,0xff,0xff,0xff,
753              0x80,0x00,0x00,0x00 }},
754 /* /98  */ {{ 0xff,0xff,0xff,0xff,
755              0xff,0xff,0xff,0xff,
756              0xff,0xff,0xff,0xff,
757              0xc0,0x00,0x00,0x00 }},
758 /* /99  */ {{ 0xff,0xff,0xff,0xff,
759              0xff,0xff,0xff,0xff,
760              0xff,0xff,0xff,0xff,
761              0xe0,0x00,0x00,0x00 }},
762 /* /100 */ {{ 0xff,0xff,0xff,0xff,
763              0xff,0xff,0xff,0xff,
764              0xff,0xff,0xff,0xff,
765              0xf0,0x00,0x00,0x00 }},
766 /* /101 */ {{ 0xff,0xff,0xff,0xff,
767              0xff,0xff,0xff,0xff,
768              0xff,0xff,0xff,0xff,
769              0xf8,0x00,0x00,0x00 }},
770 /* /102 */ {{ 0xff,0xff,0xff,0xff,
771              0xff,0xff,0xff,0xff,
772              0xff,0xff,0xff,0xff,
773              0xfc,0x00,0x00,0x00 }},
774 /* /103 */ {{ 0xff,0xff,0xff,0xff,
775              0xff,0xff,0xff,0xff,
776              0xff,0xff,0xff,0xff,
777              0xfe,0x00,0x00,0x00 }},
778 /* /104 */ {{ 0xff,0xff,0xff,0xff,
779              0xff,0xff,0xff,0xff,
780              0xff,0xff,0xff,0xff,
781              0xff,0x00,0x00,0x00 }},
782 /* /105 */ {{ 0xff,0xff,0xff,0xff,
783              0xff,0xff,0xff,0xff,
784              0xff,0xff,0xff,0xff,
785              0xff,0x80,0x00,0x00 }},
786 /* /106 */ {{ 0xff,0xff,0xff,0xff,
787              0xff,0xff,0xff,0xff,
788              0xff,0xff,0xff,0xff,
789              0xff,0xc0,0x00,0x00 }},
790 /* /107 */ {{ 0xff,0xff,0xff,0xff,
791              0xff,0xff,0xff,0xff,
792              0xff,0xff,0xff,0xff,
793              0xff,0xe0,0x00,0x00 }},
794 /* /108 */ {{ 0xff,0xff,0xff,0xff,
795              0xff,0xff,0xff,0xff,
796              0xff,0xff,0xff,0xff,
797              0xff,0xf0,0x00,0x00 }},
798 /* /109 */ {{ 0xff,0xff,0xff,0xff,
799              0xff,0xff,0xff,0xff,
800              0xff,0xff,0xff,0xff,
801              0xff,0xf8,0x00,0x00 }},
802 /* /110 */ {{ 0xff,0xff,0xff,0xff,
803              0xff,0xff,0xff,0xff,
804              0xff,0xff,0xff,0xff,
805              0xff,0xfc,0x00,0x00 }},
806 /* /111 */ {{ 0xff,0xff,0xff,0xff,
807              0xff,0xff,0xff,0xff,
808              0xff,0xff,0xff,0xff,
809              0xff,0xfe,0x00,0x00 }},
810 /* /112 */ {{ 0xff,0xff,0xff,0xff,
811              0xff,0xff,0xff,0xff,
812              0xff,0xff,0xff,0xff,
813              0xff,0xff,0x00,0x00 }},
814 /* /113 */ {{ 0xff,0xff,0xff,0xff,
815              0xff,0xff,0xff,0xff,
816              0xff,0xff,0xff,0xff,
817              0xff,0xff,0x80,0x00 }},
818 /* /114 */ {{ 0xff,0xff,0xff,0xff,
819              0xff,0xff,0xff,0xff,
820              0xff,0xff,0xff,0xff,
821              0xff,0xff,0xc0,0x00 }},
822 /* /115 */ {{ 0xff,0xff,0xff,0xff,
823              0xff,0xff,0xff,0xff,
824              0xff,0xff,0xff,0xff,
825              0xff,0xff,0xe0,0x00 }},
826 /* /116 */ {{ 0xff,0xff,0xff,0xff,
827              0xff,0xff,0xff,0xff,
828              0xff,0xff,0xff,0xff,
829              0xff,0xff,0xf0,0x00 }},
830 /* /117 */ {{ 0xff,0xff,0xff,0xff,
831              0xff,0xff,0xff,0xff,
832              0xff,0xff,0xff,0xff,
833              0xff,0xff,0xf8,0x00 }},
834 /* /118 */ {{ 0xff,0xff,0xff,0xff,
835              0xff,0xff,0xff,0xff,
836              0xff,0xff,0xff,0xff,
837              0xff,0xff,0xfc,0x00 }},
838 /* /119 */ {{ 0xff,0xff,0xff,0xff,
839              0xff,0xff,0xff,0xff,
840              0xff,0xff,0xff,0xff,
841              0xff,0xff,0xfe,0x00 }},
842 /* /120 */ {{ 0xff,0xff,0xff,0xff,
843              0xff,0xff,0xff,0xff,
844              0xff,0xff,0xff,0xff,
845              0xff,0xff,0xff,0x00 }},
846 /* /121 */ {{ 0xff,0xff,0xff,0xff,
847              0xff,0xff,0xff,0xff,
848              0xff,0xff,0xff,0xff,
849              0xff,0xff,0xff,0x80 }},
850 /* /122 */ {{ 0xff,0xff,0xff,0xff,
851              0xff,0xff,0xff,0xff,
852              0xff,0xff,0xff,0xff,
853              0xff,0xff,0xff,0xc0 }},
854 /* /123 */ {{ 0xff,0xff,0xff,0xff,
855              0xff,0xff,0xff,0xff,
856              0xff,0xff,0xff,0xff,
857              0xff,0xff,0xff,0xe0 }},
858 /* /124 */ {{ 0xff,0xff,0xff,0xff,
859              0xff,0xff,0xff,0xff,
860              0xff,0xff,0xff,0xff,
861              0xff,0xff,0xff,0xf0 }},
862 /* /125 */ {{ 0xff,0xff,0xff,0xff,
863              0xff,0xff,0xff,0xff,
864              0xff,0xff,0xff,0xff,
865              0xff,0xff,0xff,0xf8 }},
866 /* /126 */ {{ 0xff,0xff,0xff,0xff,
867              0xff,0xff,0xff,0xff,
868              0xff,0xff,0xff,0xff,
869              0xff,0xff,0xff,0xfc }},
870 /* /127 */ {{ 0xff,0xff,0xff,0xff,
871              0xff,0xff,0xff,0xff,
872              0xff,0xff,0xff,0xff,
873              0xff,0xff,0xff,0xfe }},
874 /* /128 */ {{ 0xff,0xff,0xff,0xff,
875              0xff,0xff,0xff,0xff,
876              0xff,0xff,0xff,0xff,
877              0xff,0xff,0xff,0xff }},
878 }};
879
880 } // folly