summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2020-02-11 13:22:44 +0300
committerVladimir Homutov <vl@nginx.com>2020-02-11 13:22:44 +0300
commitde5a054b338ab14fc240f1062f023f7f0ef0d605 (patch)
treeee889722e161fec97eafda94c51a70ca936ce121
parent16168dcb01ed5dbf6365be0d9ea0da68bf479194 (diff)
Made ngx_http_get_forwarded_addr_internal() non-recursive.
-rw-r--r--src/http/ngx_http_core_module.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index a603e09ce..da23af1fb 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2667,43 +2667,41 @@ ngx_http_get_forwarded_addr_internal(ngx_http_request_t *r, ngx_addr_t *addr,
u_char *xff, size_t xfflen, ngx_array_t *proxies, int recursive)
{
u_char *p;
- ngx_int_t rc;
ngx_addr_t paddr;
+ ngx_uint_t found;
- if (ngx_cidr_match(addr->sockaddr, proxies) != NGX_OK) {
- return NGX_DECLINED;
- }
+ found = 0;
- for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {
- if (*p != ' ' && *p != ',') {
- break;
- }
- }
+ do {
- for ( /* void */ ; p > xff; p--) {
- if (*p == ' ' || *p == ',') {
- p++;
- break;
+ if (ngx_cidr_match(addr->sockaddr, proxies) != NGX_OK) {
+ return found ? NGX_DONE : NGX_DECLINED;
}
- }
-
- if (ngx_parse_addr_port(r->pool, &paddr, p, xfflen - (p - xff)) != NGX_OK) {
- return NGX_DECLINED;
- }
- *addr = paddr;
+ for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {
+ if (*p != ' ' && *p != ',') {
+ break;
+ }
+ }
- if (recursive && p > xff) {
- rc = ngx_http_get_forwarded_addr_internal(r, addr, xff, p - 1 - xff,
- proxies, 1);
+ for ( /* void */ ; p > xff; p--) {
+ if (*p == ' ' || *p == ',') {
+ p++;
+ break;
+ }
+ }
- if (rc == NGX_DECLINED) {
- return NGX_DONE;
+ if (ngx_parse_addr_port(r->pool, &paddr, p, xfflen - (p - xff))
+ != NGX_OK)
+ {
+ return found ? NGX_DONE : NGX_DECLINED;
}
- /* rc == NGX_OK || rc == NGX_DONE */
- return rc;
- }
+ *addr = paddr;
+ found = 1;
+ xfflen = p - 1 - xff;
+
+ } while (recursive && p > xff);
return NGX_OK;
}