Package: geoip Version: 1.4.6.dfsg-15 Severity: wishlist Tags: patch Hi there,
Currently geoip does not handle the 6to4 mapped range (the 2002: range of v6), as it can't find them in the database for v6. It would be possible to add them to the database, but this seems like needless duplication, so I've written a fairly trivial patch to convert the mapped addresses to v4 addresses and look them up in the v4 database. I am not all that familiar with the geoip calling conventions, so please don't assume this is the best of all patches for it - it's strictly a Works For Me[TM] patch, tested on amd64 and ppc to get the endian part right. Cheers, -- ----------------------------------------------------------------- | ,''`. Stephen Gran | | : :' : sg...@debian.org | | `. `' Debian user, admin, and developer | | `- http://www.debian.org | -----------------------------------------------------------------
diff -Nru geoip-1.4.6.dfsg/debian/changelog geoip-1.4.6.dfsg/debian/changelog --- geoip-1.4.6.dfsg/debian/changelog 2009-12-06 19:41:31.000000000 +0000 +++ geoip-1.4.6.dfsg/debian/changelog 2009-12-21 00:18:17.000000000 +0000 @@ -1,3 +1,10 @@ +geoip (1.4.6.dfsg-15.1) unstable; urgency=low + + * Non-maintainer upload. + * Fix to correctly lookup 6to4 mapped addresses in the 2002: prefix + + -- Stephen Gran <sg...@debian.org> Mon, 21 Dec 2009 00:17:58 +0000 + geoip (1.4.6.dfsg-15) unstable; urgency=low * Update both databases to the 2.12.2009 version. diff -Nru geoip-1.4.6.dfsg/debian/patches/debian-changes-1.4.6.dfsg-15.1 geoip-1.4.6.dfsg/debian/patches/debian-changes-1.4.6.dfsg-15.1 --- geoip-1.4.6.dfsg/debian/patches/debian-changes-1.4.6.dfsg-15.1 1970-01-01 01:00:00.000000000 +0100 +++ geoip-1.4.6.dfsg/debian/patches/debian-changes-1.4.6.dfsg-15.1 2009-12-21 00:52:34.000000000 +0000 @@ -0,0 +1,76 @@ +--- geoip-1.4.6.dfsg.orig/libGeoIP/GeoIP.c ++++ geoip-1.4.6.dfsg/libGeoIP/GeoIP.c +@@ -18,7 +18,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "GeoIP.h" ++#include "GeoIP_internal.h" + + static geoipv6_t IPV6_NULL; + +@@ -27,6 +27,11 @@ static geoipv6_t IPV6_NULL; + #include <sys/mman.h> + #endif /* !defined(_WIN32) */ + ++#include <sys/socket.h> ++#include <netinet/in.h> ++#include <arpa/inet.h> ++ ++ + #include <errno.h> + #include <stdio.h> + #include <stdlib.h> +@@ -501,6 +506,52 @@ int _check_mtime(GeoIP *gi) { + + #define ADDR_STR_LEN (8 * 4 + 7 + 1) + unsigned int _GeoIP_seek_record_v6 (GeoIP *gi, geoipv6_t ipnum) { ++ ++ /* ++ * First we check the v6 address to see if it looks like a 6to4 address. ++ * These begin with 2002:, so it's a fairly easy prefix to check, but we ++ * have to deal with it in a way that deals with endian issues, so it's not ++ * all that pretty. Sadly, we don't seem to have portable macros like htonl ++ * for this v6 funtion just yet. Using a cast to uint32_t so that we get ++ * the first 4 bytes of the address (as the prefix will actually be in the ++ * lower two bytes on little endian machines) ++ */ ++ ++#ifdef _BIG_ENDIAN ++ if ((((__const uint32_t *) (ipnum.s6_addr))[0] & 0xffff0000) == 0x20020000) { ++#else /* _BIG_ENDIAN */ ++ if ((((__const uint32_t *) (ipnum.s6_addr))[0] & 0x0000ffff) == 0x00000220) { ++#endif /* _BIG_ENDIAN */ ++ ++ struct in_addr v4; ++ memset(&v4, 0, sizeof(struct in_addr)); ++ int part; ++ unsigned int ret; ++ int type; ++ ++ /* ++ * The v6 address field is uint8_t[16], and the first two members of that ++ * array are taken up the 2002: prefix. We want to iterate the next 4, as ++ * that will get us the mapped v4 address back. ++ */ ++ ++ for (part = 2; part <= 5; part++) { ++ v4.s_addr <<= 8; ++ v4.s_addr |= (((__const uint8_t *) (ipnum.s6_addr))[part]); ++ } ++ ++ if (gi->databaseType == GEOIP_COUNTRY_EDITION_V6) { ++ type = GEOIP_COUNTRY_EDITION; ++ } else { ++ type = gi->databaseType; ++ } ++ ++ GeoIP *gi2 = GeoIP_open_type(type, gi->flags); ++ ret = _GeoIP_seek_record(gi2, v4.s_addr); ++ free(gi2); ++ return ret; ++ } ++ + int depth; + char paddr[ADDR_STR_LEN]; + unsigned int x; diff -Nru geoip-1.4.6.dfsg/debian/patches/series geoip-1.4.6.dfsg/debian/patches/series --- geoip-1.4.6.dfsg/debian/patches/series 2009-12-06 19:41:31.000000000 +0000 +++ geoip-1.4.6.dfsg/debian/patches/series 2009-12-21 00:18:20.000000000 +0000 @@ -1,2 +1,3 @@ 01-fix_exit_code_and_v_flag.diff 02-add_asnum_support.diff +debian-changes-1.4.6.dfsg-15.1