geoip.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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-2016, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file geoip.h
  8. * \brief Header file for geoip.c.
  9. **/
  10. #ifndef TOR_GEOIP_H
  11. #define TOR_GEOIP_H
  12. #include "testsupport.h"
  13. #ifdef GEOIP_PRIVATE
  14. STATIC int geoip_parse_entry(const char *line, sa_family_t family);
  15. STATIC int geoip_get_country_by_ipv4(uint32_t ipaddr);
  16. STATIC int geoip_get_country_by_ipv6(const struct in6_addr *addr);
  17. STATIC void clear_geoip_db(void);
  18. #endif
  19. /** Entry in a map from IP address to the last time we've seen an incoming
  20. * connection from that IP address. Used by bridges only to track which
  21. * countries have them blocked, or the DoS mitigation subsystem if enabled. */
  22. typedef struct clientmap_entry_t {
  23. HT_ENTRY(clientmap_entry_t) node;
  24. tor_addr_t addr;
  25. /* Name of pluggable transport used by this client. NULL if no
  26. pluggable transport was used. */
  27. char *transport_name;
  28. /** Time when we last saw this IP address, in MINUTES since the epoch.
  29. *
  30. * (This will run out of space around 4011 CE. If Tor is still in use around
  31. * 4000 CE, please remember to add more bits to last_seen_in_minutes.) */
  32. unsigned int last_seen_in_minutes:30;
  33. unsigned int action:2;
  34. } clientmap_entry_t;
  35. int should_record_bridge_info(const or_options_t *options);
  36. int geoip_load_file(sa_family_t family, const char *filename);
  37. MOCK_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
  38. MOCK_DECL(int, geoip_get_n_countries, (void));
  39. const char *geoip_get_country_name(country_t num);
  40. MOCK_DECL(int, geoip_is_loaded, (sa_family_t family));
  41. const char *geoip_db_digest(sa_family_t family);
  42. MOCK_DECL(country_t, geoip_get_country, (const char *countrycode));
  43. void geoip_note_client_seen(geoip_client_action_t action,
  44. const tor_addr_t *addr, const char *transport_name,
  45. time_t now);
  46. void geoip_remove_old_clients(time_t cutoff);
  47. clientmap_entry_t *geoip_lookup_client(const tor_addr_t *addr,
  48. const char *transport_name,
  49. geoip_client_action_t action);
  50. void geoip_note_ns_response(geoip_ns_response_t response);
  51. char *geoip_get_transport_history(void);
  52. int geoip_get_client_history(geoip_client_action_t action,
  53. char **country_str, char **ipver_str);
  54. char *geoip_get_request_history(void);
  55. int getinfo_helper_geoip(control_connection_t *control_conn,
  56. const char *question, char **answer,
  57. const char **errmsg);
  58. void geoip_free_all(void);
  59. void geoip_start_dirreq(uint64_t dirreq_id, size_t response_size,
  60. dirreq_type_t type);
  61. void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type,
  62. dirreq_state_t new_state);
  63. void geoip_dirreq_stats_init(time_t now);
  64. void geoip_reset_dirreq_stats(time_t now);
  65. char *geoip_format_dirreq_stats(time_t now);
  66. time_t geoip_dirreq_stats_write(time_t now);
  67. void geoip_dirreq_stats_term(void);
  68. void geoip_entry_stats_init(time_t now);
  69. time_t geoip_entry_stats_write(time_t now);
  70. void geoip_entry_stats_term(void);
  71. void geoip_reset_entry_stats(time_t now);
  72. char *geoip_format_entry_stats(time_t now);
  73. void geoip_bridge_stats_init(time_t now);
  74. char *geoip_format_bridge_stats(time_t now);
  75. time_t geoip_bridge_stats_write(time_t now);
  76. void geoip_bridge_stats_term(void);
  77. const char *geoip_get_bridge_stats_extrainfo(time_t);
  78. char *geoip_get_bridge_stats_controller(time_t);
  79. char *format_client_stats_heartbeat(time_t now);
  80. #endif