1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * SPDX-License-Identifier: MPL-2.0 5 * 6 * This Source Code Form is subject to the terms of the Mozilla Public 7 * License, v. 2.0. If a copy of the MPL was not distributed with this 8 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 9 * 10 * See the COPYRIGHT file distributed with this work for additional 11 * information regarding copyright ownership. 12 */ 13 14 #ifndef DNS_GEOIP_H 15 #define DNS_GEOIP_H 1 16 17 /***** 18 ***** Module Info 19 *****/ 20 21 /*! \file dns/geoip.h 22 * \brief 23 * GeoIP/GeoIP2 data types and function prototypes. 24 */ 25 26 #if defined(HAVE_GEOIP2) 27 28 /*** 29 *** Imports 30 ***/ 31 32 #include <stdbool.h> 33 34 #include <isc/lang.h> 35 #include <isc/magic.h> 36 #include <isc/netaddr.h> 37 #include <isc/refcount.h> 38 39 #include <dns/iptable.h> 40 #include <dns/name.h> 41 #include <dns/types.h> 42 43 /*** 44 *** Types 45 ***/ 46 47 typedef enum { 48 dns_geoip_countrycode, 49 dns_geoip_countrycode3, 50 dns_geoip_countryname, 51 dns_geoip_continentcode, 52 dns_geoip_continent, 53 dns_geoip_region, 54 dns_geoip_regionname, 55 dns_geoip_country_code, 56 dns_geoip_country_code3, 57 dns_geoip_country_name, 58 dns_geoip_country_continentcode, 59 dns_geoip_country_continent, 60 dns_geoip_region_countrycode, 61 dns_geoip_region_code, 62 dns_geoip_region_name, 63 dns_geoip_city_countrycode, 64 dns_geoip_city_countrycode3, 65 dns_geoip_city_countryname, 66 dns_geoip_city_region, 67 dns_geoip_city_regionname, 68 dns_geoip_city_name, 69 dns_geoip_city_postalcode, 70 dns_geoip_city_metrocode, 71 dns_geoip_city_areacode, 72 dns_geoip_city_continentcode, 73 dns_geoip_city_continent, 74 dns_geoip_city_timezonecode, 75 dns_geoip_isp_name, 76 dns_geoip_org_name, 77 dns_geoip_as_asnum, 78 dns_geoip_domain_name, 79 dns_geoip_netspeed_id 80 } dns_geoip_subtype_t; 81 82 typedef struct dns_geoip_elem { 83 dns_geoip_subtype_t subtype; 84 void *db; 85 union { 86 char as_string[256]; 87 int as_int; 88 }; 89 } dns_geoip_elem_t; 90 91 struct dns_geoip_databases { 92 void *country; /* GeoIP2-Country or GeoLite2-Country */ 93 void *city; /* GeoIP2-CIty or GeoLite2-City */ 94 void *domain; /* GeoIP2-Domain */ 95 void *isp; /* GeoIP2-ISP */ 96 void *as; /* GeoIP2-ASN or GeoLite2-ASN */ 97 }; 98 99 /*** 100 *** Functions 101 ***/ 102 103 ISC_LANG_BEGINDECLS 104 105 bool 106 dns_geoip_match(const isc_netaddr_t *reqaddr, 107 const dns_geoip_databases_t *geoip, 108 const dns_geoip_elem_t *elt); 109 110 ISC_LANG_ENDDECLS 111 112 #endif /* HAVE_GEOIP2 */ 113 114 #endif /* DNS_GEOIP_H */ 115