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