Welcome! Log In Create A New Profile

Advanced

[nginx] svn commit: r5062 - in branches/stable-1.2: . auto/lib/geoip auto/lib/libgd src/http/modules

Anonymous User
February 11, 2013 10:36AM
Author: mdounin
Date: 2013-02-11 15:34:30 +0000 (Mon, 11 Feb 2013)
New Revision: 5062
URL: http://trac.nginx.org/nginx/changeset/5062/nginx

Log:
Merge of r5014, r5015, r5016, r5030: geoip ipv6 support.

*) Configure: fixed style of include directories.

*) Configure: fixed GeoIP library detection.

*) GeoIP: IPv6 support. When using IPv6 databases, IPv4 addresses are
looked up as IPv4-mapped IPv6 addresses. Mostly based on a patch
by Gregor Kali?\197?\161nik (ticket #250).

*) GeoIP: removed pseudo-support of "proxy" and "netspeed" databases.


Modified:
branches/stable-1.2/
branches/stable-1.2/auto/lib/geoip/conf
branches/stable-1.2/auto/lib/libgd/conf
branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c

Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2 2013-02-11 15:31:10 UTC (rev 5061)
+++ branches/stable-1.2 2013-02-11 15:34:30 UTC (rev 5062)

Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4969,4973-4974,4976-4994,4997,4999-5004,5011-5013,5019-5025
+/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4969,4973-4974,4976-4994,4997,4999-5004,5011-5016,5019-5025,5030
\ No newline at end of property
Modified: branches/stable-1.2/auto/lib/geoip/conf
===================================================================
--- branches/stable-1.2/auto/lib/geoip/conf 2013-02-11 15:31:10 UTC (rev 5061)
+++ branches/stable-1.2/auto/lib/geoip/conf 2013-02-11 15:34:30 UTC (rev 5062)
@@ -6,7 +6,7 @@
ngx_feature="GeoIP library"
ngx_feature_name=
ngx_feature_run=no
- ngx_feature_incs=
+ ngx_feature_incs="#include <GeoIP.h>"
ngx_feature_path=
ngx_feature_libs="-lGeoIP"
ngx_feature_test="GeoIP_open(NULL, 0)"
@@ -18,6 +18,7 @@
# FreeBSD port

ngx_feature="GeoIP library in /usr/local/"
+ ngx_feature_path="/usr/local/include"

if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lGeoIP"
@@ -34,7 +35,7 @@
# NetBSD port

ngx_feature="GeoIP library in /usr/pkg/"
- ngx_feature_path="/usr/pkg/include/"
+ ngx_feature_path="/usr/pkg/include"

if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lGeoIP"
@@ -64,8 +65,22 @@


if [ $ngx_found = yes ]; then
+
+ CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"

+ if [ $NGX_IPV6 = YES ]; then
+ ngx_feature="GeoIP IPv6 support"
+ ngx_feature_name="NGX_HAVE_GEOIP_V6"
+ ngx_feature_run=no
+ ngx_feature_incs="#include <stdio.h>
+ #include <GeoIP.h>"
+ #ngx_feature_path=
+ #ngx_feature_libs=
+ ngx_feature_test="printf(\"%d\", GEOIP_CITY_EDITION_REV0_V6);"
+ . auto/feature
+ fi
+
else

cat << END

Modified: branches/stable-1.2/auto/lib/libgd/conf
===================================================================
--- branches/stable-1.2/auto/lib/libgd/conf 2013-02-11 15:31:10 UTC (rev 5061)
+++ branches/stable-1.2/auto/lib/libgd/conf 2013-02-11 15:34:30 UTC (rev 5062)
@@ -35,7 +35,7 @@
# NetBSD port

ngx_feature="GD library in /usr/pkg/"
- ngx_feature_path="/usr/pkg/include/"
+ ngx_feature_path="/usr/pkg/include"

if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lgd"

Modified: branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c
===================================================================
--- branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c 2013-02-11 15:31:10 UTC (rev 5061)
+++ branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c 2013-02-11 15:34:30 UTC (rev 5062)
@@ -13,12 +13,22 @@
#include <GeoIPCity.h>


