Vladimir Homutov
February 12, 2020 11:04AM
details: https://hg.nginx.org/nginx/rev/1055e43e4fab
branches:
changeset: 7624:1055e43e4fab
user: Vladimir Homutov <vl@nginx.com>
date: Tue Feb 11 13:22:44 2020 +0300
description:
Made ngx_http_get_forwarded_addr_internal() non-recursive.

diffstat:

src/http/ngx_http_core_module.c | 62 +++++++++++++++++++---------------------
1 files changed, 30 insertions(+), 32 deletions(-)

diffs (77 lines):

diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- 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
u_char *xff, size_t xfflen, ngx_array_t *proxies, int recursive)
{
u_char *p;
- ngx_int_t rc;
ngx_addr_t paddr;
-
- if (ngx_cidr_match(addr->sockaddr, proxies) != NGX_OK) {
- return NGX_DECLINED;
- }
-
- for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {
- if (*p != ' ' && *p != ',') {
- break;
+ ngx_uint_t found;
+
+ found = 0;
+
+ do {
+
+ if (ngx_cidr_match(addr->sockaddr, proxies) != NGX_OK) {
+ return found ? NGX_DONE : NGX_DECLINED;
}
- }
-
- for ( /* void */ ; p > xff; p--) {
- if (*p == ' ' || *p == ',') {
- p++;
- break;
+
+ for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {
+ if (*p != ' ' && *p != ',') {
+ break;
+ }
}
- }
-
- if (ngx_parse_addr_port(r->pool, &paddr, p, xfflen - (p - xff)) != NGX_OK) {
- return NGX_DECLINED;
- }
-
- *addr = paddr;
-
- if (recursive && p > xff) {
- rc = ngx_http_get_forwarded_addr_internal(r, addr, xff, p - 1 - xff,
- proxies, 1);
-
- if (rc == NGX_DECLINED) {
- return NGX_DONE;
+
+ for ( /* void */ ; p > xff; p--) {
+ if (*p == ' ' || *p == ',') {
+ p++;
+ break;
+ }
}

- /* rc == NGX_OK || rc == NGX_DONE */
- return rc;
- }
+ if (ngx_parse_addr_port(r->pool, &paddr, p, xfflen - (p - xff))
+ != NGX_OK)
+ {
+ return found ? NGX_DONE : NGX_DECLINED;
+ }
+
+ *addr = paddr;
+ found = 1;
+ xfflen = p - 1 - xff;
+
+ } while (recursive && p > xff);

return NGX_OK;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Made ngx_http_get_forwarded_addr_internal() non-recursive.

Vladimir Homutov 343 February 12, 2020 11:04AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready