Mercurial > hg > nginx
comparison src/http/modules/ngx_http_geoip_module.c @ 5084:f7fe817c92a2
Correctly handle multiple X-Forwarded-For headers (ticket #106).
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 27 Feb 2013 13:29:50 +0000 |
parents | 795722a74254 |
children | f3df4e420ae7 |
comparison
equal
deleted
inserted
replaced
5083:a805dc9c85cd | 5084:f7fe817c92a2 |
---|---|
238 | 238 |
239 static u_long | 239 static u_long |
240 ngx_http_geoip_addr(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf) | 240 ngx_http_geoip_addr(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf) |
241 { | 241 { |
242 ngx_addr_t addr; | 242 ngx_addr_t addr; |
243 ngx_table_elt_t *xfwd; | 243 ngx_array_t *xfwd; |
244 struct sockaddr_in *sin; | 244 struct sockaddr_in *sin; |
245 | 245 |
246 addr.sockaddr = r->connection->sockaddr; | 246 addr.sockaddr = r->connection->sockaddr; |
247 addr.socklen = r->connection->socklen; | 247 addr.socklen = r->connection->socklen; |
248 /* addr.name = r->connection->addr_text; */ | 248 /* addr.name = r->connection->addr_text; */ |
249 | 249 |
250 xfwd = r->headers_in.x_forwarded_for; | 250 xfwd = &r->headers_in.x_forwarded_for; |
251 | 251 |
252 if (xfwd != NULL && gcf->proxies != NULL) { | 252 if (xfwd->nelts > 0 && gcf->proxies != NULL) { |
253 (void) ngx_http_get_forwarded_addr(r, &addr, xfwd->value.data, | 253 (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL, |
254 xfwd->value.len, gcf->proxies, | 254 gcf->proxies, gcf->proxy_recursive); |
255 gcf->proxy_recursive); | |
256 } | 255 } |
257 | 256 |
258 #if (NGX_HAVE_INET6) | 257 #if (NGX_HAVE_INET6) |
259 | 258 |
260 if (addr.sockaddr->sa_family == AF_INET6) { | 259 if (addr.sockaddr->sa_family == AF_INET6) { |
291 | 290 |
292 static geoipv6_t | 291 static geoipv6_t |
293 ngx_http_geoip_addr_v6(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf) | 292 ngx_http_geoip_addr_v6(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf) |
294 { | 293 { |
295 ngx_addr_t addr; | 294 ngx_addr_t addr; |
296 ngx_table_elt_t *xfwd; | 295 ngx_array_t *xfwd; |
297 in_addr_t addr4; | 296 in_addr_t addr4; |
298 struct in6_addr addr6; | 297 struct in6_addr addr6; |
299 struct sockaddr_in *sin; | 298 struct sockaddr_in *sin; |
300 struct sockaddr_in6 *sin6; | 299 struct sockaddr_in6 *sin6; |
301 | 300 |
302 addr.sockaddr = r->connection->sockaddr; | 301 addr.sockaddr = r->connection->sockaddr; |
303 addr.socklen = r->connection->socklen; | 302 addr.socklen = r->connection->socklen; |
304 /* addr.name = r->connection->addr_text; */ | 303 /* addr.name = r->connection->addr_text; */ |
305 | 304 |
306 xfwd = r->headers_in.x_forwarded_for; | 305 xfwd = &r->headers_in.x_forwarded_for; |
307 | 306 |
308 if (xfwd != NULL && gcf->proxies != NULL) { | 307 if (xfwd->nelts > 0 && gcf->proxies != NULL) { |
309 (void) ngx_http_get_forwarded_addr(r, &addr, xfwd->value.data, | 308 (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL, |
310 xfwd->value.len, gcf->proxies, | 309 gcf->proxies, gcf->proxy_recursive); |
311 gcf->proxy_recursive); | |
312 } | 310 } |
313 | 311 |
314 switch (addr.sockaddr->sa_family) { | 312 switch (addr.sockaddr->sa_family) { |
315 | 313 |
316 case AF_INET: | 314 case AF_INET: |