mirror of
https://github.com/nginx/nginx.git
synced 2024-12-11 17:59:00 +08:00
fix broken values, debug logging, and style fix
This commit is contained in:
parent
e8722b8b98
commit
37a6905cb1
@ -97,6 +97,7 @@ ngx_http_realip_handler(ngx_http_request_t *r)
|
|||||||
{
|
{
|
||||||
u_char *ip, *p;
|
u_char *ip, *p;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
in_addr_t addr;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
struct sockaddr_in *sin;
|
struct sockaddr_in *sin;
|
||||||
ngx_http_realip_from_t *from;
|
ngx_http_realip_from_t *from;
|
||||||
@ -128,7 +129,7 @@ ngx_http_realip_handler(ngx_http_request_t *r)
|
|||||||
len = r->headers_in.x_forwarded_for->value.len;
|
len = r->headers_in.x_forwarded_for->value.len;
|
||||||
ip = r->headers_in.x_forwarded_for->value.data;
|
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 == ',') {
|
if (*p == ' ' || *p == ',') {
|
||||||
p++;
|
p++;
|
||||||
len -= p - ip;
|
len -= p - ip;
|
||||||
@ -138,6 +139,9 @@ ngx_http_realip_handler(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||||
|
"realip: \"%s\"", ip);
|
||||||
|
|
||||||
/* AF_INET only */
|
/* AF_INET only */
|
||||||
|
|
||||||
sin = (struct sockaddr_in *) r->connection->sockaddr;
|
sin = (struct sockaddr_in *) r->connection->sockaddr;
|
||||||
@ -151,13 +155,19 @@ ngx_http_realip_handler(ngx_http_request_t *r)
|
|||||||
|
|
||||||
if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) {
|
if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) {
|
||||||
|
|
||||||
|
r->realip_set = 1;
|
||||||
|
|
||||||
|
addr = inet_addr((char *) ip);
|
||||||
|
|
||||||
|
if (addr == INADDR_NONE) {
|
||||||
|
return NGX_DECLINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
sin->sin_addr.s_addr = addr;
|
||||||
|
|
||||||
r->connection->addr_text.len = len;
|
r->connection->addr_text.len = len;
|
||||||
r->connection->addr_text.data = ip;
|
r->connection->addr_text.data = ip;
|
||||||
|
|
||||||
sin->sin_addr.s_addr = inet_addr((char *) ip);
|
|
||||||
|
|
||||||
r->realip_set = 1;
|
|
||||||
|
|
||||||
return NGX_DECLINED;
|
return NGX_DECLINED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user