Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: prepared proxy_bind to accept parameters.

Ruslan Ermilov
April 26, 2016 12:02PM
details: http://hg.nginx.org/nginx/rev/88f012eee7d8
branches:
changeset: 6528:88f012eee7d8
user: Roman Arutyunyan <arut@nginx.com>
date: Wed Apr 13 15:42:46 2016 +0300
description:
Upstream: prepared proxy_bind to accept parameters.

In addition, errors occurred while setting bind address are no longer ignored.

diffstat:

src/http/ngx_http_upstream.c | 96 +++++++++++++++++++++++--------------------
1 files changed, 51 insertions(+), 45 deletions(-)

diffs (148 lines):

diff -r 6d3a60a909c8 -r 88f012eee7d8 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Tue Apr 26 18:26:43 2016 +0300
+++ b/src/http/ngx_http_upstream.c Wed Apr 13 15:42:46 2016 +0300
@@ -165,8 +165,8 @@ static char *ngx_http_upstream(ngx_conf_
static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);

-static ngx_addr_t *ngx_http_upstream_get_local(ngx_http_request_t *r,
- ngx_http_upstream_local_t *local);
+static ngx_int_t ngx_http_upstream_set_local(ngx_http_request_t *r,
+ ngx_http_upstream_t *u, ngx_http_upstream_local_t *local);

static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf);
@@ -588,7 +588,10 @@ ngx_http_upstream_init_request(ngx_http_
return;
}

- u->peer.local = ngx_http_upstream_get_local(r, u->conf->local);
+ if (ngx_http_upstream_set_local(r, u, u->conf->local) != NGX_OK) {
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }

clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

@@ -5815,34 +5818,35 @@ ngx_http_upstream_bind_set_slot(ngx_conf

*local->value = cv;

- return NGX_CONF_OK;
- }
-
- local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t));
- if (local->addr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- rc = ngx_parse_addr(cf->pool, local->addr, value[1].data, value[1].len);
-
- switch (rc) {
- case NGX_OK:
- local->addr->name = value[1];
- return NGX_CONF_OK;
-
- case NGX_DECLINED:
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid address \"%V\"", &value[1]);
- /* fall through */
-
- default:
- return NGX_CONF_ERROR;
- }
+ } else {
+ local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t));
+ if (local->addr == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ rc = ngx_parse_addr(cf->pool, local->addr, value[1].data, value[1].len);
+
+ switch (rc) {
+ case NGX_OK:
+ local->addr->name = value[1];
+ break;
+
+ case NGX_DECLINED:
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid address \"%V\"", &value[1]);
+ /* fall through */
+
+ default:
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ return NGX_CONF_OK;
}


-static ngx_addr_t *
-ngx_http_upstream_get_local(ngx_http_request_t *r,
+static ngx_int_t
+ngx_http_upstream_set_local(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_http_upstream_local_t *local)
{
ngx_int_t rc;
@@ -5850,41 +5854,43 @@ ngx_http_upstream_get_local(ngx_http_req
ngx_addr_t *addr;

if (local == NULL) {
- return NULL;
+ u->peer.local = NULL;
+ return NGX_OK;
}

if (local->value == NULL) {
- return local->addr;
+ u->peer.local = local->addr;
+ return NGX_OK;
}

if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) {
- return NULL;
+ return NGX_ERROR;
}

if (val.len == 0) {
- return NULL;
+ return NGX_OK;
}

addr = ngx_palloc(r->pool, sizeof(ngx_addr_t));
if (addr == NULL) {
- return NULL;
+ return NGX_ERROR;
}

rc = ngx_parse_addr(r->pool, addr, val.data, val.len);
-
- switch (rc) {
- case NGX_OK:
- addr->name = val;
- return addr;
-
- case NGX_DECLINED:
+ if (rc == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+
+ if (rc != NGX_OK) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"invalid local address \"%V\"", &val);
- /* fall through */
-
- default:
- return NULL;
- }
+ return NGX_OK;
+ }
+
+ addr->name = val;
+ u->peer.local = addr;
+
+ return NGX_OK;
}



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

[nginx] Upstream: prepared proxy_bind to accept parameters.

Ruslan Ermilov 484 April 26, 2016 12:02PM



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

Online Users

Guests: 151
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