geoip.c revision 1b05d22789fd9a17aca4f459639bc2b6848c3160
850a31f07e132ecb33dd7d0e5d6fc2fd3eae30f9Mark Andrews * Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
850a31f07e132ecb33dd7d0e5d6fc2fd3eae30f9Mark Andrews * copyright notice and this permission notice appear in all copies.
850a31f07e132ecb33dd7d0e5d6fc2fd3eae30f9Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
6c52944ef2281095d1c317a45ea013b8f3cfa135Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
6c52944ef2281095d1c317a45ea013b8f3cfa135Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
6c52944ef2281095d1c317a45ea013b8f3cfa135Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
#include <config.h>
#include <math.h>
#ifndef WIN32
#ifndef _WINSOCKAPI_
#include <winsock2.h>
#ifdef HAVE_GEOIP
#include <GeoIP.h>
#include <GeoIPCity.h>
typedef struct geoip_state {
unsigned int family;
const char *text;
char *name;
int id;
#ifdef ISC_PLATFORM_USETHREADS
key_mutex_init(void) {
static isc_result_t
state_key_init(void) {
return (result);
if (!state_key_initialized) {
if (!state_key_initialized) {
int ret;
goto unlock;
if (ret == 0)
return (result);
static isc_result_t
#ifdef ISC_PLATFORM_USETHREADS
return (result);
sizeof(geoip_state_t));
return (ISC_R_NOMEMORY);
return (result);
return (ISC_R_SUCCESS);
static geoip_state_t *
#ifdef ISC_PLATFORM_USETHREADS
return (NULL);
return (NULL);
return (state);
return (NULL);
unsigned int family,
#ifndef HAVE_GEOIP_V6
return (NULL);
switch (subtype) {
case dns_geoip_country_code:
#ifdef HAVE_GEOIP_V6
case dns_geoip_country_code3:
#ifdef HAVE_GEOIP_V6
case dns_geoip_country_name:
#ifdef HAVE_GEOIP_V6
INSIST(0);
return (NULL);
return (text);
char *deconst;
switch (subtype) {
case dns_geoip_city_region:
switch (subtype) {
case dns_geoip_city_region:
return (deconst);
case dns_geoip_city_name:
return (deconst);
INSIST(0);
static isc_boolean_t
switch (subtype) {
case dns_geoip_city_region:
case dns_geoip_city_name:
case dns_geoip_city_metrocode:
case dns_geoip_city_areacode:
return (ISC_TRUE);
return (ISC_FALSE);
static GeoIPRecord *
#ifndef HAVE_GEOIP_V6
return (NULL);
#ifdef HAVE_GEOIP_V6
return (NULL);
return (record);
char *deconst;
switch (subtype) {
case dns_geoip_region_code:
case dns_geoip_region_name:
return (deconst);
INSIST(0);
static isc_boolean_t
switch (subtype) {
case dns_geoip_region_code:
return (ISC_TRUE);
return (ISC_FALSE);
static GeoIPRegion *
return (NULL);
return (region);
return (NULL);
return (name);
if (!found) {
if (id == 0)
return (id);
#ifdef HAVE_GEOIP
static dns_geoip_subtype_t
switch (subtype) {
case dns_geoip_countrycode:
case dns_geoip_countrycode3:
case dns_geoip_countryname:
case dns_geoip_region:
case dns_geoip_regionname:
return (ret);
#ifndef HAVE_GEOIP
return (ISC_FALSE);
const char *cs;
#ifdef HAVE_GEOIP_V6
switch (family) {
case AF_INET:
case AF_INET6:
#ifdef HAVE_GEOIP_V6
return (ISC_FALSE);
return (ISC_FALSE);
switch (subtype) {
case dns_geoip_country_code:
goto getcountry;
case dns_geoip_country_code3:
goto getcountry;
case dns_geoip_country_name:
return (ISC_FALSE);
return (ISC_TRUE);
case dns_geoip_city_region:
case dns_geoip_city_name:
return (ISC_FALSE);
return (ISC_TRUE);
case dns_geoip_city_metrocode:
return (ISC_FALSE);
return (ISC_TRUE);
case dns_geoip_city_areacode:
return (ISC_FALSE);
return (ISC_TRUE);
case dns_geoip_region_code:
case dns_geoip_region_name:
case dns_geoip_region:
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
case dns_geoip_isp_name:
goto getname;
case dns_geoip_org_name:
goto getname;
case dns_geoip_as_asnum:
goto getname;
case dns_geoip_domain_name:
return (ISC_FALSE);
return (ISC_FALSE);
if (s != NULL) {
size_t l;
return (ISC_TRUE);
return (ISC_TRUE);
case dns_geoip_netspeed_id:
return (ISC_FALSE);
return (ISC_TRUE);
case dns_geoip_countrycode:
case dns_geoip_countrycode3:
case dns_geoip_countryname:
case dns_geoip_regionname:
INSIST(0);
return (ISC_FALSE);
dns_geoip_shutdown(void) {
#ifdef HAVE_GEOIP
#ifdef ISC_PLATFORM_USETHREADS