Mercurial > hg > nginx-quic
annotate src/core/ngx_inet.c @ 6699:9cf2dce316e5
Fixed log levels of configuration parsing errors.
All the errors that prevent loading configuration must be printed on the "emerg"
log level. Previously, nginx might silently fail to load configuration in some
cases as the default log level is "error".
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 20 Sep 2016 15:07:16 +0300 |
parents | b802b7e1d9bc |
children | 3f94a0fc05cf |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
6 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
7 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
9 #include <ngx_core.h> |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2200 | 12 static ngx_int_t ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u); |
13 static ngx_int_t ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u); | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
14 static ngx_int_t ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u); |
2200 | 15 |
1647 | 16 |
17 in_addr_t | |
18 ngx_inet_addr(u_char *text, size_t len) | |
19 { | |
20 u_char *p, c; | |
21 in_addr_t addr; | |
22 ngx_uint_t octet, n; | |
23 | |
24 addr = 0; | |
25 octet = 0; | |
26 n = 0; | |
27 | |
28 for (p = text; p < text + len; p++) { | |
29 c = *p; | |
30 | |
31 if (c >= '0' && c <= '9') { | |
32 octet = octet * 10 + (c - '0'); | |
6138
bc47a7a8159c
Fixed overflow detection in ngx_inet_addr().
Valentin Bartenev <vbart@nginx.com>
parents:
6012
diff
changeset
|
33 |
bc47a7a8159c
Fixed overflow detection in ngx_inet_addr().
Valentin Bartenev <vbart@nginx.com>
parents:
6012
diff
changeset
|
34 if (octet > 255) { |
bc47a7a8159c
Fixed overflow detection in ngx_inet_addr().
Valentin Bartenev <vbart@nginx.com>
parents:
6012
diff
changeset
|
35 return INADDR_NONE; |
bc47a7a8159c
Fixed overflow detection in ngx_inet_addr().
Valentin Bartenev <vbart@nginx.com>
parents:
6012
diff
changeset
|
36 } |
bc47a7a8159c
Fixed overflow detection in ngx_inet_addr().
Valentin Bartenev <vbart@nginx.com>
parents:
6012
diff
changeset
|
37 |
1647 | 38 continue; |
39 } | |
40 | |
6012
550212836c8f
Overflow detection in ngx_inet_addr().
Ruslan Ermilov <ru@nginx.com>
parents:
5473
diff
changeset
|
41 if (c == '.') { |
1647 | 42 addr = (addr << 8) + octet; |
43 octet = 0; | |
44 n++; | |
45 continue; | |
46 } | |
47 | |
48 return INADDR_NONE; | |
49 } | |
50 | |
6012
550212836c8f
Overflow detection in ngx_inet_addr().
Ruslan Ermilov <ru@nginx.com>
parents:
5473
diff
changeset
|
51 if (n == 3) { |
1647 | 52 addr = (addr << 8) + octet; |
53 return htonl(addr); | |
54 } | |
55 | |
56 return INADDR_NONE; | |
57 } | |
58 | |
59 | |
3265 | 60 #if (NGX_HAVE_INET6) |
61 | |
62 ngx_int_t | |
63 ngx_inet6_addr(u_char *p, size_t len, u_char *addr) | |
64 { | |
65 u_char c, *zero, *digit, *s, *d; | |
66 size_t len4; | |
67 ngx_uint_t n, nibbles, word; | |
68 | |
69 if (len == 0) { | |
70 return NGX_ERROR; | |
71 } | |
72 | |
73 zero = NULL; | |
74 digit = NULL; | |
75 len4 = 0; | |
76 nibbles = 0; | |
77 word = 0; | |
78 n = 8; | |
79 | |
80 if (p[0] == ':') { | |
81 p++; | |
82 len--; | |
83 } | |
84 | |
85 for (/* void */; len; len--) { | |
86 c = *p++; | |
87 | |
88 if (c == ':') { | |
89 if (nibbles) { | |
90 digit = p; | |
91 len4 = len; | |
92 *addr++ = (u_char) (word >> 8); | |
93 *addr++ = (u_char) (word & 0xff); | |
94 | |
95 if (--n) { | |
96 nibbles = 0; | |
97 word = 0; | |
98 continue; | |
99 } | |
100 | |
101 } else { | |
102 if (zero == NULL) { | |
103 digit = p; | |
104 len4 = len; | |
105 zero = addr; | |
106 continue; | |
107 } | |
108 } | |
109 | |
110 return NGX_ERROR; | |
111 } | |
112 | |
113 if (c == '.' && nibbles) { | |
3894
4d4b5770616f
fix segfault in IPv6 parsing while processing invalid IPv4 address X.YYYY.Z
Igor Sysoev <igor@sysoev.ru>
parents:
3864
diff
changeset
|
114 if (n < 2 || digit == NULL) { |
3265 | 115 return NGX_ERROR; |
116 } | |
117 | |
118 word = ngx_inet_addr(digit, len4 - 1); | |
119 if (word == INADDR_NONE) { | |
120 return NGX_ERROR; | |
121 } | |
122 | |
123 word = ntohl(word); | |
124 *addr++ = (u_char) ((word >> 24) & 0xff); | |
125 *addr++ = (u_char) ((word >> 16) & 0xff); | |
126 n--; | |
127 break; | |
128 } | |
129 | |
130 if (++nibbles > 4) { | |
131 return NGX_ERROR; | |
132 } | |
133 | |
134 if (c >= '0' && c <= '9') { | |
135 word = word * 16 + (c - '0'); | |
136 continue; | |
137 } | |
138 | |
139 c |= 0x20; | |
140 | |
141 if (c >= 'a' && c <= 'f') { | |
142 word = word * 16 + (c - 'a') + 10; | |
143 continue; | |
144 } | |
145 | |
146 return NGX_ERROR; | |
147 } | |
148 | |
149 if (nibbles == 0 && zero == NULL) { | |
150 return NGX_ERROR; | |
151 } | |
152 | |
153 *addr++ = (u_char) (word >> 8); | |
154 *addr++ = (u_char) (word & 0xff); | |
155 | |
156 if (--n) { | |
157 if (zero) { | |
158 n *= 2; | |
159 s = addr - 1; | |
160 d = s + n; | |
161 while (s >= zero) { | |
162 *d-- = *s--; | |
163 } | |
164 ngx_memzero(zero, n); | |
165 return NGX_OK; | |
166 } | |
167 | |
168 } else { | |
169 if (zero == NULL) { | |
170 return NGX_OK; | |
171 } | |
172 } | |
173 | |
174 return NGX_ERROR; | |
175 } | |
176 | |
177 #endif | |
178 | |
179 | |
509 | 180 size_t |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
181 ngx_sock_ntop(struct sockaddr *sa, socklen_t socklen, u_char *text, size_t len, |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
182 ngx_uint_t port) |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
183 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
184 u_char *p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
185 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
186 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
187 size_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
188 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
189 #endif |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
190 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
191 struct sockaddr_un *saun; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
192 #endif |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
193 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
194 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
195 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
196 case AF_INET: |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
197 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
198 sin = (struct sockaddr_in *) sa; |
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
199 p = (u_char *) &sin->sin_addr; |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
200 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
201 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
202 p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
203 p[0], p[1], p[2], p[3], ntohs(sin->sin_port)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
204 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
205 p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
206 p[0], p[1], p[2], p[3]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
207 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
208 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
209 return (p - text); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
210 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
211 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
212 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
213 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
214 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
215 sin6 = (struct sockaddr_in6 *) sa; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
216 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
217 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
218 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
219 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
220 text[n++] = '['; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
221 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
222 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
223 n = ngx_inet6_ntop(sin6->sin6_addr.s6_addr, &text[n], len); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
224 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
225 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
226 n = ngx_sprintf(&text[1 + n], "]:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
227 ntohs(sin6->sin6_port)) - text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
228 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
229 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
230 return n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
231 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
232 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
233 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
234 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
235 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
236 saun = (struct sockaddr_un *) sa; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
237 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
238 /* on Linux sockaddr might not include sun_path at all */ |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
239 |
5313
1fe5f7fb6ced
Fixed build with signed socklen_t and unix sockets.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5312
diff
changeset
|
240 if (socklen <= (socklen_t) offsetof(struct sockaddr_un, sun_path)) { |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
241 p = ngx_snprintf(text, len, "unix:%Z"); |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
242 |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
243 } else { |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
244 p = ngx_snprintf(text, len, "unix:%s%Z", saun->sun_path); |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
245 } |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
246 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
247 /* we do not include trailing zero in address length */ |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
248 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
249 return (p - text - 1); |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
250 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
251 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
252 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
253 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
254 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
255 } |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
256 } |
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
257 |
1830 | 258 |
509 | 259 size_t |
260 ngx_inet_ntop(int family, void *addr, u_char *text, size_t len) | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
261 { |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
262 u_char *p; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
263 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
264 switch (family) { |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
265 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
266 case AF_INET: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
267 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
268 p = addr; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
269 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
270 return ngx_snprintf(text, len, "%ud.%ud.%ud.%ud", |
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
271 p[0], p[1], p[2], p[3]) |
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
272 - text; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
273 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
274 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
275 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
276 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
277 return ngx_inet6_ntop(addr, text, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
278 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
279 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
280 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
281 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
282 return 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
283 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
284 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
285 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
286 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
287 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
288 |
3276
beaf94f2f265
make ngx_inet6_ntop() non-static
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
289 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
290 ngx_inet6_ntop(u_char *p, u_char *text, size_t len) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
291 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
292 u_char *dst; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
293 size_t max, n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
294 ngx_uint_t i, zero, last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
295 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
296 if (len < NGX_INET6_ADDRSTRLEN) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
297 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
298 } |
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
299 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
300 zero = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
301 last = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
302 max = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
303 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
304 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
305 for (i = 0; i < 16; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
306 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
307 if (p[i] || p[i + 1]) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
308 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
309 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
310 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
311 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
312 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
313 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
314 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
315 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
316 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
317 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
318 if (n++ == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
319 last = i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
320 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
321 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
322 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
323 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
324 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
325 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
326 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
327 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
328 dst = text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
329 n = 16; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
330 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
331 if (zero == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
332 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
333 if ((max == 5 && p[10] == 0xff && p[11] == 0xff) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
334 || (max == 6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
335 || (max == 7 && p[14] != 0 && p[15] != 1)) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
336 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
337 n = 12; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
338 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
339 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
340 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
341 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
342 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
343 for (i = 0; i < n; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
344 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
345 if (i == zero) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
346 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
347 i += (max - 1) * 2; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
348 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
349 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
350 |
6509
7640d6c213e1
Removed redundant "u" format specifier.
Ruslan Ermilov <ru@nginx.com>
parents:
6481
diff
changeset
|
351 dst = ngx_sprintf(dst, "%xd", p[i] * 256 + p[i + 1]); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
352 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
353 if (i < 14) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
354 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
355 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
356 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
357 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
358 if (n == 12) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
359 dst = ngx_sprintf(dst, "%ud.%ud.%ud.%ud", p[12], p[13], p[14], p[15]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
360 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
361 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
362 return dst - text; |
1830 | 363 } |
364 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
365 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
366 |
1830 | 367 |
509 | 368 ngx_int_t |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
369 ngx_ptocidr(ngx_str_t *text, ngx_cidr_t *cidr) |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
370 { |
3277 | 371 u_char *addr, *mask, *last; |
372 size_t len; | |
373 ngx_int_t shift; | |
374 #if (NGX_HAVE_INET6) | |
375 ngx_int_t rc; | |
376 ngx_uint_t s, i; | |
377 #endif | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
378 |
2202 | 379 addr = text->data; |
380 last = addr + text->len; | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
381 |
2202 | 382 mask = ngx_strlchr(addr, last, '/'); |
3277 | 383 len = (mask ? mask : last) - addr; |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
384 |
3277 | 385 cidr->u.in.addr = ngx_inet_addr(addr, len); |
386 | |
387 if (cidr->u.in.addr != INADDR_NONE) { | |
388 cidr->family = AF_INET; | |
389 | |
390 if (mask == NULL) { | |
391 cidr->u.in.mask = 0xffffffff; | |
392 return NGX_OK; | |
393 } | |
2202 | 394 |
3277 | 395 #if (NGX_HAVE_INET6) |
396 } else if (ngx_inet6_addr(addr, len, cidr->u.in6.addr.s6_addr) == NGX_OK) { | |
397 cidr->family = AF_INET6; | |
398 | |
399 if (mask == NULL) { | |
400 ngx_memset(cidr->u.in6.mask.s6_addr, 0xff, 16); | |
401 return NGX_OK; | |
402 } | |
403 | |
404 #endif | |
405 } else { | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
406 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
407 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
408 |
2202 | 409 mask++; |
410 | |
411 shift = ngx_atoi(mask, last - mask); | |
412 if (shift == NGX_ERROR) { | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
413 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
414 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
415 |
3277 | 416 switch (cidr->family) { |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
417 |
3277 | 418 #if (NGX_HAVE_INET6) |
419 case AF_INET6: | |
4573
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
420 if (shift > 128) { |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
421 return NGX_ERROR; |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
422 } |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
423 |
3277 | 424 addr = cidr->u.in6.addr.s6_addr; |
425 mask = cidr->u.in6.mask.s6_addr; | |
426 rc = NGX_OK; | |
427 | |
428 for (i = 0; i < 16; i++) { | |
429 | |
430 s = (shift > 8) ? 8 : shift; | |
431 shift -= s; | |
432 | |
4582
a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
Ruslan Ermilov <ru@nginx.com>
parents:
4573
diff
changeset
|
433 mask[i] = (u_char) (0xffu << (8 - s)); |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
434 |
3277 | 435 if (addr[i] != (addr[i] & mask[i])) { |
436 rc = NGX_DONE; | |
437 addr[i] &= mask[i]; | |
438 } | |
439 } | |
440 | |
441 return rc; | |
442 #endif | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
443 |
3277 | 444 default: /* AF_INET */ |
4573
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
445 if (shift > 32) { |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
446 return NGX_ERROR; |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
447 } |
3277 | 448 |
449 if (shift) { | |
4582
a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
Ruslan Ermilov <ru@nginx.com>
parents:
4573
diff
changeset
|
450 cidr->u.in.mask = htonl((uint32_t) (0xffffffffu << (32 - shift))); |
2202 | 451 |
3277 | 452 } else { |
453 /* x86 compilers use a shl instruction that shifts by modulo 32 */ | |
454 cidr->u.in.mask = 0; | |
455 } | |
456 | |
457 if (cidr->u.in.addr == (cidr->u.in.addr & cidr->u.in.mask)) { | |
2202 | 458 return NGX_OK; |
459 } | |
460 | |
3277 | 461 cidr->u.in.addr &= cidr->u.in.mask; |
462 | |
2202 | 463 return NGX_DONE; |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
464 } |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
465 } |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
466 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
467 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
468 ngx_int_t |
6683
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
469 ngx_cidr_match(struct sockaddr *sa, ngx_array_t *cidrs) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
470 { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
471 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
472 u_char *p; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
473 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
474 in_addr_t inaddr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
475 ngx_cidr_t *cidr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
476 ngx_uint_t family, i; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
477 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
478 ngx_uint_t n; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
479 struct in6_addr *inaddr6; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
480 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
481 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
482 #if (NGX_SUPPRESS_WARN) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
483 inaddr = 0; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
484 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
485 inaddr6 = NULL; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
486 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
487 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
488 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
489 family = sa->sa_family; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
490 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
491 if (family == AF_INET) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
492 inaddr = ((struct sockaddr_in *) sa)->sin_addr.s_addr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
493 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
494 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
495 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
496 else if (family == AF_INET6) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
497 inaddr6 = &((struct sockaddr_in6 *) sa)->sin6_addr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
498 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
499 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
500 family = AF_INET; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
501 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
502 p = inaddr6->s6_addr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
503 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
504 inaddr = p[12] << 24; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
505 inaddr += p[13] << 16; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
506 inaddr += p[14] << 8; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
507 inaddr += p[15]; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
508 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
509 inaddr = htonl(inaddr); |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
510 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
511 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
512 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
513 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
514 for (cidr = cidrs->elts, i = 0; i < cidrs->nelts; i++) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
515 if (cidr[i].family != family) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
516 goto next; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
517 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
518 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
519 switch (family) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
520 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
521 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
522 case AF_INET6: |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
523 for (n = 0; n < 16; n++) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
524 if ((inaddr6->s6_addr[n] & cidr[i].u.in6.mask.s6_addr[n]) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
525 != cidr[i].u.in6.addr.s6_addr[n]) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
526 { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
527 goto next; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
528 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
529 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
530 break; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
531 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
532 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
533 #if (NGX_HAVE_UNIX_DOMAIN) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
534 case AF_UNIX: |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
535 break; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
536 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
537 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
538 default: /* AF_INET */ |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
539 if ((inaddr & cidr[i].u.in.mask) != cidr[i].u.in.addr) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
540 goto next; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
541 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
542 break; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
543 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
544 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
545 return NGX_OK; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
546 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
547 next: |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
548 continue; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
549 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
550 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
551 return NGX_DECLINED; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
552 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
553 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
554 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
555 ngx_int_t |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
556 ngx_parse_addr(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text, size_t len) |
3270 | 557 { |
558 in_addr_t inaddr; | |
559 ngx_uint_t family; | |
560 struct sockaddr_in *sin; | |
561 #if (NGX_HAVE_INET6) | |
562 struct in6_addr inaddr6; | |
563 struct sockaddr_in6 *sin6; | |
3277 | 564 |
565 /* | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
566 * prevent MSVC8 warning: |
3277 | 567 * potentially uninitialized local variable 'inaddr6' used |
568 */ | |
4983
2677c561127b
Properly initialize "struct in6_addr" with zeroes.
Ruslan Ermilov <ru@nginx.com>
parents:
4971
diff
changeset
|
569 ngx_memzero(&inaddr6, sizeof(struct in6_addr)); |
3270 | 570 #endif |
571 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
572 inaddr = ngx_inet_addr(text, len); |
3270 | 573 |
574 if (inaddr != INADDR_NONE) { | |
575 family = AF_INET; | |
576 len = sizeof(struct sockaddr_in); | |
577 | |
578 #if (NGX_HAVE_INET6) | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
579 } else if (ngx_inet6_addr(text, len, inaddr6.s6_addr) == NGX_OK) { |
3270 | 580 family = AF_INET6; |
581 len = sizeof(struct sockaddr_in6); | |
582 | |
583 #endif | |
584 } else { | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
585 return NGX_DECLINED; |
3270 | 586 } |
587 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
588 addr->sockaddr = ngx_pcalloc(pool, len); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
589 if (addr->sockaddr == NULL) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
590 return NGX_ERROR; |
3270 | 591 } |
592 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
593 addr->sockaddr->sa_family = (u_char) family; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
594 addr->socklen = len; |
3270 | 595 |
596 switch (family) { | |
597 | |
598 #if (NGX_HAVE_INET6) | |
599 case AF_INET6: | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
600 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
3270 | 601 ngx_memcpy(sin6->sin6_addr.s6_addr, inaddr6.s6_addr, 16); |
602 break; | |
603 #endif | |
604 | |
605 default: /* AF_INET */ | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
606 sin = (struct sockaddr_in *) addr->sockaddr; |
3270 | 607 sin->sin_addr.s_addr = inaddr; |
608 break; | |
609 } | |
610 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
611 return NGX_OK; |
3270 | 612 } |
613 | |
614 | |
651 | 615 ngx_int_t |
6564
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
616 ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text, |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
617 size_t len) |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
618 { |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
619 u_char *p, *last; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
620 size_t plen; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
621 ngx_int_t rc, port; |
6564
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
622 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
623 rc = ngx_parse_addr(pool, addr, text, len); |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
624 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
625 if (rc != NGX_DECLINED) { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
626 return rc; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
627 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
628 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
629 last = text + len; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
630 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
631 #if (NGX_HAVE_INET6) |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
632 if (len && text[0] == '[') { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
633 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
634 p = ngx_strlchr(text, last, ']'); |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
635 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
636 if (p == NULL || p == last - 1 || *++p != ':') { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
637 return NGX_DECLINED; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
638 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
639 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
640 text++; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
641 len -= 2; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
642 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
643 } else |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
644 #endif |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
645 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
646 { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
647 p = ngx_strlchr(text, last, ':'); |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
648 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
649 if (p == NULL) { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
650 return NGX_DECLINED; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
651 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
652 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
653 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
654 p++; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
655 plen = last - p; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
656 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
657 port = ngx_atoi(p, plen); |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
658 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
659 if (port < 1 || port > 65535) { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
660 return NGX_DECLINED; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
661 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
662 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
663 len -= plen + 1; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
664 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
665 rc = ngx_parse_addr(pool, addr, text, len); |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
666 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
667 if (rc != NGX_OK) { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
668 return rc; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
669 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
670 |
6597 | 671 ngx_inet_set_port(addr->sockaddr, (in_port_t) port); |
6564
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
672 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
673 return NGX_OK; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
674 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
675 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
676 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
677 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
678 ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u) |
651 | 679 { |
2200 | 680 u_char *p; |
6463
5df5d7d771f6
Core: allow strings without null-termination in ngx_parse_url().
Piotr Sikora <piotrsikora@google.com>
parents:
6138
diff
changeset
|
681 size_t len; |
651 | 682 |
683 p = u->url.data; | |
6463
5df5d7d771f6
Core: allow strings without null-termination in ngx_parse_url().
Piotr Sikora <piotrsikora@google.com>
parents:
6138
diff
changeset
|
684 len = u->url.len; |
651 | 685 |
6463
5df5d7d771f6
Core: allow strings without null-termination in ngx_parse_url().
Piotr Sikora <piotrsikora@google.com>
parents:
6138
diff
changeset
|
686 if (len >= 5 && ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) { |
2200 | 687 return ngx_parse_unix_domain_url(pool, u); |
651 | 688 } |
689 | |
6463
5df5d7d771f6
Core: allow strings without null-termination in ngx_parse_url().
Piotr Sikora <piotrsikora@google.com>
parents:
6138
diff
changeset
|
690 if (len && p[0] == '[') { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
691 return ngx_parse_inet6_url(pool, u); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
692 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
693 |
2200 | 694 return ngx_parse_inet_url(pool, u); |
695 } | |
696 | |
697 | |
698 static ngx_int_t | |
699 ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u) | |
700 { | |
701 #if (NGX_HAVE_UNIX_DOMAIN) | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
702 u_char *path, *uri, *last; |
2200 | 703 size_t len; |
704 struct sockaddr_un *saun; | |
705 | |
706 len = u->url.len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
707 path = u->url.data; |
2200 | 708 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
709 path += 5; |
2200 | 710 len -= 5; |
711 | |
712 if (u->uri_part) { | |
713 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
714 last = path + len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
715 uri = ngx_strlchr(path, last, ':'); |
2200 | 716 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
717 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
718 len = uri - path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
719 uri++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
720 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
721 u->uri.data = uri; |
2200 | 722 } |
723 } | |
724 | |
725 if (len == 0) { | |
726 u->err = "no path in the unix domain socket"; | |
727 return NGX_ERROR; | |
728 } | |
729 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
730 u->host.len = len++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
731 u->host.data = path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
732 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
733 if (len > sizeof(saun->sun_path)) { |
2200 | 734 u->err = "too long path in the unix domain socket"; |
735 return NGX_ERROR; | |
736 } | |
737 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
738 u->socklen = sizeof(struct sockaddr_un); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
739 saun = (struct sockaddr_un *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
740 saun->sun_family = AF_UNIX; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
741 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
742 |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
743 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
2200 | 744 if (u->addrs == NULL) { |
745 return NGX_ERROR; | |
746 } | |
747 | |
748 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un)); | |
749 if (saun == NULL) { | |
750 return NGX_ERROR; | |
751 } | |
752 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
753 u->family = AF_UNIX; |
2200 | 754 u->naddrs = 1; |
755 | |
756 saun->sun_family = AF_UNIX; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
757 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2200 | 758 |
759 u->addrs[0].sockaddr = (struct sockaddr *) saun; | |
760 u->addrs[0].socklen = sizeof(struct sockaddr_un); | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
761 u->addrs[0].name.len = len + 4; |
2200 | 762 u->addrs[0].name.data = u->url.data; |
763 | |
764 return NGX_OK; | |
765 | |
766 #else | |
767 | |
768 u->err = "the unix domain sockets are not supported on this platform"; | |
769 | |
770 return NGX_ERROR; | |
771 | |
772 #endif | |
773 } | |
774 | |
775 | |
776 static ngx_int_t | |
777 ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) | |
778 { | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
779 u_char *p, *host, *port, *last, *uri, *args; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
780 size_t len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
781 ngx_int_t n; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
782 struct sockaddr_in *sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
783 #if (NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
784 struct sockaddr_in6 *sin6; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
785 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
786 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
787 u->socklen = sizeof(struct sockaddr_in); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
788 sin = (struct sockaddr_in *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
789 sin->sin_family = AF_INET; |
2200 | 790 |
2206 | 791 u->family = AF_INET; |
792 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
793 host = u->url.data; |
2200 | 794 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
795 last = host + u->url.len; |
906 | 796 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
797 port = ngx_strlchr(host, last, ':'); |
651 | 798 |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
799 uri = ngx_strlchr(host, last, '/'); |
651 | 800 |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
801 args = ngx_strlchr(host, last, '?'); |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
802 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
803 if (args) { |
4652
215857d53cbe
Code reduction (no functional changes).
Ruslan Ermilov <ru@nginx.com>
parents:
4642
diff
changeset
|
804 if (uri == NULL || args < uri) { |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
805 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
806 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
807 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
808 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
809 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
810 if (u->listen || !u->uri_part) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
811 u->err = "invalid host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
812 return NGX_ERROR; |
651 | 813 } |
814 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
815 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
816 u->uri.data = uri; |
651 | 817 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
818 last = uri; |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
819 |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
820 if (uri < port) { |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
821 port = NULL; |
2301
148c2e840c2b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2284
diff
changeset
|
822 } |
651 | 823 } |
824 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
825 if (port) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
826 port++; |
651 | 827 |
2206 | 828 len = last - port; |
829 | |
830 n = ngx_atoi(port, len); | |
831 | |
4227 | 832 if (n < 1 || n > 65535) { |
2206 | 833 u->err = "invalid port"; |
834 return NGX_ERROR; | |
835 } | |
836 | |
837 u->port = (in_port_t) n; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
838 sin->sin_port = htons((in_port_t) n); |
2206 | 839 |
840 u->port_text.len = len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
841 u->port_text.data = port; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
842 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
843 last = port - 1; |
1671
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1647
diff
changeset
|
844 |
651 | 845 } else { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
846 if (uri == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
847 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
848 if (u->listen) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
849 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
850 /* test value as port only */ |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
851 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
852 n = ngx_atoi(host, last - host); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
853 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
854 if (n != NGX_ERROR) { |
651 | 855 |
4227 | 856 if (n < 1 || n > 65535) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
857 u->err = "invalid port"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
858 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
859 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
860 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
861 u->port = (in_port_t) n; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
862 sin->sin_port = htons((in_port_t) n); |
651 | 863 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
864 u->port_text.len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
865 u->port_text.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
866 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
867 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
868 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
869 return NGX_OK; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
870 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
871 } |
651 | 872 } |
873 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
874 u->no_port = 1; |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4983
diff
changeset
|
875 u->port = u->default_port; |
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4983
diff
changeset
|
876 sin->sin_port = htons(u->default_port); |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
877 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
878 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
879 len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
880 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
881 if (len == 0) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
882 u->err = "no host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
883 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
884 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
885 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
886 u->host.len = len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
887 u->host.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
888 |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
889 if (u->listen && len == 1 && *host == '*') { |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
890 sin->sin_addr.s_addr = INADDR_ANY; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
891 u->wildcard = 1; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
892 return NGX_OK; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
893 } |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
894 |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
895 sin->sin_addr.s_addr = ngx_inet_addr(host, len); |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
896 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
897 if (sin->sin_addr.s_addr != INADDR_NONE) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
898 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
899 if (sin->sin_addr.s_addr == INADDR_ANY) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
900 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
901 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
902 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
903 u->naddrs = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
904 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
905 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
906 if (u->addrs == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
907 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
908 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
909 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
910 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
911 if (sin == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
912 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
913 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
914 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6534
diff
changeset
|
915 ngx_memcpy(sin, &u->sockaddr, sizeof(struct sockaddr_in)); |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
916 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
917 u->addrs[0].sockaddr = (struct sockaddr *) sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
918 u->addrs[0].socklen = sizeof(struct sockaddr_in); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
919 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
920 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
921 if (p == NULL) { |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
922 return NGX_ERROR; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
923 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
924 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
925 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
926 &u->host, u->port) - p; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
927 u->addrs[0].name.data = p; |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
928 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
929 return NGX_OK; |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
930 } |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
931 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
932 if (u->no_resolve) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
933 return NGX_OK; |
906 | 934 } |
935 | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
936 if (ngx_inet_resolve_host(pool, u) != NGX_OK) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
937 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
938 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
939 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
940 u->family = u->addrs[0].sockaddr->sa_family; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
941 u->socklen = u->addrs[0].socklen; |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6534
diff
changeset
|
942 ngx_memcpy(&u->sockaddr, u->addrs[0].sockaddr, u->addrs[0].socklen); |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
943 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
944 switch (u->family) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
945 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
946 #if (NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
947 case AF_INET6: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
948 sin6 = (struct sockaddr_in6 *) &u->sockaddr; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
949 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
950 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
951 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
952 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
953 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
954 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
955 #endif |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
956 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
957 default: /* AF_INET */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
958 sin = (struct sockaddr_in *) &u->sockaddr; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
959 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
960 if (sin->sin_addr.s_addr == INADDR_ANY) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
961 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
962 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
963 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
964 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
965 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
966 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
967 return NGX_OK; |
651 | 968 } |
969 | |
970 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
971 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
972 ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
973 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
974 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
975 u_char *p, *host, *port, *last, *uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
976 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
977 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
978 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
979 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
980 u->socklen = sizeof(struct sockaddr_in6); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
981 sin6 = (struct sockaddr_in6 *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
982 sin6->sin6_family = AF_INET6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
983 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
984 host = u->url.data + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
985 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
986 last = u->url.data + u->url.len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
987 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
988 p = ngx_strlchr(host, last, ']'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
989 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
990 if (p == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
991 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
992 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
993 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
994 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
995 port = p + 1; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
996 |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
997 uri = ngx_strlchr(port, last, '/'); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
998 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
999 if (uri) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1000 if (u->listen || !u->uri_part) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1001 u->err = "invalid host"; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1002 return NGX_ERROR; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1003 } |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1004 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1005 u->uri.len = last - uri; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1006 u->uri.data = uri; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1007 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1008 last = uri; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1009 } |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1010 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1011 if (port < last) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1012 if (*port != ':') { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1013 u->err = "invalid host"; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1014 return NGX_ERROR; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1015 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1016 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1017 port++; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1018 |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1019 len = last - port; |
6533
b358d670c654
Core: fixed port handling in ngx_parse_inet6_url().
Valentin Bartenev <vbart@nginx.com>
parents:
6509
diff
changeset
|
1020 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1021 n = ngx_atoi(port, len); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1022 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1023 if (n < 1 || n > 65535) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1024 u->err = "invalid port"; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1025 return NGX_ERROR; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1026 } |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1027 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1028 u->port = (in_port_t) n; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1029 sin6->sin6_port = htons((in_port_t) n); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1030 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1031 u->port_text.len = len; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1032 u->port_text.data = port; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1033 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1034 } else { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1035 u->no_port = 1; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1036 u->port = u->default_port; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1037 sin6->sin6_port = htons(u->default_port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1038 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1039 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1040 len = p - host; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1041 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1042 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1043 u->err = "no host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1044 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1045 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1046 |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1047 u->host.len = len + 2; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1048 u->host.data = host - 1; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1049 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
1050 if (ngx_inet6_addr(host, len, sin6->sin6_addr.s6_addr) != NGX_OK) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1051 u->err = "invalid IPv6 address"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1052 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1053 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1054 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1055 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1056 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1057 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1058 |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1059 u->family = AF_INET6; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1060 u->naddrs = 1; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1061 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1062 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1063 if (u->addrs == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1064 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1065 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1066 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1067 sin6 = ngx_pcalloc(pool, sizeof(struct sockaddr_in6)); |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1068 if (sin6 == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1069 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1070 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1071 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6534
diff
changeset
|
1072 ngx_memcpy(sin6, &u->sockaddr, sizeof(struct sockaddr_in6)); |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1073 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1074 u->addrs[0].sockaddr = (struct sockaddr *) sin6; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1075 u->addrs[0].socklen = sizeof(struct sockaddr_in6); |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1076 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1077 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1078 if (p == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1079 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1080 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1081 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1082 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1083 &u->host, u->port) - p; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1084 u->addrs[0].name.data = p; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1085 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1086 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1087 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1088 #else |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1089 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1090 u->err = "the INET6 sockets are not supported on this platform"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1091 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1092 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1093 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1094 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1095 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1096 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1097 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1098 #if (NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1099 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1100 ngx_int_t |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1101 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1102 { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1103 u_char *p, *host; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1104 size_t len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1105 in_port_t port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1106 ngx_uint_t i; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1107 struct addrinfo hints, *res, *rp; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1108 struct sockaddr_in *sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1109 struct sockaddr_in6 *sin6; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1110 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1111 port = htons(u->port); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1112 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1113 host = ngx_alloc(u->host.len + 1, pool->log); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1114 if (host == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1115 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1116 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1117 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1118 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1119 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1120 ngx_memzero(&hints, sizeof(struct addrinfo)); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1121 hints.ai_family = AF_UNSPEC; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1122 hints.ai_socktype = SOCK_STREAM; |
5314
0300d97c6084
Core: guard use of AI_ADDRCONFIG.
Ruslan Ermilov <ru@nginx.com>
parents:
5313
diff
changeset
|
1123 #ifdef AI_ADDRCONFIG |
5312
ec8594b9bf11
Core: only resolve address families configured on the local system.
Ruslan Ermilov <ru@nginx.com>
parents:
5263
diff
changeset
|
1124 hints.ai_flags = AI_ADDRCONFIG; |
5314
0300d97c6084
Core: guard use of AI_ADDRCONFIG.
Ruslan Ermilov <ru@nginx.com>
parents:
5313
diff
changeset
|
1125 #endif |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1126 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1127 if (getaddrinfo((char *) host, NULL, &hints, &res) != 0) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1128 u->err = "host not found"; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1129 ngx_free(host); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1130 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1131 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1132 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1133 ngx_free(host); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1134 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1135 for (i = 0, rp = res; rp != NULL; rp = rp->ai_next) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1136 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1137 switch (rp->ai_family) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1138 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1139 case AF_INET: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1140 case AF_INET6: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1141 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1142 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1143 default: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1144 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1145 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1146 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1147 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1148 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1149 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1150 if (i == 0) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1151 u->err = "host not found"; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1152 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1153 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1154 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1155 /* MP: ngx_shared_palloc() */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1156 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1157 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t)); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1158 if (u->addrs == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1159 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1160 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1161 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1162 u->naddrs = i; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1163 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1164 i = 0; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1165 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1166 /* AF_INET addresses first */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1167 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1168 for (rp = res; rp != NULL; rp = rp->ai_next) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1169 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1170 if (rp->ai_family != AF_INET) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1171 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1172 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1173 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1174 sin = ngx_pcalloc(pool, rp->ai_addrlen); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1175 if (sin == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1176 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1177 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1178 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1179 ngx_memcpy(sin, rp->ai_addr, rp->ai_addrlen); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1180 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1181 sin->sin_port = port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1182 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1183 u->addrs[i].sockaddr = (struct sockaddr *) sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1184 u->addrs[i].socklen = rp->ai_addrlen; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1185 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1186 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1187 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1188 p = ngx_pnalloc(pool, len); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1189 if (p == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1190 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1191 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1192 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1193 len = ngx_sock_ntop((struct sockaddr *) sin, rp->ai_addrlen, p, len, 1); |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1194 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1195 u->addrs[i].name.len = len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1196 u->addrs[i].name.data = p; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1197 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1198 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1199 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1200 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1201 for (rp = res; rp != NULL; rp = rp->ai_next) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1202 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1203 if (rp->ai_family != AF_INET6) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1204 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1205 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1206 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1207 sin6 = ngx_pcalloc(pool, rp->ai_addrlen); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1208 if (sin6 == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1209 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1210 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1211 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1212 ngx_memcpy(sin6, rp->ai_addr, rp->ai_addrlen); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1213 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1214 sin6->sin6_port = port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1215 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1216 u->addrs[i].sockaddr = (struct sockaddr *) sin6; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1217 u->addrs[i].socklen = rp->ai_addrlen; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1218 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1219 len = NGX_INET6_ADDRSTRLEN + sizeof("[]:65535") - 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1220 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1221 p = ngx_pnalloc(pool, len); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1222 if (p == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1223 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1224 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1225 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1226 len = ngx_sock_ntop((struct sockaddr *) sin6, rp->ai_addrlen, p, |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1227 len, 1); |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1228 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1229 u->addrs[i].name.len = len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1230 u->addrs[i].name.data = p; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1231 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1232 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1233 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1234 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1235 freeaddrinfo(res); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1236 return NGX_OK; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1237 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1238 failed: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1239 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1240 freeaddrinfo(res); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1241 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1242 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1243 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1244 #else /* !NGX_HAVE_GETADDRINFO || !NGX_HAVE_INET6 */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1245 |
884 | 1246 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1247 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) |
651 | 1248 { |
906 | 1249 u_char *p, *host; |
651 | 1250 size_t len; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1251 in_port_t port; |
651 | 1252 in_addr_t in_addr; |
1253 ngx_uint_t i; | |
1254 struct hostent *h; | |
1255 struct sockaddr_in *sin; | |
1256 | |
1257 /* AF_INET only */ | |
1258 | |
2517
095f28fc0c4a
fix upstream port, introduced in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1259 port = htons(u->port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1260 |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1261 in_addr = ngx_inet_addr(u->host.data, u->host.len); |
651 | 1262 |
1263 if (in_addr == INADDR_NONE) { | |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1264 host = ngx_alloc(u->host.len + 1, pool->log); |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1265 if (host == NULL) { |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1266 return NGX_ERROR; |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1267 } |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1268 |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1269 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1270 |
651 | 1271 h = gethostbyname((char *) host); |
1272 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1273 ngx_free(host); |
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1274 |
651 | 1275 if (h == NULL || h->h_addr_list[0] == NULL) { |
884 | 1276 u->err = "host not found"; |
1277 return NGX_ERROR; | |
651 | 1278 } |
1279 | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1280 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } |
651 | 1281 |
1282 /* MP: ngx_shared_palloc() */ | |
1283 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
1284 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t)); |
884 | 1285 if (u->addrs == NULL) { |
1286 return NGX_ERROR; | |
651 | 1287 } |
1288 | |
884 | 1289 u->naddrs = i; |
651 | 1290 |
3864
8e77b5216894
fix u->one_addr handling in ngx_inet_resolve_host()
Igor Sysoev <igor@sysoev.ru>
parents:
3377
diff
changeset
|
1291 for (i = 0; i < u->naddrs; i++) { |
651 | 1292 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1293 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 1294 if (sin == NULL) { |
884 | 1295 return NGX_ERROR; |
651 | 1296 } |
1297 | |
1298 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1299 sin->sin_port = port; |
651 | 1300 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]); |
1301 | |
884 | 1302 u->addrs[i].sockaddr = (struct sockaddr *) sin; |
1303 u->addrs[i].socklen = sizeof(struct sockaddr_in); | |
651 | 1304 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1305 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
651 | 1306 |
2049 | 1307 p = ngx_pnalloc(pool, len); |
906 | 1308 if (p == NULL) { |
884 | 1309 return NGX_ERROR; |
651 | 1310 } |
1311 | |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1312 len = ngx_sock_ntop((struct sockaddr *) sin, |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1313 sizeof(struct sockaddr_in), p, len, 1); |
651 | 1314 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1315 u->addrs[i].name.len = len; |
906 | 1316 u->addrs[i].name.data = p; |
651 | 1317 } |
1318 | |
1319 } else { | |
1320 | |
1321 /* MP: ngx_shared_palloc() */ | |
1322 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
1323 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
884 | 1324 if (u->addrs == NULL) { |
1325 return NGX_ERROR; | |
651 | 1326 } |
1327 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1328 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 1329 if (sin == NULL) { |
884 | 1330 return NGX_ERROR; |
651 | 1331 } |
1332 | |
884 | 1333 u->naddrs = 1; |
651 | 1334 |
1335 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1336 sin->sin_port = port; |
651 | 1337 sin->sin_addr.s_addr = in_addr; |
1338 | |
884 | 1339 u->addrs[0].sockaddr = (struct sockaddr *) sin; |
1340 u->addrs[0].socklen = sizeof(struct sockaddr_in); | |
651 | 1341 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1342 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
906 | 1343 if (p == NULL) { |
884 | 1344 return NGX_ERROR; |
651 | 1345 } |
1346 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1347 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1348 &u->host, ntohs(port)) - p; |
906 | 1349 u->addrs[0].name.data = p; |
651 | 1350 } |
1351 | |
884 | 1352 return NGX_OK; |
651 | 1353 } |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1354 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1355 #endif /* NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6 */ |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1356 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1357 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1358 ngx_int_t |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1359 ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1, |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1360 struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1361 { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1362 struct sockaddr_in *sin1, *sin2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1363 #if (NGX_HAVE_INET6) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1364 struct sockaddr_in6 *sin61, *sin62; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1365 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1366 #if (NGX_HAVE_UNIX_DOMAIN) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1367 struct sockaddr_un *saun1, *saun2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1368 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1369 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1370 if (sa1->sa_family != sa2->sa_family) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1371 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1372 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1373 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1374 switch (sa1->sa_family) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1375 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1376 #if (NGX_HAVE_INET6) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1377 case AF_INET6: |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1378 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1379 sin61 = (struct sockaddr_in6 *) sa1; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1380 sin62 = (struct sockaddr_in6 *) sa2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1381 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1382 if (cmp_port && sin61->sin6_port != sin62->sin6_port) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1383 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1384 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1385 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1386 if (ngx_memcmp(&sin61->sin6_addr, &sin62->sin6_addr, 16) != 0) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1387 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1388 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1389 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1390 break; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1391 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1392 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1393 #if (NGX_HAVE_UNIX_DOMAIN) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1394 case AF_UNIX: |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1395 |
6474 | 1396 /* TODO length */ |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1397 |
6474 | 1398 saun1 = (struct sockaddr_un *) sa1; |
1399 saun2 = (struct sockaddr_un *) sa2; | |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1400 |
6474 | 1401 if (ngx_memcmp(&saun1->sun_path, &saun2->sun_path, |
1402 sizeof(saun1->sun_path)) | |
1403 != 0) | |
1404 { | |
1405 return NGX_DECLINED; | |
1406 } | |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1407 |
6474 | 1408 break; |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1409 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1410 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1411 default: /* AF_INET */ |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1412 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1413 sin1 = (struct sockaddr_in *) sa1; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1414 sin2 = (struct sockaddr_in *) sa2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1415 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1416 if (cmp_port && sin1->sin_port != sin2->sin_port) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1417 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1418 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1419 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1420 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1421 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1422 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1423 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1424 break; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1425 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1426 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1427 return NGX_OK; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1428 } |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1429 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1430 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1431 in_port_t |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1432 ngx_inet_get_port(struct sockaddr *sa) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1433 { |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1434 struct sockaddr_in *sin; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1435 #if (NGX_HAVE_INET6) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1436 struct sockaddr_in6 *sin6; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1437 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1438 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1439 switch (sa->sa_family) { |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1440 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1441 #if (NGX_HAVE_INET6) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1442 case AF_INET6: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1443 sin6 = (struct sockaddr_in6 *) sa; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1444 return ntohs(sin6->sin6_port); |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1445 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1446 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1447 #if (NGX_HAVE_UNIX_DOMAIN) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1448 case AF_UNIX: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1449 return 0; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1450 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1451 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1452 default: /* AF_INET */ |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1453 sin = (struct sockaddr_in *) sa; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1454 return ntohs(sin->sin_port); |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1455 } |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1456 } |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1457 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1458 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1459 void |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1460 ngx_inet_set_port(struct sockaddr *sa, in_port_t port) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1461 { |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1462 struct sockaddr_in *sin; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1463 #if (NGX_HAVE_INET6) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1464 struct sockaddr_in6 *sin6; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1465 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1466 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1467 switch (sa->sa_family) { |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1468 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1469 #if (NGX_HAVE_INET6) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1470 case AF_INET6: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1471 sin6 = (struct sockaddr_in6 *) sa; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1472 sin6->sin6_port = htons(port); |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1473 break; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1474 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1475 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1476 #if (NGX_HAVE_UNIX_DOMAIN) |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1477 case AF_UNIX: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1478 break; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1479 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1480 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1481 default: /* AF_INET */ |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1482 sin = (struct sockaddr_in *) sa; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1483 sin->sin_port = htons(port); |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1484 break; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1485 } |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1486 } |