comparison src/http/modules/ngx_http_realip_module.c @ 286:5bef04fc3fd5 NGINX_0_5_13

nginx 0.5.13 *) Feature: the COPY and MOVE methods. *) Bugfix: the ngx_http_realip_module set garbage for requests passed via keep-alive connection. *) Bugfix: nginx did not work on big-endian 64-bit Linux. Thanks to Andrei Nigmatulin. *) Bugfix: now when IMAP/POP3 proxy receives too long command it closes the connection right away, but not after timeout. *) Bugfix: if the "epoll" method was used and a client closed a connection prematurely, then nginx closed the connection after a send timeout only. *) Bugfix: nginx could not be built on platforms different from i386, amd64, sparc and ppc; bug appeared in 0.5.8.
author Igor Sysoev <http://sysoev.ru>
date Mon, 19 Feb 2007 00:00:00 +0300
parents 29a6403156b0
children 7cf404023f50
comparison
equal deleted inserted replaced
285:0e505c8b6528 286:5bef04fc3fd5
95 static ngx_int_t 95 static ngx_int_t
96 ngx_http_realip_handler(ngx_http_request_t *r) 96 ngx_http_realip_handler(ngx_http_request_t *r)
97 { 97 {
98 u_char *ip, *p; 98 u_char *ip, *p;
99 size_t len; 99 size_t len;
100 in_addr_t addr;
100 ngx_uint_t i; 101 ngx_uint_t i;
101 struct sockaddr_in *sin; 102 struct sockaddr_in *sin;
102 ngx_http_realip_from_t *from; 103 ngx_http_realip_from_t *from;
103 ngx_http_realip_loc_conf_t *rlcf; 104 ngx_http_realip_loc_conf_t *rlcf;
104 105
126 } 127 }
127 128
128 len = r->headers_in.x_forwarded_for->value.len; 129 len = r->headers_in.x_forwarded_for->value.len;
129 ip = r->headers_in.x_forwarded_for->value.data; 130 ip = r->headers_in.x_forwarded_for->value.data;
130 131
131 for (p = ip + len; p > ip; p--) { 132 for (p = ip + len - 1; p > ip; p--) {
132 if (*p == ' ' || *p == ',') { 133 if (*p == ' ' || *p == ',') {
133 p++; 134 p++;
134 len -= p - ip; 135 len -= p - ip;
135 ip = p; 136 ip = p;
136 break; 137 break;
137 } 138 }
138 } 139 }
139 } 140 }
141
142 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
143 "realip: \"%s\"", ip);
140 144
141 /* AF_INET only */ 145 /* AF_INET only */
142 146
143 sin = (struct sockaddr_in *) r->connection->sockaddr; 147 sin = (struct sockaddr_in *) r->connection->sockaddr;
144 148
149 "realip: %08XD %08XD %08XD", 153 "realip: %08XD %08XD %08XD",
150 sin->sin_addr.s_addr, from[i].mask, from[i].addr); 154 sin->sin_addr.s_addr, from[i].mask, from[i].addr);
151 155
152 if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) { 156 if ((sin->sin_addr.s_addr & from[i].mask) == from[i].addr) {
153 157
158 r->realip_set = 1;
159
160 addr = inet_addr((char *) ip);
161
162 if (addr == INADDR_NONE) {
163 return NGX_DECLINED;
164 }
165
166 p = ngx_palloc(r->connection->pool, len);
167 if (p == NULL) {
168 return NGX_HTTP_INTERNAL_SERVER_ERROR;
169 }
170
171 ngx_memcpy(p, ip, len);
172
173 sin->sin_addr.s_addr = addr;
174
154 r->connection->addr_text.len = len; 175 r->connection->addr_text.len = len;
155 r->connection->addr_text.data = ip; 176 r->connection->addr_text.data = p;
156
157 sin->sin_addr.s_addr = inet_addr((char *) ip);
158
159 r->realip_set = 1;
160 177
161 return NGX_DECLINED; 178 return NGX_DECLINED;
162 } 179 }
163 } 180 }
164 181