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