Mercurial > hg > nginx-quic
annotate src/core/ngx_resolver.c @ 9015:c7e103acb409
Gzip static: ranges support (ticket #2349).
In contrast to on-the-fly gzipping with gzip filter, static gzipped
representation as returned by gzip_static is persistent, and therefore
the same binary representation is available for future requests, making
it possible to use range requests.
Further, if a gzipped representation is re-generated with different
compression settings, it is expected to result in different ETag and
different size reported in the Content-Range header, making it possible
to safely use range requests anyway.
As such, ranges are now allowed for files returned by gzip_static.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 24 Jan 2023 03:01:51 +0300 |
parents | 0422365794f7 |
children |
rev | line source |
---|---|
583 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
583 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_event.h> | |
11 | |
12 | |
1649 | 13 #define NGX_RESOLVER_UDP_SIZE 4096 |
14 | |
6367 | 15 #define NGX_RESOLVER_TCP_RSIZE (2 + 65535) |
16 #define NGX_RESOLVER_TCP_WSIZE 8192 | |
17 | |
1649 | 18 |
583 | 19 typedef struct { |
1649 | 20 u_char ident_hi; |
21 u_char ident_lo; | |
22 u_char flags_hi; | |
23 u_char flags_lo; | |
24 u_char nqs_hi; | |
25 u_char nqs_lo; | |
26 u_char nan_hi; | |
27 u_char nan_lo; | |
28 u_char nns_hi; | |
29 u_char nns_lo; | |
30 u_char nar_hi; | |
31 u_char nar_lo; | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
32 } ngx_resolver_hdr_t; |
1649 | 33 |
34 | |
35 typedef struct { | |
36 u_char type_hi; | |
37 u_char type_lo; | |
38 u_char class_hi; | |
39 u_char class_lo; | |
40 } ngx_resolver_qs_t; | |
41 | |
42 | |
43 typedef struct { | |
44 u_char type_hi; | |
45 u_char type_lo; | |
46 u_char class_hi; | |
47 u_char class_lo; | |
48 u_char ttl[4]; | |
49 u_char len_hi; | |
50 u_char len_lo; | |
51 } ngx_resolver_an_t; | |
52 | |
53 | |
8523
0c5e84096d99
Core: added the ngx_rbtree_data() macro.
Vladimir Homutov <vl@nginx.com>
parents:
8475
diff
changeset
|
54 #define ngx_resolver_node(n) ngx_rbtree_data(n, ngx_resolver_node_t, node) |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
55 |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
56 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
57 static ngx_int_t ngx_udp_connect(ngx_resolver_connection_t *rec); |
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
58 static ngx_int_t ngx_tcp_connect(ngx_resolver_connection_t *rec); |
1649 | 59 |
60 | |
1906 | 61 static void ngx_resolver_cleanup(void *data); |
62 static void ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree); | |
1649 | 63 static ngx_int_t ngx_resolve_name_locked(ngx_resolver_t *r, |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
64 ngx_resolver_ctx_t *ctx, ngx_str_t *name); |
1649 | 65 static void ngx_resolver_expire(ngx_resolver_t *r, ngx_rbtree_t *tree, |
66 ngx_queue_t *queue); | |
67 static ngx_int_t ngx_resolver_send_query(ngx_resolver_t *r, | |
68 ngx_resolver_node_t *rn); | |
6367 | 69 static ngx_int_t ngx_resolver_send_udp_query(ngx_resolver_t *r, |
70 ngx_resolver_connection_t *rec, u_char *query, u_short qlen); | |
71 static ngx_int_t ngx_resolver_send_tcp_query(ngx_resolver_t *r, | |
72 ngx_resolver_connection_t *rec, u_char *query, u_short qlen); | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
73 static ngx_int_t ngx_resolver_create_name_query(ngx_resolver_t *r, |
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
74 ngx_resolver_node_t *rn, ngx_str_t *name); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
75 static ngx_int_t ngx_resolver_create_srv_query(ngx_resolver_t *r, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
76 ngx_resolver_node_t *rn, ngx_str_t *name); |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
77 static ngx_int_t ngx_resolver_create_addr_query(ngx_resolver_t *r, |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
78 ngx_resolver_node_t *rn, ngx_resolver_addr_t *addr); |
1649 | 79 static void ngx_resolver_resend_handler(ngx_event_t *ev); |
80 static time_t ngx_resolver_resend(ngx_resolver_t *r, ngx_rbtree_t *tree, | |
81 ngx_queue_t *queue); | |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
82 static ngx_uint_t ngx_resolver_resend_empty(ngx_resolver_t *r); |
6367 | 83 static void ngx_resolver_udp_read(ngx_event_t *rev); |
84 static void ngx_resolver_tcp_write(ngx_event_t *wev); | |
85 static void ngx_resolver_tcp_read(ngx_event_t *rev); | |
1649 | 86 static void ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, |
6367 | 87 size_t n, ngx_uint_t tcp); |
1649 | 88 static void ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n, |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
89 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype, |
6367 | 90 ngx_uint_t nan, ngx_uint_t trunc, ngx_uint_t ans); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
91 static void ngx_resolver_process_srv(ngx_resolver_t *r, u_char *buf, size_t n, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
92 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
93 ngx_uint_t trunc, ngx_uint_t ans); |
1649 | 94 static void ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n, |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
95 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan); |
1649 | 96 static ngx_resolver_node_t *ngx_resolver_lookup_name(ngx_resolver_t *r, |
97 ngx_str_t *name, uint32_t hash); | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
98 static ngx_resolver_node_t *ngx_resolver_lookup_srv(ngx_resolver_t *r, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
99 ngx_str_t *name, uint32_t hash); |
1649 | 100 static ngx_resolver_node_t *ngx_resolver_lookup_addr(ngx_resolver_t *r, |
101 in_addr_t addr); | |
102 static void ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
103 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); | |
104 static ngx_int_t ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, | |
105 u_char *buf, u_char *src, u_char *last); | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
106 static ngx_int_t ngx_resolver_set_timeout(ngx_resolver_t *r, |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
107 ngx_resolver_ctx_t *ctx); |
1649 | 108 static void ngx_resolver_timeout_handler(ngx_event_t *ev); |
109 static void ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn); | |
110 static void *ngx_resolver_alloc(ngx_resolver_t *r, size_t size); | |
1903 | 111 static void *ngx_resolver_calloc(ngx_resolver_t *r, size_t size); |
1649 | 112 static void ngx_resolver_free(ngx_resolver_t *r, void *p); |
113 static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p); | |
114 static void *ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size); | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
115 static ngx_resolver_addr_t *ngx_resolver_export(ngx_resolver_t *r, |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
116 ngx_resolver_node_t *rn, ngx_uint_t rotate); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
117 static void ngx_resolver_report_srv(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx); |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
118 static u_char *ngx_resolver_log_error(ngx_log_t *log, u_char *buf, size_t len); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
119 static void ngx_resolver_resolve_srv_names(ngx_resolver_ctx_t *ctx, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
120 ngx_resolver_node_t *rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
121 static void ngx_resolver_srv_names_handler(ngx_resolver_ctx_t *ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
122 static ngx_int_t ngx_resolver_cmp_srvs(const void *one, const void *two); |
1649 | 123 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
124 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
125 static void ngx_resolver_rbtree_insert_addr6_value(ngx_rbtree_node_t *temp, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
126 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
127 static ngx_resolver_node_t *ngx_resolver_lookup_addr6(ngx_resolver_t *r, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
128 struct in6_addr *addr, uint32_t hash); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
129 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
130 |
1649 | 131 |
132 ngx_resolver_t * | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
133 ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n) |
1649 | 134 { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
135 ngx_str_t s; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
136 ngx_url_t u; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
137 ngx_uint_t i, j; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
138 ngx_resolver_t *r; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
139 ngx_pool_cleanup_t *cln; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
140 ngx_resolver_connection_t *rec; |
1649 | 141 |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
142 r = ngx_pcalloc(cf->pool, sizeof(ngx_resolver_t)); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
143 if (r == NULL) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
144 return NULL; |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
145 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
146 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
147 r->event = ngx_pcalloc(cf->pool, sizeof(ngx_event_t)); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
148 if (r->event == NULL) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
149 return NULL; |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
150 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
151 |
1913
c0f873458e2b
use cf->cycle->new_log because at merge stage cf->pool->log is old log
Igor Sysoev <igor@sysoev.ru>
parents:
1906
diff
changeset
|
152 cln = ngx_pool_cleanup_add(cf->pool, 0); |
1906 | 153 if (cln == NULL) { |
154 return NULL; | |
155 } | |
156 | |
157 cln->handler = ngx_resolver_cleanup; | |
158 cln->data = r; | |
159 | |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
160 r->ipv4 = 1; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
161 |
1687 | 162 ngx_rbtree_init(&r->name_rbtree, &r->name_sentinel, |
163 ngx_resolver_rbtree_insert_value); | |
164 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
165 ngx_rbtree_init(&r->srv_rbtree, &r->srv_sentinel, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
166 ngx_resolver_rbtree_insert_value); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
167 |
1687 | 168 ngx_rbtree_init(&r->addr_rbtree, &r->addr_sentinel, |
169 ngx_rbtree_insert_value); | |
1649 | 170 |
1685 | 171 ngx_queue_init(&r->name_resend_queue); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
172 ngx_queue_init(&r->srv_resend_queue); |
1685 | 173 ngx_queue_init(&r->addr_resend_queue); |
174 | |
175 ngx_queue_init(&r->name_expire_queue); | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
176 ngx_queue_init(&r->srv_expire_queue); |
1685 | 177 ngx_queue_init(&r->addr_expire_queue); |
1649 | 178 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
179 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
180 r->ipv6 = 1; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
181 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
182 ngx_rbtree_init(&r->addr6_rbtree, &r->addr6_sentinel, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
183 ngx_resolver_rbtree_insert_addr6_value); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
184 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
185 ngx_queue_init(&r->addr6_resend_queue); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
186 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
187 ngx_queue_init(&r->addr6_expire_queue); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
188 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
189 |
1649 | 190 r->event->handler = ngx_resolver_resend_handler; |
191 r->event->data = r; | |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2490
diff
changeset
|
192 r->event->log = &cf->cycle->new_log; |
7052
70e65bf8dfd7
Resolver: cancelable resend timer event.
Ruslan Ermilov <ru@nginx.com>
parents:
7051
diff
changeset
|
193 r->event->cancelable = 1; |
1649 | 194 r->ident = -1; |
195 | |
196 r->resend_timeout = 5; | |
6367 | 197 r->tcp_timeout = 5; |
1649 | 198 r->expire = 30; |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
199 r->valid = 0; |
1649 | 200 |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2490
diff
changeset
|
201 r->log = &cf->cycle->new_log; |
3763
beca53d6ab3c
decrease resolver errors level to error
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
202 r->log_level = NGX_LOG_ERR; |
1649 | 203 |
4784
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
204 if (n) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
205 if (ngx_array_init(&r->connections, cf->pool, n, |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
206 sizeof(ngx_resolver_connection_t)) |
4784
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
207 != NGX_OK) |
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
208 { |
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
209 return NULL; |
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
210 } |
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
211 } |
dd63abf20ba7
Resolver: fixed possible memory leak in ngx_resolver_create().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4684
diff
changeset
|
212 |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
213 for (i = 0; i < n; i++) { |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
214 if (ngx_strncmp(names[i].data, "valid=", 6) == 0) { |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
215 s.len = names[i].len - 6; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
216 s.data = names[i].data + 6; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
217 |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
218 r->valid = ngx_parse_time(&s, 1); |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
219 |
4474 | 220 if (r->valid == (time_t) NGX_ERROR) { |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
221 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
222 "invalid parameter: %V", &names[i]); |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
223 return NULL; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
224 } |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
225 |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
226 continue; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
227 } |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
228 |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
229 #if (NGX_HAVE_INET6) |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
230 if (ngx_strncmp(names[i].data, "ipv4=", 5) == 0) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
231 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
232 if (ngx_strcmp(&names[i].data[5], "on") == 0) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
233 r->ipv4 = 1; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
234 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
235 } else if (ngx_strcmp(&names[i].data[5], "off") == 0) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
236 r->ipv4 = 0; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
237 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
238 } else { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
239 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
240 "invalid parameter: %V", &names[i]); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
241 return NULL; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
242 } |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
243 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
244 continue; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
245 } |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
246 |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
247 if (ngx_strncmp(names[i].data, "ipv6=", 5) == 0) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
248 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
249 if (ngx_strcmp(&names[i].data[5], "on") == 0) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
250 r->ipv6 = 1; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
251 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
252 } else if (ngx_strcmp(&names[i].data[5], "off") == 0) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
253 r->ipv6 = 0; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
254 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
255 } else { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
256 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
257 "invalid parameter: %V", &names[i]); |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
258 return NULL; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
259 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
260 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
261 continue; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
262 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
263 #endif |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
264 |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
265 ngx_memzero(&u, sizeof(ngx_url_t)); |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
266 |
4671
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
267 u.url = names[i]; |
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
268 u.default_port = 53; |
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
269 |
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
270 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
4643
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
271 if (u.err) { |
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
272 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
273 "%s in resolver \"%V\"", |
4671
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
274 u.err, &u.url); |
4643
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
275 } |
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
276 |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
277 return NULL; |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
278 } |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
279 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
280 rec = ngx_array_push_n(&r->connections, u.naddrs); |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
281 if (rec == NULL) { |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
282 return NULL; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
283 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
284 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
285 ngx_memzero(rec, u.naddrs * sizeof(ngx_resolver_connection_t)); |
4684
f5c2c9d656f9
When "resolver" is configured with a domain name, only the first
Ruslan Ermilov <ru@nginx.com>
parents:
4683
diff
changeset
|
286 |
f5c2c9d656f9
When "resolver" is configured with a domain name, only the first
Ruslan Ermilov <ru@nginx.com>
parents:
4683
diff
changeset
|
287 for (j = 0; j < u.naddrs; j++) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
288 rec[j].sockaddr = u.addrs[j].sockaddr; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
289 rec[j].socklen = u.addrs[j].socklen; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
290 rec[j].server = u.addrs[j].name; |
6367 | 291 rec[j].resolver = r; |
4684
f5c2c9d656f9
When "resolver" is configured with a domain name, only the first
Ruslan Ermilov <ru@nginx.com>
parents:
4683
diff
changeset
|
292 } |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
293 } |
1649 | 294 |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
295 #if (NGX_HAVE_INET6) |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
296 if (r->ipv4 + r->ipv6 == 0) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
297 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
298 "\"ipv4\" and \"ipv6\" cannot both be \"off\""); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
299 return NULL; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
300 } |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
301 #endif |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
302 |
7299
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
303 if (n && r->connections.nelts == 0) { |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
304 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "no name servers defined"); |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
305 return NULL; |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
306 } |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
307 |
1649 | 308 return r; |
309 } | |
310 | |
311 | |
1906 | 312 static void |
313 ngx_resolver_cleanup(void *data) | |
314 { | |
315 ngx_resolver_t *r = data; | |
316 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
317 ngx_uint_t i; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
318 ngx_resolver_connection_t *rec; |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
319 |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
320 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "cleanup resolver"); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
321 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
322 ngx_resolver_cleanup_tree(r, &r->name_rbtree); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
323 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
324 ngx_resolver_cleanup_tree(r, &r->srv_rbtree); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
325 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
326 ngx_resolver_cleanup_tree(r, &r->addr_rbtree); |
1906 | 327 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
328 #if (NGX_HAVE_INET6) |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
329 ngx_resolver_cleanup_tree(r, &r->addr6_rbtree); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
330 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
331 |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
332 if (r->event->timer_set) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
333 ngx_del_timer(r->event); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
334 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
335 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
336 rec = r->connections.elts; |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
337 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
338 for (i = 0; i < r->connections.nelts; i++) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
339 if (rec[i].udp) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
340 ngx_close_connection(rec[i].udp); |
1906 | 341 } |
342 | |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
343 if (rec[i].tcp) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
344 ngx_close_connection(rec[i].tcp); |
1906 | 345 } |
346 | |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
347 if (rec[i].read_buf) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
348 ngx_resolver_free(r, rec[i].read_buf->start); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
349 ngx_resolver_free(r, rec[i].read_buf); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
350 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
351 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
352 if (rec[i].write_buf) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
353 ngx_resolver_free(r, rec[i].write_buf->start); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
354 ngx_resolver_free(r, rec[i].write_buf); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
355 } |
1906 | 356 } |
357 } | |
358 | |
359 | |
360 static void | |
361 ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree) | |
362 { | |
363 ngx_resolver_ctx_t *ctx, *next; | |
364 ngx_resolver_node_t *rn; | |
365 | |
366 while (tree->root != tree->sentinel) { | |
367 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
368 rn = ngx_resolver_node(ngx_rbtree_min(tree->root, tree->sentinel)); |
1906 | 369 |
370 ngx_queue_remove(&rn->queue); | |
371 | |
372 for (ctx = rn->waiting; ctx; ctx = next) { | |
2006
b52cb9bf2064
style fix: remove tabs and trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1969
diff
changeset
|
373 next = ctx->next; |
1906 | 374 |
375 if (ctx->event) { | |
6844
259e2a76e8fb
Resolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov <ru@nginx.com>
parents:
6843
diff
changeset
|
376 if (ctx->event->timer_set) { |
259e2a76e8fb
Resolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov <ru@nginx.com>
parents:
6843
diff
changeset
|
377 ngx_del_timer(ctx->event); |
259e2a76e8fb
Resolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov <ru@nginx.com>
parents:
6843
diff
changeset
|
378 } |
259e2a76e8fb
Resolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov <ru@nginx.com>
parents:
6843
diff
changeset
|
379 |
1906 | 380 ngx_resolver_free(r, ctx->event); |
381 } | |
382 | |
383 ngx_resolver_free(r, ctx); | |
384 } | |
385 | |
386 ngx_rbtree_delete(tree, &rn->node); | |
387 | |
388 ngx_resolver_free_node(r, rn); | |
389 } | |
390 } | |
391 | |
392 | |
1649 | 393 ngx_resolver_ctx_t * |
394 ngx_resolve_start(ngx_resolver_t *r, ngx_resolver_ctx_t *temp) | |
395 { | |
396 in_addr_t addr; | |
397 ngx_resolver_ctx_t *ctx; | |
398 | |
399 if (temp) { | |
400 addr = ngx_inet_addr(temp->name.data, temp->name.len); | |
401 | |
402 if (addr != INADDR_NONE) { | |
403 temp->resolver = r; | |
404 temp->state = NGX_OK; | |
405 temp->naddrs = 1; | |
406 temp->addrs = &temp->addr; | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
407 temp->addr.sockaddr = (struct sockaddr *) &temp->sin; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
408 temp->addr.socklen = sizeof(struct sockaddr_in); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
409 ngx_memzero(&temp->sin, sizeof(struct sockaddr_in)); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
410 temp->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
411 temp->sin.sin_addr.s_addr = addr; |
1649 | 412 temp->quick = 1; |
413 | |
414 return temp; | |
415 } | |
416 } | |
417 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
418 if (r->connections.nelts == 0) { |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
419 return NGX_NO_RESOLVER; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
420 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
421 |
1649 | 422 ctx = ngx_resolver_calloc(r, sizeof(ngx_resolver_ctx_t)); |
423 | |
424 if (ctx) { | |
425 ctx->resolver = r; | |
426 } | |
427 | |
428 return ctx; | |
429 } | |
430 | |
431 | |
432 ngx_int_t | |
433 ngx_resolve_name(ngx_resolver_ctx_t *ctx) | |
434 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
435 size_t slen; |
1649 | 436 ngx_int_t rc; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
437 ngx_str_t name; |
1649 | 438 ngx_resolver_t *r; |
439 | |
440 r = ctx->resolver; | |
441 | |
5505
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
442 if (ctx->name.len > 0 && ctx->name.data[ctx->name.len - 1] == '.') { |
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
443 ctx->name.len--; |
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
444 } |
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
445 |
1649 | 446 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, |
447 "resolve: \"%V\"", &ctx->name); | |
448 | |
449 if (ctx->quick) { | |
450 ctx->handler(ctx); | |
451 return NGX_OK; | |
452 } | |
453 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
454 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
455 slen = ctx->service.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
456 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
457 if (ngx_strlchr(ctx->service.data, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
458 ctx->service.data + ctx->service.len, '.') |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
459 == NULL) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
460 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
461 slen += sizeof("_._tcp") - 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
462 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
463 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
464 name.len = slen + 1 + ctx->name.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
465 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
466 name.data = ngx_resolver_alloc(r, name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
467 if (name.data == NULL) { |
7039
a39bc74873fa
Resolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam <bartw@xs4all.nl>
parents:
6922
diff
changeset
|
468 goto failed; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
469 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
470 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
471 if (slen == ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
472 ngx_sprintf(name.data, "%V.%V", &ctx->service, &ctx->name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
473 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
474 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
475 ngx_sprintf(name.data, "_%V._tcp.%V", &ctx->service, &ctx->name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
476 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
477 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
478 /* lock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
479 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
480 rc = ngx_resolve_name_locked(r, ctx, &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
481 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
482 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
483 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
484 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
485 /* lock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
486 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
487 rc = ngx_resolve_name_locked(r, ctx, &ctx->name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
488 } |
1649 | 489 |
490 if (rc == NGX_OK) { | |
491 return NGX_OK; | |
492 } | |
493 | |
494 /* unlock name mutex */ | |
495 | |
496 if (rc == NGX_AGAIN) { | |
497 return NGX_OK; | |
498 } | |
499 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
500 /* NGX_ERROR */ |
1649 | 501 |
502 if (ctx->event) { | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
503 ngx_resolver_free(r, ctx->event); |
1649 | 504 } |
505 | |
7039
a39bc74873fa
Resolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam <bartw@xs4all.nl>
parents:
6922
diff
changeset
|
506 failed: |
a39bc74873fa
Resolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam <bartw@xs4all.nl>
parents:
6922
diff
changeset
|
507 |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
508 ngx_resolver_free(r, ctx); |
1649 | 509 |
510 return NGX_ERROR; | |
511 } | |
512 | |
513 | |
514 void | |
515 ngx_resolve_name_done(ngx_resolver_ctx_t *ctx) | |
516 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
517 ngx_uint_t i; |
1649 | 518 ngx_resolver_t *r; |
519 ngx_resolver_ctx_t *w, **p; | |
520 ngx_resolver_node_t *rn; | |
521 | |
522 r = ctx->resolver; | |
523 | |
524 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, | |
525 "resolve name done: %i", ctx->state); | |
526 | |
527 if (ctx->quick) { | |
528 return; | |
529 } | |
530 | |
531 if (ctx->event && ctx->event->timer_set) { | |
532 ngx_del_timer(ctx->event); | |
533 } | |
534 | |
535 /* lock name mutex */ | |
536 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
537 if (ctx->nsrvs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
538 for (i = 0; i < ctx->nsrvs; i++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
539 if (ctx->srvs[i].ctx) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
540 ngx_resolve_name_done(ctx->srvs[i].ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
541 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
542 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
543 if (ctx->srvs[i].addrs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
544 ngx_resolver_free(r, ctx->srvs[i].addrs->sockaddr); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
545 ngx_resolver_free(r, ctx->srvs[i].addrs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
546 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
547 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
548 ngx_resolver_free(r, ctx->srvs[i].name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
549 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
550 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
551 ngx_resolver_free(r, ctx->srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
552 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
553 |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
554 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) { |
1649 | 555 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
556 rn = ctx->node; |
1649 | 557 |
558 if (rn) { | |
559 p = &rn->waiting; | |
560 w = rn->waiting; | |
561 | |
562 while (w) { | |
563 if (w == ctx) { | |
564 *p = w->next; | |
565 | |
566 goto done; | |
567 } | |
568 | |
569 p = &w->next; | |
570 w = w->next; | |
571 } | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
572 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
573 ngx_log_error(NGX_LOG_ALERT, r->log, 0, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
574 "could not cancel %V resolving", &ctx->name); |
1649 | 575 } |
576 } | |
577 | |
578 done: | |
579 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
580 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
581 ngx_resolver_expire(r, &r->srv_rbtree, &r->srv_expire_queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
582 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
583 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
584 ngx_resolver_expire(r, &r->name_rbtree, &r->name_expire_queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
585 } |
1649 | 586 |
587 /* unlock name mutex */ | |
588 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
589 /* lock alloc mutex */ |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
590 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
591 if (ctx->event) { |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
592 ngx_resolver_free_locked(r, ctx->event); |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
593 } |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
594 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
595 ngx_resolver_free_locked(r, ctx); |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
596 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
597 /* unlock alloc mutex */ |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
598 |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
599 if (r->event->timer_set && ngx_resolver_resend_empty(r)) { |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
600 ngx_del_timer(r->event); |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
601 } |
1649 | 602 } |
603 | |
604 | |
605 static ngx_int_t | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
606 ngx_resolve_name_locked(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx, |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
607 ngx_str_t *name) |
1649 | 608 { |
609 uint32_t hash; | |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
610 ngx_int_t rc; |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
611 ngx_str_t cname; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
612 ngx_uint_t i, naddrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
613 ngx_queue_t *resend_queue, *expire_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
614 ngx_rbtree_t *tree; |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
615 ngx_resolver_ctx_t *next, *last; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
616 ngx_resolver_addr_t *addrs; |
1649 | 617 ngx_resolver_node_t *rn; |
618 | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
619 ngx_strlow(name->data, name->data, name->len); |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
620 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
621 hash = ngx_crc32_short(name->data, name->len); |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
622 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
623 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
624 rn = ngx_resolver_lookup_srv(r, name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
625 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
626 tree = &r->srv_rbtree; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
627 resend_queue = &r->srv_resend_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
628 expire_queue = &r->srv_expire_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
629 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
630 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
631 rn = ngx_resolver_lookup_name(r, name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
632 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
633 tree = &r->name_rbtree; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
634 resend_queue = &r->name_resend_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
635 expire_queue = &r->name_expire_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
636 } |
1649 | 637 |
638 if (rn) { | |
639 | |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
640 /* ctx can be a list after NGX_RESOLVE_CNAME */ |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
641 for (last = ctx; last->next; last = last->next); |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
642 |
1649 | 643 if (rn->valid >= ngx_time()) { |
644 | |
645 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached"); | |
646 | |
647 ngx_queue_remove(&rn->queue); | |
648 | |
649 rn->expire = ngx_time() + r->expire; | |
650 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
651 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 652 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
653 naddrs = (rn->naddrs == (u_short) -1) ? 0 : rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
654 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
655 naddrs += (rn->naddrs6 == (u_short) -1) ? 0 : rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
656 #endif |
1649 | 657 |
658 if (naddrs) { | |
659 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
660 if (naddrs == 1 && rn->naddrs == 1) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
661 addrs = NULL; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
662 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
663 } else { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
664 addrs = ngx_resolver_export(r, rn, 1); |
1649 | 665 if (addrs == NULL) { |
666 return NGX_ERROR; | |
667 } | |
668 } | |
669 | |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
670 last->next = rn->waiting; |
1649 | 671 rn->waiting = NULL; |
672 | |
673 /* unlock name mutex */ | |
674 | |
675 do { | |
676 ctx->state = NGX_OK; | |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
677 ctx->valid = rn->valid; |
1649 | 678 ctx->naddrs = naddrs; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
679 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
680 if (addrs == NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
681 ctx->addrs = &ctx->addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
682 ctx->addr.sockaddr = (struct sockaddr *) &ctx->sin; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
683 ctx->addr.socklen = sizeof(struct sockaddr_in); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
684 ngx_memzero(&ctx->sin, sizeof(struct sockaddr_in)); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
685 ctx->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
686 ctx->sin.sin_addr.s_addr = rn->u.addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
687 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
688 } else { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
689 ctx->addrs = addrs; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
690 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
691 |
1649 | 692 next = ctx->next; |
693 | |
694 ctx->handler(ctx); | |
695 | |
696 ctx = next; | |
697 } while (ctx); | |
698 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
699 if (addrs != NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
700 ngx_resolver_free(r, addrs->sockaddr); |
1649 | 701 ngx_resolver_free(r, addrs); |
702 } | |
703 | |
704 return NGX_OK; | |
705 } | |
706 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
707 if (rn->nsrvs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
708 last->next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
709 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
710 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
711 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
712 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
713 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
714 next = ctx->next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
715 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
716 ngx_resolver_resolve_srv_names(ctx, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
717 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
718 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
719 } while (ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
720 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
721 return NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
722 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
723 |
1649 | 724 /* NGX_RESOLVE_CNAME */ |
725 | |
1969 | 726 if (ctx->recursion++ < NGX_RESOLVER_MAX_RECURSION) { |
727 | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
728 cname.len = rn->cnlen; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
729 cname.data = rn->u.cname; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
730 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
731 return ngx_resolve_name_locked(r, ctx, &cname); |
1969 | 732 } |
733 | |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
734 last->next = rn->waiting; |
1969 | 735 rn->waiting = NULL; |
736 | |
737 /* unlock name mutex */ | |
738 | |
739 do { | |
740 ctx->state = NGX_RESOLVE_NXDOMAIN; | |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
741 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
1969 | 742 next = ctx->next; |
743 | |
744 ctx->handler(ctx); | |
745 | |
746 ctx = next; | |
747 } while (ctx); | |
748 | |
749 return NGX_OK; | |
1649 | 750 } |
751 | |
752 if (rn->waiting) { | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
753 if (ngx_resolver_set_timeout(r, ctx) != NGX_OK) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
754 return NGX_ERROR; |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
755 } |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
756 |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
757 last->next = rn->waiting; |
1649 | 758 rn->waiting = ctx; |
3297 | 759 ctx->state = NGX_AGAIN; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
760 ctx->async = 1; |
1649 | 761 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
762 do { |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
763 ctx->node = rn; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
764 ctx = ctx->next; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
765 } while (ctx); |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
766 |
1649 | 767 return NGX_AGAIN; |
768 } | |
769 | |
770 ngx_queue_remove(&rn->queue); | |
771 | |
772 /* lock alloc mutex */ | |
773 | |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
774 if (rn->query) { |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
775 ngx_resolver_free_locked(r, rn->query); |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
776 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
777 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
778 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
779 #endif |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
780 } |
1649 | 781 |
782 if (rn->cnlen) { | |
783 ngx_resolver_free_locked(r, rn->u.cname); | |
784 } | |
785 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
786 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) { |
1649 | 787 ngx_resolver_free_locked(r, rn->u.addrs); |
788 } | |
789 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
790 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
791 if (rn->naddrs6 > 1 && rn->naddrs6 != (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
792 ngx_resolver_free_locked(r, rn->u6.addrs6); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
793 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
794 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
795 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
796 if (rn->nsrvs) { |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
797 for (i = 0; i < (ngx_uint_t) rn->nsrvs; i++) { |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
798 if (rn->u.srvs[i].name.data) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
799 ngx_resolver_free_locked(r, rn->u.srvs[i].name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
800 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
801 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
802 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
803 ngx_resolver_free_locked(r, rn->u.srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
804 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
805 |
1649 | 806 /* unlock alloc mutex */ |
807 | |
808 } else { | |
809 | |
810 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t)); | |
811 if (rn == NULL) { | |
812 return NGX_ERROR; | |
813 } | |
814 | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
815 rn->name = ngx_resolver_dup(r, name->data, name->len); |
1649 | 816 if (rn->name == NULL) { |
817 ngx_resolver_free(r, rn); | |
818 return NGX_ERROR; | |
819 } | |
820 | |
821 rn->node.key = hash; | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
822 rn->nlen = (u_short) name->len; |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
823 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
824 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
825 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
826 #endif |
1649 | 827 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
828 ngx_rbtree_insert(tree, &rn->node); |
1649 | 829 } |
830 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
831 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
832 rc = ngx_resolver_create_srv_query(r, rn, name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
833 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
834 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
835 rc = ngx_resolver_create_name_query(r, rn, name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
836 } |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
837 |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
838 if (rc == NGX_ERROR) { |
1649 | 839 goto failed; |
840 } | |
841 | |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
842 if (rc == NGX_DECLINED) { |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
843 ngx_rbtree_delete(tree, &rn->node); |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
844 |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
845 ngx_resolver_free(r, rn->query); |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
846 ngx_resolver_free(r, rn->name); |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
847 ngx_resolver_free(r, rn); |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
848 |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
849 do { |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
850 ctx->state = NGX_RESOLVE_NXDOMAIN; |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
851 next = ctx->next; |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
852 |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
853 ctx->handler(ctx); |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
854 |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
855 ctx = next; |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
856 } while (ctx); |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
857 |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
858 return NGX_OK; |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
859 } |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
860 |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
861 rn->last_connection = r->last_connection++; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
862 if (r->last_connection == r->connections.nelts) { |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
863 r->last_connection = 0; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
864 } |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
865 |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
866 rn->naddrs = r->ipv4 ? (u_short) -1 : 0; |
6367 | 867 rn->tcp = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
868 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
869 rn->naddrs6 = r->ipv6 ? (u_short) -1 : 0; |
6367 | 870 rn->tcp6 = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
871 #endif |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
872 rn->nsrvs = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
873 |
1649 | 874 if (ngx_resolver_send_query(r, rn) != NGX_OK) { |
7312
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
875 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
876 /* immediately retry once on failure */ |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
877 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
878 rn->last_connection++; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
879 if (rn->last_connection == r->connections.nelts) { |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
880 rn->last_connection = 0; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
881 } |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
882 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
883 (void) ngx_resolver_send_query(r, rn); |
1649 | 884 } |
885 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
886 if (ngx_resolver_set_timeout(r, ctx) != NGX_OK) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
887 goto failed; |
1649 | 888 } |
889 | |
6846
c3a895b94d3f
Resolver: fixed a race between parallel name and addr resolves.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6845
diff
changeset
|
890 if (ngx_resolver_resend_empty(r)) { |
1649 | 891 ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000)); |
892 } | |
893 | |
894 rn->expire = ngx_time() + r->resend_timeout; | |
895 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
896 ngx_queue_insert_head(resend_queue, &rn->queue); |
1649 | 897 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
898 rn->code = 0; |
1649 | 899 rn->cnlen = 0; |
900 rn->valid = 0; | |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
901 rn->ttl = NGX_MAX_UINT32_VALUE; |
1649 | 902 rn->waiting = ctx; |
903 | |
904 ctx->state = NGX_AGAIN; | |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
905 ctx->async = 1; |
1649 | 906 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
907 do { |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
908 ctx->node = rn; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
909 ctx = ctx->next; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
910 } while (ctx); |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
911 |
1649 | 912 return NGX_AGAIN; |
913 | |
914 failed: | |
915 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
916 ngx_rbtree_delete(tree, &rn->node); |
1649 | 917 |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
918 if (rn->query) { |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
919 ngx_resolver_free(r, rn->query); |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
920 } |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
921 |
1649 | 922 ngx_resolver_free(r, rn->name); |
923 | |
924 ngx_resolver_free(r, rn); | |
925 | |
926 return NGX_ERROR; | |
927 } | |
583 | 928 |
929 | |
930 ngx_int_t | |
1649 | 931 ngx_resolve_addr(ngx_resolver_ctx_t *ctx) |
932 { | |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
933 u_char *name; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
934 in_addr_t addr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
935 ngx_queue_t *resend_queue, *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
936 ngx_rbtree_t *tree; |
1649 | 937 ngx_resolver_t *r; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
938 struct sockaddr_in *sin; |
1649 | 939 ngx_resolver_node_t *rn; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
940 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
941 uint32_t hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
942 struct sockaddr_in6 *sin6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
943 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
944 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
945 #if (NGX_SUPPRESS_WARN) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
946 addr = 0; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
947 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
948 hash = 0; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
949 sin6 = NULL; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
950 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
951 #endif |
1649 | 952 |
953 r = ctx->resolver; | |
954 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
955 switch (ctx->addr.sockaddr->sa_family) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
956 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
957 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
958 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
959 sin6 = (struct sockaddr_in6 *) ctx->addr.sockaddr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
960 hash = ngx_crc32_short(sin6->sin6_addr.s6_addr, 16); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
961 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
962 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
963 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
964 rn = ngx_resolver_lookup_addr6(r, &sin6->sin6_addr, hash); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
965 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
966 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
967 resend_queue = &r->addr6_resend_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
968 expire_queue = &r->addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
969 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
970 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
971 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
972 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
973 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
974 sin = (struct sockaddr_in *) ctx->addr.sockaddr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
975 addr = ntohl(sin->sin_addr.s_addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
976 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
977 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
978 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
979 rn = ngx_resolver_lookup_addr(r, addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
980 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
981 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
982 resend_queue = &r->addr_resend_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
983 expire_queue = &r->addr_expire_queue; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
984 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
985 |
1649 | 986 if (rn) { |
987 | |
988 if (rn->valid >= ngx_time()) { | |
989 | |
990 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached"); | |
991 | |
992 ngx_queue_remove(&rn->queue); | |
993 | |
994 rn->expire = ngx_time() + r->expire; | |
995 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
996 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 997 |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
998 name = ngx_resolver_dup(r, rn->name, rn->nlen); |
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
999 if (name == NULL) { |
7566
571383f75a9a
Resolver: fixed possible use-after-free while resolving PTR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7428
diff
changeset
|
1000 ngx_resolver_free(r, ctx); |
571383f75a9a
Resolver: fixed possible use-after-free while resolving PTR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7428
diff
changeset
|
1001 return NGX_ERROR; |
1649 | 1002 } |
1003 | |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
1004 ctx->name.len = rn->nlen; |
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
1005 ctx->name.data = name; |
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
1006 |
1649 | 1007 /* unlock addr mutex */ |
1008 | |
1009 ctx->state = NGX_OK; | |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
1010 ctx->valid = rn->valid; |
1649 | 1011 |
1012 ctx->handler(ctx); | |
1013 | |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
1014 ngx_resolver_free(r, name); |
1649 | 1015 |
1016 return NGX_OK; | |
1017 } | |
1018 | |
1019 if (rn->waiting) { | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
1020 if (ngx_resolver_set_timeout(r, ctx) != NGX_OK) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
1021 return NGX_ERROR; |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
1022 } |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
1023 |
1649 | 1024 ctx->next = rn->waiting; |
1025 rn->waiting = ctx; | |
3297 | 1026 ctx->state = NGX_AGAIN; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
1027 ctx->async = 1; |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
1028 ctx->node = rn; |
1649 | 1029 |
2487
9b4dce95c744
fix return code, this fixes segfault when two or more
Igor Sysoev <igor@sysoev.ru>
parents:
2486
diff
changeset
|
1030 /* unlock addr mutex */ |
9b4dce95c744
fix return code, this fixes segfault when two or more
Igor Sysoev <igor@sysoev.ru>
parents:
2486
diff
changeset
|
1031 |
9b4dce95c744
fix return code, this fixes segfault when two or more
Igor Sysoev <igor@sysoev.ru>
parents:
2486
diff
changeset
|
1032 return NGX_OK; |
1649 | 1033 } |
1034 | |
1035 ngx_queue_remove(&rn->queue); | |
1036 | |
1037 ngx_resolver_free(r, rn->query); | |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1038 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1039 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1040 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1041 #endif |
1649 | 1042 |
1043 } else { | |
1044 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t)); | |
1045 if (rn == NULL) { | |
1046 goto failed; | |
1047 } | |
1048 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1049 switch (ctx->addr.sockaddr->sa_family) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1050 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1051 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1052 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1053 rn->addr6 = sin6->sin6_addr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1054 rn->node.key = hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1055 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1056 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1057 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1058 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1059 rn->node.key = addr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1060 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1061 |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1062 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1063 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1064 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1065 #endif |
1649 | 1066 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1067 ngx_rbtree_insert(tree, &rn->node); |
1649 | 1068 } |
1069 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
1070 if (ngx_resolver_create_addr_query(r, rn, &ctx->addr) != NGX_OK) { |
1649 | 1071 goto failed; |
1072 } | |
1073 | |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1074 rn->last_connection = r->last_connection++; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1075 if (r->last_connection == r->connections.nelts) { |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1076 r->last_connection = 0; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1077 } |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1078 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1079 rn->naddrs = (u_short) -1; |
6367 | 1080 rn->tcp = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1081 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1082 rn->naddrs6 = (u_short) -1; |
6367 | 1083 rn->tcp6 = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1084 #endif |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1085 rn->nsrvs = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1086 |
1649 | 1087 if (ngx_resolver_send_query(r, rn) != NGX_OK) { |
7312
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1088 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1089 /* immediately retry once on failure */ |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1090 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1091 rn->last_connection++; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1092 if (rn->last_connection == r->connections.nelts) { |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1093 rn->last_connection = 0; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1094 } |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1095 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1096 (void) ngx_resolver_send_query(r, rn); |
1649 | 1097 } |
1098 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
1099 if (ngx_resolver_set_timeout(r, ctx) != NGX_OK) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
1100 goto failed; |
1649 | 1101 } |
1102 | |
6846
c3a895b94d3f
Resolver: fixed a race between parallel name and addr resolves.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6845
diff
changeset
|
1103 if (ngx_resolver_resend_empty(r)) { |
1649 | 1104 ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000)); |
1105 } | |
1106 | |
1107 rn->expire = ngx_time() + r->resend_timeout; | |
1108 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1109 ngx_queue_insert_head(resend_queue, &rn->queue); |
1649 | 1110 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1111 rn->code = 0; |
1649 | 1112 rn->cnlen = 0; |
1113 rn->name = NULL; | |
1114 rn->nlen = 0; | |
1115 rn->valid = 0; | |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
1116 rn->ttl = NGX_MAX_UINT32_VALUE; |
1649 | 1117 rn->waiting = ctx; |
1118 | |
1119 /* unlock addr mutex */ | |
1120 | |
1121 ctx->state = NGX_AGAIN; | |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
1122 ctx->async = 1; |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
1123 ctx->node = rn; |
1649 | 1124 |
1125 return NGX_OK; | |
1126 | |
1127 failed: | |
1128 | |
1129 if (rn) { | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1130 ngx_rbtree_delete(tree, &rn->node); |
1649 | 1131 |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1132 if (rn->query) { |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1133 ngx_resolver_free(r, rn->query); |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1134 } |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1135 |
1649 | 1136 ngx_resolver_free(r, rn); |
1137 } | |
1138 | |
1139 /* unlock addr mutex */ | |
1140 | |
1141 if (ctx->event) { | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1142 ngx_resolver_free(r, ctx->event); |
1649 | 1143 } |
1144 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1145 ngx_resolver_free(r, ctx); |
1649 | 1146 |
1147 return NGX_ERROR; | |
1148 } | |
1149 | |
1150 | |
1151 void | |
1152 ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx) | |
1153 { | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1154 ngx_queue_t *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1155 ngx_rbtree_t *tree; |
1649 | 1156 ngx_resolver_t *r; |
1157 ngx_resolver_ctx_t *w, **p; | |
1158 ngx_resolver_node_t *rn; | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
1159 |
1649 | 1160 r = ctx->resolver; |
1161 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1162 switch (ctx->addr.sockaddr->sa_family) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1163 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1164 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1165 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1166 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1167 expire_queue = &r->addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1168 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1169 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1170 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1171 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1172 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1173 expire_queue = &r->addr_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1174 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1175 |
1649 | 1176 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, |
1177 "resolve addr done: %i", ctx->state); | |
1178 | |
1179 if (ctx->event && ctx->event->timer_set) { | |
1180 ngx_del_timer(ctx->event); | |
1181 } | |
1182 | |
1183 /* lock addr mutex */ | |
1184 | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
1185 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) { |
1649 | 1186 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
1187 rn = ctx->node; |
1649 | 1188 |
1189 if (rn) { | |
1190 p = &rn->waiting; | |
1191 w = rn->waiting; | |
1192 | |
1193 while (w) { | |
1194 if (w == ctx) { | |
1195 *p = w->next; | |
1196 | |
1197 goto done; | |
1198 } | |
1199 | |
1200 p = &w->next; | |
1201 w = w->next; | |
1202 } | |
1203 } | |
1204 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1205 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1206 u_char text[NGX_SOCKADDR_STRLEN]; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1207 ngx_str_t addrtext; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1208 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1209 addrtext.data = text; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1210 addrtext.len = ngx_sock_ntop(ctx->addr.sockaddr, ctx->addr.socklen, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1211 text, NGX_SOCKADDR_STRLEN, 0); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1212 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1213 ngx_log_error(NGX_LOG_ALERT, r->log, 0, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1214 "could not cancel %V resolving", &addrtext); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1215 } |
1649 | 1216 } |
1217 | |
1218 done: | |
1219 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1220 ngx_resolver_expire(r, tree, expire_queue); |
1649 | 1221 |
1222 /* unlock addr mutex */ | |
1223 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1224 /* lock alloc mutex */ |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1225 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1226 if (ctx->event) { |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1227 ngx_resolver_free_locked(r, ctx->event); |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1228 } |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1229 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1230 ngx_resolver_free_locked(r, ctx); |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1231 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1232 /* unlock alloc mutex */ |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1233 |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1234 if (r->event->timer_set && ngx_resolver_resend_empty(r)) { |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1235 ngx_del_timer(r->event); |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1236 } |
1649 | 1237 } |
1238 | |
1239 | |
1240 static void | |
1241 ngx_resolver_expire(ngx_resolver_t *r, ngx_rbtree_t *tree, ngx_queue_t *queue) | |
1242 { | |
1243 time_t now; | |
1244 ngx_uint_t i; | |
1245 ngx_queue_t *q; | |
1246 ngx_resolver_node_t *rn; | |
1247 | |
1248 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver expire"); | |
1249 | |
1250 now = ngx_time(); | |
1251 | |
1252 for (i = 0; i < 2; i++) { | |
1253 if (ngx_queue_empty(queue)) { | |
1254 return; | |
1255 } | |
1256 | |
1257 q = ngx_queue_last(queue); | |
1258 | |
1259 rn = ngx_queue_data(q, ngx_resolver_node_t, queue); | |
1260 | |
1261 if (now <= rn->expire) { | |
1262 return; | |
1263 } | |
1264 | |
1774 | 1265 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, |
1266 "resolver expire \"%*s\"", (size_t) rn->nlen, rn->name); | |
1649 | 1267 |
1268 ngx_queue_remove(q); | |
1269 | |
1270 ngx_rbtree_delete(tree, &rn->node); | |
1271 | |
1272 ngx_resolver_free_node(r, rn); | |
1273 } | |
1274 } | |
1275 | |
1276 | |
1277 static ngx_int_t | |
1278 ngx_resolver_send_query(ngx_resolver_t *r, ngx_resolver_node_t *rn) | |
1279 { | |
6367 | 1280 ngx_int_t rc; |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1281 ngx_resolver_connection_t *rec; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1282 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1283 rec = r->connections.elts; |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1284 rec = &rec[rn->last_connection]; |
1649 | 1285 |
6367 | 1286 if (rec->log.handler == NULL) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1287 rec->log = *r->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1288 rec->log.handler = ngx_resolver_log_error; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1289 rec->log.data = rec; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1290 rec->log.action = "resolving"; |
1649 | 1291 } |
1292 | |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1293 if (rn->query && rn->naddrs == (u_short) -1) { |
6367 | 1294 rc = rn->tcp ? ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen) |
1295 : ngx_resolver_send_udp_query(r, rec, rn->query, rn->qlen); | |
1296 | |
1297 if (rc != NGX_OK) { | |
1298 return rc; | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1299 } |
1649 | 1300 } |
1301 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1302 #if (NGX_HAVE_INET6) |
6367 | 1303 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1304 if (rn->query6 && rn->naddrs6 == (u_short) -1) { |
6367 | 1305 rc = rn->tcp6 |
1306 ? ngx_resolver_send_tcp_query(r, rec, rn->query6, rn->qlen) | |
1307 : ngx_resolver_send_udp_query(r, rec, rn->query6, rn->qlen); | |
1308 | |
1309 if (rc != NGX_OK) { | |
1310 return rc; | |
1311 } | |
1312 } | |
1313 | |
1314 #endif | |
1315 | |
1316 return NGX_OK; | |
1317 } | |
1318 | |
1319 | |
1320 static ngx_int_t | |
1321 ngx_resolver_send_udp_query(ngx_resolver_t *r, ngx_resolver_connection_t *rec, | |
1322 u_char *query, u_short qlen) | |
1323 { | |
1324 ssize_t n; | |
1325 | |
1326 if (rec->udp == NULL) { | |
1327 if (ngx_udp_connect(rec) != NGX_OK) { | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1328 return NGX_ERROR; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1329 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1330 |
6367 | 1331 rec->udp->data = rec; |
1332 rec->udp->read->handler = ngx_resolver_udp_read; | |
1333 rec->udp->read->resolver = 1; | |
1334 } | |
1335 | |
1336 n = ngx_send(rec->udp, query, qlen); | |
1337 | |
7275 | 1338 if (n == NGX_ERROR) { |
7276
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1339 goto failed; |
6367 | 1340 } |
1341 | |
1342 if ((size_t) n != (size_t) qlen) { | |
1343 ngx_log_error(NGX_LOG_CRIT, &rec->log, 0, "send() incomplete"); | |
7276
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1344 goto failed; |
6367 | 1345 } |
1346 | |
1347 return NGX_OK; | |
7276
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1348 |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1349 failed: |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1350 |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1351 ngx_close_connection(rec->udp); |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1352 rec->udp = NULL; |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1353 |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1354 return NGX_ERROR; |
6367 | 1355 } |
1356 | |
1357 | |
1358 static ngx_int_t | |
1359 ngx_resolver_send_tcp_query(ngx_resolver_t *r, ngx_resolver_connection_t *rec, | |
1360 u_char *query, u_short qlen) | |
1361 { | |
1362 ngx_buf_t *b; | |
1363 ngx_int_t rc; | |
1364 | |
1365 rc = NGX_OK; | |
1366 | |
1367 if (rec->tcp == NULL) { | |
1368 b = rec->read_buf; | |
1369 | |
1370 if (b == NULL) { | |
1371 b = ngx_resolver_calloc(r, sizeof(ngx_buf_t)); | |
1372 if (b == NULL) { | |
1373 return NGX_ERROR; | |
1374 } | |
1375 | |
1376 b->start = ngx_resolver_alloc(r, NGX_RESOLVER_TCP_RSIZE); | |
1377 if (b->start == NULL) { | |
6368
d73f77bb5caf
Resolver: fixed possible resource leak introduced in 5a16d40c63de.
Ruslan Ermilov <ru@nginx.com>
parents:
6367
diff
changeset
|
1378 ngx_resolver_free(r, b); |
6367 | 1379 return NGX_ERROR; |
1380 } | |
1381 | |
1382 b->end = b->start + NGX_RESOLVER_TCP_RSIZE; | |
1383 | |
1384 rec->read_buf = b; | |
1385 } | |
1386 | |
1387 b->pos = b->start; | |
1388 b->last = b->start; | |
1389 | |
1390 b = rec->write_buf; | |
1391 | |
1392 if (b == NULL) { | |
1393 b = ngx_resolver_calloc(r, sizeof(ngx_buf_t)); | |
1394 if (b == NULL) { | |
1395 return NGX_ERROR; | |
1396 } | |
1397 | |
1398 b->start = ngx_resolver_alloc(r, NGX_RESOLVER_TCP_WSIZE); | |
1399 if (b->start == NULL) { | |
6368
d73f77bb5caf
Resolver: fixed possible resource leak introduced in 5a16d40c63de.
Ruslan Ermilov <ru@nginx.com>
parents:
6367
diff
changeset
|
1400 ngx_resolver_free(r, b); |
6367 | 1401 return NGX_ERROR; |
1402 } | |
1403 | |
1404 b->end = b->start + NGX_RESOLVER_TCP_WSIZE; | |
1405 | |
1406 rec->write_buf = b; | |
1407 } | |
1408 | |
1409 b->pos = b->start; | |
1410 b->last = b->start; | |
1411 | |
1412 rc = ngx_tcp_connect(rec); | |
1413 if (rc == NGX_ERROR) { | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1414 return NGX_ERROR; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1415 } |
6367 | 1416 |
1417 rec->tcp->data = rec; | |
1418 rec->tcp->write->handler = ngx_resolver_tcp_write; | |
8896
aa28c802409f
Resolver: make TCP write timer event cancelable.
Aleksei Bavshin <a.bavshin@f5.com>
parents:
8523
diff
changeset
|
1419 rec->tcp->write->cancelable = 1; |
6367 | 1420 rec->tcp->read->handler = ngx_resolver_tcp_read; |
1421 rec->tcp->read->resolver = 1; | |
1422 | |
1423 ngx_add_timer(rec->tcp->write, (ngx_msec_t) (r->tcp_timeout * 1000)); | |
1649 | 1424 } |
6367 | 1425 |
1426 b = rec->write_buf; | |
1427 | |
1428 if (b->end - b->last < 2 + qlen) { | |
1429 ngx_log_error(NGX_LOG_CRIT, &rec->log, 0, "buffer overflow"); | |
1430 return NGX_ERROR; | |
1431 } | |
1432 | |
1433 *b->last++ = (u_char) (qlen >> 8); | |
1434 *b->last++ = (u_char) qlen; | |
1435 b->last = ngx_cpymem(b->last, query, qlen); | |
1436 | |
1437 if (rc == NGX_OK) { | |
1438 ngx_resolver_tcp_write(rec->tcp->write); | |
1439 } | |
1649 | 1440 |
1441 return NGX_OK; | |
1442 } | |
1443 | |
1444 | |
1445 static void | |
1446 ngx_resolver_resend_handler(ngx_event_t *ev) | |
1447 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1448 time_t timer, atimer, stimer, ntimer; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1449 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1450 time_t a6timer; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1451 #endif |
1649 | 1452 ngx_resolver_t *r; |
1453 | |
1454 r = ev->data; | |
1455 | |
1456 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, | |
1457 "resolver resend handler"); | |
1458 | |
1459 /* lock name mutex */ | |
1460 | |
1461 ntimer = ngx_resolver_resend(r, &r->name_rbtree, &r->name_resend_queue); | |
1462 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1463 stimer = ngx_resolver_resend(r, &r->srv_rbtree, &r->srv_resend_queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1464 |
1649 | 1465 /* unlock name mutex */ |
1466 | |
1467 /* lock addr mutex */ | |
1468 | |
1469 atimer = ngx_resolver_resend(r, &r->addr_rbtree, &r->addr_resend_queue); | |
1679
ca317d9b5c09
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
1470 |
1649 | 1471 /* unlock addr mutex */ |
1472 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1473 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1474 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1475 /* lock addr6 mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1476 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1477 a6timer = ngx_resolver_resend(r, &r->addr6_rbtree, &r->addr6_resend_queue); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1478 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1479 /* unlock addr6 mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1480 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1481 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1482 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1483 timer = ntimer; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1484 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1485 if (timer == 0) { |
1649 | 1486 timer = atimer; |
1487 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1488 } else if (atimer) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1489 timer = ngx_min(timer, atimer); |
1649 | 1490 } |
1491 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1492 if (timer == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1493 timer = stimer; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1494 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1495 } else if (stimer) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1496 timer = ngx_min(timer, stimer); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1497 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1498 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1499 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1500 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1501 if (timer == 0) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1502 timer = a6timer; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1503 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1504 } else if (a6timer) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1505 timer = ngx_min(timer, a6timer); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1506 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1507 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1508 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1509 |
1649 | 1510 if (timer) { |
1511 ngx_add_timer(r->event, (ngx_msec_t) (timer * 1000)); | |
1512 } | |
1513 } | |
1514 | |
1515 | |
1516 static time_t | |
1517 ngx_resolver_resend(ngx_resolver_t *r, ngx_rbtree_t *tree, ngx_queue_t *queue) | |
1518 { | |
1519 time_t now; | |
1520 ngx_queue_t *q; | |
1521 ngx_resolver_node_t *rn; | |
1522 | |
1523 now = ngx_time(); | |
1524 | |
1525 for ( ;; ) { | |
1526 if (ngx_queue_empty(queue)) { | |
1527 return 0; | |
1528 } | |
1529 | |
1530 q = ngx_queue_last(queue); | |
1531 | |
1532 rn = ngx_queue_data(q, ngx_resolver_node_t, queue); | |
1533 | |
1534 if (now < rn->expire) { | |
1535 return rn->expire - now; | |
1536 } | |
1537 | |
1774 | 1538 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0, |
1539 "resolver resend \"%*s\" %p", | |
1540 (size_t) rn->nlen, rn->name, rn->waiting); | |
1649 | 1541 |
1542 ngx_queue_remove(q); | |
1543 | |
1544 if (rn->waiting) { | |
1545 | |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1546 if (++rn->last_connection == r->connections.nelts) { |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1547 rn->last_connection = 0; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1548 } |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1549 |
4683
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1550 (void) ngx_resolver_send_query(r, rn); |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1551 |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1552 rn->expire = now + r->resend_timeout; |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1553 |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1554 ngx_queue_insert_head(queue, q); |
1879
cf4ee321d195
do not delete failed DNS request if there are waiting clients
Igor Sysoev <igor@sysoev.ru>
parents:
1878
diff
changeset
|
1555 |
cf4ee321d195
do not delete failed DNS request if there are waiting clients
Igor Sysoev <igor@sysoev.ru>
parents:
1878
diff
changeset
|
1556 continue; |
1649 | 1557 } |
1558 | |
1559 ngx_rbtree_delete(tree, &rn->node); | |
1560 | |
1561 ngx_resolver_free_node(r, rn); | |
1562 } | |
1563 } | |
1564 | |
1565 | |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1566 static ngx_uint_t |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1567 ngx_resolver_resend_empty(ngx_resolver_t *r) |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1568 { |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1569 return ngx_queue_empty(&r->name_resend_queue) |
6845
9abba5b70ea0
Resolver: fixed possible premature stop of the resend timer.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6844
diff
changeset
|
1570 && ngx_queue_empty(&r->srv_resend_queue) |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1571 #if (NGX_HAVE_INET6) |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1572 && ngx_queue_empty(&r->addr6_resend_queue) |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1573 #endif |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1574 && ngx_queue_empty(&r->addr_resend_queue); |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1575 } |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1576 |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1577 |
1649 | 1578 static void |
6367 | 1579 ngx_resolver_udp_read(ngx_event_t *rev) |
1649 | 1580 { |
6367 | 1581 ssize_t n; |
1582 ngx_connection_t *c; | |
1583 ngx_resolver_connection_t *rec; | |
1584 u_char buf[NGX_RESOLVER_UDP_SIZE]; | |
1649 | 1585 |
1586 c = rev->data; | |
6367 | 1587 rec = c->data; |
1649 | 1588 |
1589 do { | |
1689 | 1590 n = ngx_udp_recv(c, buf, NGX_RESOLVER_UDP_SIZE); |
1591 | |
8371
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1592 if (n == NGX_AGAIN) { |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1593 break; |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1594 } |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1595 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1596 if (n == NGX_ERROR) { |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1597 goto failed; |
1649 | 1598 } |
1599 | |
6367 | 1600 ngx_resolver_process_response(rec->resolver, buf, n, 0); |
1649 | 1601 |
1602 } while (rev->ready); | |
8371
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1603 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1604 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1605 goto failed; |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1606 } |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1607 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1608 return; |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1609 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1610 failed: |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1611 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1612 ngx_close_connection(rec->udp); |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1613 rec->udp = NULL; |
1649 | 1614 } |
1615 | |
1616 | |
1617 static void | |
6367 | 1618 ngx_resolver_tcp_write(ngx_event_t *wev) |
1619 { | |
1620 off_t sent; | |
1621 ssize_t n; | |
1622 ngx_buf_t *b; | |
1623 ngx_resolver_t *r; | |
1624 ngx_connection_t *c; | |
1625 ngx_resolver_connection_t *rec; | |
1626 | |
1627 c = wev->data; | |
1628 rec = c->data; | |
1629 b = rec->write_buf; | |
1630 r = rec->resolver; | |
1631 | |
1632 if (wev->timedout) { | |
1633 goto failed; | |
1634 } | |
1635 | |
1636 sent = c->sent; | |
1637 | |
1638 while (wev->ready && b->pos < b->last) { | |
1639 n = ngx_send(c, b->pos, b->last - b->pos); | |
1640 | |
1641 if (n == NGX_AGAIN) { | |
1642 break; | |
1643 } | |
1644 | |
1645 if (n == NGX_ERROR) { | |
1646 goto failed; | |
1647 } | |
1648 | |
1649 b->pos += n; | |
1650 } | |
1651 | |
1652 if (b->pos != b->start) { | |
1653 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); | |
1654 b->pos = b->start; | |
1655 } | |
1656 | |
1657 if (c->sent != sent) { | |
1658 ngx_add_timer(wev, (ngx_msec_t) (r->tcp_timeout * 1000)); | |
1659 } | |
1660 | |
1661 if (ngx_handle_write_event(wev, 0) != NGX_OK) { | |
1662 goto failed; | |
1663 } | |
1664 | |
1665 return; | |
1666 | |
1667 failed: | |
1668 | |
1669 ngx_close_connection(c); | |
1670 rec->tcp = NULL; | |
1671 } | |
1672 | |
1673 | |
1674 static void | |
1675 ngx_resolver_tcp_read(ngx_event_t *rev) | |
1676 { | |
1677 u_char *p; | |
1678 size_t size; | |
1679 ssize_t n; | |
1680 u_short qlen; | |
1681 ngx_buf_t *b; | |
1682 ngx_resolver_t *r; | |
1683 ngx_connection_t *c; | |
1684 ngx_resolver_connection_t *rec; | |
1685 | |
1686 c = rev->data; | |
1687 rec = c->data; | |
1688 b = rec->read_buf; | |
1689 r = rec->resolver; | |
1690 | |
1691 while (rev->ready) { | |
1692 n = ngx_recv(c, b->last, b->end - b->last); | |
1693 | |
1694 if (n == NGX_AGAIN) { | |
1695 break; | |
1696 } | |
1697 | |
1698 if (n == NGX_ERROR || n == 0) { | |
1699 goto failed; | |
1700 } | |
1701 | |
1702 b->last += n; | |
1703 | |
1704 for ( ;; ) { | |
1705 p = b->pos; | |
1706 size = b->last - p; | |
1707 | |
1708 if (size < 2) { | |
1709 break; | |
1710 } | |
1711 | |
1712 qlen = (u_short) *p++ << 8; | |
1713 qlen += *p++; | |
1714 | |
1715 if (size < (size_t) (2 + qlen)) { | |
1716 break; | |
1717 } | |
1718 | |
1719 ngx_resolver_process_response(r, p, qlen, 1); | |
1720 | |
1721 b->pos += 2 + qlen; | |
1722 } | |
1723 | |
1724 if (b->pos != b->start) { | |
1725 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); | |
1726 b->pos = b->start; | |
1727 } | |
1728 } | |
1729 | |
1730 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
1731 goto failed; | |
1732 } | |
1733 | |
1734 return; | |
1735 | |
1736 failed: | |
1737 | |
1738 ngx_close_connection(c); | |
1739 rec->tcp = NULL; | |
1740 } | |
1741 | |
1742 | |
1743 static void | |
1744 ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, size_t n, | |
1745 ngx_uint_t tcp) | |
1649 | 1746 { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1747 char *err; |
6367 | 1748 ngx_uint_t i, times, ident, qident, flags, code, nqs, nan, trunc, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1749 qtype, qclass; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1750 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1751 ngx_uint_t qident6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1752 #endif |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1753 ngx_queue_t *q; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1754 ngx_resolver_qs_t *qs; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1755 ngx_resolver_hdr_t *response; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1756 ngx_resolver_node_t *rn; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1757 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1758 if (n < sizeof(ngx_resolver_hdr_t)) { |
1649 | 1759 goto short_response; |
1760 } | |
1761 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1762 response = (ngx_resolver_hdr_t *) buf; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1763 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1764 ident = (response->ident_hi << 8) + response->ident_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1765 flags = (response->flags_hi << 8) + response->flags_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1766 nqs = (response->nqs_hi << 8) + response->nqs_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1767 nan = (response->nan_hi << 8) + response->nan_lo; |
6367 | 1768 trunc = flags & 0x0200; |
1649 | 1769 |
1770 ngx_log_debug6(NGX_LOG_DEBUG_CORE, r->log, 0, | |
6509
7640d6c213e1
Removed redundant "u" format specifier.
Ruslan Ermilov <ru@nginx.com>
parents:
6478
diff
changeset
|
1771 "resolver DNS response %ui fl:%04Xi %ui/%ui/%ud/%ud", |
1649 | 1772 ident, flags, nqs, nan, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1773 (response->nns_hi << 8) + response->nns_lo, |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1774 (response->nar_hi << 8) + response->nar_lo); |
1649 | 1775 |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1776 /* response to a standard query */ |
6367 | 1777 if ((flags & 0xf870) != 0x8000 || (trunc && tcp)) { |
1649 | 1778 ngx_log_error(r->log_level, r->log, 0, |
6509
7640d6c213e1
Removed redundant "u" format specifier.
Ruslan Ermilov <ru@nginx.com>
parents:
6478
diff
changeset
|
1779 "invalid %s DNS response %ui fl:%04Xi", |
6367 | 1780 tcp ? "TCP" : "UDP", ident, flags); |
1649 | 1781 return; |
1782 } | |
1783 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1784 code = flags & 0xf; |
1649 | 1785 |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1786 if (code == NGX_RESOLVE_FORMERR) { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1787 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1788 times = 0; |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1789 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1790 for (q = ngx_queue_head(&r->name_resend_queue); |
6347
81d44cd4044e
Resolver: fixed possible segmentation fault on DNS format error.
Roman Arutyunyan <arut@nginx.com>
parents:
6196
diff
changeset
|
1791 q != ngx_queue_sentinel(&r->name_resend_queue) && times++ < 100; |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1792 q = ngx_queue_next(q)) |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1793 { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1794 rn = ngx_queue_data(q, ngx_resolver_node_t, queue); |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1795 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1796 if (rn->query) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1797 qident = (rn->query[0] << 8) + rn->query[1]; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1798 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1799 if (qident == ident) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1800 goto dns_error_name; |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
1801 } |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1802 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1803 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1804 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1805 if (rn->query6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1806 qident6 = (rn->query6[0] << 8) + rn->query6[1]; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1807 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1808 if (qident6 == ident) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1809 goto dns_error_name; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1810 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1811 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1812 #endif |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1813 } |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1814 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1815 goto dns_error; |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1816 } |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1817 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1818 if (code > NGX_RESOLVE_REFUSED) { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1819 goto dns_error; |
1649 | 1820 } |
1821 | |
1822 if (nqs != 1) { | |
1823 err = "invalid number of questions in DNS response"; | |
1824 goto done; | |
1825 } | |
1826 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1827 i = sizeof(ngx_resolver_hdr_t); |
1649 | 1828 |
1829 while (i < (ngx_uint_t) n) { | |
8475
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1830 |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1831 if (buf[i] & 0xc0) { |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1832 err = "unexpected compression pointer in DNS response"; |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1833 goto done; |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1834 } |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1835 |
1649 | 1836 if (buf[i] == '\0') { |
1837 goto found; | |
1838 } | |
1839 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1840 i += 1 + buf[i]; |
1649 | 1841 } |
1842 | |
1843 goto short_response; | |
1844 | |
1845 found: | |
1846 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1847 if (i++ == sizeof(ngx_resolver_hdr_t)) { |
1649 | 1848 err = "zero-length domain name in DNS response"; |
1849 goto done; | |
1850 } | |
1851 | |
1852 if (i + sizeof(ngx_resolver_qs_t) + nan * (2 + sizeof(ngx_resolver_an_t)) | |
1853 > (ngx_uint_t) n) | |
1854 { | |
1855 goto short_response; | |
1856 } | |
1857 | |
1858 qs = (ngx_resolver_qs_t *) &buf[i]; | |
1859 | |
1860 qtype = (qs->type_hi << 8) + qs->type_lo; | |
1861 qclass = (qs->class_hi << 8) + qs->class_lo; | |
1862 | |
1863 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, | |
1967
4a4b15c9c474
use correct ngx_sprintf() formats
Igor Sysoev <igor@sysoev.ru>
parents:
1966
diff
changeset
|
1864 "resolver DNS response qt:%ui cl:%ui", qtype, qclass); |
1649 | 1865 |
1866 if (qclass != 1) { | |
1867 ngx_log_error(r->log_level, r->log, 0, | |
1967
4a4b15c9c474
use correct ngx_sprintf() formats
Igor Sysoev <igor@sysoev.ru>
parents:
1966
diff
changeset
|
1868 "unknown query class %ui in DNS response", qclass); |
1649 | 1869 return; |
1870 } | |
1871 | |
1872 switch (qtype) { | |
1873 | |
1874 case NGX_RESOLVE_A: | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1875 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1876 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1877 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1878 |
6367 | 1879 ngx_resolver_process_a(r, buf, n, ident, code, qtype, nan, trunc, |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
1880 i + sizeof(ngx_resolver_qs_t)); |
1649 | 1881 |
1882 break; | |
1883 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1884 case NGX_RESOLVE_SRV: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1885 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1886 ngx_resolver_process_srv(r, buf, n, ident, code, nan, trunc, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1887 i + sizeof(ngx_resolver_qs_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1888 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1889 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1890 |
1649 | 1891 case NGX_RESOLVE_PTR: |
1892 | |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
1893 ngx_resolver_process_ptr(r, buf, n, ident, code, nan); |
1649 | 1894 |
1895 break; | |
1896 | |
1897 default: | |
1898 ngx_log_error(r->log_level, r->log, 0, | |
1967
4a4b15c9c474
use correct ngx_sprintf() formats
Igor Sysoev <igor@sysoev.ru>
parents:
1966
diff
changeset
|
1899 "unknown query type %ui in DNS response", qtype); |
1649 | 1900 return; |
1901 } | |
1902 | |
1903 return; | |
1904 | |
1905 short_response: | |
1906 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1907 err = "short DNS response"; |
1649 | 1908 |
1909 done: | |
1910 | |
1911 ngx_log_error(r->log_level, r->log, 0, err); | |
1912 | |
1913 return; | |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1914 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1915 dns_error_name: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1916 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1917 ngx_log_error(r->log_level, r->log, 0, |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1918 "DNS error (%ui: %s), query id:%ui, name:\"%*s\"", |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1919 code, ngx_resolver_strerror(code), ident, |
6478
3ef7bb882ad4
Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6460
diff
changeset
|
1920 (size_t) rn->nlen, rn->name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1921 return; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1922 |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1923 dns_error: |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1924 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1925 ngx_log_error(r->log_level, r->log, 0, |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1926 "DNS error (%ui: %s), query id:%ui", |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1927 code, ngx_resolver_strerror(code), ident); |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1928 return; |
1649 | 1929 } |
1930 | |
1931 | |
1932 static void | |
6370 | 1933 ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n, |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1934 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype, |
6367 | 1935 ngx_uint_t nan, ngx_uint_t trunc, ngx_uint_t ans) |
583 | 1936 { |
6367 | 1937 char *err; |
1938 u_char *cname; | |
1939 size_t len; | |
1940 int32_t ttl; | |
1941 uint32_t hash; | |
1942 in_addr_t *addr; | |
1943 ngx_str_t name; | |
6370 | 1944 ngx_uint_t type, class, qident, naddrs, a, i, j, start; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1945 #if (NGX_HAVE_INET6) |
6367 | 1946 struct in6_addr *addr6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1947 #endif |
6367 | 1948 ngx_resolver_an_t *an; |
1949 ngx_resolver_ctx_t *ctx, *next; | |
1950 ngx_resolver_node_t *rn; | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1951 ngx_resolver_addr_t *addrs; |
6367 | 1952 ngx_resolver_connection_t *rec; |
1649 | 1953 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1954 if (ngx_resolver_copy(r, &name, buf, |
6370 | 1955 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1956 != NGX_OK) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1957 { |
1649 | 1958 return; |
1959 } | |
1960 | |
1961 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); | |
1962 | |
1963 hash = ngx_crc32_short(name.data, name.len); | |
1964 | |
1965 /* lock name mutex */ | |
1966 | |
1967 rn = ngx_resolver_lookup_name(r, &name, hash); | |
1968 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1969 if (rn == NULL) { |
1649 | 1970 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
1971 "unexpected DNS response for %V", &name); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
1972 ngx_resolver_free(r, name.data); |
1649 | 1973 goto failed; |
1974 } | |
1975 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1976 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1977 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1978 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1979 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1980 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1981 if (rn->query6 == NULL || rn->naddrs6 != (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1982 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
1983 "unexpected DNS response for %V", &name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1984 ngx_resolver_free(r, name.data); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1985 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1986 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1987 |
6367 | 1988 if (trunc && rn->tcp6) { |
1989 ngx_resolver_free(r, name.data); | |
1990 goto failed; | |
1991 } | |
1992 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1993 qident = (rn->query6[0] << 8) + rn->query6[1]; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1994 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1995 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1996 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1997 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1998 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1999 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2000 if (rn->query == NULL || rn->naddrs != (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2001 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2002 "unexpected DNS response for %V", &name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2003 ngx_resolver_free(r, name.data); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2004 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2005 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2006 |
6367 | 2007 if (trunc && rn->tcp) { |
2008 ngx_resolver_free(r, name.data); | |
2009 goto failed; | |
2010 } | |
2011 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2012 qident = (rn->query[0] << 8) + rn->query[1]; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2013 } |
1649 | 2014 |
2015 if (ident != qident) { | |
2016 ngx_log_error(r->log_level, r->log, 0, | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2017 "wrong ident %ui in DNS response for %V, expect %ui", |
1649 | 2018 ident, &name, qident); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2019 ngx_resolver_free(r, name.data); |
1649 | 2020 goto failed; |
2021 } | |
2022 | |
3139 | 2023 ngx_resolver_free(r, name.data); |
2024 | |
6367 | 2025 if (trunc) { |
2026 | |
2027 ngx_queue_remove(&rn->queue); | |
2028 | |
2029 if (rn->waiting == NULL) { | |
2030 ngx_rbtree_delete(&r->name_rbtree, &rn->node); | |
2031 ngx_resolver_free_node(r, rn); | |
2032 goto next; | |
2033 } | |
2034 | |
2035 rec = r->connections.elts; | |
2036 rec = &rec[rn->last_connection]; | |
2037 | |
2038 switch (qtype) { | |
2039 | |
2040 #if (NGX_HAVE_INET6) | |
2041 case NGX_RESOLVE_AAAA: | |
2042 | |
2043 rn->tcp6 = 1; | |
2044 | |
2045 (void) ngx_resolver_send_tcp_query(r, rec, rn->query6, rn->qlen); | |
2046 | |
2047 break; | |
2048 #endif | |
2049 | |
2050 default: /* NGX_RESOLVE_A */ | |
2051 | |
2052 rn->tcp = 1; | |
2053 | |
2054 (void) ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen); | |
2055 } | |
2056 | |
2057 rn->expire = ngx_time() + r->resend_timeout; | |
2058 | |
2059 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue); | |
2060 | |
2061 goto next; | |
2062 } | |
2063 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2064 if (code == 0 && rn->code) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2065 code = rn->code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2066 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2067 |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2068 if (code == 0 && nan == 0) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2069 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2070 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2071 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2072 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2073 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2074 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2075 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2076 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2077 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2078 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2079 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2080 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2081 if (rn->naddrs) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2082 goto export; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2083 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2084 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2085 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2086 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2087 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2088 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2089 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2090 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2091 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2092 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2093 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2094 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2095 if (rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2096 goto export; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2097 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2098 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2099 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2100 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2101 code = NGX_RESOLVE_NXDOMAIN; |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2102 } |
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2103 |
1649 | 2104 if (code) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2105 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2106 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2107 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2108 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2109 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2110 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2111 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2112 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2113 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2114 rn->code = (u_char) code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2115 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2116 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2117 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2118 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2119 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2120 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2121 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2122 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2123 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2124 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2125 rn->code = (u_char) code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2126 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2127 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2128 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2129 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2130 |
1649 | 2131 next = rn->waiting; |
2132 rn->waiting = NULL; | |
2133 | |
2134 ngx_queue_remove(&rn->queue); | |
2135 | |
2136 ngx_rbtree_delete(&r->name_rbtree, &rn->node); | |
2137 | |
2138 /* unlock name mutex */ | |
2139 | |
2140 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2141 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2142 ctx->state = code; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
2143 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2144 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2145 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2146 ctx->handler(ctx); |
1649 | 2147 } |
2148 | |
5920
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
2149 ngx_resolver_free_node(r, rn); |
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
2150 |
1649 | 2151 return; |
2152 } | |
2153 | |
2154 i = ans; | |
2155 naddrs = 0; | |
2156 cname = NULL; | |
2157 | |
2158 for (a = 0; a < nan; a++) { | |
2159 | |
2160 start = i; | |
2161 | |
6370 | 2162 while (i < n) { |
1649 | 2163 |
2164 if (buf[i] & 0xc0) { | |
2165 i += 2; | |
2166 goto found; | |
2167 } | |
2168 | |
2169 if (buf[i] == 0) { | |
2170 i++; | |
2171 goto test_length; | |
2172 } | |
2173 | |
2174 i += 1 + buf[i]; | |
2175 } | |
2176 | |
2177 goto short_response; | |
2178 | |
2179 test_length: | |
2180 | |
2181 if (i - start < 2) { | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2182 err = "invalid name in DNS response"; |
1649 | 2183 goto invalid; |
2184 } | |
2185 | |
2186 found: | |
2187 | |
6370 | 2188 if (i + sizeof(ngx_resolver_an_t) >= n) { |
1649 | 2189 goto short_response; |
2190 } | |
2191 | |
2192 an = (ngx_resolver_an_t *) &buf[i]; | |
2193 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2194 type = (an->type_hi << 8) + an->type_lo; |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2195 class = (an->class_hi << 8) + an->class_lo; |
1649 | 2196 len = (an->len_hi << 8) + an->len_lo; |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2197 ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16) |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2198 + (an->ttl[2] << 8) + (an->ttl[3]); |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2199 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2200 if (class != 1) { |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2201 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2202 "unexpected RR class %ui in DNS response", class); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2203 goto failed; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2204 } |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2205 |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2206 if (ttl < 0) { |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2207 ttl = 0; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2208 } |
1649 | 2209 |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2210 rn->ttl = ngx_min(rn->ttl, (uint32_t) ttl); |
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2211 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2212 i += sizeof(ngx_resolver_an_t); |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2213 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2214 switch (type) { |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2215 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2216 case NGX_RESOLVE_A: |
1649 | 2217 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2218 if (qtype != NGX_RESOLVE_A) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2219 err = "unexpected A record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2220 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2221 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2222 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2223 if (len != 4) { |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2224 err = "invalid A record in DNS response"; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2225 goto invalid; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2226 } |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2227 |
6370 | 2228 if (i + 4 > n) { |
1649 | 2229 goto short_response; |
2230 } | |
2231 | |
2232 naddrs++; | |
2233 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2234 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2235 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2236 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2237 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2238 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2239 if (qtype != NGX_RESOLVE_AAAA) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2240 err = "unexpected AAAA record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2241 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2242 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2243 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2244 if (len != 16) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2245 err = "invalid AAAA record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2246 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2247 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2248 |
6370 | 2249 if (i + 16 > n) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2250 goto short_response; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2251 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2252 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2253 naddrs++; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2254 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2255 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2256 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2257 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2258 case NGX_RESOLVE_CNAME: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2259 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2260 cname = &buf[i]; |
1965 | 2261 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2262 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2263 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2264 case NGX_RESOLVE_DNAME: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2265 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2266 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2267 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2268 default: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2269 |
1966 | 2270 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2271 "unexpected RR type %ui in DNS response", type); |
1649 | 2272 } |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2273 |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2274 i += len; |
1649 | 2275 } |
2276 | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2277 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0, |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2278 "resolver naddrs:%ui cname:%p ttl:%uD", |
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2279 naddrs, cname, rn->ttl); |
1649 | 2280 |
2281 if (naddrs) { | |
2282 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2283 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2284 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2285 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2286 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2287 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2288 if (naddrs == 1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2289 addr6 = &rn->u6.addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2290 rn->naddrs6 = 1; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2291 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2292 } else { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2293 addr6 = ngx_resolver_alloc(r, naddrs * sizeof(struct in6_addr)); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2294 if (addr6 == NULL) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2295 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2296 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2297 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2298 rn->u6.addrs6 = addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2299 rn->naddrs6 = (u_short) naddrs; |
1649 | 2300 } |
2301 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2302 #if (NGX_SUPPRESS_WARN) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2303 addr = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2304 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2305 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2306 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2307 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2308 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2309 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2310 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2311 if (naddrs == 1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2312 addr = &rn->u.addr; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2313 rn->naddrs = 1; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2314 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2315 } else { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2316 addr = ngx_resolver_alloc(r, naddrs * sizeof(in_addr_t)); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2317 if (addr == NULL) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2318 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2319 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2320 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2321 rn->u.addrs = addr; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2322 rn->naddrs = (u_short) naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2323 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2324 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2325 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2326 addr6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2327 #endif |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2328 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2329 |
6370 | 2330 j = 0; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2331 i = ans; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2332 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2333 for (a = 0; a < nan; a++) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2334 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2335 for ( ;; ) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2336 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2337 if (buf[i] & 0xc0) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2338 i += 2; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2339 break; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2340 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2341 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2342 if (buf[i] == 0) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2343 i++; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2344 break; |
1649 | 2345 } |
2346 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2347 i += 1 + buf[i]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2348 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2349 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2350 an = (ngx_resolver_an_t *) &buf[i]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2351 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2352 type = (an->type_hi << 8) + an->type_lo; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2353 len = (an->len_hi << 8) + an->len_lo; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2354 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2355 i += sizeof(ngx_resolver_an_t); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2356 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2357 if (type == NGX_RESOLVE_A) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2358 |
6370 | 2359 addr[j] = htonl((buf[i] << 24) + (buf[i + 1] << 16) |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2360 + (buf[i + 2] << 8) + (buf[i + 3])); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2361 |
6370 | 2362 if (++j == naddrs) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2363 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2364 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2365 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2366 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2367 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2368 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2369 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2370 break; |
1649 | 2371 } |
2372 } | |
2373 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2374 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2375 else if (type == NGX_RESOLVE_AAAA) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2376 |
6370 | 2377 ngx_memcpy(addr6[j].s6_addr, &buf[i], 16); |
2378 | |
2379 if (++j == naddrs) { | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2380 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2381 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2382 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2383 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2384 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2385 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2386 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2387 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2388 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2389 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2390 i += len; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2391 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2392 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2393 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2394 switch (qtype) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2395 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2396 #if (NGX_HAVE_INET6) |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2397 case NGX_RESOLVE_AAAA: |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2398 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2399 if (rn->naddrs6 == (u_short) -1) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2400 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2401 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2402 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2403 break; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2404 #endif |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2405 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2406 default: /* NGX_RESOLVE_A */ |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2407 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2408 if (rn->naddrs == (u_short) -1) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2409 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2410 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2411 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2412 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2413 if (rn->naddrs != (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2414 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2415 && rn->naddrs6 != (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2416 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2417 && rn->naddrs |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2418 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2419 + rn->naddrs6 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2420 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2421 > 0) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2422 { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2423 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2424 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2425 export: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2426 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2427 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2428 naddrs = rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2429 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2430 naddrs += rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2431 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2432 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2433 if (naddrs == 1 && rn->naddrs == 1) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2434 addrs = NULL; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2435 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2436 } else { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2437 addrs = ngx_resolver_export(r, rn, 0); |
1649 | 2438 if (addrs == NULL) { |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2439 goto failed; |
1649 | 2440 } |
2441 } | |
2442 | |
2443 ngx_queue_remove(&rn->queue); | |
2444 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2445 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
1649 | 2446 rn->expire = ngx_time() + r->expire; |
2447 | |
2448 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); | |
2449 | |
2450 next = rn->waiting; | |
2451 rn->waiting = NULL; | |
2452 | |
2453 /* unlock name mutex */ | |
2454 | |
2455 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2456 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2457 ctx->state = NGX_OK; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
2458 ctx->valid = rn->valid; |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2459 ctx->naddrs = naddrs; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2460 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2461 if (addrs == NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2462 ctx->addrs = &ctx->addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2463 ctx->addr.sockaddr = (struct sockaddr *) &ctx->sin; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2464 ctx->addr.socklen = sizeof(struct sockaddr_in); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2465 ngx_memzero(&ctx->sin, sizeof(struct sockaddr_in)); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2466 ctx->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2467 ctx->sin.sin_addr.s_addr = rn->u.addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2468 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2469 } else { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2470 ctx->addrs = addrs; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2471 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2472 |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2473 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2474 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2475 ctx->handler(ctx); |
1649 | 2476 } |
2477 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2478 if (addrs != NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2479 ngx_resolver_free(r, addrs->sockaddr); |
1649 | 2480 ngx_resolver_free(r, addrs); |
2481 } | |
2482 | |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2483 ngx_resolver_free(r, rn->query); |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2484 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2485 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2486 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2487 #endif |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2488 |
1649 | 2489 return; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2490 } |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2491 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2492 if (cname) { |
1649 | 2493 |
2494 /* CNAME only */ | |
2495 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2496 if (rn->naddrs == (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2497 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2498 || rn->naddrs6 == (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2499 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2500 ) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2501 { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2502 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2503 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2504 |
6370 | 2505 if (ngx_resolver_copy(r, &name, buf, cname, buf + n) != NGX_OK) { |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2506 goto failed; |
1649 | 2507 } |
2508 | |
2509 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, | |
2510 "resolver cname:\"%V\"", &name); | |
2511 | |
1741
0829024c924d
fix segfault if response will have CNAME only
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
2512 ngx_queue_remove(&rn->queue); |
0829024c924d
fix segfault if response will have CNAME only
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
2513 |
1649 | 2514 rn->cnlen = (u_short) name.len; |
2515 rn->u.cname = name.data; | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2516 |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2517 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
1649 | 2518 rn->expire = ngx_time() + r->expire; |
2519 | |
2520 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); | |
2521 | |
6352
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2522 ngx_resolver_free(r, rn->query); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2523 rn->query = NULL; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2524 #if (NGX_HAVE_INET6) |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2525 rn->query6 = NULL; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2526 #endif |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2527 |
1649 | 2528 ctx = rn->waiting; |
2529 rn->waiting = NULL; | |
2530 | |
2531 if (ctx) { | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2532 |
6352
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2533 if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) { |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2534 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2535 /* unlock name mutex */ |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2536 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2537 do { |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2538 ctx->state = NGX_RESOLVE_NXDOMAIN; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2539 next = ctx->next; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2540 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2541 ctx->handler(ctx); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2542 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2543 ctx = next; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2544 } while (ctx); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2545 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2546 return; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2547 } |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2548 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2549 for (next = ctx; next; next = next->next) { |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2550 next->node = NULL; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2551 } |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2552 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2553 (void) ngx_resolve_name_locked(r, ctx, &name); |
1649 | 2554 } |
2555 | |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2556 /* unlock name mutex */ |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2557 |
1649 | 2558 return; |
2559 } | |
2560 | |
2561 ngx_log_error(r->log_level, r->log, 0, | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2562 "no A or CNAME types in DNS response"); |
1649 | 2563 return; |
2564 | |
2565 short_response: | |
2566 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2567 err = "short DNS response"; |
1649 | 2568 |
2569 invalid: | |
2570 | |
2571 /* unlock name mutex */ | |
2572 | |
2573 ngx_log_error(r->log_level, r->log, 0, err); | |
2574 | |
2575 return; | |
2576 | |
2577 failed: | |
2578 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2579 next: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2580 |
1649 | 2581 /* unlock name mutex */ |
2582 | |
2583 return; | |
2584 } | |
2585 | |
2586 | |
2587 static void | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2588 ngx_resolver_process_srv(ngx_resolver_t *r, u_char *buf, size_t n, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2589 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2590 ngx_uint_t trunc, ngx_uint_t ans) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2591 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2592 char *err; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2593 u_char *cname; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2594 size_t len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2595 int32_t ttl; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2596 uint32_t hash; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2597 ngx_str_t name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2598 ngx_uint_t type, qident, class, start, nsrvs, a, i, j; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2599 ngx_resolver_an_t *an; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2600 ngx_resolver_ctx_t *ctx, *next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2601 ngx_resolver_srv_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2602 ngx_resolver_node_t *rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2603 ngx_resolver_connection_t *rec; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2604 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2605 if (ngx_resolver_copy(r, &name, buf, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2606 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2607 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2608 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2609 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2610 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2611 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2612 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2613 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2614 hash = ngx_crc32_short(name.data, name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2615 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2616 rn = ngx_resolver_lookup_srv(r, &name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2617 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2618 if (rn == NULL || rn->query == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2619 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2620 "unexpected DNS response for %V", &name); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2621 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2622 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2623 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2624 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2625 if (trunc && rn->tcp) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2626 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2627 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2628 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2629 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2630 qident = (rn->query[0] << 8) + rn->query[1]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2631 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2632 if (ident != qident) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2633 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2634 "wrong ident %ui in DNS response for %V, expect %ui", |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2635 ident, &name, qident); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2636 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2637 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2638 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2639 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2640 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2641 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2642 if (trunc) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2643 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2644 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2645 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2646 if (rn->waiting == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2647 ngx_rbtree_delete(&r->srv_rbtree, &rn->node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2648 ngx_resolver_free_node(r, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2649 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2650 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2651 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2652 rec = r->connections.elts; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2653 rec = &rec[rn->last_connection]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2654 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2655 rn->tcp = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2656 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2657 (void) ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2658 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2659 rn->expire = ngx_time() + r->resend_timeout; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2660 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2661 ngx_queue_insert_head(&r->srv_resend_queue, &rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2662 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2663 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2664 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2665 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2666 if (code == 0 && rn->code) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2667 code = rn->code; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2668 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2669 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2670 if (code == 0 && nan == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2671 code = NGX_RESOLVE_NXDOMAIN; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2672 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2673 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2674 if (code) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2675 next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2676 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2677 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2678 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2679 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2680 ngx_rbtree_delete(&r->srv_rbtree, &rn->node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2681 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2682 while (next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2683 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2684 ctx->state = code; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2685 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2686 next = ctx->next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2687 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2688 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2689 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2690 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2691 ngx_resolver_free_node(r, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2692 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2693 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2694 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2695 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2696 i = ans; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2697 nsrvs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2698 cname = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2699 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2700 for (a = 0; a < nan; a++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2701 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2702 start = i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2703 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2704 while (i < n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2705 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2706 if (buf[i] & 0xc0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2707 i += 2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2708 goto found; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2709 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2710 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2711 if (buf[i] == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2712 i++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2713 goto test_length; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2714 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2715 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2716 i += 1 + buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2717 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2718 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2719 goto short_response; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2720 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2721 test_length: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2722 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2723 if (i - start < 2) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2724 err = "invalid name DNS response"; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2725 goto invalid; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2726 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2727 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2728 found: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2729 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2730 if (i + sizeof(ngx_resolver_an_t) >= n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2731 goto short_response; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2732 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2733 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2734 an = (ngx_resolver_an_t *) &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2735 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2736 type = (an->type_hi << 8) + an->type_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2737 class = (an->class_hi << 8) + an->class_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2738 len = (an->len_hi << 8) + an->len_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2739 ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2740 + (an->ttl[2] << 8) + (an->ttl[3]); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2741 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2742 if (class != 1) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2743 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2744 "unexpected RR class %ui in DNS response", class); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2745 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2746 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2747 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2748 if (ttl < 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2749 ttl = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2750 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2751 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2752 rn->ttl = ngx_min(rn->ttl, (uint32_t) ttl); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2753 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2754 i += sizeof(ngx_resolver_an_t); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2755 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2756 switch (type) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2757 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2758 case NGX_RESOLVE_SRV: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2759 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2760 if (i + 6 > n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2761 goto short_response; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2762 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2763 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2764 if (ngx_resolver_copy(r, NULL, buf, &buf[i + 6], buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2765 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2766 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2767 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2768 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2769 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2770 nsrvs++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2771 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2772 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2773 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2774 case NGX_RESOLVE_CNAME: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2775 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2776 cname = &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2777 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2778 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2779 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2780 case NGX_RESOLVE_DNAME: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2781 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2782 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2783 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2784 default: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2785 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2786 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
2787 "unexpected RR type %ui in DNS response", type); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2788 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2789 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2790 i += len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2791 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2792 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2793 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2794 "resolver nsrvs:%ui cname:%p ttl:%uD", |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2795 nsrvs, cname, rn->ttl); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2796 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2797 if (nsrvs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2798 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2799 srvs = ngx_resolver_calloc(r, nsrvs * sizeof(ngx_resolver_srv_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2800 if (srvs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2801 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2802 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2803 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2804 rn->u.srvs = srvs; |
6460
034329824dd3
Win32: fixed build after 384154fc634f.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6458
diff
changeset
|
2805 rn->nsrvs = (u_short) nsrvs; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2806 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2807 j = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2808 i = ans; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2809 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2810 for (a = 0; a < nan; a++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2811 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2812 for ( ;; ) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2813 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2814 if (buf[i] & 0xc0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2815 i += 2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2816 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2817 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2818 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2819 if (buf[i] == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2820 i++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2821 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2822 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2823 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2824 i += 1 + buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2825 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2826 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2827 an = (ngx_resolver_an_t *) &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2828 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2829 type = (an->type_hi << 8) + an->type_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2830 len = (an->len_hi << 8) + an->len_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2831 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2832 i += sizeof(ngx_resolver_an_t); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2833 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2834 if (type == NGX_RESOLVE_SRV) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2835 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2836 srvs[j].priority = (buf[i] << 8) + buf[i + 1]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2837 srvs[j].weight = (buf[i + 2] << 8) + buf[i + 3]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2838 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2839 if (srvs[j].weight == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2840 srvs[j].weight = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2841 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2842 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2843 srvs[j].port = (buf[i + 4] << 8) + buf[i + 5]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2844 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2845 if (ngx_resolver_copy(r, &srvs[j].name, buf, &buf[i + 6], |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2846 buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2847 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2848 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2849 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2850 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2851 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2852 j++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2853 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2854 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2855 i += len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2856 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2857 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2858 ngx_sort(srvs, nsrvs, sizeof(ngx_resolver_srv_t), |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2859 ngx_resolver_cmp_srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2860 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2861 ngx_resolver_free(r, rn->query); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2862 rn->query = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2863 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2864 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2865 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2866 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2867 rn->expire = ngx_time() + r->expire; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2868 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2869 ngx_queue_insert_head(&r->srv_expire_queue, &rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2870 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2871 next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2872 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2873 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2874 while (next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2875 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2876 next = ctx->next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2877 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2878 ngx_resolver_resolve_srv_names(ctx, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2879 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2880 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2881 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2882 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2883 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2884 rn->nsrvs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2885 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2886 if (cname) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2887 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2888 /* CNAME only */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2889 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2890 if (ngx_resolver_copy(r, &name, buf, cname, buf + n) != NGX_OK) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2891 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2892 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2893 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2894 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2895 "resolver cname:\"%V\"", &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2896 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2897 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2898 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2899 rn->cnlen = (u_short) name.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2900 rn->u.cname = name.data; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2901 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2902 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2903 rn->expire = ngx_time() + r->expire; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2904 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2905 ngx_queue_insert_head(&r->srv_expire_queue, &rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2906 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2907 ngx_resolver_free(r, rn->query); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2908 rn->query = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2909 #if (NGX_HAVE_INET6) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2910 rn->query6 = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2911 #endif |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2912 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2913 ctx = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2914 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2915 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2916 if (ctx) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2917 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2918 if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2919 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2920 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2921 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2922 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2923 ctx->state = NGX_RESOLVE_NXDOMAIN; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2924 next = ctx->next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2925 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2926 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2927 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2928 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2929 } while (ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2930 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2931 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2932 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2933 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2934 for (next = ctx; next; next = next->next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2935 next->node = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2936 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2937 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2938 (void) ngx_resolve_name_locked(r, ctx, &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2939 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2940 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2941 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2942 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2943 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2944 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2945 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2946 ngx_log_error(r->log_level, r->log, 0, "no SRV type in DNS response"); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2947 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2948 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2949 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2950 short_response: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2951 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2952 err = "short DNS response"; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2953 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2954 invalid: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2955 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2956 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2957 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2958 ngx_log_error(r->log_level, r->log, 0, err); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2959 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2960 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2961 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2962 failed: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2963 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2964 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2965 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2966 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2967 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2968 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2969 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2970 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2971 ngx_resolver_resolve_srv_names(ngx_resolver_ctx_t *ctx, ngx_resolver_node_t *rn) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2972 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2973 ngx_uint_t i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2974 ngx_resolver_t *r; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2975 ngx_resolver_ctx_t *cctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2976 ngx_resolver_srv_name_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2977 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2978 r = ctx->resolver; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2979 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2980 ctx->node = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2981 ctx->state = NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2982 ctx->valid = rn->valid; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2983 ctx->count = rn->nsrvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2984 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2985 srvs = ngx_resolver_calloc(r, rn->nsrvs * sizeof(ngx_resolver_srv_name_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2986 if (srvs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2987 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2988 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2989 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2990 ctx->srvs = srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2991 ctx->nsrvs = rn->nsrvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2992 |
6847
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2993 if (ctx->event && ctx->event->timer_set) { |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2994 ngx_del_timer(ctx->event); |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2995 } |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2996 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
2997 for (i = 0; i < (ngx_uint_t) rn->nsrvs; i++) { |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2998 srvs[i].name.data = ngx_resolver_alloc(r, rn->u.srvs[i].name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2999 if (srvs[i].name.data == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3000 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3001 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3002 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3003 srvs[i].name.len = rn->u.srvs[i].name.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3004 ngx_memcpy(srvs[i].name.data, rn->u.srvs[i].name.data, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3005 srvs[i].name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3006 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3007 cctx = ngx_resolve_start(r, NULL); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3008 if (cctx == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3009 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3010 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3011 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3012 cctx->name = srvs[i].name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3013 cctx->handler = ngx_resolver_srv_names_handler; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3014 cctx->data = ctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3015 cctx->srvs = &srvs[i]; |
6847
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
3016 cctx->timeout = ctx->timeout; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3017 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3018 srvs[i].priority = rn->u.srvs[i].priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3019 srvs[i].weight = rn->u.srvs[i].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3020 srvs[i].port = rn->u.srvs[i].port; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3021 srvs[i].ctx = cctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3022 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3023 if (ngx_resolve_name(cctx) == NGX_ERROR) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3024 srvs[i].ctx = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3025 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3026 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3027 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3028 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3029 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3030 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3031 failed: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3032 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3033 ctx->state = NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3034 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3035 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3036 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3037 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3038 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3039 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3040 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3041 ngx_resolver_srv_names_handler(ngx_resolver_ctx_t *cctx) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3042 { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3043 ngx_uint_t i; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3044 ngx_addr_t *addrs; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3045 ngx_resolver_t *r; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3046 ngx_sockaddr_t *sockaddr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3047 ngx_resolver_ctx_t *ctx; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3048 ngx_resolver_srv_name_t *srv; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3049 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3050 r = cctx->resolver; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3051 ctx = cctx->data; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3052 srv = cctx->srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3053 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3054 ctx->count--; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
3055 ctx->async |= cctx->async; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3056 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3057 srv->ctx = NULL; |
6714
c3e3de6d2672
Resolver: introduced state field in ngx_resolver_srv_name_t.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6593
diff
changeset
|
3058 srv->state = cctx->state; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3059 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3060 if (cctx->naddrs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3061 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3062 ctx->valid = ngx_min(ctx->valid, cctx->valid); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3063 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3064 addrs = ngx_resolver_calloc(r, cctx->naddrs * sizeof(ngx_addr_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3065 if (addrs == NULL) { |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3066 srv->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3067 goto done; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3068 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3069 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3070 sockaddr = ngx_resolver_alloc(r, cctx->naddrs * sizeof(ngx_sockaddr_t)); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3071 if (sockaddr == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3072 ngx_resolver_free(r, addrs); |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3073 srv->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3074 goto done; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3075 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3076 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3077 for (i = 0; i < cctx->naddrs; i++) { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3078 addrs[i].sockaddr = &sockaddr[i].sockaddr; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3079 addrs[i].socklen = cctx->addrs[i].socklen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3080 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3081 ngx_memcpy(&sockaddr[i], cctx->addrs[i].sockaddr, |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3082 addrs[i].socklen); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3083 |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6559
diff
changeset
|
3084 ngx_inet_set_port(addrs[i].sockaddr, srv->port); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3085 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3086 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3087 srv->addrs = addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3088 srv->naddrs = cctx->naddrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3089 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3090 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3091 done: |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3092 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3093 ngx_resolve_name_done(cctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3094 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3095 if (ctx->count == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3096 ngx_resolver_report_srv(r, ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3097 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3098 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3099 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3100 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3101 static void |
1649 | 3102 ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n, |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3103 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan) |
1649 | 3104 { |
3105 char *err; | |
3106 size_t len; | |
3107 in_addr_t addr; | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
3108 int32_t ttl; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3109 ngx_int_t octet; |
1649 | 3110 ngx_str_t name; |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3111 ngx_uint_t mask, type, class, qident, a, i, start; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3112 ngx_queue_t *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3113 ngx_rbtree_t *tree; |
1649 | 3114 ngx_resolver_an_t *an; |
3115 ngx_resolver_ctx_t *ctx, *next; | |
3116 ngx_resolver_node_t *rn; | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3117 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3118 uint32_t hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3119 ngx_int_t digit; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3120 struct in6_addr addr6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3121 #endif |
1649 | 3122 |
6372 | 3123 if (ngx_resolver_copy(r, &name, buf, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3124 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3125 != NGX_OK) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3126 { |
5472
ab493c60d9ff
Resolver: fixes in PTR processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5471
diff
changeset
|
3127 return; |
1649 | 3128 } |
3129 | |
6372 | 3130 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); |
3131 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3132 /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3133 |
1649 | 3134 addr = 0; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3135 i = sizeof(ngx_resolver_hdr_t); |
1649 | 3136 |
3137 for (mask = 0; mask < 32; mask += 8) { | |
3138 len = buf[i++]; | |
3139 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3140 octet = ngx_atoi(&buf[i], len); |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3141 if (octet == NGX_ERROR || octet > 255) { |
1649 | 3142 goto invalid_in_addr_arpa; |
3143 } | |
3144 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3145 addr += octet << mask; |
1649 | 3146 i += len; |
3147 } | |
3148 | |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3149 if (ngx_strcasecmp(&buf[i], (u_char *) "\7in-addr\4arpa") == 0) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3150 i += sizeof("\7in-addr\4arpa"); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3151 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3152 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3153 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3154 rn = ngx_resolver_lookup_addr(r, addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3155 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3156 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3157 expire_queue = &r->addr_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3158 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3159 goto valid; |
1649 | 3160 } |
3161 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3162 invalid_in_addr_arpa: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3163 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3164 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3165 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3166 i = sizeof(ngx_resolver_hdr_t); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3167 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3168 for (octet = 15; octet >= 0; octet--) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3169 if (buf[i++] != '\1') { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3170 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3171 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3172 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3173 digit = ngx_hextoi(&buf[i++], 1); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3174 if (digit == NGX_ERROR) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3175 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3176 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3177 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3178 addr6.s6_addr[octet] = (u_char) digit; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3179 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3180 if (buf[i++] != '\1') { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3181 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3182 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3183 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3184 digit = ngx_hextoi(&buf[i++], 1); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3185 if (digit == NGX_ERROR) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3186 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3187 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3188 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3189 addr6.s6_addr[octet] += (u_char) (digit * 16); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3190 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3191 |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3192 if (ngx_strcasecmp(&buf[i], (u_char *) "\3ip6\4arpa") == 0) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3193 i += sizeof("\3ip6\4arpa"); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3194 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3195 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3196 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3197 hash = ngx_crc32_short(addr6.s6_addr, 16); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3198 rn = ngx_resolver_lookup_addr6(r, &addr6, hash); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3199 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3200 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3201 expire_queue = &r->addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3202 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3203 goto valid; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3204 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3205 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3206 invalid_ip6_arpa: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3207 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3208 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3209 ngx_log_error(r->log_level, r->log, 0, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3210 "invalid in-addr.arpa or ip6.arpa name in DNS response"); |
6372 | 3211 ngx_resolver_free(r, name.data); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3212 return; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3213 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3214 valid: |
1649 | 3215 |
3216 if (rn == NULL || rn->query == NULL) { | |
3217 ngx_log_error(r->log_level, r->log, 0, | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3218 "unexpected DNS response for %V", &name); |
6372 | 3219 ngx_resolver_free(r, name.data); |
1649 | 3220 goto failed; |
3221 } | |
3222 | |
3223 qident = (rn->query[0] << 8) + rn->query[1]; | |
3224 | |
3225 if (ident != qident) { | |
3226 ngx_log_error(r->log_level, r->log, 0, | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3227 "wrong ident %ui in DNS response for %V, expect %ui", |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3228 ident, &name, qident); |
6372 | 3229 ngx_resolver_free(r, name.data); |
1649 | 3230 goto failed; |
3231 } | |
3232 | |
6372 | 3233 ngx_resolver_free(r, name.data); |
3234 | |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3235 if (code == 0 && nan == 0) { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3236 code = NGX_RESOLVE_NXDOMAIN; |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3237 } |
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3238 |
1649 | 3239 if (code) { |
3240 next = rn->waiting; | |
3241 rn->waiting = NULL; | |
3242 | |
3243 ngx_queue_remove(&rn->queue); | |
3244 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3245 ngx_rbtree_delete(tree, &rn->node); |
1649 | 3246 |
3247 /* unlock addr mutex */ | |
3248 | |
3249 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3250 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3251 ctx->state = code; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
3252 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3253 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3254 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3255 ctx->handler(ctx); |
1649 | 3256 } |
3257 | |
5920
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
3258 ngx_resolver_free_node(r, rn); |
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
3259 |
1649 | 3260 return; |
3261 } | |
3262 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3263 i += sizeof(ngx_resolver_qs_t); |
1649 | 3264 |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3265 for (a = 0; a < nan; a++) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3266 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3267 start = i; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3268 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3269 while (i < n) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3270 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3271 if (buf[i] & 0xc0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3272 i += 2; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3273 goto found; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3274 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3275 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3276 if (buf[i] == 0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3277 i++; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3278 goto test_length; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3279 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3280 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3281 i += 1 + buf[i]; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3282 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3283 |
1649 | 3284 goto short_response; |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3285 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3286 test_length: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3287 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3288 if (i - start < 2) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3289 err = "invalid name in DNS response"; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3290 goto invalid; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3291 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3292 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3293 found: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3294 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3295 if (i + sizeof(ngx_resolver_an_t) >= n) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3296 goto short_response; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3297 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3298 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3299 an = (ngx_resolver_an_t *) &buf[i]; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3300 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3301 type = (an->type_hi << 8) + an->type_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3302 class = (an->class_hi << 8) + an->class_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3303 len = (an->len_hi << 8) + an->len_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3304 ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16) |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3305 + (an->ttl[2] << 8) + (an->ttl[3]); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3306 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3307 if (class != 1) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3308 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3309 "unexpected RR class %ui in DNS response", class); |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3310 goto failed; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3311 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3312 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3313 if (ttl < 0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3314 ttl = 0; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3315 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3316 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3317 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0, |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3318 "resolver qt:%ui cl:%ui len:%uz", |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3319 type, class, len); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3320 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3321 i += sizeof(ngx_resolver_an_t); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3322 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3323 switch (type) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3324 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3325 case NGX_RESOLVE_PTR: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3326 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3327 goto ptr; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3328 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3329 case NGX_RESOLVE_CNAME: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3330 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3331 break; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3332 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3333 default: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3334 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3335 ngx_log_error(r->log_level, r->log, 0, |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3336 "unexpected RR type %ui in DNS response", type); |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3337 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3338 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3339 i += len; |
1649 | 3340 } |
3341 | |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3342 /* unlock addr mutex */ |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3343 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3344 ngx_log_error(r->log_level, r->log, 0, |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3345 "no PTR type in DNS response"); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3346 return; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3347 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3348 ptr: |
1649 | 3349 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3350 if (ngx_resolver_copy(r, &name, buf, buf + i, buf + n) != NGX_OK) { |
5472
ab493c60d9ff
Resolver: fixes in PTR processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5471
diff
changeset
|
3351 goto failed; |
1649 | 3352 } |
3353 | |
3354 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver an:%V", &name); | |
3355 | |
2486
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3356 if (name.len != (size_t) rn->nlen |
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3357 || ngx_strncmp(name.data, rn->name, name.len) != 0) |
1649 | 3358 { |
2482
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3359 if (rn->nlen) { |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3360 ngx_resolver_free(r, rn->name); |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3361 } |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3362 |
2490
1c87647b7ca5
fix building by msvc, introduced in r2487
Igor Sysoev <igor@sysoev.ru>
parents:
2487
diff
changeset
|
3363 rn->nlen = (u_short) name.len; |
1649 | 3364 rn->name = name.data; |
3365 | |
2486
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3366 name.data = ngx_resolver_dup(r, rn->name, name.len); |
1649 | 3367 if (name.data == NULL) { |
3368 goto failed; | |
3369 } | |
3370 } | |
3371 | |
3372 ngx_queue_remove(&rn->queue); | |
3373 | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
3374 rn->valid = ngx_time() + (r->valid ? r->valid : ttl); |
1649 | 3375 rn->expire = ngx_time() + r->expire; |
3376 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3377 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 3378 |
3379 next = rn->waiting; | |
3380 rn->waiting = NULL; | |
3381 | |
3382 /* unlock addr mutex */ | |
3383 | |
3384 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3385 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3386 ctx->state = NGX_OK; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
3387 ctx->valid = rn->valid; |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3388 ctx->name = name; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3389 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3390 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3391 ctx->handler(ctx); |
1649 | 3392 } |
3393 | |
3394 ngx_resolver_free(r, name.data); | |
3395 | |
3396 return; | |
3397 | |
3398 short_response: | |
3399 | |
3400 err = "short DNS response"; | |
3401 | |
3402 invalid: | |
3403 | |
3404 /* unlock addr mutex */ | |
3405 | |
3406 ngx_log_error(r->log_level, r->log, 0, err); | |
3407 | |
3408 return; | |
3409 | |
3410 failed: | |
3411 | |
3412 /* unlock addr mutex */ | |
3413 | |
3414 return; | |
3415 } | |
3416 | |
3417 | |
3418 static ngx_resolver_node_t * | |
3419 ngx_resolver_lookup_name(ngx_resolver_t *r, ngx_str_t *name, uint32_t hash) | |
3420 { | |
3421 ngx_int_t rc; | |
3422 ngx_rbtree_node_t *node, *sentinel; | |
3423 ngx_resolver_node_t *rn; | |
3424 | |
3425 node = r->name_rbtree.root; | |
3426 sentinel = r->name_rbtree.sentinel; | |
3427 | |
3428 while (node != sentinel) { | |
3429 | |
3430 if (hash < node->key) { | |
3431 node = node->left; | |
3432 continue; | |
3433 } | |
3434 | |
3435 if (hash > node->key) { | |
3436 node = node->right; | |
3437 continue; | |
3438 } | |
3439 | |
3440 /* hash == node->key */ | |
3441 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3442 rn = ngx_resolver_node(node); |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3443 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3444 rc = ngx_memn2cmp(name->data, rn->name, name->len, rn->nlen); |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3445 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3446 if (rc == 0) { |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3447 return rn; |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3448 } |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3449 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3450 node = (rc < 0) ? node->left : node->right; |
1649 | 3451 } |
3452 | |
3453 /* not found */ | |
3454 | |
3455 return NULL; | |
3456 } | |
3457 | |
3458 | |
3459 static ngx_resolver_node_t * | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3460 ngx_resolver_lookup_srv(ngx_resolver_t *r, ngx_str_t *name, uint32_t hash) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3461 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3462 ngx_int_t rc; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3463 ngx_rbtree_node_t *node, *sentinel; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3464 ngx_resolver_node_t *rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3465 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3466 node = r->srv_rbtree.root; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3467 sentinel = r->srv_rbtree.sentinel; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3468 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3469 while (node != sentinel) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3470 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3471 if (hash < node->key) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3472 node = node->left; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3473 continue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3474 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3475 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3476 if (hash > node->key) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3477 node = node->right; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3478 continue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3479 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3480 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3481 /* hash == node->key */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3482 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3483 rn = ngx_resolver_node(node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3484 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3485 rc = ngx_memn2cmp(name->data, rn->name, name->len, rn->nlen); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3486 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3487 if (rc == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3488 return rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3489 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3490 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3491 node = (rc < 0) ? node->left : node->right; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3492 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3493 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3494 /* not found */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3495 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3496 return NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3497 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3498 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3499 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3500 static ngx_resolver_node_t * |
1649 | 3501 ngx_resolver_lookup_addr(ngx_resolver_t *r, in_addr_t addr) |
3502 { | |
3503 ngx_rbtree_node_t *node, *sentinel; | |
3504 | |
3505 node = r->addr_rbtree.root; | |
3506 sentinel = r->addr_rbtree.sentinel; | |
3507 | |
3508 while (node != sentinel) { | |
3509 | |
3510 if (addr < node->key) { | |
3511 node = node->left; | |
3512 continue; | |
3513 } | |
3514 | |
3515 if (addr > node->key) { | |
3516 node = node->right; | |
3517 continue; | |
3518 } | |
3519 | |
3520 /* addr == node->key */ | |
3521 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3522 return ngx_resolver_node(node); |
1649 | 3523 } |
3524 | |
3525 /* not found */ | |
3526 | |
3527 return NULL; | |
3528 } | |
3529 | |
3530 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3531 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3532 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3533 static ngx_resolver_node_t * |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3534 ngx_resolver_lookup_addr6(ngx_resolver_t *r, struct in6_addr *addr, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3535 uint32_t hash) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3536 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3537 ngx_int_t rc; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3538 ngx_rbtree_node_t *node, *sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3539 ngx_resolver_node_t *rn; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3540 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3541 node = r->addr6_rbtree.root; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3542 sentinel = r->addr6_rbtree.sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3543 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3544 while (node != sentinel) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3545 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3546 if (hash < node->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3547 node = node->left; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3548 continue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3549 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3550 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3551 if (hash > node->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3552 node = node->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3553 continue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3554 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3555 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3556 /* hash == node->key */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3557 |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3558 rn = ngx_resolver_node(node); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3559 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3560 rc = ngx_memcmp(addr, &rn->addr6, 16); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3561 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3562 if (rc == 0) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3563 return rn; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3564 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3565 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3566 node = (rc < 0) ? node->left : node->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3567 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3568 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3569 /* not found */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3570 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3571 return NULL; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3572 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3573 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3574 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3575 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3576 |
1649 | 3577 static void |
3578 ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
3579 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
3580 { | |
3581 ngx_rbtree_node_t **p; | |
3582 ngx_resolver_node_t *rn, *rn_temp; | |
3583 | |
3584 for ( ;; ) { | |
3585 | |
3586 if (node->key < temp->key) { | |
3587 | |
3588 p = &temp->left; | |
3589 | |
3590 } else if (node->key > temp->key) { | |
3591 | |
3592 p = &temp->right; | |
3593 | |
3594 } else { /* node->key == temp->key */ | |
3595 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3596 rn = ngx_resolver_node(node); |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3597 rn_temp = ngx_resolver_node(temp); |
1649 | 3598 |
3143
ab6258e18099
fix resolver cache rbtree comparison
Igor Sysoev <igor@sysoev.ru>
parents:
3139
diff
changeset
|
3599 p = (ngx_memn2cmp(rn->name, rn_temp->name, rn->nlen, rn_temp->nlen) |
ab6258e18099
fix resolver cache rbtree comparison
Igor Sysoev <igor@sysoev.ru>
parents:
3139
diff
changeset
|
3600 < 0) ? &temp->left : &temp->right; |
1649 | 3601 } |
3602 | |
3603 if (*p == sentinel) { | |
3604 break; | |
3605 } | |
3606 | |
3607 temp = *p; | |
3608 } | |
3609 | |
3610 *p = node; | |
3611 node->parent = temp; | |
3612 node->left = sentinel; | |
3613 node->right = sentinel; | |
3614 ngx_rbt_red(node); | |
3615 } | |
3616 | |
3617 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3618 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3619 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3620 static void |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3621 ngx_resolver_rbtree_insert_addr6_value(ngx_rbtree_node_t *temp, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3622 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3623 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3624 ngx_rbtree_node_t **p; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3625 ngx_resolver_node_t *rn, *rn_temp; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3626 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3627 for ( ;; ) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3628 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3629 if (node->key < temp->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3630 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3631 p = &temp->left; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3632 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3633 } else if (node->key > temp->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3634 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3635 p = &temp->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3636 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3637 } else { /* node->key == temp->key */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3638 |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3639 rn = ngx_resolver_node(node); |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3640 rn_temp = ngx_resolver_node(temp); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3641 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3642 p = (ngx_memcmp(&rn->addr6, &rn_temp->addr6, 16) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3643 < 0) ? &temp->left : &temp->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3644 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3645 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3646 if (*p == sentinel) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3647 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3648 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3649 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3650 temp = *p; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3651 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3652 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3653 *p = node; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3654 node->parent = temp; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3655 node->left = sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3656 node->right = sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3657 ngx_rbt_red(node); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3658 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3659 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3660 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3661 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3662 |
1649 | 3663 static ngx_int_t |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3664 ngx_resolver_create_name_query(ngx_resolver_t *r, ngx_resolver_node_t *rn, |
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3665 ngx_str_t *name) |
1649 | 3666 { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3667 u_char *p, *s; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3668 size_t len, nlen; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3669 ngx_uint_t ident; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3670 ngx_resolver_qs_t *qs; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3671 ngx_resolver_hdr_t *query; |
1649 | 3672 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3673 nlen = name->len ? (1 + name->len + 1) : 1; |
3306
61bdaac6c668
fix resolving an empty name (".")
Igor Sysoev <igor@sysoev.ru>
parents:
3299
diff
changeset
|
3674 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3675 len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t); |
1649 | 3676 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3677 #if (NGX_HAVE_INET6) |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3678 p = ngx_resolver_alloc(r, len * (r->ipv4 + r->ipv6)); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3679 #else |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3680 p = ngx_resolver_alloc(r, len); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3681 #endif |
1649 | 3682 if (p == NULL) { |
3683 return NGX_ERROR; | |
3684 } | |
3685 | |
3686 rn->qlen = (u_short) len; | |
8908
0422365794f7
Resolver: fixed memory leak for the "ipv4=off" case.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8907
diff
changeset
|
3687 rn->query = p; |
1649 | 3688 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3689 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3690 if (r->ipv6) { |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3691 rn->query6 = r->ipv4 ? (p + len) : p; |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3692 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3693 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3694 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3695 query = (ngx_resolver_hdr_t *) p; |
1649 | 3696 |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3697 if (r->ipv4) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3698 ident = ngx_random(); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3699 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3700 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3701 "resolve: \"%V\" A %i", name, ident & 0xffff); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3702 |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3703 query->ident_hi = (u_char) ((ident >> 8) & 0xff); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3704 query->ident_lo = (u_char) (ident & 0xff); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3705 } |
1649 | 3706 |
3707 /* recursion query */ | |
3708 query->flags_hi = 1; query->flags_lo = 0; | |
3709 | |
3710 /* one question */ | |
3711 query->nqs_hi = 0; query->nqs_lo = 1; | |
3712 query->nan_hi = 0; query->nan_lo = 0; | |
3713 query->nns_hi = 0; query->nns_lo = 0; | |
3714 query->nar_hi = 0; query->nar_lo = 0; | |
3715 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3716 p += sizeof(ngx_resolver_hdr_t) + nlen; |
1649 | 3717 |
3718 qs = (ngx_resolver_qs_t *) p; | |
3719 | |
3720 /* query type */ | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3721 qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_A; |
1649 | 3722 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3723 /* IN query class */ |
1649 | 3724 qs->class_hi = 0; qs->class_lo = 1; |
3725 | |
3726 /* convert "www.example.com" to "\3www\7example\3com\0" */ | |
3727 | |
3728 len = 0; | |
3729 p--; | |
3730 *p-- = '\0'; | |
3731 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3732 if (name->len == 0) { |
4610
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3733 return NGX_DECLINED; |
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3734 } |
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3735 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3736 for (s = name->data + name->len - 1; s >= name->data; s--) { |
1649 | 3737 if (*s != '.') { |
3738 *p = *s; | |
3739 len++; | |
3740 | |
3741 } else { | |
4556
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3742 if (len == 0 || len > 255) { |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3743 return NGX_DECLINED; |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3744 } |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3745 |
1649 | 3746 *p = (u_char) len; |
3747 len = 0; | |
3748 } | |
3749 | |
3750 p--; | |
3751 } | |
3752 | |
4556
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3753 if (len == 0 || len > 255) { |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3754 return NGX_DECLINED; |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3755 } |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3756 |
1649 | 3757 *p = (u_char) len; |
3758 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3759 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3760 if (!r->ipv6) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3761 return NGX_OK; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3762 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3763 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3764 p = rn->query6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3765 |
8907
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3766 if (r->ipv4) { |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3767 ngx_memcpy(p, rn->query, rn->qlen); |
2a77754cd9fe
The "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
8896
diff
changeset
|
3768 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3769 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3770 query = (ngx_resolver_hdr_t *) p; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3771 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3772 ident = ngx_random(); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3773 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3774 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, |
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3775 "resolve: \"%V\" AAAA %i", name, ident & 0xffff); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3776 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3777 query->ident_hi = (u_char) ((ident >> 8) & 0xff); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3778 query->ident_lo = (u_char) (ident & 0xff); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3779 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3780 p += sizeof(ngx_resolver_hdr_t) + nlen; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3781 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3782 qs = (ngx_resolver_qs_t *) p; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3783 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3784 qs->type_lo = NGX_RESOLVE_AAAA; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3785 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3786 |
1649 | 3787 return NGX_OK; |
3788 } | |
3789 | |
3790 | |
3791 static ngx_int_t | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3792 ngx_resolver_create_srv_query(ngx_resolver_t *r, ngx_resolver_node_t *rn, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3793 ngx_str_t *name) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3794 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3795 u_char *p, *s; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3796 size_t len, nlen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3797 ngx_uint_t ident; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3798 ngx_resolver_qs_t *qs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3799 ngx_resolver_hdr_t *query; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3800 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3801 nlen = name->len ? (1 + name->len + 1) : 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3802 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3803 len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3804 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3805 p = ngx_resolver_alloc(r, len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3806 if (p == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3807 return NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3808 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3809 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3810 rn->qlen = (u_short) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3811 rn->query = p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3812 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3813 query = (ngx_resolver_hdr_t *) p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3814 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3815 ident = ngx_random(); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3816 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3817 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3818 "resolve: \"%V\" SRV %i", name, ident & 0xffff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3819 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3820 query->ident_hi = (u_char) ((ident >> 8) & 0xff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3821 query->ident_lo = (u_char) (ident & 0xff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3822 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3823 /* recursion query */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3824 query->flags_hi = 1; query->flags_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3825 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3826 /* one question */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3827 query->nqs_hi = 0; query->nqs_lo = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3828 query->nan_hi = 0; query->nan_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3829 query->nns_hi = 0; query->nns_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3830 query->nar_hi = 0; query->nar_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3831 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3832 p += sizeof(ngx_resolver_hdr_t) + nlen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3833 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3834 qs = (ngx_resolver_qs_t *) p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3835 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3836 /* query type */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3837 qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_SRV; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3838 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3839 /* IN query class */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3840 qs->class_hi = 0; qs->class_lo = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3841 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3842 /* converts "www.example.com" to "\3www\7example\3com\0" */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3843 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3844 len = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3845 p--; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3846 *p-- = '\0'; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3847 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3848 if (name->len == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3849 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3850 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3851 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3852 for (s = name->data + name->len - 1; s >= name->data; s--) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3853 if (*s != '.') { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3854 *p = *s; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3855 len++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3856 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3857 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3858 if (len == 0 || len > 255) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3859 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3860 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3861 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3862 *p = (u_char) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3863 len = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3864 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3865 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3866 p--; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3867 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3868 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3869 if (len == 0 || len > 255) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3870 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3871 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3872 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3873 *p = (u_char) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3874 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3875 return NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3876 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3877 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3878 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3879 static ngx_int_t |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3880 ngx_resolver_create_addr_query(ngx_resolver_t *r, ngx_resolver_node_t *rn, |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3881 ngx_resolver_addr_t *addr) |
1649 | 3882 { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3883 u_char *p, *d; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3884 size_t len; |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3885 in_addr_t inaddr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3886 ngx_int_t n; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3887 ngx_uint_t ident; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3888 ngx_resolver_hdr_t *query; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3889 struct sockaddr_in *sin; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3890 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3891 struct sockaddr_in6 *sin6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3892 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3893 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3894 switch (addr->sockaddr->sa_family) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3895 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3896 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3897 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3898 len = sizeof(ngx_resolver_hdr_t) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3899 + 64 + sizeof(".ip6.arpa.") - 1 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3900 + sizeof(ngx_resolver_qs_t); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3901 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3902 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3903 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3904 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3905 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3906 len = sizeof(ngx_resolver_hdr_t) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3907 + sizeof(".255.255.255.255.in-addr.arpa.") - 1 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3908 + sizeof(ngx_resolver_qs_t); |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
3909 } |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3910 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3911 p = ngx_resolver_alloc(r, len); |
1649 | 3912 if (p == NULL) { |
3913 return NGX_ERROR; | |
3914 } | |
3915 | |
3916 rn->query = p; | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3917 query = (ngx_resolver_hdr_t *) p; |
1649 | 3918 |
3919 ident = ngx_random(); | |
3920 | |
3921 query->ident_hi = (u_char) ((ident >> 8) & 0xff); | |
3922 query->ident_lo = (u_char) (ident & 0xff); | |
3923 | |
3924 /* recursion query */ | |
3925 query->flags_hi = 1; query->flags_lo = 0; | |
3926 | |
3927 /* one question */ | |
3928 query->nqs_hi = 0; query->nqs_lo = 1; | |
3929 query->nan_hi = 0; query->nan_lo = 0; | |
3930 query->nns_hi = 0; query->nns_lo = 0; | |
3931 query->nar_hi = 0; query->nar_lo = 0; | |
3932 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3933 p += sizeof(ngx_resolver_hdr_t); |
1649 | 3934 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3935 switch (addr->sockaddr->sa_family) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3936 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3937 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3938 case AF_INET6: |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3939 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3940 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3941 for (n = 15; n >= 0; n--) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3942 p = ngx_sprintf(p, "\1%xd\1%xd", |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3943 sin6->sin6_addr.s6_addr[n] & 0xf, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3944 (sin6->sin6_addr.s6_addr[n] >> 4) & 0xf); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3945 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3946 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3947 p = ngx_cpymem(p, "\3ip6\4arpa\0", 10); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3948 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3949 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3950 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3951 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3952 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3953 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3954 sin = (struct sockaddr_in *) addr->sockaddr; |
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3955 inaddr = ntohl(sin->sin_addr.s_addr); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3956 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3957 for (n = 0; n < 32; n += 8) { |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3958 d = ngx_sprintf(&p[1], "%ud", (inaddr >> n) & 0xff); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3959 *p = (u_char) (d - &p[1]); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3960 p = d; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3961 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3962 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3963 p = ngx_cpymem(p, "\7in-addr\4arpa\0", 14); |
1649 | 3964 } |
3965 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3966 /* query type "PTR", IN query class */ |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3967 p = ngx_cpymem(p, "\0\14\0\1", 4); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3968 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3969 rn->qlen = (u_short) (p - rn->query); |
1649 | 3970 |
3971 return NGX_OK; | |
3972 } | |
3973 | |
3974 | |
3975 static ngx_int_t | |
3976 ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src, | |
3977 u_char *last) | |
3978 { | |
3979 char *err; | |
3980 u_char *p, *dst; | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
3981 size_t len; |
1649 | 3982 ngx_uint_t i, n; |
3983 | |
3984 p = src; | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
3985 len = 0; |
1649 | 3986 |
3987 /* | |
3988 * compression pointers allow to create endless loop, so we set limit; | |
3989 * 128 pointers should be enough to store 255-byte name | |
3990 */ | |
3991 | |
3992 for (i = 0; i < 128; i++) { | |
3993 n = *p++; | |
3994 | |
3995 if (n == 0) { | |
3996 goto done; | |
3997 } | |
3998 | |
3999 if (n & 0xc0) { | |
8472
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
4000 if ((n & 0xc0) != 0xc0) { |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
4001 err = "invalid label type in DNS response"; |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
4002 goto invalid; |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
4003 } |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
4004 |
8471
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
4005 if (p >= last) { |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
4006 err = "name is out of DNS response"; |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
4007 goto invalid; |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
4008 } |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
4009 |
2314
52987a023486
fix compression pointer for big (>255) DNS responses
Igor Sysoev <igor@sysoev.ru>
parents:
2282
diff
changeset
|
4010 n = ((n & 0x3f) << 8) + *p; |
1649 | 4011 p = &buf[n]; |
4012 | |
4013 } else { | |
4014 len += 1 + n; | |
4015 p = &p[n]; | |
4016 } | |
4017 | |
4018 if (p >= last) { | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
4019 err = "name is out of DNS response"; |
1649 | 4020 goto invalid; |
4021 } | |
4022 } | |
4023 | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
4024 err = "compression pointers loop in DNS response"; |
1649 | 4025 |
4026 invalid: | |
4027 | |
4028 ngx_log_error(r->log_level, r->log, 0, err); | |
4029 | |
4030 return NGX_ERROR; | |
4031 | |
4032 done: | |
4033 | |
4034 if (name == NULL) { | |
583 | 4035 return NGX_OK; |
4036 } | |
4037 | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
4038 if (len == 0) { |
5764
f166c521b619
Style: use ngx_str_null().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents:
5600
diff
changeset
|
4039 ngx_str_null(name); |
3298
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
4040 return NGX_OK; |
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
4041 } |
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
4042 |
1649 | 4043 dst = ngx_resolver_alloc(r, len); |
4044 if (dst == NULL) { | |
4045 return NGX_ERROR; | |
4046 } | |
4047 | |
4048 name->data = dst; | |
4049 | |
4050 for ( ;; ) { | |
8473
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4051 n = *src++; |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4052 |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4053 if (n == 0) { |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
4054 name->len = dst - name->data - 1; |
8473
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4055 return NGX_OK; |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4056 } |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4057 |
4267
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4058 if (n & 0xc0) { |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4059 n = ((n & 0x3f) << 8) + *src; |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4060 src = &buf[n]; |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4061 |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4062 } else { |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
4063 ngx_strlow(dst, src, n); |
1649 | 4064 dst += n; |
4065 src += n; | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
4066 *dst++ = '.'; |
1649 | 4067 } |
4068 } | |
4069 } | |
4070 | |
4071 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4072 static ngx_int_t |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4073 ngx_resolver_set_timeout(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx) |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4074 { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4075 if (ctx->event || ctx->timeout == 0) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4076 return NGX_OK; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4077 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4078 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4079 ctx->event = ngx_resolver_calloc(r, sizeof(ngx_event_t)); |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4080 if (ctx->event == NULL) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4081 return NGX_ERROR; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4082 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4083 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4084 ctx->event->handler = ngx_resolver_timeout_handler; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4085 ctx->event->data = ctx; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4086 ctx->event->log = r->log; |
7052
70e65bf8dfd7
Resolver: cancelable resend timer event.
Ruslan Ermilov <ru@nginx.com>
parents:
7051
diff
changeset
|
4087 ctx->event->cancelable = ctx->cancelable; |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4088 ctx->ident = -1; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4089 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4090 ngx_add_timer(ctx->event, ctx->timeout); |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4091 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4092 return NGX_OK; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4093 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4094 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4095 |
1649 | 4096 static void |
4097 ngx_resolver_timeout_handler(ngx_event_t *ev) | |
4098 { | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4099 ngx_resolver_ctx_t *ctx; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4100 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4101 ctx = ev->data; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4102 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4103 ctx->state = NGX_RESOLVE_TIMEDOUT; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4104 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4105 ctx->handler(ctx); |
1649 | 4106 } |
4107 | |
4108 | |
4109 static void | |
4110 ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn) | |
4111 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4112 ngx_uint_t i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4113 |
1649 | 4114 /* lock alloc mutex */ |
4115 | |
4116 if (rn->query) { | |
4117 ngx_resolver_free_locked(r, rn->query); | |
4118 } | |
4119 | |
4120 if (rn->name) { | |
4121 ngx_resolver_free_locked(r, rn->name); | |
4122 } | |
4123 | |
4124 if (rn->cnlen) { | |
4125 ngx_resolver_free_locked(r, rn->u.cname); | |
4126 } | |
4127 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4128 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) { |
1649 | 4129 ngx_resolver_free_locked(r, rn->u.addrs); |
4130 } | |
4131 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4132 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4133 if (rn->naddrs6 > 1 && rn->naddrs6 != (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4134 ngx_resolver_free_locked(r, rn->u6.addrs6); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4135 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4136 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4137 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4138 if (rn->nsrvs) { |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4139 for (i = 0; i < (ngx_uint_t) rn->nsrvs; i++) { |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4140 if (rn->u.srvs[i].name.data) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4141 ngx_resolver_free_locked(r, rn->u.srvs[i].name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4142 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4143 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4144 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4145 ngx_resolver_free_locked(r, rn->u.srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4146 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4147 |
1649 | 4148 ngx_resolver_free_locked(r, rn); |
4149 | |
4150 /* unlock alloc mutex */ | |
4151 } | |
4152 | |
4153 | |
4154 static void * | |
4155 ngx_resolver_alloc(ngx_resolver_t *r, size_t size) | |
4156 { | |
4157 u_char *p; | |
4158 | |
4159 /* lock alloc mutex */ | |
4160 | |
4161 p = ngx_alloc(size, r->log); | |
4162 | |
4163 /* unlock alloc mutex */ | |
4164 | |
4165 return p; | |
4166 } | |
4167 | |
4168 | |
1903 | 4169 static void * |
1649 | 4170 ngx_resolver_calloc(ngx_resolver_t *r, size_t size) |
4171 { | |
4172 u_char *p; | |
4173 | |
4174 p = ngx_resolver_alloc(r, size); | |
4175 | |
4176 if (p) { | |
4177 ngx_memzero(p, size); | |
4178 } | |
4179 | |
4180 return p; | |
4181 } | |
4182 | |
4183 | |
4184 static void | |
4185 ngx_resolver_free(ngx_resolver_t *r, void *p) | |
4186 { | |
4187 /* lock alloc mutex */ | |
4188 | |
4189 ngx_free(p); | |
4190 | |
4191 /* unlock alloc mutex */ | |
4192 } | |
4193 | |
4194 | |
4195 static void | |
4196 ngx_resolver_free_locked(ngx_resolver_t *r, void *p) | |
4197 { | |
4198 ngx_free(p); | |
4199 } | |
4200 | |
4201 | |
4202 static void * | |
4203 ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size) | |
4204 { | |
4205 void *dst; | |
4206 | |
4207 dst = ngx_resolver_alloc(r, size); | |
4208 | |
4209 if (dst == NULL) { | |
4210 return dst; | |
4211 } | |
4212 | |
4213 ngx_memcpy(dst, src, size); | |
4214 | |
4215 return dst; | |
4216 } | |
4217 | |
4218 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4219 static ngx_resolver_addr_t * |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4220 ngx_resolver_export(ngx_resolver_t *r, ngx_resolver_node_t *rn, |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4221 ngx_uint_t rotate) |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4222 { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4223 ngx_uint_t d, i, j, n; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4224 in_addr_t *addr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4225 ngx_sockaddr_t *sockaddr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4226 struct sockaddr_in *sin; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4227 ngx_resolver_addr_t *dst; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4228 #if (NGX_HAVE_INET6) |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4229 struct in6_addr *addr6; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4230 struct sockaddr_in6 *sin6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4231 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4232 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4233 n = rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4234 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4235 n += rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4236 #endif |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4237 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4238 dst = ngx_resolver_calloc(r, n * sizeof(ngx_resolver_addr_t)); |
4892
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4239 if (dst == NULL) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4240 return NULL; |
4892
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4241 } |
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4242 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4243 sockaddr = ngx_resolver_calloc(r, n * sizeof(ngx_sockaddr_t)); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4244 if (sockaddr == NULL) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4245 ngx_resolver_free(r, dst); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4246 return NULL; |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4247 } |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4248 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4249 i = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4250 d = rotate ? ngx_random() % n : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4251 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4252 if (rn->naddrs) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4253 j = rotate ? ngx_random() % rn->naddrs : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4254 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4255 addr = (rn->naddrs == 1) ? &rn->u.addr : rn->u.addrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4256 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4257 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4258 sin = &sockaddr[d].sockaddr_in; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4259 sin->sin_family = AF_INET; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4260 sin->sin_addr.s_addr = addr[j++]; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4261 dst[d].sockaddr = (struct sockaddr *) sin; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4262 dst[d++].socklen = sizeof(struct sockaddr_in); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4263 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4264 if (d == n) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4265 d = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4266 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4267 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4268 if (j == (ngx_uint_t) rn->naddrs) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4269 j = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4270 } |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4271 } while (++i < (ngx_uint_t) rn->naddrs); |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4272 } |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4273 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4274 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4275 if (rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4276 j = rotate ? ngx_random() % rn->naddrs6 : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4277 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4278 addr6 = (rn->naddrs6 == 1) ? &rn->u6.addr6 : rn->u6.addrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4279 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4280 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4281 sin6 = &sockaddr[d].sockaddr_in6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4282 sin6->sin6_family = AF_INET6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4283 ngx_memcpy(sin6->sin6_addr.s6_addr, addr6[j++].s6_addr, 16); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4284 dst[d].sockaddr = (struct sockaddr *) sin6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4285 dst[d++].socklen = sizeof(struct sockaddr_in6); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4286 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4287 if (d == n) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4288 d = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4289 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4290 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4291 if (j == rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4292 j = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4293 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4294 } while (++i < n); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4295 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4296 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4297 |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4298 return dst; |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4299 } |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4300 |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4301 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4302 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4303 ngx_resolver_report_srv(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4304 { |
6460
034329824dd3
Win32: fixed build after 384154fc634f.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6458
diff
changeset
|
4305 ngx_uint_t naddrs, nsrvs, nw, i, j, k, l, m, n, w; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4306 ngx_resolver_addr_t *addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4307 ngx_resolver_srv_name_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4308 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4309 srvs = ctx->srvs; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4310 nsrvs = ctx->nsrvs; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4311 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4312 naddrs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4313 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4314 for (i = 0; i < nsrvs; i++) { |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4315 if (srvs[i].state == NGX_ERROR) { |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4316 ctx->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4317 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4318 |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4319 ctx->handler(ctx); |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4320 return; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4321 } |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4322 |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4323 naddrs += srvs[i].naddrs; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4324 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4325 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4326 if (naddrs == 0) { |
7428
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4327 ctx->state = srvs[0].state; |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4328 |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4329 for (i = 0; i < nsrvs; i++) { |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4330 if (srvs[i].state == NGX_RESOLVE_NXDOMAIN) { |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4331 ctx->state = NGX_RESOLVE_NXDOMAIN; |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4332 break; |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4333 } |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4334 } |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4335 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4336 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4337 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4338 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4339 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4340 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4341 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4342 addrs = ngx_resolver_calloc(r, naddrs * sizeof(ngx_resolver_addr_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4343 if (addrs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4344 ctx->state = NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4345 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4346 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4347 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4348 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4349 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4350 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4351 i = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4352 n = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4353 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4354 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4355 nw = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4356 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4357 for (j = i; j < nsrvs; j++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4358 if (srvs[j].priority != srvs[i].priority) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4359 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4360 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4361 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4362 nw += srvs[j].naddrs * srvs[j].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4363 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4364 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4365 if (nw == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4366 goto next_srv; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4367 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4368 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4369 w = ngx_random() % nw; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4370 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4371 for (k = i; k < j; k++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4372 if (w < srvs[k].naddrs * srvs[k].weight) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4373 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4374 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4375 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4376 w -= srvs[k].naddrs * srvs[k].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4377 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4378 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4379 for (l = i; l < j; l++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4380 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4381 for (m = 0; m < srvs[k].naddrs; m++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4382 addrs[n].socklen = srvs[k].addrs[m].socklen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4383 addrs[n].sockaddr = srvs[k].addrs[m].sockaddr; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4384 addrs[n].name = srvs[k].name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4385 addrs[n].priority = srvs[k].priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4386 addrs[n].weight = srvs[k].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4387 n++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4388 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4389 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4390 if (++k == j) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4391 k = i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4392 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4393 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4394 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4395 next_srv: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4396 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4397 i = j; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4398 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4399 } while (i < ctx->nsrvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4400 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4401 ctx->state = NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4402 ctx->addrs = addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4403 ctx->naddrs = naddrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4404 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4405 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4406 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4407 ngx_resolver_free(r, addrs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4408 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4409 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4410 |
1649 | 4411 char * |
4412 ngx_resolver_strerror(ngx_int_t err) | |
4413 { | |
4414 static char *errors[] = { | |
4415 "Format error", /* FORMERR */ | |
4416 "Server failure", /* SERVFAIL */ | |
4417 "Host not found", /* NXDOMAIN */ | |
4418 "Unimplemented", /* NOTIMP */ | |
4419 "Operation refused" /* REFUSED */ | |
4420 }; | |
4421 | |
4422 if (err > 0 && err < 6) { | |
4423 return errors[err - 1]; | |
4424 } | |
4425 | |
4426 if (err == NGX_RESOLVE_TIMEDOUT) { | |
4427 return "Operation timed out"; | |
4428 } | |
4429 | |
4430 return "Unknown error"; | |
4431 } | |
4432 | |
4433 | |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4434 static u_char * |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4435 ngx_resolver_log_error(ngx_log_t *log, u_char *buf, size_t len) |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4436 { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4437 u_char *p; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4438 ngx_resolver_connection_t *rec; |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4439 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4440 p = buf; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4441 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4442 if (log->action) { |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4443 p = ngx_snprintf(buf, len, " while %s", log->action); |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4444 len -= p - buf; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4445 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4446 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4447 rec = log->data; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4448 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4449 if (rec) { |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4450 p = ngx_snprintf(p, len, ", resolver: %V", &rec->server); |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4451 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4452 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4453 return p; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4454 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4455 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4456 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
4457 static ngx_int_t |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4458 ngx_udp_connect(ngx_resolver_connection_t *rec) |
1649 | 4459 { |
4460 int rc; | |
4461 ngx_int_t event; | |
4462 ngx_event_t *rev, *wev; | |
4463 ngx_socket_t s; | |
4464 ngx_connection_t *c; | |
4465 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4466 s = ngx_socket(rec->sockaddr->sa_family, SOCK_DGRAM, 0); |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4467 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4468 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "UDP socket %d", s); |
583 | 4469 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4892
diff
changeset
|
4470 if (s == (ngx_socket_t) -1) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4471 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
583 | 4472 ngx_socket_n " failed"); |
4473 return NGX_ERROR; | |
4474 } | |
4475 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4476 c = ngx_get_connection(s, &rec->log); |
583 | 4477 |
4478 if (c == NULL) { | |
4479 if (ngx_close_socket(s) == -1) { | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4480 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
7290
91ea68dd1501
Added missing space after ngx_close_socket_n.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7276
diff
changeset
|
4481 ngx_close_socket_n " failed"); |
583 | 4482 } |
4483 | |
4484 return NGX_ERROR; | |
4485 } | |
4486 | |
1649 | 4487 if (ngx_nonblocking(s) == -1) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4488 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
1649 | 4489 ngx_nonblocking_n " failed"); |
4490 | |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4491 goto failed; |
1649 | 4492 } |
4493 | |
583 | 4494 rev = c->read; |
4495 wev = c->write; | |
4496 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4497 rev->log = &rec->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4498 wev->log = &rec->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4499 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4500 rec->udp = c; |
583 | 4501 |
4502 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
4503 | |
8396
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4504 c->start_time = ngx_current_msec; |
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4505 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4506 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, &rec->log, 0, |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4507 "connect to %V, fd:%d #%uA", &rec->server, s, c->number); |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4508 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4509 rc = connect(s, rec->sockaddr, rec->socklen); |
1649 | 4510 |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
4511 /* TODO: iocp */ |
583 | 4512 |
4513 if (rc == -1) { | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4514 ngx_log_error(NGX_LOG_CRIT, &rec->log, ngx_socket_errno, |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4515 "connect() failed"); |
583 | 4516 |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4517 goto failed; |
583 | 4518 } |
4519 | |
1649 | 4520 /* UDP sockets are always ready to write */ |
4521 wev->ready = 1; | |
4522 | |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4523 event = (ngx_event_flags & NGX_USE_CLEAR_EVENT) ? |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4524 /* kqueue, epoll */ NGX_CLEAR_EVENT: |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4525 /* select, poll, /dev/poll */ NGX_LEVEL_EVENT; |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4526 /* eventport event type has no meaning: oneshot only */ |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4527 |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4528 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4529 goto failed; |
583 | 4530 } |
4531 | |
4532 return NGX_OK; | |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4533 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4534 failed: |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4535 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4536 ngx_close_connection(c); |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4537 rec->udp = NULL; |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4538 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4539 return NGX_ERROR; |
583 | 4540 } |
6367 | 4541 |
4542 | |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
4543 static ngx_int_t |
6367 | 4544 ngx_tcp_connect(ngx_resolver_connection_t *rec) |
4545 { | |
4546 int rc; | |
4547 ngx_int_t event; | |
4548 ngx_err_t err; | |
4549 ngx_uint_t level; | |
4550 ngx_socket_t s; | |
4551 ngx_event_t *rev, *wev; | |
4552 ngx_connection_t *c; | |
4553 | |
4554 s = ngx_socket(rec->sockaddr->sa_family, SOCK_STREAM, 0); | |
4555 | |
4556 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "TCP socket %d", s); | |
4557 | |
4558 if (s == (ngx_socket_t) -1) { | |
4559 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4560 ngx_socket_n " failed"); | |
4561 return NGX_ERROR; | |
4562 } | |
4563 | |
4564 c = ngx_get_connection(s, &rec->log); | |
4565 | |
4566 if (c == NULL) { | |
4567 if (ngx_close_socket(s) == -1) { | |
4568 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
7290
91ea68dd1501
Added missing space after ngx_close_socket_n.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7276
diff
changeset
|
4569 ngx_close_socket_n " failed"); |
6367 | 4570 } |
4571 | |
4572 return NGX_ERROR; | |
4573 } | |
4574 | |
4575 if (ngx_nonblocking(s) == -1) { | |
4576 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4577 ngx_nonblocking_n " failed"); | |
4578 | |
4579 goto failed; | |
4580 } | |
4581 | |
4582 rev = c->read; | |
4583 wev = c->write; | |
4584 | |
4585 rev->log = &rec->log; | |
4586 wev->log = &rec->log; | |
4587 | |
4588 rec->tcp = c; | |
4589 | |
4590 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
4591 | |
8396
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4592 c->start_time = ngx_current_msec; |
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4593 |
6367 | 4594 if (ngx_add_conn) { |
4595 if (ngx_add_conn(c) == NGX_ERROR) { | |
4596 goto failed; | |
4597 } | |
4598 } | |
4599 | |
4600 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, &rec->log, 0, | |
4601 "connect to %V, fd:%d #%uA", &rec->server, s, c->number); | |
4602 | |
4603 rc = connect(s, rec->sockaddr, rec->socklen); | |
4604 | |
4605 if (rc == -1) { | |
4606 err = ngx_socket_errno; | |
4607 | |
4608 | |
4609 if (err != NGX_EINPROGRESS | |
4610 #if (NGX_WIN32) | |
4611 /* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */ | |
4612 && err != NGX_EAGAIN | |
4613 #endif | |
4614 ) | |
4615 { | |
4616 if (err == NGX_ECONNREFUSED | |
4617 #if (NGX_LINUX) | |
4618 /* | |
4619 * Linux returns EAGAIN instead of ECONNREFUSED | |
4620 * for unix sockets if listen queue is full | |
4621 */ | |
4622 || err == NGX_EAGAIN | |
4623 #endif | |
4624 || err == NGX_ECONNRESET | |
4625 || err == NGX_ENETDOWN | |
4626 || err == NGX_ENETUNREACH | |
4627 || err == NGX_EHOSTDOWN | |
4628 || err == NGX_EHOSTUNREACH) | |
4629 { | |
4630 level = NGX_LOG_ERR; | |
4631 | |
4632 } else { | |
4633 level = NGX_LOG_CRIT; | |
4634 } | |
4635 | |
7275 | 4636 ngx_log_error(level, &rec->log, err, "connect() to %V failed", |
6367 | 4637 &rec->server); |
4638 | |
4639 ngx_close_connection(c); | |
4640 rec->tcp = NULL; | |
4641 | |
4642 return NGX_ERROR; | |
4643 } | |
4644 } | |
4645 | |
4646 if (ngx_add_conn) { | |
4647 if (rc == -1) { | |
4648 | |
4649 /* NGX_EINPROGRESS */ | |
4650 | |
4651 return NGX_AGAIN; | |
4652 } | |
4653 | |
4654 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "connected"); | |
4655 | |
4656 wev->ready = 1; | |
4657 | |
4658 return NGX_OK; | |
4659 } | |
4660 | |
4661 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { | |
4662 | |
4663 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, ngx_socket_errno, | |
4664 "connect(): %d", rc); | |
4665 | |
4666 if (ngx_blocking(s) == -1) { | |
4667 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4668 ngx_blocking_n " failed"); | |
4669 goto failed; | |
4670 } | |
4671 | |
4672 /* | |
4673 * FreeBSD's aio allows to post an operation on non-connected socket. | |
4674 * NT does not support it. | |
4675 * | |
4676 * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT | |
4677 */ | |
4678 | |
4679 rev->ready = 1; | |
4680 wev->ready = 1; | |
4681 | |
4682 return NGX_OK; | |
4683 } | |
4684 | |
4685 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
4686 | |
4687 /* kqueue */ | |
4688 | |
4689 event = NGX_CLEAR_EVENT; | |
4690 | |
4691 } else { | |
4692 | |
4693 /* select, poll, /dev/poll */ | |
4694 | |
4695 event = NGX_LEVEL_EVENT; | |
4696 } | |
4697 | |
4698 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { | |
4699 goto failed; | |
4700 } | |
4701 | |
4702 if (rc == -1) { | |
4703 | |
4704 /* NGX_EINPROGRESS */ | |
4705 | |
4706 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { | |
4707 goto failed; | |
4708 } | |
4709 | |
4710 return NGX_AGAIN; | |
4711 } | |
4712 | |
4713 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "connected"); | |
4714 | |
4715 wev->ready = 1; | |
4716 | |
4717 return NGX_OK; | |
4718 | |
4719 failed: | |
4720 | |
4721 ngx_close_connection(c); | |
4722 rec->tcp = NULL; | |
4723 | |
4724 return NGX_ERROR; | |
4725 } | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4726 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4727 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4728 static ngx_int_t |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4729 ngx_resolver_cmp_srvs(const void *one, const void *two) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4730 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4731 ngx_int_t p1, p2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4732 ngx_resolver_srv_t *first, *second; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4733 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4734 first = (ngx_resolver_srv_t *) one; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4735 second = (ngx_resolver_srv_t *) two; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4736 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4737 p1 = first->priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4738 p2 = second->priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4739 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4740 return p1 - p2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4741 } |