Mercurial > hg > nginx
annotate src/core/ngx_inet.c @ 4104:84f34973684c
Version bump.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 14 Sep 2011 15:20:01 +0000 |
parents | 4d4b5770616f |
children | 4af8ea9c3a86 |
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 |
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
|
4 */ |
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 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #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
|
8 #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
|
9 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2200 | 11 static ngx_int_t ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u); |
12 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
|
13 static ngx_int_t ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u); |
2200 | 14 |
1647 | 15 |
16 in_addr_t | |
17 ngx_inet_addr(u_char *text, size_t len) | |
18 { | |
19 u_char *p, c; | |
20 in_addr_t addr; | |
21 ngx_uint_t octet, n; | |
22 | |
23 addr = 0; | |
24 octet = 0; | |
25 n = 0; | |
26 | |
27 for (p = text; p < text + len; p++) { | |
28 | |
29 c = *p; | |
30 | |
31 if (c >= '0' && c <= '9') { | |
32 octet = octet * 10 + (c - '0'); | |
33 continue; | |
34 } | |
35 | |
36 if (c == '.' && octet < 256) { | |
37 addr = (addr << 8) + octet; | |
38 octet = 0; | |
39 n++; | |
40 continue; | |
41 } | |
42 | |
43 return INADDR_NONE; | |
44 } | |
45 | |
46 if (n != 3) { | |
47 return INADDR_NONE; | |
48 } | |
49 | |
50 if (octet < 256) { | |
51 addr = (addr << 8) + octet; | |
52 return htonl(addr); | |
53 } | |
54 | |
55 return INADDR_NONE; | |
56 } | |
57 | |
58 | |
3265 | 59 #if (NGX_HAVE_INET6) |
60 | |
61 ngx_int_t | |
62 ngx_inet6_addr(u_char *p, size_t len, u_char *addr) | |
63 { | |
64 u_char c, *zero, *digit, *s, *d; | |
65 size_t len4; | |
66 ngx_uint_t n, nibbles, word; | |
67 | |
68 if (len == 0) { | |
69 return NGX_ERROR; | |
70 } | |
71 | |
72 zero = NULL; | |
73 digit = NULL; | |
74 len4 = 0; | |
75 nibbles = 0; | |
76 word = 0; | |
77 n = 8; | |
78 | |
79 if (p[0] == ':') { | |
80 p++; | |
81 len--; | |
82 } | |
83 | |
84 for (/* void */; len; len--) { | |
85 c = *p++; | |
86 | |
87 if (c == ':') { | |
88 if (nibbles) { | |
89 digit = p; | |
90 len4 = len; | |
91 *addr++ = (u_char) (word >> 8); | |
92 *addr++ = (u_char) (word & 0xff); | |
93 | |
94 if (--n) { | |
95 nibbles = 0; | |
96 word = 0; | |
97 continue; | |
98 } | |
99 | |
100 } else { | |
101 if (zero == NULL) { | |
102 digit = p; | |
103 len4 = len; | |
104 zero = addr; | |
105 continue; | |
106 } | |
107 } | |
108 | |
109 return NGX_ERROR; | |
110 } | |
111 | |
112 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
|
113 if (n < 2 || digit == NULL) { |
3265 | 114 return NGX_ERROR; |
115 } | |
116 | |
117 word = ngx_inet_addr(digit, len4 - 1); | |
118 if (word == INADDR_NONE) { | |
119 return NGX_ERROR; | |
120 } | |
121 | |
122 word = ntohl(word); | |
123 *addr++ = (u_char) ((word >> 24) & 0xff); | |
124 *addr++ = (u_char) ((word >> 16) & 0xff); | |
125 n--; | |
126 break; | |
127 } | |
128 | |
129 if (++nibbles > 4) { | |
130 return NGX_ERROR; | |
131 } | |
132 | |
133 if (c >= '0' && c <= '9') { | |
134 word = word * 16 + (c - '0'); | |
135 continue; | |
136 } | |
137 | |
138 c |= 0x20; | |
139 | |
140 if (c >= 'a' && c <= 'f') { | |
141 word = word * 16 + (c - 'a') + 10; | |
142 continue; | |
143 } | |
144 | |
145 return NGX_ERROR; | |
146 } | |
147 | |
148 if (nibbles == 0 && zero == NULL) { | |
149 return NGX_ERROR; | |
150 } | |
151 | |
152 *addr++ = (u_char) (word >> 8); | |
153 *addr++ = (u_char) (word & 0xff); | |
154 | |
155 if (--n) { | |
156 if (zero) { | |
157 n *= 2; | |
158 s = addr - 1; | |
159 d = s + n; | |
160 while (s >= zero) { | |
161 *d-- = *s--; | |
162 } | |
163 ngx_memzero(zero, n); | |
164 return NGX_OK; | |
165 } | |
166 | |
167 } else { | |
168 if (zero == NULL) { | |
169 return NGX_OK; | |
170 } | |
171 } | |
172 | |
173 return NGX_ERROR; | |
174 } | |
175 | |
176 #endif | |
177 | |
178 | |
509 | 179 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
180 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
|
181 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
182 u_char *p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
183 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
184 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
185 size_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
186 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
187 #endif |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
188 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
189 struct sockaddr_un *saun; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
190 #endif |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
191 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
192 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
193 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
194 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
|
195 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
196 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
|
197 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
|
198 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
199 if (port) { |
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:%d", |
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], ntohs(sin->sin_port)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
202 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
203 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
|
204 p[0], p[1], p[2], p[3]); |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
207 return (p - text); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
208 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
209 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
210 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
211 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
212 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
213 sin6 = (struct sockaddr_in6 *) sa; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
214 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
215 n = 0; |
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 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
218 text[n++] = '['; |
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 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
221 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
|
222 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
223 if (port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
224 n = ngx_sprintf(&text[1 + n], "]:%d", |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
225 ntohs(sin6->sin6_port)) - text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
226 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
227 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
228 return n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
229 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
230 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
231 #if (NGX_HAVE_UNIX_DOMAIN) |
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 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
234 saun = (struct sockaddr_un *) sa; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
235 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
236 /* we do not include trailing zero in address length */ |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
237 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
238 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
|
239 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
240 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2856
diff
changeset
|
241 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
242 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
243 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
244 } |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
245 } |
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
246 |
1830 | 247 |
509 | 248 size_t |
249 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
|
250 { |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
251 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
|
252 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
253 switch (family) { |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
254 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
255 case AF_INET: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
256 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
257 p = addr; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
258 |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
259 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
|
260 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
|
261 - text; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
262 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
263 #if (NGX_HAVE_INET6) |
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 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
266 return ngx_inet6_ntop(addr, text, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
267 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
268 #endif |
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 default: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
271 return 0; |
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 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
274 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
275 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
276 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
277 |
3276
beaf94f2f265
make ngx_inet6_ntop() non-static
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
278 size_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
279 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
|
280 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
281 u_char *dst; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
282 size_t max, n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
283 ngx_uint_t i, zero, last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
284 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
285 if (len < NGX_INET6_ADDRSTRLEN) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
286 return 0; |
291
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
287 } |
117ccc7c4055
nginx-0.0.3-2004-03-16-16:35:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
288 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
289 zero = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
290 last = (ngx_uint_t) -1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
291 max = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
292 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
293 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
294 for (i = 0; i < 16; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
295 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
296 if (p[i] || p[i + 1]) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
297 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
298 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
299 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
300 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
301 } |
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 n = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
304 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
305 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
306 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
307 if (n++ == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
308 last = i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
309 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
310 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
311 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
312 if (max < n) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
313 zero = last; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
314 max = n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
315 } |
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 dst = text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
318 n = 16; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
319 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
320 if (zero == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
321 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
322 if ((max == 5 && p[10] == 0xff && p[11] == 0xff) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
323 || (max == 6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
324 || (max == 7 && p[14] != 0 && p[15] != 1)) |
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 n = 12; |
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 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
330 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
331 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
332 for (i = 0; i < n; i += 2) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
333 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
334 if (i == zero) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
335 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
336 i += (max - 1) * 2; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
337 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
338 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
339 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
340 dst = 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
|
341 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
342 if (i < 14) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
343 *dst++ = ':'; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
344 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
345 } |
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 if (n == 12) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
348 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
|
349 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
350 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
351 return dst - text; |
1830 | 352 } |
353 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
354 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
355 |
1830 | 356 |
509 | 357 ngx_int_t |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
358 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
|
359 { |
3277 | 360 u_char *addr, *mask, *last; |
361 size_t len; | |
362 ngx_int_t shift; | |
363 #if (NGX_HAVE_INET6) | |
364 ngx_int_t rc; | |
365 ngx_uint_t s, i; | |
366 #endif | |
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 addr = text->data; |
369 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
|
370 |
2202 | 371 mask = ngx_strlchr(addr, last, '/'); |
3277 | 372 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
|
373 |
3277 | 374 cidr->u.in.addr = ngx_inet_addr(addr, len); |
375 | |
376 if (cidr->u.in.addr != INADDR_NONE) { | |
377 cidr->family = AF_INET; | |
378 | |
379 if (mask == NULL) { | |
380 cidr->u.in.mask = 0xffffffff; | |
381 return NGX_OK; | |
382 } | |
2202 | 383 |
3277 | 384 #if (NGX_HAVE_INET6) |
385 } else if (ngx_inet6_addr(addr, len, cidr->u.in6.addr.s6_addr) == NGX_OK) { | |
386 cidr->family = AF_INET6; | |
387 | |
388 if (mask == NULL) { | |
389 ngx_memset(cidr->u.in6.mask.s6_addr, 0xff, 16); | |
390 return NGX_OK; | |
391 } | |
392 | |
393 #endif | |
394 } else { | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
395 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
396 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
397 |
2202 | 398 mask++; |
399 | |
400 shift = ngx_atoi(mask, last - mask); | |
401 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
|
402 return NGX_ERROR; |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
403 } |
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
404 |
3277 | 405 switch (cidr->family) { |
2537
a472d954c534
prepare ngx_ptocidr() for IPv6
Igor Sysoev <igor@sysoev.ru>
parents:
2517
diff
changeset
|
406 |
3277 | 407 #if (NGX_HAVE_INET6) |
408 case AF_INET6: | |
409 addr = cidr->u.in6.addr.s6_addr; | |
410 mask = cidr->u.in6.mask.s6_addr; | |
411 rc = NGX_OK; | |
412 | |
413 for (i = 0; i < 16; i++) { | |
414 | |
415 s = (shift > 8) ? 8 : shift; | |
416 shift -= s; | |
417 | |
418 mask[i] = (u_char) (0 - (1 << (8 - s))); | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
419 |
3277 | 420 if (addr[i] != (addr[i] & mask[i])) { |
421 rc = NGX_DONE; | |
422 addr[i] &= mask[i]; | |
423 } | |
424 } | |
425 | |
426 return rc; | |
427 #endif | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
340
diff
changeset
|
428 |
3277 | 429 default: /* AF_INET */ |
430 | |
431 if (shift) { | |
432 cidr->u.in.mask = htonl((ngx_uint_t) (0 - (1 << (32 - shift)))); | |
2202 | 433 |
3277 | 434 } else { |
435 /* x86 compilers use a shl instruction that shifts by modulo 32 */ | |
436 cidr->u.in.mask = 0; | |
437 } | |
438 | |
439 if (cidr->u.in.addr == (cidr->u.in.addr & cidr->u.in.mask)) { | |
2202 | 440 return NGX_OK; |
441 } | |
442 | |
3277 | 443 cidr->u.in.addr &= cidr->u.in.mask; |
444 | |
2202 | 445 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
|
446 } |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
447 } |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
448 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
404
diff
changeset
|
449 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
450 ngx_int_t |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
451 ngx_parse_addr(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text, size_t len) |
3270 | 452 { |
453 in_addr_t inaddr; | |
454 ngx_uint_t family; | |
455 struct sockaddr_in *sin; | |
456 #if (NGX_HAVE_INET6) | |
457 struct in6_addr inaddr6; | |
458 struct sockaddr_in6 *sin6; | |
3277 | 459 |
460 /* | |
461 * prevent MSVC8 waring: | |
462 * potentially uninitialized local variable 'inaddr6' used | |
463 */ | |
464 ngx_memzero(inaddr6.s6_addr, sizeof(struct in6_addr)); | |
3270 | 465 #endif |
466 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
467 inaddr = ngx_inet_addr(text, len); |
3270 | 468 |
469 if (inaddr != INADDR_NONE) { | |
470 family = AF_INET; | |
471 len = sizeof(struct sockaddr_in); | |
472 | |
473 #if (NGX_HAVE_INET6) | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
474 } else if (ngx_inet6_addr(text, len, inaddr6.s6_addr) == NGX_OK) { |
3270 | 475 family = AF_INET6; |
476 len = sizeof(struct sockaddr_in6); | |
477 | |
478 #endif | |
479 } else { | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
480 return NGX_DECLINED; |
3270 | 481 } |
482 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
483 addr->sockaddr = ngx_pcalloc(pool, len); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
484 if (addr->sockaddr == NULL) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
485 return NGX_ERROR; |
3270 | 486 } |
487 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
488 addr->sockaddr->sa_family = (u_char) family; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
489 addr->socklen = len; |
3270 | 490 |
491 switch (family) { | |
492 | |
493 #if (NGX_HAVE_INET6) | |
494 case AF_INET6: | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
495 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
3270 | 496 ngx_memcpy(sin6->sin6_addr.s6_addr, inaddr6.s6_addr, 16); |
497 break; | |
498 #endif | |
499 | |
500 default: /* AF_INET */ | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
501 sin = (struct sockaddr_in *) addr->sockaddr; |
3270 | 502 sin->sin_addr.s_addr = inaddr; |
503 break; | |
504 } | |
505 | |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3270
diff
changeset
|
506 return NGX_OK; |
3270 | 507 } |
508 | |
509 | |
651 | 510 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
511 ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u) |
651 | 512 { |
2200 | 513 u_char *p; |
651 | 514 |
515 p = u->url.data; | |
516 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
906
diff
changeset
|
517 if (ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) { |
2200 | 518 return ngx_parse_unix_domain_url(pool, u); |
651 | 519 } |
520 | |
521 if ((p[0] == ':' || p[0] == '/') && !u->listen) { | |
522 u->err = "invalid host"; | |
523 return NGX_ERROR; | |
524 } | |
525 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
526 if (p[0] == '[') { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
527 return ngx_parse_inet6_url(pool, u); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
528 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
529 |
2200 | 530 return ngx_parse_inet_url(pool, u); |
531 } | |
532 | |
533 | |
534 static ngx_int_t | |
535 ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u) | |
536 { | |
537 #if (NGX_HAVE_UNIX_DOMAIN) | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
538 u_char *path, *uri, *last; |
2200 | 539 size_t len; |
540 struct sockaddr_un *saun; | |
541 | |
542 len = u->url.len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
543 path = u->url.data; |
2200 | 544 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
545 path += 5; |
2200 | 546 len -= 5; |
547 | |
548 if (u->uri_part) { | |
549 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
550 last = path + len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
551 uri = ngx_strlchr(path, last, ':'); |
2200 | 552 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
553 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
554 len = uri - path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
555 uri++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
556 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
557 u->uri.data = uri; |
2200 | 558 } |
559 } | |
560 | |
561 if (len == 0) { | |
562 u->err = "no path in the unix domain socket"; | |
563 return NGX_ERROR; | |
564 } | |
565 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
566 u->host.len = len++; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
567 u->host.data = path; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
568 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
569 if (len > sizeof(saun->sun_path)) { |
2200 | 570 u->err = "too long path in the unix domain socket"; |
571 return NGX_ERROR; | |
572 } | |
573 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
574 u->socklen = sizeof(struct sockaddr_un); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
575 saun = (struct sockaddr_un *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
576 saun->sun_family = AF_UNIX; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
577 (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
|
578 |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
579 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
2200 | 580 if (u->addrs == NULL) { |
581 return NGX_ERROR; | |
582 } | |
583 | |
584 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un)); | |
585 if (saun == NULL) { | |
586 return NGX_ERROR; | |
587 } | |
588 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
589 u->family = AF_UNIX; |
2200 | 590 u->naddrs = 1; |
591 | |
592 saun->sun_family = AF_UNIX; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
593 (void) ngx_cpystrn((u_char *) saun->sun_path, path, len); |
2200 | 594 |
595 u->addrs[0].sockaddr = (struct sockaddr *) saun; | |
596 u->addrs[0].socklen = sizeof(struct sockaddr_un); | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
597 u->addrs[0].name.len = len + 4; |
2200 | 598 u->addrs[0].name.data = u->url.data; |
599 | |
600 return NGX_OK; | |
601 | |
602 #else | |
603 | |
604 u->err = "the unix domain sockets are not supported on this platform"; | |
605 | |
606 return NGX_ERROR; | |
607 | |
608 #endif | |
609 } | |
610 | |
611 | |
612 static ngx_int_t | |
613 ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) | |
614 { | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
615 u_char *p, *host, *port, *last, *uri, *args; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
616 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
617 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
618 struct hostent *h; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
619 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
620 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
621 u->socklen = sizeof(struct sockaddr_in); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
622 sin = (struct sockaddr_in *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
623 sin->sin_family = AF_INET; |
2200 | 624 |
2206 | 625 u->family = AF_INET; |
626 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
627 host = u->url.data; |
2200 | 628 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
629 last = host + u->url.len; |
906 | 630 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
631 port = ngx_strlchr(host, last, ':'); |
651 | 632 |
2283
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
633 uri = ngx_strlchr(host, last, '/'); |
651 | 634 |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
635 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
|
636 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
637 if (args) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
638 if (uri == NULL) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
639 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
640 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
641 } else if (args < uri) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
642 uri = args; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
643 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
644 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2283
diff
changeset
|
645 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
646 if (uri) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
647 if (u->listen || !u->uri_part) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
648 u->err = "invalid host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
649 return NGX_ERROR; |
651 | 650 } |
651 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
652 u->uri.len = last - uri; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
653 u->uri.data = uri; |
651 | 654 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
655 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
|
656 |
231b52f8adc0
fix case when URL has no port, but has ":" in URI part,
Igor Sysoev <igor@sysoev.ru>
parents:
2206
diff
changeset
|
657 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
|
658 port = NULL; |
2301
148c2e840c2b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2284
diff
changeset
|
659 } |
651 | 660 } |
661 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
662 if (port) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
663 port++; |
651 | 664 |
2206 | 665 len = last - port; |
666 | |
667 if (len == 0) { | |
651 | 668 u->err = "invalid port"; |
669 return NGX_ERROR; | |
670 } | |
671 | |
2206 | 672 n = ngx_atoi(port, len); |
673 | |
674 if (n < 1 || n > 65536) { | |
675 u->err = "invalid port"; | |
676 return NGX_ERROR; | |
677 } | |
678 | |
679 u->port = (in_port_t) n; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
680 sin->sin_port = htons((in_port_t) n); |
2206 | 681 |
682 u->port_text.len = len; | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
683 u->port_text.data = port; |
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 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
|
686 |
651 | 687 } else { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
688 if (uri == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
689 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
690 if (u->listen) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
691 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
692 /* test value as port only */ |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
693 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
694 n = ngx_atoi(host, last - host); |
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 if (n != NGX_ERROR) { |
651 | 697 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
698 if (n < 1 || n > 65536) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
699 u->err = "invalid port"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
700 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
701 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
702 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
703 u->port = (in_port_t) n; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
704 sin->sin_port = htons((in_port_t) n); |
651 | 705 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
706 u->port_text.len = last - host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
707 u->port_text.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
708 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
709 u->wildcard = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
710 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
711 return NGX_OK; |
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 } |
651 | 714 } |
715 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
716 u->no_port = 1; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
717 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
718 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
719 len = last - host; |
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 if (len == 0) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
722 u->err = "no host"; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
723 return NGX_ERROR; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
724 } |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
725 |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
726 if (len == 1 && *host == '*') { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
727 len = 0; |
651 | 728 } |
729 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
730 u->host.len = len; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
731 u->host.data = host; |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
732 |
2206 | 733 if (u->no_resolve) { |
734 return NGX_OK; | |
735 } | |
736 | |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
737 if (len) { |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
738 sin->sin_addr.s_addr = ngx_inet_addr(host, len); |
884 | 739 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
740 if (sin->sin_addr.s_addr == INADDR_NONE) { |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
741 p = ngx_alloc(++len, pool->log); |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
742 if (p == NULL) { |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
743 return NGX_ERROR; |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
744 } |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
745 |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
746 (void) ngx_cpystrn(p, host, len); |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
747 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
748 h = gethostbyname((const char *) p); |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
749 |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
750 ngx_free(p); |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
751 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
752 if (h == NULL || h->h_addr_list[0] == NULL) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
753 u->err = "host not found"; |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
754 return NGX_ERROR; |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
755 } |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
756 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
757 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]); |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
760 if (sin->sin_addr.s_addr == INADDR_ANY) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
761 u->wildcard = 1; |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
762 } |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
763 |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
764 } else { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
765 sin->sin_addr.s_addr = INADDR_ANY; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
766 u->wildcard = 1; |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
767 } |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
712
diff
changeset
|
768 |
906 | 769 if (u->no_port) { |
770 u->port = u->default_port; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
771 sin->sin_port = htons(u->default_port); |
906 | 772 } |
773 | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
774 if (u->listen) { |
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2202
diff
changeset
|
775 return NGX_OK; |
906 | 776 } |
777 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
778 if (ngx_inet_resolve_host(pool, u) != NGX_OK) { |
651 | 779 return NGX_ERROR; |
780 } | |
781 | |
782 return NGX_OK; | |
783 } | |
784 | |
785 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
786 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
787 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
|
788 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
789 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
790 u_char *p, *host, *port, *last, *uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
791 size_t len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
792 ngx_int_t n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
793 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
794 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
795 u->socklen = sizeof(struct sockaddr_in6); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
796 sin6 = (struct sockaddr_in6 *) &u->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
797 sin6->sin6_family = AF_INET6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
798 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
799 host = u->url.data + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
800 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
801 last = u->url.data + u->url.len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
802 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
803 p = ngx_strlchr(host, last, ']'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
804 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
805 if (p == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
806 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
807 return NGX_ERROR; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
810 if (last - p) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
811 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
812 port = p + 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
813 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
814 uri = ngx_strlchr(port, last, '/'); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
815 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
816 if (uri) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
817 if (u->listen || !u->uri_part) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
818 u->err = "invalid host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
819 return NGX_ERROR; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
822 u->uri.len = last - uri; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
823 u->uri.data = uri; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
826 if (*port == ':') { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
827 port++; |
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 len = last - port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
830 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
831 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
832 u->err = "invalid port"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
833 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
834 } |
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 n = ngx_atoi(port, len); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
837 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
838 if (n < 1 || n > 65536) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
839 u->err = "invalid port"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
840 return NGX_ERROR; |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
843 u->port = (in_port_t) n; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
844 sin6->sin6_port = htons((in_port_t) n); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
845 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
846 u->port_text.len = len; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
847 u->port_text.data = port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
848 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
849 } else { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
850 u->no_port = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
851 } |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
854 len = p - host; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
855 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
856 if (len == 0) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
857 u->err = "no host"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
858 return NGX_ERROR; |
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 |
3266 | 861 u->host.len = len; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
862 u->host.data = host; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
863 |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3267
diff
changeset
|
864 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
|
865 u->err = "invalid IPv6 address"; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
866 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
867 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
868 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
869 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
870 u->wildcard = 1; |
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 u->family = AF_INET6; |
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 (u->no_resolve) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
876 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
877 } |
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 if (u->no_port) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
880 u->port = u->default_port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
881 sin6->sin6_port = htons(u->default_port); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
882 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
883 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
884 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
885 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
886 #else |
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 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
|
889 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
890 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
891 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
892 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
893 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
894 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
895 |
884 | 896 ngx_int_t |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
897 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) |
651 | 898 { |
906 | 899 u_char *p, *host; |
651 | 900 size_t len; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
901 in_port_t port; |
651 | 902 in_addr_t in_addr; |
903 ngx_uint_t i; | |
904 struct hostent *h; | |
905 struct sockaddr_in *sin; | |
906 | |
907 /* AF_INET only */ | |
908 | |
2517
095f28fc0c4a
fix upstream port, introduced in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
909 port = htons(u->port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
910 |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
911 in_addr = ngx_inet_addr(u->host.data, u->host.len); |
651 | 912 |
913 if (in_addr == INADDR_NONE) { | |
3267
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
914 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
|
915 if (host == NULL) { |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
916 return NGX_ERROR; |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
917 } |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
918 |
fb4f7605505f
replace inet_addr() with ngx_inet_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
3266
diff
changeset
|
919 (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
|
920 |
651 | 921 h = gethostbyname((char *) host); |
922 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
923 ngx_free(host); |
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
924 |
651 | 925 if (h == NULL || h->h_addr_list[0] == NULL) { |
884 | 926 u->err = "host not found"; |
927 return NGX_ERROR; | |
651 | 928 } |
929 | |
884 | 930 if (u->one_addr == 0) { |
931 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } | |
932 | |
933 } else { | |
934 i = 1; | |
935 } | |
651 | 936 |
937 /* MP: ngx_shared_palloc() */ | |
938 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
939 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t)); |
884 | 940 if (u->addrs == NULL) { |
941 return NGX_ERROR; | |
651 | 942 } |
943 | |
884 | 944 u->naddrs = i; |
651 | 945 |
3864
8e77b5216894
fix u->one_addr handling in ngx_inet_resolve_host()
Igor Sysoev <igor@sysoev.ru>
parents:
3377
diff
changeset
|
946 for (i = 0; i < u->naddrs; i++) { |
651 | 947 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
948 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 949 if (sin == NULL) { |
884 | 950 return NGX_ERROR; |
651 | 951 } |
952 | |
953 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
954 sin->sin_port = port; |
651 | 955 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]); |
956 | |
884 | 957 u->addrs[i].sockaddr = (struct sockaddr *) sin; |
958 u->addrs[i].socklen = sizeof(struct sockaddr_in); | |
651 | 959 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
960 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
651 | 961 |
2049 | 962 p = ngx_pnalloc(pool, len); |
906 | 963 if (p == NULL) { |
884 | 964 return NGX_ERROR; |
651 | 965 } |
966 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
967 len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1); |
651 | 968 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
969 u->addrs[i].name.len = len; |
906 | 970 u->addrs[i].name.data = p; |
651 | 971 } |
972 | |
973 } else { | |
974 | |
975 /* MP: ngx_shared_palloc() */ | |
976 | |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
977 u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t)); |
884 | 978 if (u->addrs == NULL) { |
979 return NGX_ERROR; | |
651 | 980 } |
981 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1380
diff
changeset
|
982 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in)); |
651 | 983 if (sin == NULL) { |
884 | 984 return NGX_ERROR; |
651 | 985 } |
986 | |
884 | 987 u->naddrs = 1; |
651 | 988 |
989 sin->sin_family = AF_INET; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
990 sin->sin_port = port; |
651 | 991 sin->sin_addr.s_addr = in_addr; |
992 | |
884 | 993 u->addrs[0].sockaddr = (struct sockaddr *) sin; |
994 u->addrs[0].socklen = sizeof(struct sockaddr_in); | |
651 | 995 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
996 p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1); |
906 | 997 if (p == NULL) { |
884 | 998 return NGX_ERROR; |
651 | 999 } |
1000 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2301
diff
changeset
|
1001 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
|
1002 &u->host, ntohs(port)) - p; |
906 | 1003 u->addrs[0].name.data = p; |
651 | 1004 } |
1005 | |
884 | 1006 return NGX_OK; |
651 | 1007 } |