tor  0.4.2.0-alpha-dev
Data Structures | Typedefs | Functions
geoip.h File Reference
#include "orconfig.h"
#include "lib/net/nettypes.h"
#include "lib/testsupport/testsupport.h"
#include "lib/net/inaddr_st.h"
#include "lib/geoip/country.h"

Go to the source code of this file.

Data Structures

struct  geoip_country_t
 

Typedefs

typedef struct geoip_country_t geoip_country_t
 

Functions

int geoip_get_country_by_ipv4 (uint32_t ipaddr)
 
int geoip_get_country_by_ipv6 (const struct in6_addr *addr)
 
const struct smartlist_tgeoip_get_countries (void)
 
int geoip_load_file (sa_family_t family, const char *filename, int severity)
 
 MOCK_DECL (int, geoip_get_country_by_addr,(const struct tor_addr_t *addr))
 
 MOCK_DECL (int, geoip_get_n_countries,(void))
 
const char * geoip_get_country_name (country_t num)
 
 MOCK_DECL (int, geoip_is_loaded,(sa_family_t family))
 
const char * geoip_db_digest (sa_family_t family)
 
 MOCK_DECL (country_t, geoip_get_country,(const char *countrycode))
 
void geoip_free_all (void)
 

Detailed Description

Header file for geoip.c.

Definition in file geoip.h.

Typedef Documentation

◆ geoip_country_t

A per-country GeoIP record.

Function Documentation

◆ geoip_db_digest()

const char* geoip_db_digest ( sa_family_t  family)

Return the hex-encoded SHA1 digest of the loaded GeoIP file. The result does not need to be deallocated, but will be overwritten by the next call of hex_str().

Definition at line 467 of file geoip.c.

References DIGEST_LEN, geoip_digest, hex_str(), and tor_assert().

◆ geoip_free_all()

void geoip_free_all ( void  )

Release all storage held in this file.

Definition at line 504 of file geoip.c.

References clear_geoip_db(), and geoip_digest.

◆ geoip_get_countries()

const struct smartlist_t* geoip_get_countries ( void  )

Return a list of geoip_country_t for all known countries.

Definition at line 83 of file geoip.c.

References geoip_countries, and init_geoip_countries().

Referenced by geoip_get_request_history().

◆ geoip_get_country_by_ipv4()

int geoip_get_country_by_ipv4 ( uint32_t  ipaddr)

Given an IP address in host order, return a number representing the country to which that address belongs, -1 for "No geoip information available", or 0 for the 'unknown country'. The return value will always be less than geoip_get_n_countries(). To decode it, call geoip_get_country_name().

Definition at line 385 of file geoip.c.

References geoip_ipv4_entry_t::country, geoip_ipv4_compare_key_to_entry_(), geoip_ipv4_entries, and smartlist_bsearch().

Referenced by MOCK_IMPL().

◆ geoip_get_country_by_ipv6()

int geoip_get_country_by_ipv6 ( const struct in6_addr addr)

Given an IPv6 address, return a number representing the country to which that address belongs, -1 for "No geoip information available", or 0 for the 'unknown country'. The return value will always be less than geoip_get_n_countries(). To decode it, call geoip_get_country_name().

Definition at line 401 of file geoip.c.

Referenced by MOCK_IMPL().

◆ geoip_get_country_name()

const char* geoip_get_country_name ( country_t  num)

Return the two-letter country code associated with the number num, or "??" for an unknown value.

Definition at line 441 of file geoip.c.

References geoip_countries.

◆ geoip_load_file()

int geoip_load_file ( sa_family_t  family,
const char *  filename,
int  severity 
)

Clear appropriate GeoIP database, based on family, and reload it from the file filename. Return 0 on success, -1 on failure.

Recognized line formats for IPv4 are: INTIPLOW,INTIPHIGH,CC and "INTIPLOW","INTIPHIGH","CC","CC3","COUNTRY NAME" where INTIPLOW and INTIPHIGH are IPv4 addresses encoded as 4-byte unsigned integers, and CC is a country code.

Recognized line format for IPv6 is: IPV6LOW,IPV6HIGH,CC where IPV6LOW and IPV6HIGH are IPv6 addresses and CC is a country code.

It also recognizes, and skips over, blank lines and lines that start with '#' (comments).

Definition at line 318 of file geoip.c.

References geoip_countries, geoip_ipv4_entries, init_geoip_countries(), LD_GENERAL, log_fn, SMARTLIST_FOREACH, tor_assert(), tor_fopen_cloexec(), and tor_free.