Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 6528:88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
In addition, errors occurred while setting bind address are no longer ignored.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 13 Apr 2016 15:42:46 +0300 |
parents | 2cd019520210 |
children | 1d0e03db9f8e |
comparison
equal
deleted
inserted
replaced
6527:6d3a60a909c8 | 6528:88f012eee7d8 |
---|---|
163 | 163 |
164 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); | 164 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
165 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | 165 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, |
166 void *conf); | 166 void *conf); |
167 | 167 |
168 static ngx_addr_t *ngx_http_upstream_get_local(ngx_http_request_t *r, | 168 static ngx_int_t ngx_http_upstream_set_local(ngx_http_request_t *r, |
169 ngx_http_upstream_local_t *local); | 169 ngx_http_upstream_t *u, ngx_http_upstream_local_t *local); |
170 | 170 |
171 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); | 171 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
172 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); | 172 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
173 | 173 |
174 #if (NGX_HTTP_SSL) | 174 #if (NGX_HTTP_SSL) |
586 if (u->create_request(r) != NGX_OK) { | 586 if (u->create_request(r) != NGX_OK) { |
587 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 587 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
588 return; | 588 return; |
589 } | 589 } |
590 | 590 |
591 u->peer.local = ngx_http_upstream_get_local(r, u->conf->local); | 591 if (ngx_http_upstream_set_local(r, u, u->conf->local) != NGX_OK) { |
592 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
593 return; | |
594 } | |
592 | 595 |
593 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 596 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
594 | 597 |
595 u->output.alignment = clcf->directio_alignment; | 598 u->output.alignment = clcf->directio_alignment; |
596 u->output.pool = r->pool; | 599 u->output.pool = r->pool; |
5813 return NGX_CONF_ERROR; | 5816 return NGX_CONF_ERROR; |
5814 } | 5817 } |
5815 | 5818 |
5816 *local->value = cv; | 5819 *local->value = cv; |
5817 | 5820 |
5818 return NGX_CONF_OK; | 5821 } else { |
5819 } | 5822 local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); |
5820 | 5823 if (local->addr == NULL) { |
5821 local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); | 5824 return NGX_CONF_ERROR; |
5822 if (local->addr == NULL) { | 5825 } |
5823 return NGX_CONF_ERROR; | 5826 |
5824 } | 5827 rc = ngx_parse_addr(cf->pool, local->addr, value[1].data, value[1].len); |
5825 | 5828 |
5826 rc = ngx_parse_addr(cf->pool, local->addr, value[1].data, value[1].len); | 5829 switch (rc) { |
5827 | 5830 case NGX_OK: |
5828 switch (rc) { | 5831 local->addr->name = value[1]; |
5829 case NGX_OK: | 5832 break; |
5830 local->addr->name = value[1]; | 5833 |
5831 return NGX_CONF_OK; | 5834 case NGX_DECLINED: |
5832 | 5835 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5833 case NGX_DECLINED: | 5836 "invalid address \"%V\"", &value[1]); |
5834 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 5837 /* fall through */ |
5835 "invalid address \"%V\"", &value[1]); | 5838 |
5836 /* fall through */ | 5839 default: |
5837 | 5840 return NGX_CONF_ERROR; |
5838 default: | 5841 } |
5839 return NGX_CONF_ERROR; | 5842 } |
5840 } | 5843 |
5841 } | 5844 return NGX_CONF_OK; |
5842 | 5845 } |
5843 | 5846 |
5844 static ngx_addr_t * | 5847 |
5845 ngx_http_upstream_get_local(ngx_http_request_t *r, | 5848 static ngx_int_t |
5849 ngx_http_upstream_set_local(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
5846 ngx_http_upstream_local_t *local) | 5850 ngx_http_upstream_local_t *local) |
5847 { | 5851 { |
5848 ngx_int_t rc; | 5852 ngx_int_t rc; |
5849 ngx_str_t val; | 5853 ngx_str_t val; |
5850 ngx_addr_t *addr; | 5854 ngx_addr_t *addr; |
5851 | 5855 |
5852 if (local == NULL) { | 5856 if (local == NULL) { |
5853 return NULL; | 5857 u->peer.local = NULL; |
5858 return NGX_OK; | |
5854 } | 5859 } |
5855 | 5860 |
5856 if (local->value == NULL) { | 5861 if (local->value == NULL) { |
5857 return local->addr; | 5862 u->peer.local = local->addr; |
5863 return NGX_OK; | |
5858 } | 5864 } |
5859 | 5865 |
5860 if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) { | 5866 if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) { |
5861 return NULL; | 5867 return NGX_ERROR; |
5862 } | 5868 } |
5863 | 5869 |
5864 if (val.len == 0) { | 5870 if (val.len == 0) { |
5865 return NULL; | 5871 return NGX_OK; |
5866 } | 5872 } |
5867 | 5873 |
5868 addr = ngx_palloc(r->pool, sizeof(ngx_addr_t)); | 5874 addr = ngx_palloc(r->pool, sizeof(ngx_addr_t)); |
5869 if (addr == NULL) { | 5875 if (addr == NULL) { |
5870 return NULL; | 5876 return NGX_ERROR; |
5871 } | 5877 } |
5872 | 5878 |
5873 rc = ngx_parse_addr(r->pool, addr, val.data, val.len); | 5879 rc = ngx_parse_addr(r->pool, addr, val.data, val.len); |
5874 | 5880 if (rc == NGX_ERROR) { |
5875 switch (rc) { | 5881 return NGX_ERROR; |
5876 case NGX_OK: | 5882 } |
5877 addr->name = val; | 5883 |
5878 return addr; | 5884 if (rc != NGX_OK) { |
5879 | |
5880 case NGX_DECLINED: | |
5881 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 5885 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
5882 "invalid local address \"%V\"", &val); | 5886 "invalid local address \"%V\"", &val); |
5883 /* fall through */ | 5887 return NGX_OK; |
5884 | 5888 } |
5885 default: | 5889 |
5886 return NULL; | 5890 addr->name = val; |
5887 } | 5891 u->peer.local = addr; |
5892 | |
5893 return NGX_OK; | |
5888 } | 5894 } |
5889 | 5895 |
5890 | 5896 |
5891 char * | 5897 char * |
5892 ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, | 5898 ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |