aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_realip_module.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/http/modules/ngx_http_realip_module.c b/src/http/modules/ngx_http_realip_module.c
index 91ba695fd..bd5c31cdc 100644
--- a/src/http/modules/ngx_http_realip_module.c
+++ b/src/http/modules/ngx_http_realip_module.c
@@ -97,6 +97,7 @@ ngx_http_realip_handler(ngx_http_request_t *r)
{
u_char *ip, *p;
size_t len;
+ in_addr_t addr;
ngx_uint_t i;
struct sockaddr_in *sin;
ngx_http_realip_from_t *from;
@@ -128,16 +129,19 @@ ngx_http_realip_handler(ngx_http_request_t *r)
len = r->headers_in.x_forwarded_for->value.len;
ip = r->headers_in.x_forwarded_for->value.data;
- for (p = ip + len; p > ip; p--) {
+ for (p = ip + len - 1; p > ip; p--) {
if (*p == ' ' || *p == ',') {
- p++;
- len -= p - ip;
- ip = p;
- break;
+ p++;
+ len -= p - ip;
+ ip = p;
+ break;
}
}
}
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "realip: \"%s\"", ip);
+
/* AF_INET only */
sin = (struct sockaddr_in *) r->connection->sockaddr;
@@ -151,12 +155,18 @@ ngx_http_realip_handler(ngx_http_request_t *r)
if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) {
- r->connection->addr_text.len = len;
- r->connection->addr_text.data = ip;
+ r->realip_set = 1;
- sin->sin_addr.s_addr = inet_addr((char *) ip);
+ addr = inet_addr((char *) ip);
- r->realip_set = 1;
+ if (addr == INADDR_NONE) {
+ return NGX_DECLINED;
+ }
+
+ sin->sin_addr.s_addr = addr;
+
+ r->connection->addr_text.len = len;
+ r->connection->addr_text.data = ip;
return NGX_DECLINED;
}