+#define NGX_GEOIP_COUNTRY_CODE 0
+#define NGX_GEOIP_COUNTRY_CODE3 1
+#define NGX_GEOIP_COUNTRY_NAME 2
+
+
typedef struct {
GeoIP *country;
GeoIP *org;
GeoIP *city;
ngx_array_t *proxies; /* array of ngx_cidr_t */
ngx_flag_t proxy_recursive;
+#if (NGX_HAVE_GEOIP_V6)
+ unsigned country_v6:1;
+ unsigned org_v6:1;
+ unsigned city_v6:1;
+#endif
} ngx_http_geoip_conf_t;


@@ -28,10 +38,32 @@
} ngx_http_geoip_var_t;


-typedef char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
+typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *,
+ u_long addr);

-static u_long ngx_http_geoip_addr(ngx_http_request_t *r,
- ngx_http_geoip_conf_t *gcf);
+
+ngx_http_geoip_variable_handler_pt ngx_http_geoip_country_functions[] = {
+ GeoIP_country_code_by_ipnum,
+ GeoIP_country_code3_by_ipnum,
+ GeoIP_country_name_by_ipnum,
+};
+
+
+#if (NGX_HAVE_GEOIP_V6)
+
+typedef const char *(*ngx_http_geoip_variable_handler_v6_pt)(GeoIP *,
+ geoipv6_t addr);
+
+
+ngx_http_geoip_variable_handler_v6_pt ngx_http_geoip_country_v6_functions[] = {
+ GeoIP_country_code_by_ipnum_v6,
+ GeoIP_country_code3_by_ipnum_v6,
+ GeoIP_country_name_by_ipnum_v6,
+};
+
+#endif
+
+
static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_geoip_org_variable(ngx_http_request_t *r,
@@ -138,19 +170,19 @@

{ ngx_string("geoip_country_code"), NULL,
ngx_http_geoip_country_variable,
- (uintptr_t) GeoIP_country_code_by_ipnum, 0, 0 },
+ NGX_GEOIP_COUNTRY_CODE, 0, 0 },

{ ngx_string("geoip_country_code3"), NULL,
ngx_http_geoip_country_variable,
- (uintptr_t) GeoIP_country_code3_by_ipnum, 0, 0 },
+ NGX_GEOIP_COUNTRY_CODE3, 0, 0 },

{ ngx_string("geoip_country_name"), NULL,
ngx_http_geoip_country_variable,
- (uintptr_t) GeoIP_country_name_by_ipnum, 0, 0 },
+ NGX_GEOIP_COUNTRY_NAME, 0, 0 },

{ ngx_string("geoip_org"), NULL,
ngx_http_geoip_org_variable,
- (uintptr_t) GeoIP_name_by_ipnum, 0, 0 },
+ 0, 0, 0 },

{ ngx_string("geoip_city_continent_code"), NULL,
ngx_http_geoip_city_variable,
@@ -255,12 +287,68 @@
}


+#if (NGX_HAVE_GEOIP_V6)
+
+static geoipv6_t
+ngx_http_geoip_addr_v6(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf)
+{
+ ngx_addr_t addr;
+ ngx_table_elt_t *xfwd;
+ in_addr_t addr4;
+ struct in6_addr addr6;
+ struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6;
+
+ addr.sockaddr = r->connection->sockaddr;
+ addr.socklen = r->connection->socklen;
+ /* addr.name = r->connection->addr_text; */
+
+ xfwd = r->headers_in.x_forwarded_for;
+
+ if (xfwd != NULL && gcf->proxies != NULL) {
+ (void) ngx_http_get_forwarded_addr(r, &addr, xfwd->value.data,
+ xfwd->value.len, gcf->proxies,
+ gcf->proxy_recursive);
+ }
+
+ switch (addr.sockaddr->sa_family) {
+
+ case AF_INET:
+ /* Produce IPv4-mapped IPv6 address. */
+ sin = (struct sockaddr_in *) addr.sockaddr;
+ addr4 = ntohl(sin->sin_addr.s_addr);
+
+ ngx_memzero(&addr6, sizeof(struct in6_addr));
+ addr6.s6_addr[10] = 0xff;
+ addr6.s6_addr[11] = 0xff;
+ addr6.s6_addr[12] = addr4 >> 24;
+ addr6.s6_addr[13] = addr4 >> 16;
+ addr6.s6_addr[14] = addr4 >> 8;
+ addr6.s6_addr[15] = addr4;
+ return addr6;
+
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *) addr.sockaddr;
+ return sin6->sin6_addr;
+
+ default:
+ return in6addr_any;
+ }
+}
+
+#endif
+
+
static ngx_int_t
ngx_http_geoip_country_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
- ngx_http_geoip_variable_handler_pt handler =
- (ngx_http_geoip_variable_handler_pt) data;
+ ngx_http_geoip_variable_handler_pt handler =
+ ngx_http_geoip_country_functions[data];
+#if (NGX_HAVE_GEOIP_V6)
+ ngx_http_geoip_variable_handler_v6_pt handler_v6 =
+ ngx_http_geoip_country_v6_functions[data];
+#endif

