comparison src/http/modules/ngx_http_realip_module.c @ 5605:3a72b1805c52

Added server-side support for PROXY protocol v1 (ticket #355). Client address specified in the PROXY protocol header is now saved in the $proxy_protocol_addr variable and can be used in the realip module. This is currently not implemented for mail.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 17 Mar 2014 17:41:24 +0400
parents 05ba5bce31e0
children cebe43bace93
comparison
equal deleted inserted replaced
5604:22d485944c20 5605:3a72b1805c52
11 11
12 12
13 #define NGX_HTTP_REALIP_XREALIP 0 13 #define NGX_HTTP_REALIP_XREALIP 0
14 #define NGX_HTTP_REALIP_XFWD 1 14 #define NGX_HTTP_REALIP_XFWD 1
15 #define NGX_HTTP_REALIP_HEADER 2 15 #define NGX_HTTP_REALIP_HEADER 2
16 #define NGX_HTTP_REALIP_PROXY 3
16 17
17 18
18 typedef struct { 19 typedef struct {
19 ngx_array_t *from; /* array of ngx_cidr_t */ 20 ngx_array_t *from; /* array of ngx_cidr_t */
20 ngx_uint_t type; 21 ngx_uint_t type;
154 155
155 value = NULL; 156 value = NULL;
156 157
157 break; 158 break;
158 159
160 case NGX_HTTP_REALIP_PROXY:
161
162 value = &r->connection->proxy_protocol_addr;
163
164 if (value->len == 0) {
165 return NGX_DECLINED;
166 }
167
168 xfwd = NULL;
169
170 break;
171
159 default: /* NGX_HTTP_REALIP_HEADER */ 172 default: /* NGX_HTTP_REALIP_HEADER */
160 173
161 part = &r->headers_in.headers.part; 174 part = &r->headers_in.headers.part;
162 header = part->elts; 175 header = part->elts;
163 176
338 return NGX_CONF_OK; 351 return NGX_CONF_OK;
339 } 352 }
340 353
341 if (ngx_strcmp(value[1].data, "X-Forwarded-For") == 0) { 354 if (ngx_strcmp(value[1].data, "X-Forwarded-For") == 0) {
342 rlcf->type = NGX_HTTP_REALIP_XFWD; 355 rlcf->type = NGX_HTTP_REALIP_XFWD;
356 return NGX_CONF_OK;
357 }
358
359 if (ngx_strcmp(value[1].data, "proxy_protocol") == 0) {
360 rlcf->type = NGX_HTTP_REALIP_PROXY;
343 return NGX_CONF_OK; 361 return NGX_CONF_OK;
344 } 362 }
345 363
346 rlcf->type = NGX_HTTP_REALIP_HEADER; 364 rlcf->type = NGX_HTTP_REALIP_HEADER;
347 rlcf->hash = ngx_hash_strlow(value[1].data, value[1].data, value[1].len); 365 rlcf->hash = ngx_hash_strlow(value[1].data, value[1].data, value[1].len);