summaryrefslogtreecommitdiff
path: root/src/or/geoip.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2012-03-28 15:52:33 +0200
committerLinus Nordberg <linus@torproject.org>2012-10-17 10:54:52 +0200
commitc03e3d66a910d103d3cce50a3bc1b778f68c36f2 (patch)
tree3fc10f5ab188b7fffd00f94b0048937456694ac3 /src/or/geoip.c
parent31e224173bda6feb2e9894ba7b820affc3f44a9c (diff)
downloadtor-c03e3d66a910d103d3cce50a3bc1b778f68c36f2.tar.gz
tor-c03e3d66a910d103d3cce50a3bc1b778f68c36f2.zip
Minor tweaks and comments to nils' geoip v6 code.
Diffstat (limited to 'src/or/geoip.c')
-rw-r--r--src/or/geoip.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 4c28eebe59..e19b62ad50 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -48,7 +48,8 @@ static smartlist_t *geoip_countries = NULL;
* The index is encoded in the pointer, and 1 is added so that NULL can mean
* not found. */
static strmap_t *country_idxplus1_by_lc_code = NULL;
-/** A list of all known geoip_ipv4_entry_t, sorted by ip_low. */
+/** Lists of all known geoip_ipv4_entry_t and geoip_ipv6_entry_t, sorted
+ * by their respective ip_low. */
static smartlist_t *geoip_ipv4_entries = NULL, *geoip_ipv6_entries = NULL;
/** SHA1 digest of the GeoIP file to include in extra-info descriptors. */
@@ -203,7 +204,11 @@ geoip_ipv6_add_entry(struct in6_addr low, struct in6_addr high, const char *coun
}
/** Add an entry to the GeoIP ipv6 table, parsing it from <b>line</b>. The
- * format is as for geoip_ipv6_load_file(). */
+ * format is as for geoip_load_file(). */
+/* XXX5053 Should this code also support parsing Maxmind's GeoIPv6.csv
+ * format directly, similar to how their v4 format is also accepted? That
+ * would enable people to use their commercial IPv6 databases instead of
+ * our free one, if they wanted. -KL */
/*private*/ int
geoip_ipv6_parse_entry(const char *line)
{
@@ -260,10 +265,13 @@ _geoip_ipv6_compare_entries(const void **_a, const void **_b)
}
/** bsearch helper: return -1, 1, or 0 based on comparison of an IPv6 (a pointer
- * to a in6_addr in host order) to a geoip_ipv4_entry_t */
+ * to a in6_addr in host order) to a geoip_ipv6_entry_t */
static int
_geoip_ipv6_compare_key_to_entry(const void *_key, const void **_member)
{
+ /* XXX5053 The following comment isn't correct anymore and I'm not 100%
+ * certain how to fix it, because I don't know what alignment issues
+ * there could be. -KL */
/* No alignment issue here, since _key really is a pointer to uint32_t */
const struct in6_addr *addr = (struct in6_addr *)_key;
const geoip_ipv6_entry_t *entry = *_member;
@@ -374,6 +382,10 @@ geoip_load_file(sa_family_t family, const char *filename, const or_options_t *op
/* Remember file digest so that we can include it in our extra-info
* descriptors. */
+ /* XXX5053 This is a bug! We overwrite geoip_digest with whichever file
+ * we parse last. We'll want to add a separate geoip6_digest and write
+ * a geoip6-db-digest line to our extra-info descriptor. Needs a
+ * dir-spec.txt patch, too. -KL */
crypto_digest_get_digest(geoip_digest_env, geoip_digest, DIGEST_LEN);
crypto_digest_free(geoip_digest_env);
@@ -396,6 +408,11 @@ geoip_get_country_by_ipv4(uint32_t ipaddr)
return ent ? (int)ent->country : 0;
}
+/** 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().
+ */
int
geoip_get_country_by_ipv6(const struct in6_addr *addr)
{
@@ -450,6 +467,9 @@ geoip_get_country_name(country_t num)
int
geoip_is_loaded(void)
{
+ /* 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
+ * address parameter to this function? -KL */
return geoip_countries != NULL && (geoip_ipv4_entries != NULL || geoip_ipv6_entries != NULL);
}