const char *val;
ngx_http_geoip_conf_t *gcf;
@@ -271,7 +359,13 @@
goto not_found;
}

+#if (NGX_HAVE_GEOIP_V6)
+ val = gcf->country_v6
+ ? handler_v6(gcf->country, ngx_http_geoip_addr_v6(r, gcf))
+ : handler(gcf->country, ngx_http_geoip_addr(r, gcf));
+#else
val = handler(gcf->country, ngx_http_geoip_addr(r, gcf));
+#endif

if (val == NULL) {
goto not_found;
@@ -297,9 +391,6 @@
ngx_http_geoip_org_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
- ngx_http_geoip_variable_handler_pt handler =
- (ngx_http_geoip_variable_handler_pt) data;
-
size_t len;
char *val;
ngx_http_geoip_conf_t *gcf;
@@ -310,7 +401,15 @@
goto not_found;
}

- val = handler(gcf->org, ngx_http_geoip_addr(r, gcf));
+#if (NGX_HAVE_GEOIP_V6)
+ val = gcf->org_v6
+ ? GeoIP_name_by_ipnum_v6(gcf->org,
+ ngx_http_geoip_addr_v6(r, gcf))
+ : GeoIP_name_by_ipnum(gcf->org,
+ ngx_http_geoip_addr(r, gcf));
+#else
+ val = GeoIP_name_by_ipnum(gcf->org, ngx_http_geoip_addr(r, gcf));
+#endif

if (val == NULL) {
goto not_found;
@@ -500,7 +599,15 @@
gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module);

if (gcf->city) {
+#if (NGX_HAVE_GEOIP_V6)
+ return gcf->city_v6
+ ? GeoIP_record_by_ipnum_v6(gcf->city,
+ ngx_http_geoip_addr_v6(r, gcf))
+ : GeoIP_record_by_ipnum(gcf->city,
+ ngx_http_geoip_addr(r, gcf));
+#else
return GeoIP_record_by_ipnum(gcf->city, ngx_http_geoip_addr(r, gcf));
+#endif
}

return NULL;
@@ -598,11 +705,16 @@
switch (gcf->country->databaseType) {

case GEOIP_COUNTRY_EDITION:
- case GEOIP_PROXY_EDITION:
- case GEOIP_NETSPEED_EDITION:

return NGX_CONF_OK;

+#if (NGX_HAVE_GEOIP_V6)
+ case GEOIP_COUNTRY_EDITION_V6:
+
+ gcf->country_v6 = 1;
+ return NGX_CONF_OK;
+#endif
+
default:
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid GeoIP database \"%V\" type:%d",
@@ -654,6 +766,16 @@

return NGX_CONF_OK;

+#if (NGX_HAVE_GEOIP_V6)
+ case GEOIP_ISP_EDITION_V6:
+ case GEOIP_ORG_EDITION_V6:
+ case GEOIP_DOMAIN_EDITION_V6:
+ case GEOIP_ASNUM_EDITION_V6:
+
+ gcf->org_v6 = 1;
+ return NGX_CONF_OK;
+#endif
+
default:
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid GeoIP database \"%V\" type:%d",
@@ -703,6 +825,14 @@

return NGX_CONF_OK;

+#if (NGX_HAVE_GEOIP_V6)
+ case GEOIP_CITY_EDITION_REV0_V6:
+ case GEOIP_CITY_EDITION_REV1_V6:
+
+ gcf->city_v6 = 1;
+ return NGX_CONF_OK;
+#endif
+
default:
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid GeoIP City database \"%V\" type:%d",

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] svn commit: r5062 - in branches/stable-1.2: . auto/lib/geoip auto/lib/libgd src/http/modules

Anonymous User 715 February 11, 2013 10:36AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 221
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready