You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2016/03/26 04:54:30 UTC
[2/2] trafficserver git commit: TS-4284 Adds support for IPv6 for the
legacy DB
TS-4284 Adds support for IPv6 for the legacy DB
This closes #535
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/5b2622ea
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/5b2622ea
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/5b2622ea
Branch: refs/heads/master
Commit: 5b2622eace3694529b39e9f7173742a1a0d4fe3a
Parents: acd06a7
Author: Leif Hedstrom <zw...@apache.org>
Authored: Fri Mar 18 16:24:19 2016 -0600
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Fri Mar 25 13:16:42 2016 -0600
----------------------------------------------------------------------
plugins/experimental/geoip_acl/acl.cc | 17 ++++++++++++++---
plugins/experimental/geoip_acl/acl.h | 1 +
2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b2622ea/plugins/experimental/geoip_acl/acl.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/geoip_acl/acl.cc b/plugins/experimental/geoip_acl/acl.cc
index b7048a1..b1c25e6 100644
--- a/plugins/experimental/geoip_acl/acl.cc
+++ b/plugins/experimental/geoip_acl/acl.cc
@@ -28,15 +28,22 @@
// Implementation of the ACL base class. This wraps the underlying Geo library
// that we've found and used.
GeoDBHandle Acl::_geoip;
+GeoDBHandle Acl::_geoip6;
// Maxmind v1 APIs
#if HAVE_GEOIP_H
bool
Acl::init()
{
- TSDebug(PLUGIN_NAME, "Initialized with Maxmind GeoIP (v1)");
+ TSDebug(PLUGIN_NAME, "initialized IPv4 GeoIP DB");
_geoip = GeoIP_new(GEOIP_MMAP_CACHE); // GEOIP_STANDARD seems to break threaded apps...
+ // Setup IPv6 if possible
+ if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+ _geoip6 = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_MMAP_CACHE | GEOIP_MEMORY_CACHE);
+ TSDebug(PLUGIN_NAME, "initialized IPv6 GeoIP DB");
+ }
+
return true;
}
@@ -50,6 +57,7 @@ int
Acl::country_id_by_addr(const sockaddr *addr) const
{
int iso = -1;
+ int v = 4;
switch (addr->sa_family) {
case AF_INET: {
@@ -58,13 +66,16 @@ Acl::country_id_by_addr(const sockaddr *addr) const
iso = GeoIP_id_by_ipnum(_geoip, ip);
} break;
case AF_INET6: {
- TSDebug(PLUGIN_NAME, "eval(): Unsupported protocol, IPv6");
+ geoipv6_t ip = reinterpret_cast<const struct sockaddr_in6 *>(addr)->sin6_addr;
+
+ iso = GeoIP_id_by_ipnum_v6(_geoip6, ip);
+ v = 6;
} break;
default:
break;
}
- TSDebug(PLUGIN_NAME, "eval(): Client IP seems to come from ISO=%d", iso);
+ TSDebug(PLUGIN_NAME, "eval(): Client IPv%d seems to come from ISO=%d", v, iso);
return iso;
}
#else /* !HAVE_GEOIP_H */
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5b2622ea/plugins/experimental/geoip_acl/acl.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/geoip_acl/acl.h b/plugins/experimental/geoip_acl/acl.h
index 3af88d9..8225869 100644
--- a/plugins/experimental/geoip_acl/acl.h
+++ b/plugins/experimental/geoip_acl/acl.h
@@ -85,6 +85,7 @@ protected:
bool _allow;
int _added_tokens;
static GeoDBHandle _geoip;
+ static GeoDBHandle _geoip6;
};