/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8                                :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2022 Justine Alexandra Roberts Tunney                              â
â                                                                              â
â Permission to use, copy, modify, and/or distribute this software for         â
â any purpose with or without fee is hereby granted, provided that the         â
â above copyright notice and this permission notice appear in all copies.      â
â                                                                              â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             â
â PERFORMANCE OF THIS SOFTWARE.                                                â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "net/http/ip.h"

/**
 * Returns true if `x` is Cloudflare IPv4 address.
 *
 * @see https://www.cloudflare.com/ips/ (April 8, 2021)
 */
bool IsCloudflareIp(uint32_t x) {
  return (x & 0xfffffc00) == 0x6715f400 ||  // 103.21.244.0/22
         (x & 0xfffffc00) == 0x6716c800 ||  // 103.22.200.0/22
         (x & 0xfffffc00) == 0x671f0400 ||  // 103.31.4.0/22
         (x & 0xfff80000) == 0x68100000 ||  // 104.16.0.0/13
         (x & 0xfffc0000) == 0x68180000 ||  // 104.24.0.0/14
         (x & 0xffffc000) == 0x6ca2c000 ||  // 108.162.192.0/18
         (x & 0xfffffc00) == 0x83004800 ||  // 131.0.72.0/22
         (x & 0xffffc000) == 0x8d654000 ||  // 141.101.64.0/18
         (x & 0xfffe0000) == 0xa29e0000 ||  // 162.158.0.0/15
         (x & 0xfff80000) == 0xac400000 ||  // 172.64.0.0/13
         (x & 0xfffff000) == 0xadf53000 ||  // 173.245.48.0/20
         (x & 0xfffff000) == 0xbc726000 ||  // 188.114.96.0/20
         (x & 0xfffff000) == 0xbe5df000 ||  // 190.93.240.0/20
         (x & 0xfffffc00) == 0xc5eaf000 ||  // 197.234.240.0/22
         (x & 0xffff8000) == 0xc6298000;    // 198.41.128.0/17
}
