1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for geoip.c.
15 #include "testsupport.h"
19 STATIC
int geoip_parse_entry(const char *line
, sa_family_t family
);
20 STATIC
int geoip_get_country_by_ipv4(uint32_t ipaddr
);
21 STATIC
int geoip_get_country_by_ipv6(const struct in6_addr
*addr
);
22 STATIC
void clear_geoip_db(void);
23 #endif /* defined(GEOIP_PRIVATE) */
25 /** Entry in a map from IP address to the last time we've seen an incoming
26 * connection from that IP address. Used by bridges only to track which
27 * countries have them blocked, or the DoS mitigation subsystem if enabled. */
28 typedef struct clientmap_entry_t
{
29 HT_ENTRY(clientmap_entry_t
) node
;
31 /* Name of pluggable transport used by this client. NULL if no
32 pluggable transport was used. */
35 /** Time when we last saw this IP address, in MINUTES since the epoch.
37 * (This will run out of space around 4011 CE. If Tor is still in use around
38 * 4000 CE, please remember to add more bits to last_seen_in_minutes.) */
39 unsigned int last_seen_in_minutes
:30;
40 unsigned int action
:2;
42 /* This object is used to keep some statistics per client address for the
43 * DoS mitigation subsystem. */
44 dos_client_stats_t dos_stats
;
47 int should_record_bridge_info(const or_options_t
*options
);
48 int geoip_load_file(sa_family_t family
, const char *filename
);
49 MOCK_DECL(int, geoip_get_country_by_addr
, (const tor_addr_t
*addr
));
50 MOCK_DECL(int, geoip_get_n_countries
, (void));
51 const char *geoip_get_country_name(country_t num
);
52 MOCK_DECL(int, geoip_is_loaded
, (sa_family_t family
));
53 const char *geoip_db_digest(sa_family_t family
);
54 MOCK_DECL(country_t
, geoip_get_country
, (const char *countrycode
));
56 void geoip_note_client_seen(geoip_client_action_t action
,
57 const tor_addr_t
*addr
, const char *transport_name
,
59 void geoip_remove_old_clients(time_t cutoff
);
60 clientmap_entry_t
*geoip_lookup_client(const tor_addr_t
*addr
,
61 const char *transport_name
,
62 geoip_client_action_t action
);
63 size_t geoip_client_cache_total_allocation(void);
64 size_t geoip_client_cache_handle_oom(time_t now
, size_t min_remove_bytes
);
66 void geoip_note_ns_response(geoip_ns_response_t response
);
67 char *geoip_get_transport_history(void);
68 int geoip_get_client_history(geoip_client_action_t action
,
69 char **country_str
, char **ipver_str
);
70 char *geoip_get_request_history(void);
71 int getinfo_helper_geoip(control_connection_t
*control_conn
,
72 const char *question
, char **answer
,
74 void geoip_free_all(void);
76 void geoip_start_dirreq(uint64_t dirreq_id
, size_t response_size
,
78 void geoip_change_dirreq_state(uint64_t dirreq_id
, dirreq_type_t type
,
79 dirreq_state_t new_state
);
81 void geoip_dirreq_stats_init(time_t now
);
82 void geoip_reset_dirreq_stats(time_t now
);
83 char *geoip_format_dirreq_stats(time_t now
);
84 time_t geoip_dirreq_stats_write(time_t now
);
85 void geoip_dirreq_stats_term(void);
86 void geoip_entry_stats_init(time_t now
);
87 time_t geoip_entry_stats_write(time_t now
);
88 void geoip_entry_stats_term(void);
89 void geoip_reset_entry_stats(time_t now
);
90 char *geoip_format_entry_stats(time_t now
);
91 void geoip_bridge_stats_init(time_t now
);
92 char *geoip_format_bridge_stats(time_t now
);
93 time_t geoip_bridge_stats_write(time_t now
);
94 void geoip_bridge_stats_term(void);
95 const char *geoip_get_bridge_stats_extrainfo(time_t);
96 char *geoip_get_bridge_stats_controller(time_t);
97 char *format_client_stats_heartbeat(time_t now
);
99 #endif /* !defined(TOR_GEOIP_H) */