diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2011-05-16 13:54:42 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2011-05-16 13:54:42 +0000 |
| commit | 529b5f19385c71c174598636726f63ab1238de9f (patch) | |
| tree | 6be4ec8a968696e6602f13aa82997c05f5ba45e5 | |
| parent | dd39f600144a7d0aa9e8448ea75675d588eda898 (diff) | |
| download | nginx-529b5f19385c71c174598636726f63ab1238de9f.tar.gz nginx-529b5f19385c71c174598636726f63ab1238de9f.tar.bz2 | |
support IPv4 mapped to IPv6 in geo module
| -rw-r--r-- | src/http/modules/ngx_http_geo_module.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c index e60f1f4fb..7c5019605 100644 --- a/src/http/modules/ngx_http_geo_module.c +++ b/src/http/modules/ngx_http_geo_module.c @@ -257,17 +257,41 @@ ngx_http_geo_real_addr(ngx_http_request_t *r, ngx_http_geo_ctx_t *ctx) { struct sockaddr_in *sin; ngx_http_variable_value_t *v; +#if (NGX_HAVE_INET6) + u_char *p; + in_addr_t addr; + struct sockaddr_in6 *sin6; +#endif if (ctx->index == -1) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http geo started: %V", &r->connection->addr_text); - if (r->connection->sockaddr->sa_family != AF_INET) { - return 0; + switch (r->connection->sockaddr->sa_family) { + + case AF_INET: + sin = (struct sockaddr_in *) r->connection->sockaddr; + return ntohl(sin->sin_addr.s_addr); + +#if (NGX_HAVE_INET6) + + case AF_INET6: + sin6 = (struct sockaddr_in6 *) r->connection->sockaddr; + + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { + p = sin6->sin6_addr.s6_addr; + addr = p[12] << 24; + addr += p[13] << 16; + addr += p[14] << 8; + addr += p[15]; + + return addr; + } + +#endif } - sin = (struct sockaddr_in *) r->connection->sockaddr; - return ntohl(sin->sin_addr.s_addr); + return INADDR_NONE; } v = ngx_http_get_flushed_variable(r, ctx->index); |
