Mercurial > hg > nginx-quic
annotate src/core/ngx_inet.c @ 5142:afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 27 Mar 2013 15:18:34 +0000 |
parents | c9059bd5445b |
children | 05ba5bce31e0 |
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 | |
30 c = *p; | |
31 | |
32 if (c >= '0' && c <= '9') { | |
33 octet = octet * 10 + (c - '0'); | |
34 continue; | |
35 } | |
36 | |
37 if (c == '.' && octet < 256) { | |
38 addr = (addr << 8) + octet; | |
39 octet = 0; | |
40 n++; | |
41 continue; | |
42 } | |
43 | |
44 return INADDR_NONE; | |
45 } | |
46 | |
4584
3d51fa5a110d
Reduced the number of lines of code in ngx_inet_addr().
Ruslan Ermilov <ru@nginx.com>
parents:
4582
diff
changeset
|
47 if (n == 3 && octet < 256) { |
1647 | 48 addr = (addr << 8) + octet; |
49 return htonl(addr); | |
50 } | |
51 | |
52 return INADDR_NONE; | |
53 } | |
54 | |
55 | |
3265 | 56 #if (NGX_HAVE_INET6) |
57 | |
58 ngx_int_t | |
59 ngx_inet6_addr(u_char *p, size_t len, u_char *addr) | |
60 { | |
61 u_char c, *zero, *digit, *s, *d; | |
62 size_t len4; | |
63 ngx_uint_t n, nibbles, word; | |
64 | |
65 if (len == 0) { | |
66 return NGX_ERROR; | |
67 } | |
68 | |
69 zero = NULL; | |
70 digit = NULL; | |
71 len4 = 0; | |
72 nibbles = 0; | |
73 word = 0; | |
74 n = 8; | |
75 | |
76 if (p[0] == ':') { | |
77 p++; | |
78 len--; | |
79 } | |
80 | |
81 for (/* void */; len; len--) { | |
82 c = *p++; | |
83 | |
84 if (c == ':') { | |
85 if (nibbles) { | |
86 digit = p; | |
87 len4 = len; | |
88 *addr++ = (u_char) (word >> 8); | |
89 *addr++ = (u_char) (word & 0xff); | |
90 | |
91 if (--n) { | |
92 nibbles = 0; | |
93 word = 0; | |
94 continue; | |
95 } | |
96 | |
97 } else { | |
98 if (zero == NULL) { | |
99 digit = p; | |
100 len4 = len; | |
101 zero = addr; | |
102 continue; | |
103 } | |
104 } | |
105 | |
106 return NGX_ERROR; | |
107 } | |
108 | |
109 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
|
110 if (n < 2 || digit == NULL) { |
3265 | 111 return NGX_ERROR; |
112 } | |
113 | |
114 word = ngx_inet_addr(digit, len4 - 1); | |
115 if (word == INADDR_NONE) { | |
116 return NGX_ERROR; | |
117 } | |
118 | |
119 word = ntohl(word); | |
120 *addr++ = (u_char) ((word >> 24) & 0xff); | |
121 *addr++ = (u_char) ((word >> 16) & 0xff); | |
122 n--; | |
123 break; | |
124 } | |
125 | |
126 if (++nibbles > 4) { | |
127 return NGX_ERROR; | |
128 } | |
129 | |
130 if (c >= '0' && c <= '9') { | |
131 word = word * 16 + (c - '0'); | |
132 continue; | |
133 } | |
134 | |
135 c |= 0x20; | |
136 | |
137 if (c >= 'a' && c <= 'f') { | |
138 word = word * 16 + (c - 'a') + 10; | |
139 continue; | |
140 } | |
141 | |
142 return NGX_ERROR; | |
143 } | |
144 | |
145 if (nibbles == 0 && zero == NULL) { | |
146 return NGX_ERROR; | |
147 } | |
148 | |
149 *addr++ = (u_char) (word >> 8); | |
150 *addr++ = (u_char) (word & 0xff); | |
151 | |
152 if (--n) { | |
153 if (zero) { | |
154 n *= 2; | |
155 s = addr - 1; | |
156 d = s + n; | |
157 while (s >= zero) { | |
158 *d-- = *s--; | |
159 } | |
160 ngx_memzero(zero, n); | |
161 return NGX_OK; | |
162 } | |
163 | |
164 } else { | |
165 if (zero == NULL) { | |
166 return NGX_OK; | |
167 } | |
168 } | |
169 | |
170 return NGX_ERROR; | |
171 } | |
172 | |
173 #endif | |
174 | |
175 | |
509 | 176 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
177 ngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len, 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
|
178 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
179 u_char *p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
180 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
181 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
182 size_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
183 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
184 #endif |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
185 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
186 struct sockaddr_un *saun; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
187 #endif |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
188 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
189 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
190 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
191 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
|
192 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
193 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
|
194 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
|
195 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
196 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
197 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
|
198 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
|
199 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
200 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
|
201 p[0], p[1], p[2], p[3]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
202 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
203 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
204 return (p - text); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
205 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
206 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
207 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
208 case AF_INET6: |
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 sin6 = (struct sockaddr_in6 *) sa; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
211 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
212 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
213 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
214 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
215 text[n++] = '['; |
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 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
218 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
|
219 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
220 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
221 n = ngx_sprintf(&text[1 + n], "]:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
222 ntohs(sin6->sin6_port)) - text; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
225 return n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
226 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
227 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
228 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
229 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
230 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
231 saun = (struct sockaddr_un *) sa; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
232 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
233 /* we do not include trailing zero in address length */ |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
234 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
235 return ngx_snprintf(text, len, "unix:%s%Z", saun->sun_path) - text - 1; |
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 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
238 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
239 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
240 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
241 } |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
242 } |
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
243 |
1830 | 244 |
509 | 245 size_t |
246 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
|
247 { |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
248 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
|
249 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
250 switch (family) { |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
251 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
252 case AF_INET: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
253 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
254 p = addr; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
255 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
256 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
|
257 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
|
258 - text; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
259 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
260 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
261 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
262 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
263 return ngx_inet6_ntop(addr, text, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
264 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
265 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
266 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
267 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
268 return 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
269 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
270 } |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
273 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
274 |
3276
beaf94f2f265
make ngx_inet6_ntop() non-static
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
275 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
276 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
|
277 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
278 u_char *dst; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
279 size_t max, n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
280 ngx_uint_t i, zero, last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
281 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
282 if (len < NGX_INET6_ADDRSTRLEN) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
283 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
284 } |
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
285 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
286 zero = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
287 last = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
288 max = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
289 n = 0; |
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 for (i = 0; i < 16; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
292 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
293 if (p[i] || p[i + 1]) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
294 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
295 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
296 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
297 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
298 } |
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 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
301 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
302 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
303 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
304 if (n++ == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
305 last = i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
306 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
307 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
308 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
309 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
310 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
311 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
312 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
313 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
314 dst = text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
315 n = 16; |
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 if (zero == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
318 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
319 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
|
320 || (max == 6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
321 || (max == 7 && p[14] != 0 && p[15] != 1)) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
322 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
323 n = 12; |
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 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
327 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
328 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
329 for (i = 0; i < n; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
330 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
331 if (i == zero) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
332 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
333 i += (max - 1) * 2; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
334 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
335 } |
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 dst = ngx_sprintf(dst, "%uxi", p[i] * 256 + p[i + 1]); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
338 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
339 if (i < 14) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
340 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
341 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
342 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
343 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
344 if (n == 12) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
345 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
|
346 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
347 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
348 return dst - text; |
1830 | 349 } |
350 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
351 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
352 |
1830 | 353 |
509 | 354 ngx_int_t |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
355 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
|
356 { |
3277 | 357 u_char *addr, *mask, *last; |
358 size_t len; | |
359 ngx_int_t shift; | |
360 #if (NGX_HAVE_INET6) | |
361 ngx_int_t rc; | |
362 ngx_uint_t s, i; | |
363 #endif | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
364 |
2202 | 365 addr = text->data; |
366 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
|
367 |
2202 | 368 mask = ngx_strlchr(addr, last, '/'); |
3277 | 369 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
|
370 |
3277 | 371 cidr->u.in.addr = ngx_inet_addr(addr, len); |
372 | |
373 if (cidr->u.in.addr != INADDR_NONE) { | |
374 cidr->family = AF_INET; | |
375 | |
376 if (mask == NULL) { | |
377 cidr->u.in.mask = 0xffffffff; | |
378 return NGX_OK; | |
379 } | |
2202 | 380 |
3277 | 381 #if (NGX_HAVE_INET6) |
382 } else if (ngx_inet6_addr(addr, len, cidr->u.in6.addr.s6_addr) == NGX_OK) { | |
383 cidr->family = AF_INET6; | |
384 | |
385 if (mask == NULL) { | |
386 ngx_memset(cidr->u.in6.mask.s6_addr, 0xff, 16); | |
387 return NGX_OK; | |
388 } | |
389 | |
390 #endif | |
391 } else { | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
392 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
393 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
394 |
2202 | 395 mask++; |
396 | |
397 shift = ngx_atoi(mask, last - mask); | |
398 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
|
399 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
400 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
401 |
3277 | 402 switch (cidr->family) { |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
403 |
3277 | 404 #if (NGX_HAVE_INET6) |
405 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
|
406 if (shift > 128) { |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
407 return NGX_ERROR; |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
408 } |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
409 |
3277 | 410 addr = cidr->u.in6.addr.s6_addr; |
411 mask = cidr->u.in6.mask.s6_addr; | |
412 rc = NGX_OK; | |
413 | |
414 for (i = 0; i < 16; i++) { | |
415 | |
416 s = (shift > 8) ? 8 : shift; | |
417 shift -= s; | |
418 | |
4582
a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
Ruslan Ermilov <ru@nginx.com>
parents:
4573
diff
changeset
|
419 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
|
420 |
3277 | 421 if (addr[i] != (addr[i] & mask[i])) { |
422 rc = NGX_DONE; | |
423 addr[i] &= mask[i]; | |
424 } | |
425 } | |
426 | |
427 return rc; | |
428 #endif | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
429 |
3277 | 430 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
|
431 if (shift > 32) { |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
432 return NGX_ERROR; |
98a2518a98dc
In ngx_ptocidr(), check that the supplied prefix length is within
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
433 } |
3277 | 434 |
435 if (shift) { | |
4582
a8881886a5f7
Improved readability of the code that produces bitmask from prefix.
Ruslan Ermilov <ru@nginx.com>
parents:
4573
diff
changeset
|
436 cidr->u.in.mask = htonl((uint32_t) (0xffffffffu << (32 - shift))); |
2202 | 437 |
3277 | 438 } else { |
439 /* x86 compilers use a shl instruction that shifts by modulo 32 */ | |
440 cidr->u.in.mask = 0; | |
441 } | |
442 | |
443 if (cidr->u.in.addr == (cidr->u.in.addr & cidr->u.in.mask)) { | |
2202 | 444 return NGX_OK; |
445 } | |
446 | |
3277 | 447 cidr->u.in.addr &= cidr->u.in.mask; |
448 | |
2202 | 449 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
|
450 } |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
451 } |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
452 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
453 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
454 ngx_int_t |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
455 ngx_parse_addr(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text, size_t len) |
3270 | 456 { |
457 in_addr_t inaddr; | |
458 ngx_uint_t family; | |
459 struct sockaddr_in *sin; | |
460 #if (NGX_HAVE_INET6) | |
461 struct in6_addr inaddr6; | |
462 struct sockaddr_in6 *sin6; | |
3277 | 463 |
464 /* | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
465 * prevent MSVC8 warning: |
3277 | 466 * potentially uninitialized local variable 'inaddr6' used |
467 */ | |
4983
2677c561127b
Properly initialize "struct in6_addr" with zeroes.
Ruslan Ermilov <ru@nginx.com>
parents:
4971
diff
changeset
|
468 ngx_memzero(&inaddr6, sizeof(struct in6_addr)); |
3270 | 469 #endif |
470 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
471 inaddr = ngx_inet_addr(text, len); |
3270 | 472 |
473 if (inaddr != INADDR_NONE) { | |
474 family = AF_INET; | |
475 len = sizeof(struct sockaddr_in); | |
476 | |
477 #if (NGX_HAVE_INET6) | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
478 } else if (ngx_inet6_addr(text, len, inaddr6.s6_addr) == NGX_OK) { |
3270 | 479 family = AF_INET6; |
480 len = sizeof(struct sockaddr_in6); | |
481 | |
482 #endif | |
483 } else { | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
484 return NGX_DECLINED; |
3270 | 485 } |
486 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
487 addr->sockaddr = ngx_pcalloc(pool, len); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
488 if (addr->sockaddr == NULL) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
489 return NGX_ERROR; |
3270 | 490 } |
491 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
492 addr->sockaddr->sa_family = (u_char) family; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
493 addr->socklen = len; |
3270 | 494 |
495 switch (family) { | |
496 | |
497 #if (NGX_HAVE_INET6) | |
498 case AF_INET6: | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
499 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
3270 | 500 ngx_memcpy(sin6->sin6_addr.s6_addr, inaddr6.s6_addr, 16); |
501 break; | |
502 #endif | |
503 | |
504 default: /* AF_INET */ | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
505 sin = (struct sockaddr_in *) addr->sockaddr; |
3270 | 506 sin->sin_addr.s_addr = inaddr; |
507 break; | |
508 } | |
509 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
510 return NGX_OK; |
3270 | 511 } |
512 | |
513 | |
651 | 514 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
515 ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u) |
651 | 516 { |
2200 | 517 u_char *p; |
651 | 518 |
519 p = u->url.data; | |
520 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
906
diff
changeset
|
521 if (ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) { |
2200 | 522 return ngx_parse_unix_domain_url(pool, u); |
651 | 523 } |
524 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
525 if (p[0] == '[') { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
526 return ngx_parse_inet6_url(pool, u); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
527 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
528 |
2200 | 529 return ngx_parse_inet_url(pool, u); |
530 } | |
531 | |
532 | |
533 static ngx_int_t | |
534 ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u) | |
535 { | |
536 #if (NGX_HAVE_UNIX_DOMAIN) | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
537 u_char *path, *uri, *last; |
2200 | 538 size_t len; |
539 struct sockaddr_un *saun; | |
540 | |
541 len = u->url.len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
542 path = u->url.data; |
2200 | 543 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
544 path += 5; |
2200 | 545 len -= 5; |
546 | |
547 if (u->uri_part) { | |
548 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
549 last = path + len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
550 uri = ngx_strlchr(path, last, ':'); |
2200 | 551 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
552 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
553 len = uri - path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
554 uri++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
555 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
556 u->uri.data = uri; |
2200 | 557 } |
558 } | |
559 | |
560 if (len == 0) { | |
561 u->err = "no path in the unix domain socket"; | |
562 return NGX_ERROR; | |
563 } | |
564 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
565 u->host.len = len++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
566 u->host.data = path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
567 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
568 if (len > sizeof(saun->sun_path)) { |
2200 | 569 u->err = "too long path in the unix domain socket"; |
570 return NGX_ERROR; | |
571 } | |
572 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
573 u->socklen = sizeof(struct sockaddr_un); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
574 saun = (struct sockaddr_un *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
575 saun->sun_family = AF_UNIX; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
576 (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
|
577 |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
578 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
2200 | 579 if (u->addrs == NULL) { |
580 return NGX_ERROR; | |
581 } | |
582 | |
583 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un)); | |
584 if (saun == NULL) { | |
585 return NGX_ERROR; | |
586 } | |
587 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
588 u->family = AF_UNIX; |
2200 | 589 u->naddrs = 1; |
590 | |
591 saun->sun_family = AF_UNIX; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
592 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2200 | 593 |
594 u->addrs[0].sockaddr = (struct sockaddr *) saun; | |
595 u->addrs[0].socklen = sizeof(struct sockaddr_un); | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
596 u->addrs[0].name.len = len + 4; |
2200 | 597 u->addrs[0].name.data = u->url.data; |
598 | |
599 return NGX_OK; | |
600 | |
601 #else | |
602 | |
603 u->err = "the unix domain sockets are not supported on this platform"; | |
604 | |
605 return NGX_ERROR; | |
606 | |
607 #endif | |
608 } | |
609 | |
610 | |
611 static ngx_int_t | |
612 ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) | |
613 { | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
614 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
|
615 size_t len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
616 ngx_int_t n; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
617 struct sockaddr_in *sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
618 #if (NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
619 struct sockaddr_in6 *sin6; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
620 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
621 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
622 u->socklen = sizeof(struct sockaddr_in); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
623 sin = (struct sockaddr_in *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
624 sin->sin_family = AF_INET; |
2200 | 625 |
2206 | 626 u->family = AF_INET; |
627 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
628 host = u->url.data; |
2200 | 629 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
630 last = host + u->url.len; |
906 | 631 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
632 port = ngx_strlchr(host, last, ':'); |
651 | 633 |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
634 uri = ngx_strlchr(host, last, '/'); |
651 | 635 |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
636 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
|
637 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
638 if (args) { |
4652
215857d53cbe
Code reduction (no functional changes).
Ruslan Ermilov <ru@nginx.com>
parents:
4642
diff
changeset
|
639 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
|
640 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
641 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
642 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
643 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
644 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
645 if (u->listen || !u->uri_part) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
646 u->err = "invalid host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
647 return NGX_ERROR; |
651 | 648 } |
649 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
650 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
651 u->uri.data = uri; |
651 | 652 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
653 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
|
654 |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
655 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
|
656 port = NULL; |
2301
148c2e840c2b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2284
diff
changeset
|
657 } |
651 | 658 } |
659 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
660 if (port) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
661 port++; |
651 | 662 |
2206 | 663 len = last - port; |
664 | |
665 n = ngx_atoi(port, len); | |
666 | |
4227 | 667 if (n < 1 || n > 65535) { |
2206 | 668 u->err = "invalid port"; |
669 return NGX_ERROR; | |
670 } | |
671 | |
672 u->port = (in_port_t) n; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
673 sin->sin_port = htons((in_port_t) n); |
2206 | 674 |
675 u->port_text.len = len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
676 u->port_text.data = port; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
677 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
678 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
|
679 |
651 | 680 } else { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
681 if (uri == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
682 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
683 if (u->listen) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
684 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
685 /* test value as port only */ |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
686 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
687 n = ngx_atoi(host, last - host); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
688 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
689 if (n != NGX_ERROR) { |
651 | 690 |
4227 | 691 if (n < 1 || n > 65535) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
692 u->err = "invalid port"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
693 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
694 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
695 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
696 u->port = (in_port_t) n; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
697 sin->sin_port = htons((in_port_t) n); |
651 | 698 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
699 u->port_text.len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
700 u->port_text.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
701 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
702 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
703 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
704 return NGX_OK; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
705 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
706 } |
651 | 707 } |
708 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
709 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
|
710 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
|
711 sin->sin_port = htons(u->default_port); |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
712 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
713 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
714 len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
715 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
716 if (len == 0) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
717 u->err = "no host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
718 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
719 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
720 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
721 u->host.len = len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
722 u->host.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
723 |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
724 if (u->listen && len == 1 && *host == '*') { |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
725 sin->sin_addr.s_addr = INADDR_ANY; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
726 u->wildcard = 1; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
727 return NGX_OK; |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
728 } |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
729 |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
730 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
|
731 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
732 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
|
733 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
734 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
|
735 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
736 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
737 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
738 u->naddrs = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
739 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
740 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
|
741 if (u->addrs == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
742 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
743 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
744 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
745 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
|
746 if (sin == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
747 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
748 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
749 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
750 ngx_memcpy(sin, u->sockaddr, sizeof(struct sockaddr_in)); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
751 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
752 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
|
753 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
|
754 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
755 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
|
756 if (p == NULL) { |
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
757 return NGX_ERROR; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
758 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
759 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
760 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
|
761 &u->host, u->port) - p; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
762 u->addrs[0].name.data = p; |
4969
2efa05bbbc1e
Simplified URL parsing code.
Ruslan Ermilov <ru@nginx.com>
parents:
4670
diff
changeset
|
763 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
764 return NGX_OK; |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
765 } |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
766 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
767 if (u->no_resolve) { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
768 return NGX_OK; |
906 | 769 } |
770 | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
771 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
|
772 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
773 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
774 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
775 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
|
776 u->socklen = u->addrs[0].socklen; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
777 ngx_memcpy(u->sockaddr, u->addrs[0].sockaddr, u->addrs[0].socklen); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
778 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
779 switch (u->family) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
780 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
781 #if (NGX_HAVE_INET6) |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
782 case AF_INET6: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
783 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
|
784 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
785 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
|
786 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
787 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
788 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
789 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
790 #endif |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
791 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
792 default: /* AF_INET */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
793 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
|
794 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
795 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
|
796 u->wildcard = 1; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
797 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
798 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
799 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
800 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
801 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
802 return NGX_OK; |
651 | 803 } |
804 | |
805 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
806 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
807 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
|
808 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
809 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
810 u_char *p, *host, *port, *last, *uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
811 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
812 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
813 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
814 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
815 u->socklen = sizeof(struct sockaddr_in6); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
816 sin6 = (struct sockaddr_in6 *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
817 sin6->sin6_family = AF_INET6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
818 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
819 host = u->url.data + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
820 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
821 last = u->url.data + u->url.len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
822 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
823 p = ngx_strlchr(host, last, ']'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
824 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
825 if (p == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
826 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
827 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
828 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
829 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
830 if (last - p) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
831 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
832 port = p + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
833 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
834 uri = ngx_strlchr(port, last, '/'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
835 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
836 if (uri) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
837 if (u->listen || !u->uri_part) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
838 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
839 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
840 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
841 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
842 u->uri.len = last - uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
843 u->uri.data = uri; |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
844 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
845 last = uri; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
846 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
847 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
848 if (*port == ':') { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
849 port++; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
850 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
851 len = last - port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
852 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
853 n = ngx_atoi(port, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
854 |
4227 | 855 if (n < 1 || n > 65535) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
856 u->err = "invalid port"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
857 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
858 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
859 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
860 u->port = (in_port_t) n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
861 sin6->sin6_port = htons((in_port_t) n); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
862 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
863 u->port_text.len = len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
864 u->port_text.data = port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
865 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
866 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
867 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
|
868 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
|
869 sin6->sin6_port = htons(u->default_port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
870 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
871 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
872 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
873 len = p - host; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
874 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
875 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
876 u->err = "no host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
877 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
878 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
879 |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
880 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
|
881 u->host.data = host - 1; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
882 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
883 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
|
884 u->err = "invalid IPv6 address"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
885 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
886 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
887 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
888 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
889 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
890 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
891 |
4670
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
892 u->family = AF_INET6; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
893 u->naddrs = 1; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
894 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
895 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
|
896 if (u->addrs == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
897 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
898 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
899 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
900 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
|
901 if (sin6 == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
902 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
903 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
904 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
905 ngx_memcpy(sin6, u->sockaddr, sizeof(struct sockaddr_in6)); |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
906 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
907 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
|
908 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
|
909 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
910 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
|
911 if (p == NULL) { |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
912 return NGX_ERROR; |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
913 } |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
914 |
c070fa19511e
Support for IPv6 literals in proxy_pass and so on.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4652
diff
changeset
|
915 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
|
916 &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
|
917 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
|
918 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
919 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
920 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
921 #else |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
922 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
923 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
|
924 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
925 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
926 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
927 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
928 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
929 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
930 |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
931 #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
|
932 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
933 ngx_int_t |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
934 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
|
935 { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
936 u_char *p, *host; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
937 size_t len; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
938 in_port_t port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
939 ngx_uint_t i; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
940 struct addrinfo hints, *res, *rp; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
941 struct sockaddr_in *sin; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
942 struct sockaddr_in6 *sin6; |
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 port = htons(u->port); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
945 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
946 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
|
947 if (host == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
948 return NGX_ERROR; |
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 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
951 (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
|
952 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
953 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
|
954 hints.ai_family = AF_UNSPEC; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
955 hints.ai_socktype = SOCK_STREAM; |
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 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
|
958 u->err = "host not found"; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
959 ngx_free(host); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
960 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
961 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
962 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
963 ngx_free(host); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
964 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
965 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
|
966 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
967 switch (rp->ai_family) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
968 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
969 case AF_INET: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
970 case AF_INET6: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
971 break; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
972 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
973 default: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
974 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
975 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
976 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
977 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
978 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
979 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
980 if (i == 0) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
981 u->err = "host not found"; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
982 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
983 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
984 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
985 /* MP: ngx_shared_palloc() */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
986 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
987 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
|
988 if (u->addrs == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
989 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
990 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
991 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
992 u->naddrs = i; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
993 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
994 i = 0; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
995 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
996 /* AF_INET addresses first */ |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
997 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
998 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
|
999 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1000 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
|
1001 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1002 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1003 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1004 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
|
1005 if (sin == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1006 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1007 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1008 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1009 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
|
1010 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1011 sin->sin_port = port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1012 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1013 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
|
1014 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
|
1015 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1016 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
|
1017 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1018 p = ngx_pnalloc(pool, len); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1019 if (p == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1020 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1021 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1022 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1023 len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1024 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1025 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
|
1026 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
|
1027 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1028 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1029 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1030 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1031 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
|
1032 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1033 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
|
1034 continue; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1035 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1036 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1037 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
|
1038 if (sin6 == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1039 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1040 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1041 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1042 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
|
1043 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1044 sin6->sin6_port = port; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1045 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1046 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
|
1047 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
|
1048 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1049 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
|
1050 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1051 p = ngx_pnalloc(pool, len); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1052 if (p == NULL) { |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1053 goto failed; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1054 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1055 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1056 len = ngx_sock_ntop((struct sockaddr *) sin6, p, len, 1); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1057 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1058 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
|
1059 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
|
1060 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1061 i++; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1062 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1063 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1064 freeaddrinfo(res); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1065 return NGX_OK; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1066 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1067 failed: |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1068 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1069 freeaddrinfo(res); |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1070 return NGX_ERROR; |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1071 } |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1072 |
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1073 #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
|
1074 |
884 | 1075 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1076 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) |
651 | 1077 { |
906 | 1078 u_char *p, *host; |
651 | 1079 size_t len; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1080 in_port_t port; |
651 | 1081 in_addr_t in_addr; |
1082 ngx_uint_t i; | |
1083 struct hostent *h; | |
1084 struct sockaddr_in *sin; | |
1085 | |
1086 /* AF_INET only */ | |
1087 | |
2517
095f28fc0c4a
fix upstream port, introduced in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1088 port = htons(u->port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1089 |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1090 in_addr = ngx_inet_addr(u->host.data, u->host.len); |
651 | 1091 |
1092 if (in_addr == INADDR_NONE) { | |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1093 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
|
1094 if (host == NULL) { |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1095 return NGX_ERROR; |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1096 } |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1097 |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
1098 (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
|
1099 |
651 | 1100 h = gethostbyname((char *) host); |
1101 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1102 ngx_free(host); |
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1103 |
651 | 1104 if (h == NULL || h->h_addr_list[0] == NULL) { |
884 | 1105 u->err = "host not found"; |
1106 return NGX_ERROR; | |
651 | 1107 } |
1108 | |
4971
eaf95350d75c
Implemented IPv6 support for URLs specified using domain names.
Ruslan Ermilov <ru@nginx.com>
parents:
4970
diff
changeset
|
1109 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } |
651 | 1110 |
1111 /* MP: ngx_shared_palloc() */ | |
1112 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
1113 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t)); |
884 | 1114 if (u->addrs == NULL) { |
1115 return NGX_ERROR; | |
651 | 1116 } |
1117 | |
884 | 1118 u->naddrs = i; |
651 | 1119 |
3864
8e77b5216894
fix u->one_addr handling in ngx_inet_resolve_host()
Igor Sysoev <igor@sysoev.ru>
parents:
3377
diff
changeset
|
1120 for (i = 0; i < u->naddrs; i++) { |
651 | 1121 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1122 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 1123 if (sin == NULL) { |
884 | 1124 return NGX_ERROR; |
651 | 1125 } |
1126 | |
1127 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1128 sin->sin_port = port; |
651 | 1129 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]); |
1130 | |
884 | 1131 u->addrs[i].sockaddr = (struct sockaddr *) sin; |
1132 u->addrs[i].socklen = sizeof(struct sockaddr_in); | |
651 | 1133 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1134 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
651 | 1135 |
2049 | 1136 p = ngx_pnalloc(pool, len); |
906 | 1137 if (p == NULL) { |
884 | 1138 return NGX_ERROR; |
651 | 1139 } |
1140 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1141 len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1); |
651 | 1142 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1143 u->addrs[i].name.len = len; |
906 | 1144 u->addrs[i].name.data = p; |
651 | 1145 } |
1146 | |
1147 } else { | |
1148 | |
1149 /* MP: ngx_shared_palloc() */ | |
1150 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
1151 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
884 | 1152 if (u->addrs == NULL) { |
1153 return NGX_ERROR; | |
651 | 1154 } |
1155 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
1156 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 1157 if (sin == NULL) { |
884 | 1158 return NGX_ERROR; |
651 | 1159 } |
1160 | |
884 | 1161 u->naddrs = 1; |
651 | 1162 |
1163 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1164 sin->sin_port = port; |
651 | 1165 sin->sin_addr.s_addr = in_addr; |
1166 | |
884 | 1167 u->addrs[0].sockaddr = (struct sockaddr *) sin; |
1168 u->addrs[0].socklen = sizeof(struct sockaddr_in); | |
651 | 1169 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1170 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
906 | 1171 if (p == NULL) { |
884 | 1172 return NGX_ERROR; |
651 | 1173 } |
1174 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1175 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
|
1176 &u->host, ntohs(port)) - p; |
906 | 1177 u->addrs[0].name.data = p; |
651 | 1178 } |
1179 | |
884 | 1180 return NGX_OK; |
651 | 1181 } |
4971
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 #endif /* NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6 */ |