Mercurial > hg > nginx
comparison src/http/modules/ngx_http_realip_module.c @ 1114:3f354952e91d
fix broken values, debug logging, and style fix
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 15 Feb 2007 15:05:26 +0000 |
parents | 68c85f283043 |
children | cec2866f29bd |
comparison
equal
deleted
inserted
replaced
1113:f1d7cf0f68e3 | 1114:3f354952e91d |
---|---|
95 static ngx_int_t | 95 static ngx_int_t |
96 ngx_http_realip_handler(ngx_http_request_t *r) | 96 ngx_http_realip_handler(ngx_http_request_t *r) |
97 { | 97 { |
98 u_char *ip, *p; | 98 u_char *ip, *p; |
99 size_t len; | 99 size_t len; |
100 in_addr_t addr; | |
100 ngx_uint_t i; | 101 ngx_uint_t i; |
101 struct sockaddr_in *sin; | 102 struct sockaddr_in *sin; |
102 ngx_http_realip_from_t *from; | 103 ngx_http_realip_from_t *from; |
103 ngx_http_realip_loc_conf_t *rlcf; | 104 ngx_http_realip_loc_conf_t *rlcf; |
104 | 105 |
126 } | 127 } |
127 | 128 |
128 len = r->headers_in.x_forwarded_for->value.len; | 129 len = r->headers_in.x_forwarded_for->value.len; |
129 ip = r->headers_in.x_forwarded_for->value.data; | 130 ip = r->headers_in.x_forwarded_for->value.data; |
130 | 131 |
131 for (p = ip + len; p > ip; p--) { | 132 for (p = ip + len - 1; p > ip; p--) { |
132 if (*p == ' ' || *p == ',') { | 133 if (*p == ' ' || *p == ',') { |
133 p++; | 134 p++; |
134 len -= p - ip; | 135 len -= p - ip; |
135 ip = p; | 136 ip = p; |
136 break; | 137 break; |
137 } | 138 } |
138 } | 139 } |
139 } | 140 } |
141 | |
142 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
143 "realip: \"%s\"", ip); | |
140 | 144 |
141 /* AF_INET only */ | 145 /* AF_INET only */ |
142 | 146 |
143 sin = (struct sockaddr_in *) r->connection->sockaddr; | 147 sin = (struct sockaddr_in *) r->connection->sockaddr; |
144 | 148 |
149 "realip: %08XD %08XD %08XD", | 153 "realip: %08XD %08XD %08XD", |
150 sin->sin_addr.s_addr, from[i].mask, from[i].addr); | 154 sin->sin_addr.s_addr, from[i].mask, from[i].addr); |
151 | 155 |
152 if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) { | 156 if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) { |
153 | 157 |
158 r->realip_set = 1; | |
159 | |
160 addr = inet_addr((char *) ip); | |
161 | |
162 if (addr == INADDR_NONE) { | |
163 return NGX_DECLINED; | |
164 } | |
165 | |
166 sin->sin_addr.s_addr = addr; | |
167 | |
154 r->connection->addr_text.len = len; | 168 r->connection->addr_text.len = len; |
155 r->connection->addr_text.data = ip; | 169 r->connection->addr_text.data = ip; |
156 | |
157 sin->sin_addr.s_addr = inet_addr((char *) ip); | |
158 | |
159 r->realip_set = 1; | |
160 | 170 |
161 return NGX_DECLINED; | 171 return NGX_DECLINED; |
162 } | 172 } |
163 } | 173 } |
164 | 174 |