1 /* $NetBSD: geoip.c,v 1.1.1.3 2014/12/10 03:34:24 christos Exp $ */
4 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
25 #include <named/log.h>
26 #include <named/geoip.h>
28 #include <dns/geoip.h>
31 static dns_geoip_databases_t geoip_table
= {
32 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
36 init_geoip_db(GeoIP
**dbp
, GeoIPDBTypes edition
, GeoIPDBTypes fallback
,
37 GeoIPOptions method
, const char *name
)
51 if (! GeoIP_db_avail(edition
)) {
52 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
53 NS_LOGMODULE_SERVER
, ISC_LOG_INFO
,
54 "GeoIP %s (type %d) DB not available", name
, edition
);
58 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
59 NS_LOGMODULE_SERVER
, ISC_LOG_INFO
,
60 "initializing GeoIP %s (type %d) DB", name
, edition
);
62 db
= GeoIP_open_type(edition
, method
);
64 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
65 NS_LOGMODULE_SERVER
, ISC_LOG_ERROR
,
66 "failed to initialize GeoIP %s (type %d) DB%s",
67 name
, edition
, fallback
== 0
68 ? "geoip matches using this database will fail" : "");
72 info
= GeoIP_database_info(db
);
74 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
75 NS_LOGMODULE_SERVER
, ISC_LOG_INFO
,
82 init_geoip_db(dbp
, fallback
, 0, method
, name
);
85 #endif /* HAVE_GEOIP */
93 if (ns_g_geoip
== NULL
)
94 ns_g_geoip
= &geoip_table
;
99 ns_geoip_load(char *dir
) {
109 method
= GEOIP_STANDARD
;
111 method
= GEOIP_MMAP_CACHE
;
116 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
117 NS_LOGMODULE_SERVER
, ISC_LOG_INFO
,
118 "using \"%s\" as GeoIP directory", dir
);
119 GeoIP_setup_custom_directory(dir
);
122 init_geoip_db(&ns_g_geoip
->country_v4
, GEOIP_COUNTRY_EDITION
, 0,
123 method
, "Country (IPv4)");
125 init_geoip_db(&ns_g_geoip
->country_v6
, GEOIP_COUNTRY_EDITION_V6
, 0,
126 method
, "Country (IPv6)");
129 init_geoip_db(&ns_g_geoip
->city_v4
, GEOIP_CITY_EDITION_REV1
,
130 GEOIP_CITY_EDITION_REV0
, method
, "City (IPv4)");
131 #if defined(HAVE_GEOIP_V6) && defined(HAVE_GEOIP_CITY_V6)
132 init_geoip_db(&ns_g_geoip
->city_v6
, GEOIP_CITY_EDITION_REV1_V6
,
133 GEOIP_CITY_EDITION_REV0_V6
, method
, "City (IPv6)");
136 init_geoip_db(&ns_g_geoip
->region
, GEOIP_REGION_EDITION_REV1
,
137 GEOIP_REGION_EDITION_REV0
, method
, "Region");
139 init_geoip_db(&ns_g_geoip
->isp
, GEOIP_ISP_EDITION
, 0,
141 init_geoip_db(&ns_g_geoip
->org
, GEOIP_ORG_EDITION
, 0,
143 init_geoip_db(&ns_g_geoip
->as
, GEOIP_ASNUM_EDITION
, 0,
145 init_geoip_db(&ns_g_geoip
->domain
, GEOIP_DOMAIN_EDITION
, 0,
147 init_geoip_db(&ns_g_geoip
->netspeed
, GEOIP_NETSPEED_EDITION
, 0,
149 #endif /* HAVE_GEOIP */