Mercurial > hg > nginx-quic
annotate src/core/ngx_inet.c @ 7462:be2af41d3620
SSL: variables support in ssl_certificate and ssl_certificate_key.
To evaluate variables, a request is created in the certificate callback,
and then freed. To do this without side effects on the stub_status
counters and connection state, an additional function was introduced,
ngx_http_alloc_request().
Only works with OpenSSL 1.0.2+, since there is no SSL_CTX_set_cert_cb()
in older versions.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Feb 2019 16:42:05 +0300 |
parents | 935b1902a7dd |
children | 4f9b72a229c1 |
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; |
7122
935b1902a7dd
Fixed build without IPv6, broken by 874171c3c71a.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7120
diff
changeset
|
185 #if (NGX_HAVE_INET6 || NGX_HAVE_UNIX_DOMAIN) |
935b1902a7dd
Fixed build without IPv6, broken by 874171c3c71a.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7120
diff
changeset
|
186 size_t n; |
935b1902a7dd
Fixed build without IPv6, broken by 874171c3c71a.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7120
diff
changeset
|
187 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
188 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
189 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
190 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
191 #endif |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
192 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
193 struct sockaddr_un *saun; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
194 #endif |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
195 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
196 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
197 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
198 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
|
199 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
200 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
|
201 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
|
202 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
203 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
204 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
|
205 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
|
206 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
207 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
|
208 p[0], p[1], p[2], p[3]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
209 } |
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 return (p - text); |
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 #if (NGX_HAVE_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 case AF_INET6: |
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 sin6 = (struct sockaddr_in6 *) sa; |
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 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
220 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
221 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
222 text[n++] = '['; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
223 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
224 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
225 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
|
226 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
227 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
228 n = ngx_sprintf(&text[1 + n], "]:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
229 ntohs(sin6->sin6_port)) - text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
230 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
231 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
232 return n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
233 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
234 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
235 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
236 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
237 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
238 saun = (struct sockaddr_un *) sa; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
239 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
240 /* 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
|
241 |
5313
1fe5f7fb6ced
Fixed build with signed socklen_t and unix sockets.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5312
diff
changeset
|
242 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
|
243 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
|
244 |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
245 } else { |
7120
874171c3c71a
Fixed handling of non-null-terminated unix sockets.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6731
diff
changeset
|
246 n = ngx_strnlen((u_char *) saun->sun_path, |
874171c3c71a
Fixed handling of non-null-terminated unix sockets.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6731
diff
changeset
|
247 socklen - offsetof(struct sockaddr_un, sun_path)); |
874171c3c71a
Fixed handling of non-null-terminated unix sockets.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6731
diff
changeset
|
248 p = ngx_snprintf(text, len, "unix:%*s%Z", n, saun->sun_path); |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
249 } |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
250 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
251 /* we do not include trailing zero in address length */ |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
252 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
253 return (p - text - 1); |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
254 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
255 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
256 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
257 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
258 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
259 } |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
260 } |
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
261 |
1830 | 262 |
509 | 263 size_t |
264 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
|
265 { |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
266 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
|
267 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
268 switch (family) { |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
269 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
270 case AF_INET: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
271 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
272 p = addr; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
273 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
274 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
|
275 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
|
276 - text; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
277 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
278 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
279 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
280 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
281 return ngx_inet6_ntop(addr, text, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
282 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
283 #endif |
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 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
286 return 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
287 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
288 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
289 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
290 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
291 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
292 |
3276
beaf94f2f265
make ngx_inet6_ntop() non-static
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
293 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
294 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
|
295 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
296 u_char *dst; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
297 size_t max, n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
298 ngx_uint_t i, zero, last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
299 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
300 if (len < NGX_INET6_ADDRSTRLEN) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
301 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
302 } |
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
303 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
304 zero = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
305 last = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
306 max = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
307 n = 0; |
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 for (i = 0; i < 16; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
310 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
311 if (p[i] || p[i + 1]) { |
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 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
314 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
315 max = n; |
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 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
319 continue; |
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 if (n++ == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
323 last = i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
324 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
325 } |
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 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
328 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
329 max = n; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
332 dst = text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
333 n = 16; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
334 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
335 if (zero == 0) { |
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 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
|
338 || (max == 6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
339 || (max == 7 && p[14] != 0 && p[15] != 1)) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
340 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
341 n = 12; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
344 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
345 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
346 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
347 for (i = 0; i < n; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
348 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
349 if (i == zero) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
350 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
351 i += (max - 1) * 2; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
352 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
353 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
354 |
6509
7640d6c213e1
Removed redundant "u" format specifier.
Ruslan Ermilov <ru@nginx.com>
parents:
6481
diff
changeset
|
355 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
|
356 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
357 if (i < 14) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
358 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
359 } |
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 if (n == 12) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
363 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
|
364 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
365 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
366 return dst - text; |
1830 | 367 } |
368 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
369 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
370 |
1830 | 371 |
509 | 372 ngx_int_t |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
373 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
|
374 { |
3277 | 375 u_char *addr, *mask, *last; |
376 size_t len; | |
377 ngx_int_t shift; | |
378 #if (NGX_HAVE_INET6) | |
379 ngx_int_t rc; | |
380 ngx_uint_t s, i; | |
381 #endif | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
382 |
2202 | 383 addr = text->data; |
384 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
|
385 |
2202 | 386 mask = ngx_strlchr(addr, last, '/'); |
3277 | 387 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
|
388 |
3277 | 389 cidr->u.in.addr = ngx_inet_addr(addr, len); |
390 | |
391 if (cidr->u.in.addr != INADDR_NONE) { | |
392 cidr->family = AF_INET; | |
393 | |
394 if (mask == NULL) { | |
395 cidr->u.in.mask = 0xffffffff; | |
396 return NGX_OK; | |
397 } | |
2202 | 398 |
3277 | 399 #if (NGX_HAVE_INET6) |
400 } else if (ngx_inet6_addr(addr, len, cidr->u.in6.addr.s6_addr) == NGX_OK) { | |
401 cidr->family = AF_INET6; | |
402 | |
403 if (mask == NULL) { | |
404 ngx_memset(cidr->u.in6.mask.s6_addr, 0xff, 16); | |
405 return NGX_OK; | |
406 } | |
407 | |
408 #endif | |
409 } else { | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
410 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
411 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
412 |
2202 | 413 mask++; |
414 | |
415 shift = ngx_atoi(mask, last - mask); | |
416 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
|
417 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
418 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
419 |
3277 | 420 switch (cidr->family) { |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
421 |
3277 | 422 #if (NGX_HAVE_INET6) |
423 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
|
424 if (shift > 128) { |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
425 return NGX_ERROR; |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
426 } |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
427 |
3277 | 428 addr = cidr->u.in6.addr.s6_addr; |
429 mask = cidr->u.in6.mask.s6_addr; | |
430 rc = NGX_OK; | |
431 | |
432 for (i = 0; i < 16; i++) { | |
433 | |
434 s = (shift > 8) ? 8 : shift; | |
435 shift -= s; | |
436 | |
4582
a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
Ruslan Ermilov <ru@nginx.com>
parents:
4573
diff
changeset
|
437 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
|
438 |
3277 | 439 if (addr[i] != (addr[i] & mask[i])) { |
440 rc = NGX_DONE; | |
441 addr[i] &= mask[i]; | |
442 } | |
443 } | |
444 | |
445 return rc; | |
446 #endif | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
447 |
3277 | 448 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
|
449 if (shift > 32) { |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
450 return NGX_ERROR; |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
451 } |
3277 | 452 |
453 if (shift) { | |
4582
a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
Ruslan Ermilov <ru@nginx.com>
parents:
4573
diff
changeset
|
454 cidr->u.in.mask = htonl((uint32_t) (0xffffffffu << (32 - shift))); |
2202 | 455 |
3277 | 456 } else { |
457 /* x86 compilers use a shl instruction that shifts by modulo 32 */ | |
458 cidr->u.in.mask = 0; | |
459 } | |
460 | |
461 if (cidr->u.in.addr == (cidr->u.in.addr & cidr->u.in.mask)) { | |
2202 | 462 return NGX_OK; |
463 } | |
464 | |
3277 | 465 cidr->u.in.addr &= cidr->u.in.mask; |
466 | |
2202 | 467 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
|
468 } |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
469 } |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
470 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
471 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
472 ngx_int_t |
6683
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
473 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
|
474 { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
475 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
476 u_char *p; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
477 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
478 in_addr_t inaddr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
479 ngx_cidr_t *cidr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
480 ngx_uint_t family, i; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
481 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
482 ngx_uint_t n; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
483 struct in6_addr *inaddr6; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
484 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
485 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
486 #if (NGX_SUPPRESS_WARN) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
487 inaddr = 0; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
488 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
489 inaddr6 = NULL; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
490 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
491 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
492 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
493 family = sa->sa_family; |
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 (family == AF_INET) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
496 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
|
497 } |
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 (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
500 else if (family == AF_INET6) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
501 inaddr6 = &((struct sockaddr_in6 *) sa)->sin6_addr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
502 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
503 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
504 family = AF_INET; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
505 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
506 p = inaddr6->s6_addr; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
507 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
508 inaddr = p[12] << 24; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
509 inaddr += p[13] << 16; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
510 inaddr += p[14] << 8; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
511 inaddr += p[15]; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
512 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
513 inaddr = htonl(inaddr); |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
514 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
515 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
516 #endif |
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 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
|
519 if (cidr[i].family != family) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
520 goto next; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
521 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
522 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
523 switch (family) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
524 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
525 #if (NGX_HAVE_INET6) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
526 case AF_INET6: |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
527 for (n = 0; n < 16; n++) { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
528 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
|
529 != cidr[i].u.in6.addr.s6_addr[n]) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
530 { |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
531 goto next; |
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 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
534 break; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
535 #endif |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
536 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
537 #if (NGX_HAVE_UNIX_DOMAIN) |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
538 case AF_UNIX: |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
539 break; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
540 #endif |
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 default: /* AF_INET */ |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
543 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
|
544 goto next; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
545 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
546 break; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
547 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
548 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
549 return NGX_OK; |
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 next: |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
552 continue; |
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 return NGX_DECLINED; |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
556 } |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
557 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
558 |
b802b7e1d9bc
Core: introduced ngx_cidr_match() function.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6597
diff
changeset
|
559 ngx_int_t |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
560 ngx_parse_addr(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text, size_t len) |
3270 | 561 { |
562 in_addr_t inaddr; | |
563 ngx_uint_t family; | |
564 struct sockaddr_in *sin; | |
565 #if (NGX_HAVE_INET6) | |
566 struct in6_addr inaddr6; | |
567 struct sockaddr_in6 *sin6; | |
3277 | 568 |
569 /* | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
570 * prevent MSVC8 warning: |
3277 | 571 * potentially uninitialized local variable 'inaddr6' used |
572 */ | |
4983
2677c561127b
Properly initialize "struct in6_addr" with zeroes.
Ruslan Ermilov <ru@nginx.com>
parents:
4971
diff
changeset
|
573 ngx_memzero(&inaddr6, sizeof(struct in6_addr)); |
3270 | 574 #endif |
575 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
576 inaddr = ngx_inet_addr(text, len); |
3270 | 577 |
578 if (inaddr != INADDR_NONE) { | |
579 family = AF_INET; | |
580 len = sizeof(struct sockaddr_in); | |
581 | |
582 #if (NGX_HAVE_INET6) | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
583 } else if (ngx_inet6_addr(text, len, inaddr6.s6_addr) == NGX_OK) { |
3270 | 584 family = AF_INET6; |
585 len = sizeof(struct sockaddr_in6); | |
586 | |
587 #endif | |
588 } else { | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
589 return NGX_DECLINED; |
3270 | 590 } |
591 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
592 addr->sockaddr = ngx_pcalloc(pool, len); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
593 if (addr->sockaddr == NULL) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
594 return NGX_ERROR; |
3270 | 595 } |
596 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
597 addr->sockaddr->sa_family = (u_char) family; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
598 addr->socklen = len; |
3270 | 599 |
600 switch (family) { | |
601 | |
602 #if (NGX_HAVE_INET6) | |
603 case AF_INET6: | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
604 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
3270 | 605 ngx_memcpy(sin6->sin6_addr.s6_addr, inaddr6.s6_addr, 16); |
606 break; | |
607 #endif | |
608 | |
609 default: /* AF_INET */ | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
610 sin = (struct sockaddr_in *) addr->sockaddr; |
3270 | 611 sin->sin_addr.s_addr = inaddr; |
612 break; | |
613 } | |
614 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
615 return NGX_OK; |
3270 | 616 } |
617 | |
618 | |
651 | 619 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
|
620 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
|
621 size_t len) |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
622 { |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
623 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
|
624 size_t plen; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
625 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
|
626 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
627 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
|
628 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
629 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
|
630 return rc; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
631 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
632 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
633 last = text + len; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
634 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
635 #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
|
636 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
|
637 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
638 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
|
639 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
640 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
|
641 return NGX_DECLINED; |
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 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
644 text++; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
645 len -= 2; |
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 } else |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
648 #endif |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
649 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
650 { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
651 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
|
652 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
653 if (p == NULL) { |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
654 return NGX_DECLINED; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
655 } |
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 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
658 p++; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
659 plen = last - p; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
660 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
661 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
|
662 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
663 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
|
664 return NGX_DECLINED; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
665 } |
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 len -= plen + 1; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
668 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
669 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
|
670 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
671 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
|
672 return rc; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
673 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
674 |
6597 | 675 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
|
676 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
677 return NGX_OK; |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
678 } |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
679 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
680 |
19db5a6bc34e
Realip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6559
diff
changeset
|
681 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
682 ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u) |
651 | 683 { |
2200 | 684 u_char *p; |
6463
5df5d7d771f6
Core: allow strings without null-termination in ngx_parse_url().
Piotr Sikora <piotrsikora@google.com>
parents:
6138
diff
changeset
|
685 size_t len; |
651 | 686 |
687 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
|
688 len = u->url.len; |
651 | 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 >= 5 && ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) { |
2200 | 691 return ngx_parse_unix_domain_url(pool, u); |
651 | 692 } |
693 | |
6463
5df5d7d771f6
Core: allow strings without null-termination in ngx_parse_url().
Piotr Sikora <piotrsikora@google.com>
parents:
6138
diff
changeset
|
694 if (len && p[0] == '[') { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
695 return ngx_parse_inet6_url(pool, u); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
696 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
697 |
2200 | 698 return ngx_parse_inet_url(pool, u); |
699 } | |
700 | |
701 | |
702 static ngx_int_t | |
703 ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u) | |
704 { | |
705 #if (NGX_HAVE_UNIX_DOMAIN) | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
706 u_char *path, *uri, *last; |
2200 | 707 size_t len; |
708 struct sockaddr_un *saun; | |
709 | |
710 len = u->url.len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
711 path = u->url.data; |
2200 | 712 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
713 path += 5; |
2200 | 714 len -= 5; |
715 | |
716 if (u->uri_part) { | |
717 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
718 last = path + len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
719 uri = ngx_strlchr(path, last, ':'); |
2200 | 720 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
721 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
722 len = uri - path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
723 uri++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
724 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
725 u->uri.data = uri; |
2200 | 726 } |
727 } | |
728 | |
729 if (len == 0) { | |
730 u->err = "no path in the unix domain socket"; | |
731 return NGX_ERROR; | |
732 } | |
733 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
734 u->host.len = len++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
735 u->host.data = path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
736 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
737 if (len > sizeof(saun->sun_path)) { |
2200 | 738 u->err = "too long path in the unix domain socket"; |
739 return NGX_ERROR; | |
740 } | |
741 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
742 u->socklen = sizeof(struct sockaddr_un); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
743 saun = (struct sockaddr_un *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
744 saun->sun_family = AF_UNIX; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
745 (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
|
746 |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
747 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
2200 | 748 if (u->addrs == NULL) { |
749 return NGX_ERROR; | |
750 } | |
751 | |
752 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un)); | |
753 if (saun == NULL) { | |
754 return NGX_ERROR; | |
755 } | |
756 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
757 u->family = AF_UNIX; |
2200 | 758 u->naddrs = 1; |
759 | |
760 saun->sun_family = AF_UNIX; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
761 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2200 | 762 |
763 u->addrs[0].sockaddr = (struct sockaddr *) saun; | |
764 u->addrs[0].socklen = sizeof(struct sockaddr_un); | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
765 u->addrs[0].name.len = len + 4; |
2200 | 766 u->addrs[0].name.data = u->url.data; |
767 | |
768 return NGX_OK; | |
769 | |
770 #else | |
771 | |
772 u->err = "the unix domain sockets are not supported on this platform"; | |
773 | |
774 return NGX_ERROR; | |
775 | |
776 #endif | |
777 } | |
778 | |
779 | |
780 static ngx_int_t | |
781 ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) | |
782 { | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
783 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
|
784 size_t len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
785 ngx_int_t n; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
786 struct sockaddr_in *sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
787 #if (NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
788 struct sockaddr_in6 *sin6; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
789 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
790 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
791 u->socklen = sizeof(struct sockaddr_in); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
792 sin = (struct sockaddr_in *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
793 sin->sin_family = AF_INET; |
2200 | 794 |
2206 | 795 u->family = AF_INET; |
796 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
797 host = u->url.data; |
2200 | 798 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
799 last = host + u->url.len; |
906 | 800 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
801 port = ngx_strlchr(host, last, ':'); |
651 | 802 |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
803 uri = ngx_strlchr(host, last, '/'); |
651 | 804 |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
805 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
|
806 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
807 if (args) { |
4652
215857d53cbe
Code reduction (no functional changes).
Ruslan Ermilov <ru@nginx.com>
parents:
4642
diff
changeset
|
808 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
|
809 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
810 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
811 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
812 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
813 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
814 if (u->listen || !u->uri_part) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
815 u->err = "invalid host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
816 return NGX_ERROR; |
651 | 817 } |
818 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
819 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
820 u->uri.data = uri; |
651 | 821 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
822 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
|
823 |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
824 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
|
825 port = NULL; |
2301
148c2e840c2b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2284
diff
changeset
|
826 } |
651 | 827 } |
828 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
829 if (port) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
830 port++; |
651 | 831 |
2206 | 832 len = last - port; |
833 | |
834 n = ngx_atoi(port, len); | |
835 | |
4227 | 836 if (n < 1 || n > 65535) { |
2206 | 837 u->err = "invalid port"; |
838 return NGX_ERROR; | |
839 } | |
840 | |
841 u->port = (in_port_t) n; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
842 sin->sin_port = htons((in_port_t) n); |
2206 | 843 |
844 u->port_text.len = len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
845 u->port_text.data = port; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
846 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
847 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
|
848 |
651 | 849 } else { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
850 if (uri == NULL) { |
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 if (u->listen) { |
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 /* test value as port only */ |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
855 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
856 n = ngx_atoi(host, last - host); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
857 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
858 if (n != NGX_ERROR) { |
651 | 859 |
4227 | 860 if (n < 1 || n > 65535) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
861 u->err = "invalid port"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
862 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
863 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
864 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
865 u->port = (in_port_t) n; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
866 sin->sin_port = htons((in_port_t) n); |
651 | 867 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
868 u->port_text.len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
869 u->port_text.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
870 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
871 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
872 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
873 return NGX_OK; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
874 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
875 } |
651 | 876 } |
877 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
878 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
|
879 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
|
880 sin->sin_port = htons(u->default_port); |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
881 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
882 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
883 len = last - host; |
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 if (len == 0) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
886 u->err = "no host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
887 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
888 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
889 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
890 u->host.len = len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
891 u->host.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
892 |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
893 if (u->listen && len == 1 && *host == '*') { |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
894 sin->sin_addr.s_addr = INADDR_ANY; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
895 u->wildcard = 1; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
896 return NGX_OK; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
897 } |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
898 |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
899 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
|
900 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
901 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
|
902 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
903 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
|
904 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
905 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
906 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
907 u->naddrs = 1; |
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 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
|
910 if (u->addrs == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
911 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
912 } |
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 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
|
915 if (sin == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
916 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
917 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
918 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6534
diff
changeset
|
919 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
|
920 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
921 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
|
922 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
|
923 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
924 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
|
925 if (p == NULL) { |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
926 return NGX_ERROR; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
927 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
928 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
929 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
|
930 &u->host, u->port) - p; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
931 u->addrs[0].name.data = p; |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
932 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
933 return NGX_OK; |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
934 } |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
935 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
936 if (u->no_resolve) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
937 return NGX_OK; |
906 | 938 } |
939 | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
940 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
|
941 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
942 } |
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 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
|
945 u->socklen = u->addrs[0].socklen; |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6534
diff
changeset
|
946 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
|
947 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
948 switch (u->family) { |
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 (NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
951 case AF_INET6: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
952 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
|
953 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
954 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
|
955 u->wildcard = 1; |
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 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
958 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
959 #endif |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
960 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
961 default: /* AF_INET */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
962 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
|
963 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
964 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
|
965 u->wildcard = 1; |
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 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
968 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
969 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
970 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
971 return NGX_OK; |
651 | 972 } |
973 | |
974 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
975 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
976 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
|
977 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
978 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
979 u_char *p, *host, *port, *last, *uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
980 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
981 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
982 struct sockaddr_in6 *sin6; |
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 u->socklen = sizeof(struct sockaddr_in6); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
985 sin6 = (struct sockaddr_in6 *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
986 sin6->sin6_family = AF_INET6; |
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 host = u->url.data + 1; |
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 last = u->url.data + u->url.len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
991 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
992 p = ngx_strlchr(host, last, ']'); |
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 if (p == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
995 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
996 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
997 } |
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 port = p + 1; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1000 |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1001 uri = ngx_strlchr(port, last, '/'); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1002 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1003 if (uri) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1004 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
|
1005 u->err = "invalid host"; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1006 return NGX_ERROR; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1007 } |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1008 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1009 u->uri.len = last - uri; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1010 u->uri.data = uri; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1011 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1012 last = uri; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1013 } |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1014 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1015 if (port < last) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1016 if (*port != ':') { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1017 u->err = "invalid host"; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1018 return NGX_ERROR; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1019 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1020 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1021 port++; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1022 |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1023 len = last - port; |
6533
b358d670c654
Core: fixed port handling in ngx_parse_inet6_url().
Valentin Bartenev <vbart@nginx.com>
parents:
6509
diff
changeset
|
1024 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1025 n = ngx_atoi(port, len); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1026 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1027 if (n < 1 || n > 65535) { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1028 u->err = "invalid port"; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1029 return NGX_ERROR; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1030 } |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1031 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1032 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
|
1033 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
|
1034 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1035 u->port_text.len = len; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1036 u->port_text.data = port; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1037 |
6534
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1038 } else { |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1039 u->no_port = 1; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1040 u->port = u->default_port; |
19a54ba76c04
Removed a surplus condition from ngx_parse_inet6_url().
Ruslan Ermilov <ru@nginx.com>
parents:
6533
diff
changeset
|
1041 sin6->sin6_port = htons(u->default_port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1042 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1043 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1044 len = p - host; |
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 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1047 u->err = "no host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1048 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1049 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1050 |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1051 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
|
1052 u->host.data = host - 1; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1053 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
1054 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
|
1055 u->err = "invalid IPv6 address"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1056 return NGX_ERROR; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1059 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1060 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1061 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1062 |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1063 u->family = AF_INET6; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1064 u->naddrs = 1; |
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 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
|
1067 if (u->addrs == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1068 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1069 } |
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 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
|
1072 if (sin6 == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1073 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1074 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1075 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6534
diff
changeset
|
1076 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
|
1077 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1078 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
|
1079 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
|
1080 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1081 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
|
1082 if (p == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1083 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1084 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1085 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
1086 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
|
1087 &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
|
1088 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
|
1089 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1090 return NGX_OK; |
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 #else |
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 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
|
1095 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1096 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1097 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1098 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1099 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1100 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1101 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1102 #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
|
1103 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1104 ngx_int_t |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1105 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
|
1106 { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1107 u_char *p, *host; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1108 size_t len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1109 in_port_t port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1110 ngx_uint_t i; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1111 struct addrinfo hints, *res, *rp; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1112 struct sockaddr_in *sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1113 struct sockaddr_in6 *sin6; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1114 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1115 port = htons(u->port); |
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 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
|
1118 if (host == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1119 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1120 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1121 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1122 (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
|
1123 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1124 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
|
1125 hints.ai_family = AF_UNSPEC; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1126 hints.ai_socktype = SOCK_STREAM; |
5314
0300d97c6084
Core: guard use of AI_ADDRCONFIG.
Ruslan Ermilov <ru@nginx.com>
parents:
5313
diff
changeset
|
1127 #ifdef AI_ADDRCONFIG |
5312
ec8594b9bf11
Core: only resolve address families configured on the local system.
Ruslan Ermilov <ru@nginx.com>
parents:
5263
diff
changeset
|
1128 hints.ai_flags = AI_ADDRCONFIG; |
5314
0300d97c6084
Core: guard use of AI_ADDRCONFIG.
Ruslan Ermilov <ru@nginx.com>
parents:
5313
diff
changeset
|
1129 #endif |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1130 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1131 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
|
1132 u->err = "host not found"; |
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 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1135 } |
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 ngx_free(host); |
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 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
|
1140 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1141 switch (rp->ai_family) { |
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 case AF_INET: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1144 case AF_INET6: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1145 break; |
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 default: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1148 continue; |
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 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1151 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1152 } |
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 if (i == 0) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1155 u->err = "host not found"; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1156 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1157 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1158 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1159 /* MP: ngx_shared_palloc() */ |
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 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
|
1162 if (u->addrs == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1163 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1164 } |
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 u->naddrs = i; |
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 i = 0; |
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 /* AF_INET addresses first */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1171 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1172 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
|
1173 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1174 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
|
1175 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1176 } |
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 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
|
1179 if (sin == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1180 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1181 } |
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 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
|
1184 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1185 sin->sin_port = port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1186 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1187 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
|
1188 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
|
1189 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1190 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
|
1191 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1192 p = ngx_pnalloc(pool, len); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1193 if (p == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1194 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1195 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1196 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1197 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
|
1198 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1199 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
|
1200 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
|
1201 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1202 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1203 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1204 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1205 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
|
1206 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1207 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
|
1208 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1209 } |
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 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
|
1212 if (sin6 == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1213 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1214 } |
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 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
|
1217 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1218 sin6->sin6_port = port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1219 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1220 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
|
1221 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
|
1222 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1223 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
|
1224 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1225 p = ngx_pnalloc(pool, len); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1226 if (p == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1227 goto failed; |
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 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1230 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
|
1231 len, 1); |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1232 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1233 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
|
1234 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
|
1235 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1236 i++; |
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 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1239 freeaddrinfo(res); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1240 return NGX_OK; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1241 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1242 failed: |
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 freeaddrinfo(res); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1245 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1246 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1247 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1248 #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
|
1249 |
884 | 1250 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1251 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) |
651 | 1252 { |
906 | 1253 u_char *p, *host; |
651 | 1254 size_t len; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1255 in_port_t port; |
651 | 1256 in_addr_t in_addr; |
1257 ngx_uint_t i; | |
1258 struct hostent *h; | |
1259 struct sockaddr_in *sin; | |
1260 | |
1261 /* AF_INET only */ | |
1262 | |
2517
095f28fc0c4a
fix upstream port, introduced in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1263 port = htons(u->port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1264 |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1265 in_addr = ngx_inet_addr(u->host.data, u->host.len); |
651 | 1266 |
1267 if (in_addr == INADDR_NONE) { | |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1268 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
|
1269 if (host == NULL) { |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1270 return NGX_ERROR; |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1271 } |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1272 |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1273 (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
|
1274 |
651 | 1275 h = gethostbyname((char *) host); |
1276 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1277 ngx_free(host); |
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1278 |
651 | 1279 if (h == NULL || h->h_addr_list[0] == NULL) { |
884 | 1280 u->err = "host not found"; |
1281 return NGX_ERROR; | |
651 | 1282 } |
1283 | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1284 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } |
651 | 1285 |
1286 /* MP: ngx_shared_palloc() */ | |
1287 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
1288 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t)); |
884 | 1289 if (u->addrs == NULL) { |
1290 return NGX_ERROR; | |
651 | 1291 } |
1292 | |
884 | 1293 u->naddrs = i; |
651 | 1294 |
3864
8e77b5216894
fix u->one_addr handling in ngx_inet_resolve_host()
Igor Sysoev <igor@sysoev.ru>
parents:
3377
diff
changeset
|
1295 for (i = 0; i < u->naddrs; i++) { |
651 | 1296 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1297 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 1298 if (sin == NULL) { |
884 | 1299 return NGX_ERROR; |
651 | 1300 } |
1301 | |
1302 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1303 sin->sin_port = port; |
651 | 1304 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]); |
1305 | |
884 | 1306 u->addrs[i].sockaddr = (struct sockaddr *) sin; |
1307 u->addrs[i].socklen = sizeof(struct sockaddr_in); | |
651 | 1308 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1309 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
651 | 1310 |
2049 | 1311 p = ngx_pnalloc(pool, len); |
906 | 1312 if (p == NULL) { |
884 | 1313 return NGX_ERROR; |
651 | 1314 } |
1315 | |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5005
diff
changeset
|
1316 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
|
1317 sizeof(struct sockaddr_in), p, len, 1); |
651 | 1318 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1319 u->addrs[i].name.len = len; |
906 | 1320 u->addrs[i].name.data = p; |
651 | 1321 } |
1322 | |
1323 } else { | |
1324 | |
1325 /* MP: ngx_shared_palloc() */ | |
1326 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
1327 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
884 | 1328 if (u->addrs == NULL) { |
1329 return NGX_ERROR; | |
651 | 1330 } |
1331 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1332 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 1333 if (sin == NULL) { |
884 | 1334 return NGX_ERROR; |
651 | 1335 } |
1336 | |
884 | 1337 u->naddrs = 1; |
651 | 1338 |
1339 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1340 sin->sin_port = port; |
651 | 1341 sin->sin_addr.s_addr = in_addr; |
1342 | |
884 | 1343 u->addrs[0].sockaddr = (struct sockaddr *) sin; |
1344 u->addrs[0].socklen = sizeof(struct sockaddr_in); | |
651 | 1345 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1346 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
906 | 1347 if (p == NULL) { |
884 | 1348 return NGX_ERROR; |
651 | 1349 } |
1350 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1351 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
|
1352 &u->host, ntohs(port)) - p; |
906 | 1353 u->addrs[0].name.data = p; |
651 | 1354 } |
1355 | |
884 | 1356 return NGX_OK; |
651 | 1357 } |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1358 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1359 #endif /* NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6 */ |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1360 |
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 ngx_int_t |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1363 ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1, |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1364 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
|
1365 { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1366 struct sockaddr_in *sin1, *sin2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1367 #if (NGX_HAVE_INET6) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1368 struct sockaddr_in6 *sin61, *sin62; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1369 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1370 #if (NGX_HAVE_UNIX_DOMAIN) |
6731
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1371 size_t len; |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1372 struct sockaddr_un *saun1, *saun2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1373 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1374 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1375 if (sa1->sa_family != sa2->sa_family) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1376 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1377 } |
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 switch (sa1->sa_family) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1380 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1381 #if (NGX_HAVE_INET6) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1382 case AF_INET6: |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1383 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1384 sin61 = (struct sockaddr_in6 *) sa1; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1385 sin62 = (struct sockaddr_in6 *) sa2; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1386 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1387 if (cmp_port && sin61->sin6_port != sin62->sin6_port) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1388 return NGX_DECLINED; |
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 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1391 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
|
1392 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1393 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1394 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1395 break; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1396 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1397 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1398 #if (NGX_HAVE_UNIX_DOMAIN) |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1399 case AF_UNIX: |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1400 |
6474 | 1401 saun1 = (struct sockaddr_un *) sa1; |
1402 saun2 = (struct sockaddr_un *) sa2; | |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1403 |
6731
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1404 if (slen1 < slen2) { |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1405 len = slen1 - offsetof(struct sockaddr_un, sun_path); |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1406 |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1407 } else { |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1408 len = slen2 - offsetof(struct sockaddr_un, sun_path); |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1409 } |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1410 |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1411 if (len > sizeof(saun1->sun_path)) { |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1412 len = sizeof(saun1->sun_path); |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1413 } |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1414 |
3f94a0fc05cf
Core: sockaddr lengths now respected by ngx_cmp_sockaddr().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6683
diff
changeset
|
1415 if (ngx_memcmp(&saun1->sun_path, &saun2->sun_path, len) != 0) { |
6474 | 1416 return NGX_DECLINED; |
1417 } | |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1418 |
6474 | 1419 break; |
5473
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1420 #endif |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1421 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1422 default: /* AF_INET */ |
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 sin1 = (struct sockaddr_in *) sa1; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1425 sin2 = (struct sockaddr_in *) sa2; |
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 if (cmp_port && sin1->sin_port != sin2->sin_port) { |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1428 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1429 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1430 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1431 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
|
1432 return NGX_DECLINED; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1433 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1434 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1435 break; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1436 } |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1437 |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1438 return NGX_OK; |
d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
Ruslan Ermilov <ru@nginx.com>
parents:
5314
diff
changeset
|
1439 } |
6593
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 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1442 in_port_t |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1443 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
|
1444 { |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1445 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
|
1446 #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
|
1447 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
|
1448 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1449 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1450 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
|
1451 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1452 #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
|
1453 case AF_INET6: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1454 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
|
1455 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
|
1456 #endif |
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 #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
|
1459 case AF_UNIX: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1460 return 0; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1461 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1462 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1463 default: /* AF_INET */ |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1464 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
|
1465 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
|
1466 } |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1467 } |
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 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1470 void |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1471 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
|
1472 { |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1473 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
|
1474 #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
|
1475 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
|
1476 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1477 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1478 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
|
1479 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1480 #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
|
1481 case AF_INET6: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1482 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
|
1483 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
|
1484 break; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1485 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1486 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1487 #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
|
1488 case AF_UNIX: |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1489 break; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1490 #endif |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1491 |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1492 default: /* AF_INET */ |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1493 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
|
1494 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
|
1495 break; |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1496 } |
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6567
diff
changeset
|
1497 } |