1 /*
2  * Project    : ipv6calc
3  * File       : databases/lib/libipv6calc_db_wrapper_GeoIP2.h
4  * Version    : $Id: b2e984338cbead417a37d7c9c218274ce02fd23c $
5  * Copyright  : 2019-2021 by Peter Bieringer <pb (at) bieringer.de>
6  *
7  * Information:
8  *  Header file for libipv6calc_db_wrapper_GeoIP2.c
9  */
10 
11 #include "ipv6calctypes.h"
12 
13 #ifndef _libipv6calc_db_wrapper_GeoIP2_h
14 
15 #define _libipv6calc_db_wrapper_GeoIP2_h 1
16 
17 // database types
18 #define GeoIP2_DB_COUNTRY_LITE				1
19 #define GeoIP2_DB_CITY_LITE				2
20 #define GeoIP2_DB_ASN					3
21 #define GeoIP2_DB_COUNTRY				4	// commercial
22 #define GeoIP2_DB_CITY					5	// commercial
23 #define GeoIP2_DB_ISP					6	// commercial
24 #define GeoIP2_DB_MAX					GeoIP2_DB_ISP
25 
26 #define IPV6CALC_DB_GEOIP2_INTERNAL_FREE		0x00000001
27 #define IPV6CALC_DB_GEOIP2_INTERNAL_COMM		0x00000002
28 
29 /*@unused@*/ static const db_file_desc2 libipv6calc_db_wrapper_GeoIP2_db_file_desc[] = {
30 	// country (lite)
31 	{ GeoIP2_DB_COUNTRY_LITE
32 		, "GeoLite2-Country.mmdb"
33 		, "IPv4/v6 CountryCode (FREE)"
34 		, IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_IP_TO_GEONAMEID | IPV6CALC_DB_IP_TO_COUNTRY | IPV6CALC_DB_GEOIP
35 		, IPV6CALC_DB_GEOIP2_INTERNAL_FREE
36 	},
37 
38 	// city (lite)
39 	{ GeoIP2_DB_CITY_LITE
40 		, "GeoLite2-City.mmdb"
41 		, "IPv4/v6 City (FREE)"
42 		, IPV6CALC_DB_IP_TO_CITY | IPV6CALC_DB_IP_TO_REGION | IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_GEOIP | IPV6CALC_DB_IP_TO_GEONAMEID
43 		, IPV6CALC_DB_GEOIP2_INTERNAL_FREE
44 	},
45 
46 	// ASN (lite)
47 	{ GeoIP2_DB_ASN
48 		, "GeoLite2-ASN.mmdb"
49 		, "IPv4/v6 ASN (FREE)"
50 		, IPV6CALC_DB_IP_TO_AS | IPV6CALC_DB_GEOIP
51 		, IPV6CALC_DB_GEOIP2_INTERNAL_FREE
52 	},
53 
54 	// country
55 	{ GeoIP2_DB_COUNTRY
56 		, "Geo2-Country.mmdb"
57 		, "IPv4/v6 CountryCode (COMM)"
58 		, IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_IP_TO_GEONAMEID | IPV6CALC_DB_IP_TO_COUNTRY | IPV6CALC_DB_GEOIP
59 		, IPV6CALC_DB_GEOIP2_INTERNAL_COMM
60 	},
61 
62 	// city
63 	{ GeoIP2_DB_CITY
64 		, "Geo2-City.mmdb"
65 		, "IPv4/v6 City (COMM)"
66 		, IPV6CALC_DB_IP_TO_CITY | IPV6CALC_DB_IP_TO_REGION | IPV6CALC_DB_IP_TO_CC | IPV6CALC_DB_GEOIP | IPV6CALC_DB_IP_TO_GEONAMEID
67 		, IPV6CALC_DB_GEOIP2_INTERNAL_COMM
68 	},
69 
70 	// ISP
71 	{ GeoIP2_DB_ISP
72 		, "Geo2-ISP.mmdb"
73 		, "IPv4/v6 ISP (COMM)"
74 		, IPV6CALC_DB_IP_TO_AS | IPV6CALC_DB_GEOIP
75 		, IPV6CALC_DB_GEOIP2_INTERNAL_COMM
76 	},
77 };
78 
79 
80 // features
81 extern uint32_t wrapper_features_GeoIP2;
82 
83 #endif
84 
85 extern int         libipv6calc_db_wrapper_GeoIP2_wrapper_init(void);
86 extern int         libipv6calc_db_wrapper_GeoIP2_wrapper_cleanup(void);
87 extern void        libipv6calc_db_wrapper_GeoIP2_wrapper_info(char* string, const size_t size);
88 extern void        libipv6calc_db_wrapper_GeoIP2_wrapper_print_db_info(const int level_verbose, const char *prefix_string);
89 extern char       *libipv6calc_db_wrapper_GeoIP2_wrapper_db_info_used(void);
90 extern int         libipv6calc_db_wrapper_GeoIP2_has_features(const uint32_t features);
91 
92 #ifdef SUPPORT_GEOIP2
93 #include "libipv6calc_db_wrapper_MMDB.h"
94 
95 extern int         libipv6calc_db_wrapper_GeoIP2_wrapper_country_code_by_addr(const ipv6calc_ipaddr *ipaddrp, char *country, const size_t country_len);
96 extern uint32_t    libipv6calc_db_wrapper_GeoIP2_wrapper_asn_by_addr(const ipv6calc_ipaddr *ipaddrp);
97 extern uint32_t    libipv6calc_db_wrapper_GeoIP2_wrapper_GeonameID_by_addr(const ipv6calc_ipaddr *ipaddrp, int *source_ptr);
98 extern int         libipv6calc_db_wrapper_GeoIP2_all_by_addr(const ipv6calc_ipaddr *ipaddrp, libipv6calc_db_wrapper_geolocation_record *recordp);
99 
100 extern char geoip2_db_dir[PATH_MAX];
101 extern int  geoip2_db_comm_to_free_switch_min_delta_months;
102 extern int  geoip2_db_only_type;
103 
104 extern int         libipv6calc_db_wrapper_GeoIP2_db_avail(const unsigned int type);
105 extern int         libipv6calc_db_wrapper_GeoIP2_open_type(const unsigned int type_flag);
106 
107 extern const char *libipv6calc_db_wrapper_GeoIP2_dbdescription(const unsigned int type);
108 extern char       *libipv6calc_db_wrapper_GeoIP2_database_info(const unsigned int type);
109 #endif
110