comparison src/http/modules/ngx_http_realip_module.c @ 6563:26feae43987f

Realip: take client port from PROXY protocol header. Previously, when the client address was changed to the one from the PROXY protocol header, the client port ($remote_port) was reset to zero. Now the client port is also changed to the one from the PROXY protocol header.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 23 May 2016 18:44:22 +0300
parents b13d3a6f0512
children 3af0e65a461a
comparison
equal deleted inserted replaced
6562:b13d3a6f0512 6563:26feae43987f
136 ngx_addr_t addr; 136 ngx_addr_t addr;
137 ngx_array_t *xfwd; 137 ngx_array_t *xfwd;
138 ngx_list_part_t *part; 138 ngx_list_part_t *part;
139 ngx_table_elt_t *header; 139 ngx_table_elt_t *header;
140 ngx_connection_t *c; 140 ngx_connection_t *c;
141 struct sockaddr_in *sin;
142 #if (NGX_HAVE_INET6)
143 struct sockaddr_in6 *sin6;
144 #endif
141 ngx_http_realip_ctx_t *ctx; 145 ngx_http_realip_ctx_t *ctx;
142 ngx_http_realip_loc_conf_t *rlcf; 146 ngx_http_realip_loc_conf_t *rlcf;
143 147
144 ctx = ngx_http_get_module_ctx(r, ngx_http_realip_module); 148 ctx = ngx_http_get_module_ctx(r, ngx_http_realip_module);
145 149
235 239
236 if (ngx_http_get_forwarded_addr(r, &addr, xfwd, value, rlcf->from, 240 if (ngx_http_get_forwarded_addr(r, &addr, xfwd, value, rlcf->from,
237 rlcf->recursive) 241 rlcf->recursive)
238 != NGX_DECLINED) 242 != NGX_DECLINED)
239 { 243 {
244 if (rlcf->type == NGX_HTTP_REALIP_PROXY) {
245
246 switch (addr.sockaddr->sa_family) {
247
248 #if (NGX_HAVE_INET6)
249 case AF_INET6:
250 sin6 = (struct sockaddr_in6 *) addr.sockaddr;
251 sin6->sin6_port = htons(c->proxy_protocol_port);
252 break;
253 #endif
254
255 default: /* AF_INET */
256 sin = (struct sockaddr_in *) addr.sockaddr;
257 sin->sin_port = htons(c->proxy_protocol_port);
258 break;
259 }
260 }
261
240 return ngx_http_realip_set_addr(r, &addr); 262 return ngx_http_realip_set_addr(r, &addr);
241 } 263 }
242 264
243 return NGX_DECLINED; 265 return NGX_DECLINED;
244 } 266 }