mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
White space.
This commit is contained in:
parent
74c6dafed6
commit
e2313d8622
@ -1532,7 +1532,8 @@ options_act(const or_options_t *old_options)
|
|||||||
}
|
}
|
||||||
/* And maybe load geoip ipv6 file */
|
/* And maybe load geoip ipv6 file */
|
||||||
if (options->GeoIPv6File &&
|
if (options->GeoIPv6File &&
|
||||||
((!old_options || !opt_streq(old_options->GeoIPv6File, options->GeoIPv6File))
|
((!old_options || !opt_streq(old_options->GeoIPv6File,
|
||||||
|
options->GeoIPv6File))
|
||||||
|| !geoip_is_loaded())) {
|
|| !geoip_is_loaded())) {
|
||||||
/* XXXX Don't use this "<default>" junk; make our filename options
|
/* XXXX Don't use this "<default>" junk; make our filename options
|
||||||
* understand prefixes somehow. See also comment for GeoIPFile. */
|
* understand prefixes somehow. See also comment for GeoIPFile. */
|
||||||
@ -1550,7 +1551,6 @@ options_act(const or_options_t *old_options)
|
|||||||
tor_free(actual_fname);
|
tor_free(actual_fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (options->CellStatistics || options->DirReqStatistics ||
|
if (options->CellStatistics || options->DirReqStatistics ||
|
||||||
options->EntryStatistics || options->ExitPortStatistics ||
|
options->EntryStatistics || options->ExitPortStatistics ||
|
||||||
options->ConnDirectionStatistics ||
|
options->ConnDirectionStatistics ||
|
||||||
|
@ -167,11 +167,12 @@ geoip_ipv4_compare_key_to_entry_(const void *_key, const void **_member)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add an entry to the GeoIP IPv6 table, mapping all IPs between <b>low</b> and
|
/** Add an entry to the GeoIP IPv6 table, mapping all IPs between
|
||||||
* <b>high</b>, inclusive, to the 2-letter country code <b>country</b>.
|
* <b>low</b> and <b>high</b>, inclusive, to the 2-letter country code
|
||||||
*/
|
* <b>country</b>. */
|
||||||
static void
|
static void
|
||||||
geoip_ipv6_add_entry(struct in6_addr low, struct in6_addr high, const char *country)
|
geoip_ipv6_add_entry(struct in6_addr low, struct in6_addr high,
|
||||||
|
const char *country)
|
||||||
{
|
{
|
||||||
intptr_t idx;
|
intptr_t idx;
|
||||||
geoip_ipv6_entry_t *ent;
|
geoip_ipv6_entry_t *ent;
|
||||||
@ -264,8 +265,8 @@ geoip_ipv6_compare_entries_(const void **_a, const void **_b)
|
|||||||
return memcmp(&a->ip_low, &b->ip_low, sizeof(struct in6_addr));
|
return memcmp(&a->ip_low, &b->ip_low, sizeof(struct in6_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** bsearch helper: return -1, 1, or 0 based on comparison of an IPv6 (a pointer
|
/** bsearch helper: return -1, 1, or 0 based on comparison of an IPv6
|
||||||
* to a in6_addr in host order) to a geoip_ipv6_entry_t */
|
* (a pointer to a in6_addr in host order) to a geoip_ipv6_entry_t */
|
||||||
static int
|
static int
|
||||||
geoip_ipv6_compare_key_to_entry_(const void *_key, const void **_member)
|
geoip_ipv6_compare_key_to_entry_(const void *_key, const void **_member)
|
||||||
{
|
{
|
||||||
@ -324,7 +325,8 @@ init_geoip_countries(void)
|
|||||||
* with '#' (comments).
|
* with '#' (comments).
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
geoip_load_file(sa_family_t family, const char *filename, const or_options_t *options)
|
geoip_load_file(sa_family_t family, const char *filename,
|
||||||
|
const or_options_t *options)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
const char *msg = "";
|
const char *msg = "";
|
||||||
@ -343,20 +345,23 @@ geoip_load_file(sa_family_t family, const char *filename, const or_options_t *op
|
|||||||
|
|
||||||
if (family == AF_INET) {
|
if (family == AF_INET) {
|
||||||
if (geoip_ipv4_entries) {
|
if (geoip_ipv4_entries) {
|
||||||
SMARTLIST_FOREACH(geoip_ipv4_entries, geoip_ipv4_entry_t *, e, tor_free(e));
|
SMARTLIST_FOREACH(geoip_ipv4_entries, geoip_ipv4_entry_t *, e,
|
||||||
|
tor_free(e));
|
||||||
smartlist_free(geoip_ipv4_entries);
|
smartlist_free(geoip_ipv4_entries);
|
||||||
}
|
}
|
||||||
geoip_ipv4_entries = smartlist_new();
|
geoip_ipv4_entries = smartlist_new();
|
||||||
} else { /* AF_INET6 */
|
} else { /* AF_INET6 */
|
||||||
if (geoip_ipv6_entries) {
|
if (geoip_ipv6_entries) {
|
||||||
SMARTLIST_FOREACH(geoip_ipv6_entries, geoip_ipv6_entry_t *, e, tor_free(e));
|
SMARTLIST_FOREACH(geoip_ipv6_entries, geoip_ipv6_entry_t *, e,
|
||||||
|
tor_free(e));
|
||||||
smartlist_free(geoip_ipv6_entries);
|
smartlist_free(geoip_ipv6_entries);
|
||||||
}
|
}
|
||||||
geoip_ipv6_entries = smartlist_new();
|
geoip_ipv6_entries = smartlist_new();
|
||||||
}
|
}
|
||||||
geoip_digest_env = crypto_digest_new();
|
geoip_digest_env = crypto_digest_new();
|
||||||
|
|
||||||
log_notice(LD_GENERAL, "Parsing GEOIP %s file %s.", (family == AF_INET) ? "ipv4" : "ipv6", filename);
|
log_notice(LD_GENERAL, "Parsing GEOIP %s file %s.",
|
||||||
|
(family == AF_INET) ? "ipv4" : "ipv6", filename);
|
||||||
while (!feof(f)) {
|
while (!feof(f)) {
|
||||||
char buf[512];
|
char buf[512];
|
||||||
if (fgets(buf, (int)sizeof(buf), f) == NULL)
|
if (fgets(buf, (int)sizeof(buf), f) == NULL)
|
||||||
@ -404,7 +409,8 @@ geoip_get_country_by_ipv4(uint32_t ipaddr)
|
|||||||
geoip_ipv4_entry_t *ent;
|
geoip_ipv4_entry_t *ent;
|
||||||
if (!geoip_ipv4_entries)
|
if (!geoip_ipv4_entries)
|
||||||
return -1;
|
return -1;
|
||||||
ent = smartlist_bsearch(geoip_ipv4_entries, &ipaddr, geoip_ipv4_compare_key_to_entry_);
|
ent = smartlist_bsearch(geoip_ipv4_entries, &ipaddr,
|
||||||
|
geoip_ipv4_compare_key_to_entry_);
|
||||||
return ent ? (int)ent->country : 0;
|
return ent ? (int)ent->country : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,11 +426,11 @@ geoip_get_country_by_ipv6(const struct in6_addr *addr)
|
|||||||
|
|
||||||
if (!geoip_ipv6_entries)
|
if (!geoip_ipv6_entries)
|
||||||
return -1;
|
return -1;
|
||||||
ent = smartlist_bsearch(geoip_ipv6_entries, addr, geoip_ipv6_compare_key_to_entry_);
|
ent = smartlist_bsearch(geoip_ipv6_entries, addr,
|
||||||
|
geoip_ipv6_compare_key_to_entry_);
|
||||||
return ent ? (int)ent->country : 0;
|
return ent ? (int)ent->country : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Given an IP address, return a number representing the country to which
|
/** Given an IP address, return a number representing the country to which
|
||||||
* that address belongs, -1 for "No geoip information available", or 0 for
|
* that address belongs, -1 for "No geoip information available", or 0 for
|
||||||
* the 'unknown country'. The return value will always be less than
|
* the 'unknown country'. The return value will always be less than
|
||||||
@ -470,7 +476,8 @@ geoip_is_loaded(void)
|
|||||||
/* XXX5053 Saying that we have loaded a GeoIP database if have _either_
|
/* XXX5053 Saying that we have loaded a GeoIP database if have _either_
|
||||||
* a v4 or v6 database might be problematic. Maybe we need to add an
|
* a v4 or v6 database might be problematic. Maybe we need to add an
|
||||||
* address parameter to this function? -KL */
|
* address parameter to this function? -KL */
|
||||||
return geoip_countries != NULL && (geoip_ipv4_entries != NULL || geoip_ipv6_entries != NULL);
|
return geoip_countries != NULL &&
|
||||||
|
(geoip_ipv4_entries != NULL || geoip_ipv6_entries != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the hex-encoded SHA1 digest of the loaded GeoIP file. The
|
/** Return the hex-encoded SHA1 digest of the loaded GeoIP file. The
|
||||||
@ -990,7 +997,8 @@ geoip_get_dirreq_history(geoip_client_action_t action,
|
|||||||
* to export geoip data yet. This counts both IPv4 and IPv6 clients
|
* to export geoip data yet. This counts both IPv4 and IPv6 clients
|
||||||
* since they're in the same clientmap list. */
|
* since they're in the same clientmap list. */
|
||||||
char *
|
char *
|
||||||
geoip_get_client_history(geoip_client_action_t action, int *total_ipv4, int *total_ipv6)
|
geoip_get_client_history(geoip_client_action_t action, int *total_ipv4,
|
||||||
|
int *total_ipv6)
|
||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
unsigned granularity = IP_GRANULARITY;
|
unsigned granularity = IP_GRANULARITY;
|
||||||
@ -1412,16 +1420,17 @@ geoip_format_bridge_stats(time_t now)
|
|||||||
return NULL; /* Not initialized. */
|
return NULL; /* Not initialized. */
|
||||||
|
|
||||||
format_iso_time(written, now);
|
format_iso_time(written, now);
|
||||||
data = geoip_get_client_history(GEOIP_CLIENT_CONNECT, &total_ipv4, &total_ipv6);
|
data = geoip_get_client_history(GEOIP_CLIENT_CONNECT, &total_ipv4,
|
||||||
|
&total_ipv6);
|
||||||
|
|
||||||
tor_asprintf(&out,
|
tor_asprintf(&out,
|
||||||
"bridge-stats-end %s (%ld s)\n"
|
"bridge-stats-end %s (%ld s)\n"
|
||||||
"bridge-ips %s\n"
|
"bridge-ips %s\n"
|
||||||
"bridge-ip-versions v4=%d,v6=%d\n",
|
"bridge-ip-versions v4=%d,v6=%d\n",
|
||||||
written, duration,
|
written, duration,
|
||||||
data ? data : "",
|
data ? data : "",
|
||||||
total_ipv4,
|
total_ipv4,
|
||||||
total_ipv6);
|
total_ipv6);
|
||||||
tor_free(data);
|
tor_free(data);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@ -1571,7 +1580,8 @@ geoip_format_entry_stats(time_t now)
|
|||||||
|
|
||||||
tor_assert(now >= start_of_entry_stats_interval);
|
tor_assert(now >= start_of_entry_stats_interval);
|
||||||
|
|
||||||
data = geoip_get_client_history(GEOIP_CLIENT_CONNECT, &total_ipv4, &total_ipv6);
|
data = geoip_get_client_history(GEOIP_CLIENT_CONNECT, &total_ipv4,
|
||||||
|
&total_ipv6);
|
||||||
format_iso_time(t, now);
|
format_iso_time(t, now);
|
||||||
tor_asprintf(&result,
|
tor_asprintf(&result,
|
||||||
"entry-stats-end %s (%u s)\n"
|
"entry-stats-end %s (%u s)\n"
|
||||||
@ -1658,11 +1668,13 @@ clear_geoip_db(void)
|
|||||||
|
|
||||||
strmap_free(country_idxplus1_by_lc_code, NULL);
|
strmap_free(country_idxplus1_by_lc_code, NULL);
|
||||||
if (geoip_ipv4_entries) {
|
if (geoip_ipv4_entries) {
|
||||||
SMARTLIST_FOREACH(geoip_ipv4_entries, geoip_ipv4_entry_t *, ent, tor_free(ent));
|
SMARTLIST_FOREACH(geoip_ipv4_entries, geoip_ipv4_entry_t *, ent,
|
||||||
|
tor_free(ent));
|
||||||
smartlist_free(geoip_ipv4_entries);
|
smartlist_free(geoip_ipv4_entries);
|
||||||
}
|
}
|
||||||
if (geoip_ipv6_entries) {
|
if (geoip_ipv6_entries) {
|
||||||
SMARTLIST_FOREACH(geoip_ipv6_entries, geoip_ipv6_entry_t *, ent, tor_free(ent));
|
SMARTLIST_FOREACH(geoip_ipv6_entries, geoip_ipv6_entry_t *, ent,
|
||||||
|
tor_free(ent));
|
||||||
smartlist_free(geoip_ipv6_entries);
|
smartlist_free(geoip_ipv6_entries);
|
||||||
}
|
}
|
||||||
geoip_countries = NULL;
|
geoip_countries = NULL;
|
||||||
|
@ -19,7 +19,8 @@ int geoip_get_country_by_ipv4(uint32_t ipaddr);
|
|||||||
int geoip_get_country_by_ipv6(const struct in6_addr *addr);
|
int geoip_get_country_by_ipv6(const struct in6_addr *addr);
|
||||||
#endif
|
#endif
|
||||||
int should_record_bridge_info(const or_options_t *options);
|
int should_record_bridge_info(const or_options_t *options);
|
||||||
int geoip_load_file(sa_family_t family, const char *filename, const or_options_t *options);
|
int geoip_load_file(sa_family_t family, const char *filename,
|
||||||
|
const or_options_t *options);
|
||||||
int geoip_get_country_by_addr(const tor_addr_t *addr);
|
int geoip_get_country_by_addr(const tor_addr_t *addr);
|
||||||
int geoip_get_n_countries(void);
|
int geoip_get_n_countries(void);
|
||||||
const char *geoip_get_country_name(country_t num);
|
const char *geoip_get_country_name(country_t num);
|
||||||
@ -33,7 +34,8 @@ void geoip_remove_old_clients(time_t cutoff);
|
|||||||
|
|
||||||
void geoip_note_ns_response(geoip_client_action_t action,
|
void geoip_note_ns_response(geoip_client_action_t action,
|
||||||
geoip_ns_response_t response);
|
geoip_ns_response_t response);
|
||||||
char *geoip_get_client_history(geoip_client_action_t action, int *total_ipv4, int *total_ipv6);
|
char *geoip_get_client_history(geoip_client_action_t action, int *total_ipv4,
|
||||||
|
int *total_ipv6);
|
||||||
char *geoip_get_request_history(geoip_client_action_t action);
|
char *geoip_get_request_history(geoip_client_action_t action);
|
||||||
int getinfo_helper_geoip(control_connection_t *control_conn,
|
int getinfo_helper_geoip(control_connection_t *control_conn,
|
||||||
const char *question, char **answer,
|
const char *question, char **answer,
|
||||||
|
@ -1485,13 +1485,15 @@ test_geoip(void)
|
|||||||
|
|
||||||
/* Make sure that country ID actually works. */
|
/* Make sure that country ID actually works. */
|
||||||
#define SET_TEST_IPV6(i) in6.s6_addr32[3] = htonl((uint32_t) i)
|
#define SET_TEST_IPV6(i) in6.s6_addr32[3] = htonl((uint32_t) i)
|
||||||
#define CHECK_COUNTRY(country, val) do { \
|
#define CHECK_COUNTRY(country, val) do { \
|
||||||
/* test ipv4 country lookup */ \
|
/* test ipv4 country lookup */ \
|
||||||
test_streq(country, geoip_get_country_name(geoip_get_country_by_ipv4(val))); \
|
test_streq(country, \
|
||||||
/* test ipv6 country lookup */ \
|
geoip_get_country_name(geoip_get_country_by_ipv4(val))); \
|
||||||
SET_TEST_IPV6(val); \
|
/* test ipv6 country lookup */ \
|
||||||
test_streq(country, geoip_get_country_name(geoip_get_country_by_ipv6(&in6))); \
|
SET_TEST_IPV6(val); \
|
||||||
} while(0)
|
test_streq(country, \
|
||||||
|
geoip_get_country_name(geoip_get_country_by_ipv6(&in6))); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
CHECK_COUNTRY("??", 3);
|
CHECK_COUNTRY("??", 3);
|
||||||
CHECK_COUNTRY("ab", 32);
|
CHECK_COUNTRY("ab", 32);
|
||||||
@ -1511,14 +1513,14 @@ test_geoip(void)
|
|||||||
* using ipv4. Since our fake geoip database is the same between
|
* using ipv4. Since our fake geoip database is the same between
|
||||||
* ipv4 and ipv6, we should get the same result no matter which
|
* ipv4 and ipv6, we should get the same result no matter which
|
||||||
* address family we pick for each IP. */
|
* address family we pick for each IP. */
|
||||||
#define SET_TEST_ADDRESS(i) do { \
|
#define SET_TEST_ADDRESS(i) do { \
|
||||||
if ((i) & 1) { \
|
if ((i) & 1) { \
|
||||||
SET_TEST_IPV6(i); \
|
SET_TEST_IPV6(i); \
|
||||||
tor_addr_from_in6(&addr, &in6); \
|
tor_addr_from_in6(&addr, &in6); \
|
||||||
} else { \
|
} else { \
|
||||||
tor_addr_from_ipv4h(&addr, (uint32_t) i); \
|
tor_addr_from_ipv4h(&addr, (uint32_t) i); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while (0)
|
||||||
|
|
||||||
get_options_mutable()->BridgeRelay = 1;
|
get_options_mutable()->BridgeRelay = 1;
|
||||||
get_options_mutable()->BridgeRecordUsageByCountry = 1;
|
get_options_mutable()->BridgeRecordUsageByCountry = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user