Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reintroduce *working* GeoIPEnableHostnameLookups!

  • Loading branch information...
commit 1766a902d8e56c12e05c7b6a0cb350e2bb0e53c6 1 parent 0f3a56e
@rvagg authored
Showing with 39 additions and 11 deletions.
  1. +7 −0 Changes
  2. +15 −0 README.md
  3. +17 −11 mod_geoip.c
View
7 Changes
@@ -1,3 +1,10 @@
+1.2.7-RV3 Jul 7th 2012
+ - Introduced GeoIPEnableHostnameLookups config option to do name lookups on the X-Forwarded-For match, result is stored in GEOIP_HOST environment variable (useful for logging amongst other things) (Rod Vagg)
+1.2.7-RV2 Jul 6th 2012
+ - Added fallback to remote_ip where X-Forwarded-For handler fails to find a non-private match (Kevin Gaudin)
+ - Introduced GeoIPUseLeftPublicXForwardedForIP config option to switch to new X-Forwarded-For handler, left GeoIPUseLastXForwardedForIP and default option in place and still active (Rod Vagg)
+1.2.7-RV1 Apr 22nd 2012
+ - Added proper X-Forwarded-For handling, see http://rod.vagg.org/2012/04/a-mod_geoip2-that-properly-handles-x-forwarded-for/ (Rod Vagg)
1.2.7 Aug 23th 2011
- Add support for GEOIP_NETSPEED_REV1 ( Boris Zentner )
- Experimental support for GEOIP_COUNTRY_EDITION_V6 ( Boris Zentner )
View
15 README.md
@@ -1,3 +1,8 @@
+# mod_geoip2_xff
+
+**mod_geoip2 with fancy, new-fangled X-Forwarded-For handling**
+---------------------
+
A fork of [MaxMind](http://www.maxmind.com)'s
[mod_geoip2](http://www.maxmind.com/app/mod_geoip) with more intelligent
X-Forwarded-For handling, as per
@@ -19,6 +24,14 @@ You can compare with the current MaxMind release
To enable this special mode you need to turn the **GeoIPUseLeftPublicXForwardedForIP**
flag **On** in your apache config.
+An additional config option is also available: **GeoIPEnableHostnameLookups**, when
+set to **On** mod_geoip2 will attempt to resolve the matched IP address and store
+the result in the GEOIP_HOST environment variable. This is useful for logging or
+other basic remote host based configuration.
+
+Changes for this fork are being recorded in the
+[Changes](https://github.com/rvagg/mod_geoip2_xff/blob/master/Changes) file.
+
Contributions more than welcome!
Thanks to Kevin Gaudin for his contributions to fall back to the RemoteIP
@@ -29,3 +42,5 @@ Original MaxMind README is
Follow the same instructions found in the original
[INSTALL](https://github.com/rvagg/mod_geoip2_xff/blob/master/INSTALL).
+
+**See [Downloads](https://github.com/rvagg/mod_geoip2_xff/downloads) for tarballs.**
View
28 mod_geoip.c
@@ -380,6 +380,9 @@ geoip_header_parser(request_rec * r)
char *ipaddr_ptr = 0;
char *comma_ptr;
char *found_ip;
+ apr_sockaddr_t *sa;
+ char *hostname = 0;
+
cfg = ap_get_module_config(r->server->module_config, &geoip_module);
if (!cfg)
@@ -472,20 +475,23 @@ geoip_header_parser(request_rec * r)
}
}
#endif
- unsigned long ip = inet_addr(ipaddr);
- char *hostname;
- struct hostent *host = NULL;
- if (cfg->GeoIPEnableHostnameLookups)
- host = gethostbyaddr((char *)&ip, 4, AF_INET);
- hostname = host != NULL ? host->h_name : ipaddr;
+
+ if (cfg->GeoIPEnableHostnameLookups
+ && apr_sockaddr_info_get(&sa, ipaddr, APR_INET, 0, 0, r->pool) == APR_SUCCESS
+ && apr_getnameinfo(&hostname, sa, 0) == APR_SUCCESS) {
+ ap_str_tolower(hostname);
+ }
+
+ if (!hostname)
+ hostname = ipaddr;
if (cfg->GeoIPOutput & GEOIP_NOTES) {
- apr_table_setn(r->notes, "GEOIP_ADDR", ipaddr);
- apr_table_setn(r->notes, "GEOIP_HOST", hostname);
+ apr_table_setn(r->notes, "GEOIP_ADDR", ipaddr);
+ apr_table_setn(r->notes, "GEOIP_HOST", hostname);
}
- if (cfg->GeoIPOutput & GEOIP_ENV) {
- apr_table_setn(r->subprocess_env, "GEOIP_ADDR", ipaddr);
- apr_table_setn(r->subprocess_env, "GEOIP_HOST", hostname);
+ if (cfg->GeoIPOutput & GEOIP_ENV) {
+ apr_table_setn(r->subprocess_env, "GEOIP_ADDR", ipaddr);
+ apr_table_setn(r->subprocess_env, "GEOIP_HOST", hostname);
}
for (i = 0; i < cfg->numGeoIPFiles; i++) {
Please sign in to comment.
Something went wrong with that request. Please try again.