Mercurial > hg > nginx-quic
annotate src/core/ngx_resolver.c @ 8501:e617d0ba387a quic
QUIC: optimized initial secrets key length computation.
AES-128 key length is known in compile time.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 16 Jun 2021 17:55:57 +0300 |
parents | 4364b39de407 |
children | 0c5e84096d99 |
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 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
54 #define ngx_resolver_node(n) \ |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
55 (ngx_resolver_node_t *) \ |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
56 ((u_char *) (n) - offsetof(ngx_resolver_node_t, node)) |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
57 |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
58 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
59 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
|
60 static ngx_int_t ngx_tcp_connect(ngx_resolver_connection_t *rec); |
1649 | 61 |
62 | |
1906 | 63 static void ngx_resolver_cleanup(void *data); |
64 static void ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree); | |
1649 | 65 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
|
66 ngx_resolver_ctx_t *ctx, ngx_str_t *name); |
1649 | 67 static void ngx_resolver_expire(ngx_resolver_t *r, ngx_rbtree_t *tree, |
68 ngx_queue_t *queue); | |
69 static ngx_int_t ngx_resolver_send_query(ngx_resolver_t *r, | |
70 ngx_resolver_node_t *rn); | |
6367 | 71 static ngx_int_t ngx_resolver_send_udp_query(ngx_resolver_t *r, |
72 ngx_resolver_connection_t *rec, u_char *query, u_short qlen); | |
73 static ngx_int_t ngx_resolver_send_tcp_query(ngx_resolver_t *r, | |
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 ngx_resolver_node_t *rn, ngx_resolver_addr_t *addr); |
1649 | 81 static void ngx_resolver_resend_handler(ngx_event_t *ev); |
82 static time_t ngx_resolver_resend(ngx_resolver_t *r, ngx_rbtree_t *tree, | |
83 ngx_queue_t *queue); | |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
84 static ngx_uint_t ngx_resolver_resend_empty(ngx_resolver_t *r); |
6367 | 85 static void ngx_resolver_udp_read(ngx_event_t *rev); |
86 static void ngx_resolver_tcp_write(ngx_event_t *wev); | |
87 static void ngx_resolver_tcp_read(ngx_event_t *rev); | |
1649 | 88 static void ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, |
6367 | 89 size_t n, ngx_uint_t tcp); |
1649 | 90 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
|
91 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype, |
6367 | 92 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
|
93 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
|
94 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
|
95 ngx_uint_t trunc, ngx_uint_t ans); |
1649 | 96 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
|
97 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan); |
1649 | 98 static ngx_resolver_node_t *ngx_resolver_lookup_name(ngx_resolver_t *r, |
99 ngx_str_t *name, uint32_t hash); | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
100 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
|
101 ngx_str_t *name, uint32_t hash); |
1649 | 102 static ngx_resolver_node_t *ngx_resolver_lookup_addr(ngx_resolver_t *r, |
103 in_addr_t addr); | |
104 static void ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
105 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); | |
106 static ngx_int_t ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, | |
107 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
|
108 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
|
109 ngx_resolver_ctx_t *ctx); |
1649 | 110 static void ngx_resolver_timeout_handler(ngx_event_t *ev); |
111 static void ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn); | |
112 static void *ngx_resolver_alloc(ngx_resolver_t *r, size_t size); | |
1903 | 113 static void *ngx_resolver_calloc(ngx_resolver_t *r, size_t size); |
1649 | 114 static void ngx_resolver_free(ngx_resolver_t *r, void *p); |
115 static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p); | |
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 ngx_resolver_node_t *rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
123 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
|
124 static ngx_int_t ngx_resolver_cmp_srvs(const void *one, const void *two); |
1649 | 125 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
126 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 struct in6_addr *addr, uint32_t hash); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
131 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
132 |
1649 | 133 |
134 ngx_resolver_t * | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
135 ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n) |
1649 | 136 { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
137 ngx_str_t s; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
138 ngx_url_t u; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
139 ngx_uint_t i, j; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
140 ngx_resolver_t *r; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
141 ngx_pool_cleanup_t *cln; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
142 ngx_resolver_connection_t *rec; |
1649 | 143 |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
144 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
|
145 if (r == NULL) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
146 return NULL; |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
147 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
148 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
149 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
|
150 if (r->event == NULL) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
151 return NULL; |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
152 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
153 |
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
|
154 cln = ngx_pool_cleanup_add(cf->pool, 0); |
1906 | 155 if (cln == NULL) { |
156 return NULL; | |
157 } | |
158 | |
159 cln->handler = ngx_resolver_cleanup; | |
160 cln->data = r; | |
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) |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
230 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
|
231 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
232 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
|
233 r->ipv6 = 1; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
234 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
235 } 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
|
236 r->ipv6 = 0; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
237 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
238 } else { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
239 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
|
240 "invalid parameter: %V", &names[i]); |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
241 return NULL; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
242 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
243 |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
244 continue; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
245 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
246 #endif |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
247 |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
248 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
|
249 |
4671
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
250 u.url = names[i]; |
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
251 u.default_port = 53; |
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
252 |
af9342747669
Support for IPv6 literals and an optional port in resolver.
Ruslan Ermilov <ru@nginx.com>
parents:
4653
diff
changeset
|
253 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
|
254 if (u.err) { |
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
255 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
|
256 "%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
|
257 u.err, &u.url); |
4643
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
258 } |
bc5f881323b8
Fixed potential null pointer dereference in ngx_resolver_create().
Ruslan Ermilov <ru@nginx.com>
parents:
4619
diff
changeset
|
259 |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
260 return NULL; |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
261 } |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
262 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
263 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
|
264 if (rec == NULL) { |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
265 return NULL; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
266 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
267 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
268 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
|
269 |
f5c2c9d656f9
When "resolver" is configured with a domain name, only the first
Ruslan Ermilov <ru@nginx.com>
parents:
4683
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 rec[j].server = u.addrs[j].name; |
6367 | 274 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
|
275 } |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
276 } |
1649 | 277 |
7299
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
278 if (n && r->connections.nelts == 0) { |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
279 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
|
280 return NULL; |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
281 } |
faf14dc9ab4d
Resolver: require name servers.
Ruslan Ermilov <ru@nginx.com>
parents:
7298
diff
changeset
|
282 |
1649 | 283 return r; |
284 } | |
285 | |
286 | |
1906 | 287 static void |
288 ngx_resolver_cleanup(void *data) | |
289 { | |
290 ngx_resolver_t *r = data; | |
291 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
292 ngx_uint_t i; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
293 ngx_resolver_connection_t *rec; |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3902
diff
changeset
|
294 |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
295 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
|
296 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
297 ngx_resolver_cleanup_tree(r, &r->name_rbtree); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
298 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
299 ngx_resolver_cleanup_tree(r, &r->srv_rbtree); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
300 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
301 ngx_resolver_cleanup_tree(r, &r->addr_rbtree); |
1906 | 302 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
303 #if (NGX_HAVE_INET6) |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
304 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
|
305 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
306 |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
307 if (r->event->timer_set) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
308 ngx_del_timer(r->event); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
309 } |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
310 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
311 rec = r->connections.elts; |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
312 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
313 for (i = 0; i < r->connections.nelts; i++) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
314 if (rec[i].udp) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
315 ngx_close_connection(rec[i].udp); |
1906 | 316 } |
317 | |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
318 if (rec[i].tcp) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
319 ngx_close_connection(rec[i].tcp); |
1906 | 320 } |
321 | |
7298
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
322 if (rec[i].read_buf) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
323 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
|
324 ngx_resolver_free(r, rec[i].read_buf); |
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 |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
327 if (rec[i].write_buf) { |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
328 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
|
329 ngx_resolver_free(r, rec[i].write_buf); |
f37d8fb25de5
Resolver: allocate resolver from configuration pool.
Ruslan Ermilov <ru@nginx.com>
parents:
7290
diff
changeset
|
330 } |
1906 | 331 } |
332 } | |
333 | |
334 | |
335 static void | |
336 ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree) | |
337 { | |
338 ngx_resolver_ctx_t *ctx, *next; | |
339 ngx_resolver_node_t *rn; | |
340 | |
341 while (tree->root != tree->sentinel) { | |
342 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
343 rn = ngx_resolver_node(ngx_rbtree_min(tree->root, tree->sentinel)); |
1906 | 344 |
345 ngx_queue_remove(&rn->queue); | |
346 | |
347 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
|
348 next = ctx->next; |
1906 | 349 |
350 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
|
351 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
|
352 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
|
353 } |
259e2a76e8fb
Resolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov <ru@nginx.com>
parents:
6843
diff
changeset
|
354 |
1906 | 355 ngx_resolver_free(r, ctx->event); |
356 } | |
357 | |
358 ngx_resolver_free(r, ctx); | |
359 } | |
360 | |
361 ngx_rbtree_delete(tree, &rn->node); | |
362 | |
363 ngx_resolver_free_node(r, rn); | |
364 } | |
365 } | |
366 | |
367 | |
1649 | 368 ngx_resolver_ctx_t * |
369 ngx_resolve_start(ngx_resolver_t *r, ngx_resolver_ctx_t *temp) | |
370 { | |
371 in_addr_t addr; | |
372 ngx_resolver_ctx_t *ctx; | |
373 | |
374 if (temp) { | |
375 addr = ngx_inet_addr(temp->name.data, temp->name.len); | |
376 | |
377 if (addr != INADDR_NONE) { | |
378 temp->resolver = r; | |
379 temp->state = NGX_OK; | |
380 temp->naddrs = 1; | |
381 temp->addrs = &temp->addr; | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 temp->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
386 temp->sin.sin_addr.s_addr = addr; |
1649 | 387 temp->quick = 1; |
388 | |
389 return temp; | |
390 } | |
391 } | |
392 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
393 if (r->connections.nelts == 0) { |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
394 return NGX_NO_RESOLVER; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
395 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1679
diff
changeset
|
396 |
1649 | 397 ctx = ngx_resolver_calloc(r, sizeof(ngx_resolver_ctx_t)); |
398 | |
399 if (ctx) { | |
400 ctx->resolver = r; | |
401 } | |
402 | |
403 return ctx; | |
404 } | |
405 | |
406 | |
407 ngx_int_t | |
408 ngx_resolve_name(ngx_resolver_ctx_t *ctx) | |
409 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
410 size_t slen; |
1649 | 411 ngx_int_t rc; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
412 ngx_str_t name; |
1649 | 413 ngx_resolver_t *r; |
414 | |
415 r = ctx->resolver; | |
416 | |
5505
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
417 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
|
418 ctx->name.len--; |
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
419 } |
d091d16ed398
Resolver: added support for domain names with a trailing dot.
Yichun Zhang <agentzh@gmail.com>
parents:
5485
diff
changeset
|
420 |
1649 | 421 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, |
422 "resolve: \"%V\"", &ctx->name); | |
423 | |
424 if (ctx->quick) { | |
425 ctx->handler(ctx); | |
426 return NGX_OK; | |
427 } | |
428 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
429 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
430 slen = ctx->service.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
431 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
432 if (ngx_strlchr(ctx->service.data, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
433 ctx->service.data + ctx->service.len, '.') |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
434 == NULL) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
435 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
436 slen += sizeof("_._tcp") - 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
437 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
438 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
439 name.len = slen + 1 + ctx->name.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
440 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
441 name.data = ngx_resolver_alloc(r, name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
442 if (name.data == NULL) { |
7039
a39bc74873fa
Resolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam <bartw@xs4all.nl>
parents:
6922
diff
changeset
|
443 goto failed; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
444 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
445 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
446 if (slen == ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
447 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
|
448 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
449 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
450 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
|
451 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
452 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
453 /* lock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
454 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
455 rc = ngx_resolve_name_locked(r, ctx, &name); |
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 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
458 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
459 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
460 /* lock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
461 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
462 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
|
463 } |
1649 | 464 |
465 if (rc == NGX_OK) { | |
466 return NGX_OK; | |
467 } | |
468 | |
469 /* unlock name mutex */ | |
470 | |
471 if (rc == NGX_AGAIN) { | |
472 return NGX_OK; | |
473 } | |
474 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
475 /* NGX_ERROR */ |
1649 | 476 |
477 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
|
478 ngx_resolver_free(r, ctx->event); |
1649 | 479 } |
480 | |
7039
a39bc74873fa
Resolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam <bartw@xs4all.nl>
parents:
6922
diff
changeset
|
481 failed: |
a39bc74873fa
Resolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam <bartw@xs4all.nl>
parents:
6922
diff
changeset
|
482 |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
483 ngx_resolver_free(r, ctx); |
1649 | 484 |
485 return NGX_ERROR; | |
486 } | |
487 | |
488 | |
489 void | |
490 ngx_resolve_name_done(ngx_resolver_ctx_t *ctx) | |
491 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
492 ngx_uint_t i; |
1649 | 493 ngx_resolver_t *r; |
494 ngx_resolver_ctx_t *w, **p; | |
495 ngx_resolver_node_t *rn; | |
496 | |
497 r = ctx->resolver; | |
498 | |
499 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, | |
500 "resolve name done: %i", ctx->state); | |
501 | |
502 if (ctx->quick) { | |
503 return; | |
504 } | |
505 | |
506 if (ctx->event && ctx->event->timer_set) { | |
507 ngx_del_timer(ctx->event); | |
508 } | |
509 | |
510 /* lock name mutex */ | |
511 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
512 if (ctx->nsrvs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
513 for (i = 0; i < ctx->nsrvs; i++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
514 if (ctx->srvs[i].ctx) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
515 ngx_resolve_name_done(ctx->srvs[i].ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
516 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
517 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
518 if (ctx->srvs[i].addrs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
519 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
|
520 ngx_resolver_free(r, ctx->srvs[i].addrs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
521 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
522 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
523 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
|
524 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
525 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
526 ngx_resolver_free(r, ctx->srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
527 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
528 |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
529 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) { |
1649 | 530 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
531 rn = ctx->node; |
1649 | 532 |
533 if (rn) { | |
534 p = &rn->waiting; | |
535 w = rn->waiting; | |
536 | |
537 while (w) { | |
538 if (w == ctx) { | |
539 *p = w->next; | |
540 | |
541 goto done; | |
542 } | |
543 | |
544 p = &w->next; | |
545 w = w->next; | |
546 } | |
6458
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_log_error(NGX_LOG_ALERT, r->log, 0, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
549 "could not cancel %V resolving", &ctx->name); |
1649 | 550 } |
551 } | |
552 | |
553 done: | |
554 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
555 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
556 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
|
557 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
558 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
559 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
|
560 } |
1649 | 561 |
562 /* unlock name mutex */ | |
563 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
564 /* 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
|
565 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
566 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
|
567 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
|
568 } |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
569 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
570 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
|
571 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
572 /* unlock alloc mutex */ |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
573 |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
574 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
|
575 ngx_del_timer(r->event); |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
576 } |
1649 | 577 } |
578 | |
579 | |
580 static ngx_int_t | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
581 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
|
582 ngx_str_t *name) |
1649 | 583 { |
584 uint32_t hash; | |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
585 ngx_int_t rc; |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
586 ngx_str_t cname; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
587 ngx_uint_t i, naddrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
588 ngx_queue_t *resend_queue, *expire_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
589 ngx_rbtree_t *tree; |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
590 ngx_resolver_ctx_t *next, *last; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
591 ngx_resolver_addr_t *addrs; |
1649 | 592 ngx_resolver_node_t *rn; |
593 | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
594 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
|
595 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
596 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
|
597 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
598 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
599 rn = ngx_resolver_lookup_srv(r, name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
600 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
601 tree = &r->srv_rbtree; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
602 resend_queue = &r->srv_resend_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
603 expire_queue = &r->srv_expire_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
604 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
605 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
606 rn = ngx_resolver_lookup_name(r, name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
607 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
608 tree = &r->name_rbtree; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
609 resend_queue = &r->name_resend_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
610 expire_queue = &r->name_expire_queue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
611 } |
1649 | 612 |
613 if (rn) { | |
614 | |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
615 /* 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
|
616 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
|
617 |
1649 | 618 if (rn->valid >= ngx_time()) { |
619 | |
620 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached"); | |
621 | |
622 ngx_queue_remove(&rn->queue); | |
623 | |
624 rn->expire = ngx_time() + r->expire; | |
625 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
626 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 627 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
628 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
|
629 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
630 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
|
631 #endif |
1649 | 632 |
633 if (naddrs) { | |
634 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
635 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
|
636 addrs = NULL; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
637 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
638 } else { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
639 addrs = ngx_resolver_export(r, rn, 1); |
1649 | 640 if (addrs == NULL) { |
641 return NGX_ERROR; | |
642 } | |
643 } | |
644 | |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
645 last->next = rn->waiting; |
1649 | 646 rn->waiting = NULL; |
647 | |
648 /* unlock name mutex */ | |
649 | |
650 do { | |
651 ctx->state = NGX_OK; | |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
652 ctx->valid = rn->valid; |
1649 | 653 ctx->naddrs = naddrs; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
654 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
655 if (addrs == NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
656 ctx->addrs = &ctx->addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
657 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
|
658 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
|
659 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
|
660 ctx->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
661 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
|
662 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
663 } else { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
664 ctx->addrs = addrs; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
665 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
666 |
1649 | 667 next = ctx->next; |
668 | |
669 ctx->handler(ctx); | |
670 | |
671 ctx = next; | |
672 } while (ctx); | |
673 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
674 if (addrs != NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
675 ngx_resolver_free(r, addrs->sockaddr); |
1649 | 676 ngx_resolver_free(r, addrs); |
677 } | |
678 | |
679 return NGX_OK; | |
680 } | |
681 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
682 if (rn->nsrvs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
683 last->next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
684 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
685 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
686 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
687 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
688 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
689 next = ctx->next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
690 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
691 ngx_resolver_resolve_srv_names(ctx, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
692 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
693 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
694 } while (ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
695 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
696 return NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
697 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
698 |
1649 | 699 /* NGX_RESOLVE_CNAME */ |
700 | |
1969 | 701 if (ctx->recursion++ < NGX_RESOLVER_MAX_RECURSION) { |
702 | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
703 cname.len = rn->cnlen; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
704 cname.data = rn->u.cname; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
705 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
706 return ngx_resolve_name_locked(r, ctx, &cname); |
1969 | 707 } |
708 | |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
709 last->next = rn->waiting; |
1969 | 710 rn->waiting = NULL; |
711 | |
712 /* unlock name mutex */ | |
713 | |
714 do { | |
715 ctx->state = NGX_RESOLVE_NXDOMAIN; | |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
716 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
1969 | 717 next = ctx->next; |
718 | |
719 ctx->handler(ctx); | |
720 | |
721 ctx = next; | |
722 } while (ctx); | |
723 | |
724 return NGX_OK; | |
1649 | 725 } |
726 | |
727 if (rn->waiting) { | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
728 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
|
729 return NGX_ERROR; |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
730 } |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
731 |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
732 last->next = rn->waiting; |
1649 | 733 rn->waiting = ctx; |
3297 | 734 ctx->state = NGX_AGAIN; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
735 ctx->async = 1; |
1649 | 736 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
737 do { |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
738 ctx->node = rn; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
739 ctx = ctx->next; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
740 } while (ctx); |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
741 |
1649 | 742 return NGX_AGAIN; |
743 } | |
744 | |
745 ngx_queue_remove(&rn->queue); | |
746 | |
747 /* lock alloc mutex */ | |
748 | |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
749 if (rn->query) { |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
750 ngx_resolver_free_locked(r, rn->query); |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
751 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
752 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
753 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
754 #endif |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
755 } |
1649 | 756 |
757 if (rn->cnlen) { | |
758 ngx_resolver_free_locked(r, rn->u.cname); | |
759 } | |
760 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
761 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) { |
1649 | 762 ngx_resolver_free_locked(r, rn->u.addrs); |
763 } | |
764 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
765 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
766 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
|
767 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
|
768 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
769 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
770 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
771 if (rn->nsrvs) { |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
772 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
|
773 if (rn->u.srvs[i].name.data) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
774 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
|
775 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
776 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
777 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
778 ngx_resolver_free_locked(r, rn->u.srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
779 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
780 |
1649 | 781 /* unlock alloc mutex */ |
782 | |
783 } else { | |
784 | |
785 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t)); | |
786 if (rn == NULL) { | |
787 return NGX_ERROR; | |
788 } | |
789 | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
790 rn->name = ngx_resolver_dup(r, name->data, name->len); |
1649 | 791 if (rn->name == NULL) { |
792 ngx_resolver_free(r, rn); | |
793 return NGX_ERROR; | |
794 } | |
795 | |
796 rn->node.key = hash; | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
797 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
|
798 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
799 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
800 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
801 #endif |
1649 | 802 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
803 ngx_rbtree_insert(tree, &rn->node); |
1649 | 804 } |
805 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
806 if (ctx->service.len) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
807 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
|
808 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
809 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
810 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
|
811 } |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
812 |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
813 if (rc == NGX_ERROR) { |
1649 | 814 goto failed; |
815 } | |
816 | |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
817 if (rc == NGX_DECLINED) { |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
818 ngx_rbtree_delete(tree, &rn->node); |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
819 |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
820 ngx_resolver_free(r, rn->query); |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
821 ngx_resolver_free(r, rn->name); |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
822 ngx_resolver_free(r, rn); |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
823 |
6349
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
824 do { |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
825 ctx->state = NGX_RESOLVE_NXDOMAIN; |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
826 next = ctx->next; |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
827 |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
828 ctx->handler(ctx); |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
829 |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
830 ctx = next; |
978e79b95c9f
Resolver: fixed CNAME processing for several requests.
Ruslan Ermilov <ru@nginx.com>
parents:
6348
diff
changeset
|
831 } while (ctx); |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
832 |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
833 return NGX_OK; |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
834 } |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
835 |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
836 rn->last_connection = r->last_connection++; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
837 if (r->last_connection == r->connections.nelts) { |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
838 r->last_connection = 0; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
839 } |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
840 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
841 rn->naddrs = (u_short) -1; |
6367 | 842 rn->tcp = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
843 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
844 rn->naddrs6 = r->ipv6 ? (u_short) -1 : 0; |
6367 | 845 rn->tcp6 = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
846 #endif |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
847 rn->nsrvs = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
848 |
1649 | 849 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
|
850 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
851 /* immediately retry once on failure */ |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
852 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
853 rn->last_connection++; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
854 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
|
855 rn->last_connection = 0; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
856 } |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
857 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
858 (void) ngx_resolver_send_query(r, rn); |
1649 | 859 } |
860 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
861 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
|
862 goto failed; |
1649 | 863 } |
864 | |
6846
c3a895b94d3f
Resolver: fixed a race between parallel name and addr resolves.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6845
diff
changeset
|
865 if (ngx_resolver_resend_empty(r)) { |
1649 | 866 ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000)); |
867 } | |
868 | |
869 rn->expire = ngx_time() + r->resend_timeout; | |
870 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
871 ngx_queue_insert_head(resend_queue, &rn->queue); |
1649 | 872 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
873 rn->code = 0; |
1649 | 874 rn->cnlen = 0; |
875 rn->valid = 0; | |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
876 rn->ttl = NGX_MAX_UINT32_VALUE; |
1649 | 877 rn->waiting = ctx; |
878 | |
879 ctx->state = NGX_AGAIN; | |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
880 ctx->async = 1; |
1649 | 881 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
882 do { |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
883 ctx->node = rn; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
884 ctx = ctx->next; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
885 } while (ctx); |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
886 |
1649 | 887 return NGX_AGAIN; |
888 | |
889 failed: | |
890 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
891 ngx_rbtree_delete(tree, &rn->node); |
1649 | 892 |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
893 if (rn->query) { |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
894 ngx_resolver_free(r, rn->query); |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
895 } |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
896 |
1649 | 897 ngx_resolver_free(r, rn->name); |
898 | |
899 ngx_resolver_free(r, rn); | |
900 | |
901 return NGX_ERROR; | |
902 } | |
583 | 903 |
904 | |
905 ngx_int_t | |
1649 | 906 ngx_resolve_addr(ngx_resolver_ctx_t *ctx) |
907 { | |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
908 u_char *name; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
909 in_addr_t addr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
910 ngx_queue_t *resend_queue, *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
911 ngx_rbtree_t *tree; |
1649 | 912 ngx_resolver_t *r; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
913 struct sockaddr_in *sin; |
1649 | 914 ngx_resolver_node_t *rn; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
915 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
916 uint32_t hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
917 struct sockaddr_in6 *sin6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
918 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
919 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
920 #if (NGX_SUPPRESS_WARN) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
921 addr = 0; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
922 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
923 hash = 0; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
924 sin6 = NULL; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
925 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
926 #endif |
1649 | 927 |
928 r = ctx->resolver; | |
929 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
930 switch (ctx->addr.sockaddr->sa_family) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
931 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
932 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
933 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
934 sin6 = (struct sockaddr_in6 *) ctx->addr.sockaddr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
935 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
|
936 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
937 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
938 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
939 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
|
940 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
941 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
942 resend_queue = &r->addr6_resend_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
943 expire_queue = &r->addr6_expire_queue; |
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 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
946 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
947 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
948 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
949 sin = (struct sockaddr_in *) ctx->addr.sockaddr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
950 addr = ntohl(sin->sin_addr.s_addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
951 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
952 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
953 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
954 rn = ngx_resolver_lookup_addr(r, addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
955 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
956 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
957 resend_queue = &r->addr_resend_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
958 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
|
959 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
960 |
1649 | 961 if (rn) { |
962 | |
963 if (rn->valid >= ngx_time()) { | |
964 | |
965 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached"); | |
966 | |
967 ngx_queue_remove(&rn->queue); | |
968 | |
969 rn->expire = ngx_time() + r->expire; | |
970 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
971 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 972 |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
973 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
|
974 if (name == NULL) { |
7566
571383f75a9a
Resolver: fixed possible use-after-free while resolving PTR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7428
diff
changeset
|
975 ngx_resolver_free(r, ctx); |
571383f75a9a
Resolver: fixed possible use-after-free while resolving PTR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7428
diff
changeset
|
976 return NGX_ERROR; |
1649 | 977 } |
978 | |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
979 ctx->name.len = rn->nlen; |
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
980 ctx->name.data = name; |
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
981 |
1649 | 982 /* unlock addr mutex */ |
983 | |
984 ctx->state = NGX_OK; | |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
985 ctx->valid = rn->valid; |
1649 | 986 |
987 ctx->handler(ctx); | |
988 | |
2484
cf3cd450049c
store name pointer in variable allocated on stack
Igor Sysoev <igor@sysoev.ru>
parents:
2483
diff
changeset
|
989 ngx_resolver_free(r, name); |
1649 | 990 |
991 return NGX_OK; | |
992 } | |
993 | |
994 if (rn->waiting) { | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
995 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
|
996 return NGX_ERROR; |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
997 } |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
998 |
1649 | 999 ctx->next = rn->waiting; |
1000 rn->waiting = ctx; | |
3297 | 1001 ctx->state = NGX_AGAIN; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
1002 ctx->async = 1; |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
1003 ctx->node = rn; |
1649 | 1004 |
2487
9b4dce95c744
fix return code, this fixes segfault when two or more
Igor Sysoev <igor@sysoev.ru>
parents:
2486
diff
changeset
|
1005 /* unlock addr mutex */ |
9b4dce95c744
fix return code, this fixes segfault when two or more
Igor Sysoev <igor@sysoev.ru>
parents:
2486
diff
changeset
|
1006 |
9b4dce95c744
fix return code, this fixes segfault when two or more
Igor Sysoev <igor@sysoev.ru>
parents:
2486
diff
changeset
|
1007 return NGX_OK; |
1649 | 1008 } |
1009 | |
1010 ngx_queue_remove(&rn->queue); | |
1011 | |
1012 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
|
1013 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1014 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1015 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1016 #endif |
1649 | 1017 |
1018 } else { | |
1019 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t)); | |
1020 if (rn == NULL) { | |
1021 goto failed; | |
1022 } | |
1023 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1024 switch (ctx->addr.sockaddr->sa_family) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1025 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1026 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1027 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1028 rn->addr6 = sin6->sin6_addr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1029 rn->node.key = hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1030 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1031 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1032 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1033 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1034 rn->node.key = addr; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1035 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1036 |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1037 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1038 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1039 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1040 #endif |
1649 | 1041 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1042 ngx_rbtree_insert(tree, &rn->node); |
1649 | 1043 } |
1044 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
1045 if (ngx_resolver_create_addr_query(r, rn, &ctx->addr) != NGX_OK) { |
1649 | 1046 goto failed; |
1047 } | |
1048 | |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1049 rn->last_connection = r->last_connection++; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1050 if (r->last_connection == r->connections.nelts) { |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1051 r->last_connection = 0; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1052 } |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1053 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1054 rn->naddrs = (u_short) -1; |
6367 | 1055 rn->tcp = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1056 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1057 rn->naddrs6 = (u_short) -1; |
6367 | 1058 rn->tcp6 = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1059 #endif |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1060 rn->nsrvs = 0; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1061 |
1649 | 1062 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
|
1063 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1064 /* immediately retry once on failure */ |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1065 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1066 rn->last_connection++; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1067 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
|
1068 rn->last_connection = 0; |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1069 } |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1070 |
54683f650cbd
Resolver: retry sending queries on errors (ticket #1511).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7299
diff
changeset
|
1071 (void) ngx_resolver_send_query(r, rn); |
1649 | 1072 } |
1073 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
1074 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
|
1075 goto failed; |
1649 | 1076 } |
1077 | |
6846
c3a895b94d3f
Resolver: fixed a race between parallel name and addr resolves.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6845
diff
changeset
|
1078 if (ngx_resolver_resend_empty(r)) { |
1649 | 1079 ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000)); |
1080 } | |
1081 | |
1082 rn->expire = ngx_time() + r->resend_timeout; | |
1083 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1084 ngx_queue_insert_head(resend_queue, &rn->queue); |
1649 | 1085 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1086 rn->code = 0; |
1649 | 1087 rn->cnlen = 0; |
1088 rn->name = NULL; | |
1089 rn->nlen = 0; | |
1090 rn->valid = 0; | |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
1091 rn->ttl = NGX_MAX_UINT32_VALUE; |
1649 | 1092 rn->waiting = ctx; |
1093 | |
1094 /* unlock addr mutex */ | |
1095 | |
1096 ctx->state = NGX_AGAIN; | |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
1097 ctx->async = 1; |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
1098 ctx->node = rn; |
1649 | 1099 |
1100 return NGX_OK; | |
1101 | |
1102 failed: | |
1103 | |
1104 if (rn) { | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1105 ngx_rbtree_delete(tree, &rn->node); |
1649 | 1106 |
1960
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1107 if (rn->query) { |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1108 ngx_resolver_free(r, rn->query); |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1109 } |
1609b3c3d604
fix memory leak on resolver query send failure
Igor Sysoev <igor@sysoev.ru>
parents:
1914
diff
changeset
|
1110 |
1649 | 1111 ngx_resolver_free(r, rn); |
1112 } | |
1113 | |
1114 /* unlock addr mutex */ | |
1115 | |
1116 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
|
1117 ngx_resolver_free(r, ctx->event); |
1649 | 1118 } |
1119 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1120 ngx_resolver_free(r, ctx); |
1649 | 1121 |
1122 return NGX_ERROR; | |
1123 } | |
1124 | |
1125 | |
1126 void | |
1127 ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx) | |
1128 { | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1129 ngx_queue_t *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1130 ngx_rbtree_t *tree; |
1649 | 1131 ngx_resolver_t *r; |
1132 ngx_resolver_ctx_t *w, **p; | |
1133 ngx_resolver_node_t *rn; | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
1134 |
1649 | 1135 r = ctx->resolver; |
1136 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1137 switch (ctx->addr.sockaddr->sa_family) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1138 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1139 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1140 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1141 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1142 expire_queue = &r->addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1143 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1144 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1145 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1146 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1147 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1148 expire_queue = &r->addr_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1149 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1150 |
1649 | 1151 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, |
1152 "resolve addr done: %i", ctx->state); | |
1153 | |
1154 if (ctx->event && ctx->event->timer_set) { | |
1155 ngx_del_timer(ctx->event); | |
1156 } | |
1157 | |
1158 /* lock addr mutex */ | |
1159 | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
1160 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) { |
1649 | 1161 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
1162 rn = ctx->node; |
1649 | 1163 |
1164 if (rn) { | |
1165 p = &rn->waiting; | |
1166 w = rn->waiting; | |
1167 | |
1168 while (w) { | |
1169 if (w == ctx) { | |
1170 *p = w->next; | |
1171 | |
1172 goto done; | |
1173 } | |
1174 | |
1175 p = &w->next; | |
1176 w = w->next; | |
1177 } | |
1178 } | |
1179 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1180 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1181 u_char text[NGX_SOCKADDR_STRLEN]; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1182 ngx_str_t addrtext; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1183 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1184 addrtext.data = text; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1185 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
|
1186 text, NGX_SOCKADDR_STRLEN, 0); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1187 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1188 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
|
1189 "could not cancel %V resolving", &addrtext); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1190 } |
1649 | 1191 } |
1192 | |
1193 done: | |
1194 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1195 ngx_resolver_expire(r, tree, expire_queue); |
1649 | 1196 |
1197 /* unlock addr mutex */ | |
1198 | |
1904
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1199 /* 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
|
1200 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1201 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
|
1202 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
|
1203 } |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1204 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1205 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
|
1206 |
538f06aa8118
fix memory leaks, use unlocked ngx_resolver_free() for seldom failed cases
Igor Sysoev <igor@sysoev.ru>
parents:
1903
diff
changeset
|
1207 /* unlock alloc mutex */ |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1208 |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1209 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
|
1210 ngx_del_timer(r->event); |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1211 } |
1649 | 1212 } |
1213 | |
1214 | |
1215 static void | |
1216 ngx_resolver_expire(ngx_resolver_t *r, ngx_rbtree_t *tree, ngx_queue_t *queue) | |
1217 { | |
1218 time_t now; | |
1219 ngx_uint_t i; | |
1220 ngx_queue_t *q; | |
1221 ngx_resolver_node_t *rn; | |
1222 | |
1223 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver expire"); | |
1224 | |
1225 now = ngx_time(); | |
1226 | |
1227 for (i = 0; i < 2; i++) { | |
1228 if (ngx_queue_empty(queue)) { | |
1229 return; | |
1230 } | |
1231 | |
1232 q = ngx_queue_last(queue); | |
1233 | |
1234 rn = ngx_queue_data(q, ngx_resolver_node_t, queue); | |
1235 | |
1236 if (now <= rn->expire) { | |
1237 return; | |
1238 } | |
1239 | |
1774 | 1240 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, |
1241 "resolver expire \"%*s\"", (size_t) rn->nlen, rn->name); | |
1649 | 1242 |
1243 ngx_queue_remove(q); | |
1244 | |
1245 ngx_rbtree_delete(tree, &rn->node); | |
1246 | |
1247 ngx_resolver_free_node(r, rn); | |
1248 } | |
1249 } | |
1250 | |
1251 | |
1252 static ngx_int_t | |
1253 ngx_resolver_send_query(ngx_resolver_t *r, ngx_resolver_node_t *rn) | |
1254 { | |
6367 | 1255 ngx_int_t rc; |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1256 ngx_resolver_connection_t *rec; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1257 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1258 rec = r->connections.elts; |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1259 rec = &rec[rn->last_connection]; |
1649 | 1260 |
6367 | 1261 if (rec->log.handler == NULL) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1262 rec->log = *r->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1263 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
|
1264 rec->log.data = rec; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
1265 rec->log.action = "resolving"; |
1649 | 1266 } |
1267 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1268 if (rn->naddrs == (u_short) -1) { |
6367 | 1269 rc = rn->tcp ? ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen) |
1270 : ngx_resolver_send_udp_query(r, rec, rn->query, rn->qlen); | |
1271 | |
1272 if (rc != NGX_OK) { | |
1273 return rc; | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1274 } |
1649 | 1275 } |
1276 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1277 #if (NGX_HAVE_INET6) |
6367 | 1278 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1279 if (rn->query6 && rn->naddrs6 == (u_short) -1) { |
6367 | 1280 rc = rn->tcp6 |
1281 ? ngx_resolver_send_tcp_query(r, rec, rn->query6, rn->qlen) | |
1282 : ngx_resolver_send_udp_query(r, rec, rn->query6, rn->qlen); | |
1283 | |
1284 if (rc != NGX_OK) { | |
1285 return rc; | |
1286 } | |
1287 } | |
1288 | |
1289 #endif | |
1290 | |
1291 return NGX_OK; | |
1292 } | |
1293 | |
1294 | |
1295 static ngx_int_t | |
1296 ngx_resolver_send_udp_query(ngx_resolver_t *r, ngx_resolver_connection_t *rec, | |
1297 u_char *query, u_short qlen) | |
1298 { | |
1299 ssize_t n; | |
1300 | |
1301 if (rec->udp == NULL) { | |
1302 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
|
1303 return NGX_ERROR; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1304 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1305 |
6367 | 1306 rec->udp->data = rec; |
1307 rec->udp->read->handler = ngx_resolver_udp_read; | |
1308 rec->udp->read->resolver = 1; | |
1309 } | |
1310 | |
1311 n = ngx_send(rec->udp, query, qlen); | |
1312 | |
7275 | 1313 if (n == NGX_ERROR) { |
7276
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1314 goto failed; |
6367 | 1315 } |
1316 | |
1317 if ((size_t) n != (size_t) qlen) { | |
1318 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
|
1319 goto failed; |
6367 | 1320 } |
1321 | |
1322 return NGX_OK; | |
7276
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1323 |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1324 failed: |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1325 |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1326 ngx_close_connection(rec->udp); |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1327 rec->udp = NULL; |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1328 |
a90f7812de35
Resolver: close UDP socket on error or incomplete send.
Ruslan Ermilov <ru@nginx.com>
parents:
7275
diff
changeset
|
1329 return NGX_ERROR; |
6367 | 1330 } |
1331 | |
1332 | |
1333 static ngx_int_t | |
1334 ngx_resolver_send_tcp_query(ngx_resolver_t *r, ngx_resolver_connection_t *rec, | |
1335 u_char *query, u_short qlen) | |
1336 { | |
1337 ngx_buf_t *b; | |
1338 ngx_int_t rc; | |
1339 | |
1340 rc = NGX_OK; | |
1341 | |
1342 if (rec->tcp == NULL) { | |
1343 b = rec->read_buf; | |
1344 | |
1345 if (b == NULL) { | |
1346 b = ngx_resolver_calloc(r, sizeof(ngx_buf_t)); | |
1347 if (b == NULL) { | |
1348 return NGX_ERROR; | |
1349 } | |
1350 | |
1351 b->start = ngx_resolver_alloc(r, NGX_RESOLVER_TCP_RSIZE); | |
1352 if (b->start == NULL) { | |
6368
d73f77bb5caf
Resolver: fixed possible resource leak introduced in 5a16d40c63de.
Ruslan Ermilov <ru@nginx.com>
parents:
6367
diff
changeset
|
1353 ngx_resolver_free(r, b); |
6367 | 1354 return NGX_ERROR; |
1355 } | |
1356 | |
1357 b->end = b->start + NGX_RESOLVER_TCP_RSIZE; | |
1358 | |
1359 rec->read_buf = b; | |
1360 } | |
1361 | |
1362 b->pos = b->start; | |
1363 b->last = b->start; | |
1364 | |
1365 b = rec->write_buf; | |
1366 | |
1367 if (b == NULL) { | |
1368 b = ngx_resolver_calloc(r, sizeof(ngx_buf_t)); | |
1369 if (b == NULL) { | |
1370 return NGX_ERROR; | |
1371 } | |
1372 | |
1373 b->start = ngx_resolver_alloc(r, NGX_RESOLVER_TCP_WSIZE); | |
1374 if (b->start == NULL) { | |
6368
d73f77bb5caf
Resolver: fixed possible resource leak introduced in 5a16d40c63de.
Ruslan Ermilov <ru@nginx.com>
parents:
6367
diff
changeset
|
1375 ngx_resolver_free(r, b); |
6367 | 1376 return NGX_ERROR; |
1377 } | |
1378 | |
1379 b->end = b->start + NGX_RESOLVER_TCP_WSIZE; | |
1380 | |
1381 rec->write_buf = b; | |
1382 } | |
1383 | |
1384 b->pos = b->start; | |
1385 b->last = b->start; | |
1386 | |
1387 rc = ngx_tcp_connect(rec); | |
1388 if (rc == NGX_ERROR) { | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1389 return NGX_ERROR; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1390 } |
6367 | 1391 |
1392 rec->tcp->data = rec; | |
1393 rec->tcp->write->handler = ngx_resolver_tcp_write; | |
1394 rec->tcp->read->handler = ngx_resolver_tcp_read; | |
1395 rec->tcp->read->resolver = 1; | |
1396 | |
1397 ngx_add_timer(rec->tcp->write, (ngx_msec_t) (r->tcp_timeout * 1000)); | |
1649 | 1398 } |
6367 | 1399 |
1400 b = rec->write_buf; | |
1401 | |
1402 if (b->end - b->last < 2 + qlen) { | |
1403 ngx_log_error(NGX_LOG_CRIT, &rec->log, 0, "buffer overflow"); | |
1404 return NGX_ERROR; | |
1405 } | |
1406 | |
1407 *b->last++ = (u_char) (qlen >> 8); | |
1408 *b->last++ = (u_char) qlen; | |
1409 b->last = ngx_cpymem(b->last, query, qlen); | |
1410 | |
1411 if (rc == NGX_OK) { | |
1412 ngx_resolver_tcp_write(rec->tcp->write); | |
1413 } | |
1649 | 1414 |
1415 return NGX_OK; | |
1416 } | |
1417 | |
1418 | |
1419 static void | |
1420 ngx_resolver_resend_handler(ngx_event_t *ev) | |
1421 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1422 time_t timer, atimer, stimer, ntimer; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1423 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1424 time_t a6timer; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1425 #endif |
1649 | 1426 ngx_resolver_t *r; |
1427 | |
1428 r = ev->data; | |
1429 | |
1430 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, | |
1431 "resolver resend handler"); | |
1432 | |
1433 /* lock name mutex */ | |
1434 | |
1435 ntimer = ngx_resolver_resend(r, &r->name_rbtree, &r->name_resend_queue); | |
1436 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1437 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
|
1438 |
1649 | 1439 /* unlock name mutex */ |
1440 | |
1441 /* lock addr mutex */ | |
1442 | |
1443 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
|
1444 |
1649 | 1445 /* unlock addr mutex */ |
1446 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1447 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1448 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1449 /* lock addr6 mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1450 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1451 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
|
1452 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1453 /* unlock addr6 mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1454 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1455 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1456 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1457 timer = ntimer; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1458 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1459 if (timer == 0) { |
1649 | 1460 timer = atimer; |
1461 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1462 } else if (atimer) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1463 timer = ngx_min(timer, atimer); |
1649 | 1464 } |
1465 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1466 if (timer == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1467 timer = stimer; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1468 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1469 } else if (stimer) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1470 timer = ngx_min(timer, stimer); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1471 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
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 if (timer == 0) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1476 timer = a6timer; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1477 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1478 } else if (a6timer) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1479 timer = ngx_min(timer, a6timer); |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1482 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
1483 |
1649 | 1484 if (timer) { |
1485 ngx_add_timer(r->event, (ngx_msec_t) (timer * 1000)); | |
1486 } | |
1487 } | |
1488 | |
1489 | |
1490 static time_t | |
1491 ngx_resolver_resend(ngx_resolver_t *r, ngx_rbtree_t *tree, ngx_queue_t *queue) | |
1492 { | |
1493 time_t now; | |
1494 ngx_queue_t *q; | |
1495 ngx_resolver_node_t *rn; | |
1496 | |
1497 now = ngx_time(); | |
1498 | |
1499 for ( ;; ) { | |
1500 if (ngx_queue_empty(queue)) { | |
1501 return 0; | |
1502 } | |
1503 | |
1504 q = ngx_queue_last(queue); | |
1505 | |
1506 rn = ngx_queue_data(q, ngx_resolver_node_t, queue); | |
1507 | |
1508 if (now < rn->expire) { | |
1509 return rn->expire - now; | |
1510 } | |
1511 | |
1774 | 1512 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0, |
1513 "resolver resend \"%*s\" %p", | |
1514 (size_t) rn->nlen, rn->name, rn->waiting); | |
1649 | 1515 |
1516 ngx_queue_remove(q); | |
1517 | |
1518 if (rn->waiting) { | |
1519 | |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1520 if (++rn->last_connection == r->connections.nelts) { |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1521 rn->last_connection = 0; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1522 } |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
1523 |
4683
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1524 (void) ngx_resolver_send_query(r, rn); |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1525 |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1526 rn->expire = now + r->resend_timeout; |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1527 |
84d8e60b65f0
Fixed crash in ngx_resolver_cleanup_tree().
Ruslan Ermilov <ru@nginx.com>
parents:
4671
diff
changeset
|
1528 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
|
1529 |
cf4ee321d195
do not delete failed DNS request if there are waiting clients
Igor Sysoev <igor@sysoev.ru>
parents:
1878
diff
changeset
|
1530 continue; |
1649 | 1531 } |
1532 | |
1533 ngx_rbtree_delete(tree, &rn->node); | |
1534 | |
1535 ngx_resolver_free_node(r, rn); | |
1536 } | |
1537 } | |
1538 | |
1539 | |
6196
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1540 static ngx_uint_t |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1541 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
|
1542 { |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1543 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
|
1544 && 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
|
1545 #if (NGX_HAVE_INET6) |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1546 && 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
|
1547 #endif |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1548 && 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
|
1549 } |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1550 |
c3ec43580a48
Resolver: canceled resend timer on empty resend queues.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6126
diff
changeset
|
1551 |
1649 | 1552 static void |
6367 | 1553 ngx_resolver_udp_read(ngx_event_t *rev) |
1649 | 1554 { |
6367 | 1555 ssize_t n; |
1556 ngx_connection_t *c; | |
1557 ngx_resolver_connection_t *rec; | |
1558 u_char buf[NGX_RESOLVER_UDP_SIZE]; | |
1649 | 1559 |
1560 c = rev->data; | |
6367 | 1561 rec = c->data; |
1649 | 1562 |
1563 do { | |
1689 | 1564 n = ngx_udp_recv(c, buf, NGX_RESOLVER_UDP_SIZE); |
1565 | |
8371
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1566 if (n == NGX_AGAIN) { |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1567 break; |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1568 } |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1569 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1570 if (n == NGX_ERROR) { |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1571 goto failed; |
1649 | 1572 } |
1573 | |
6367 | 1574 ngx_resolver_process_response(rec->resolver, buf, n, 0); |
1649 | 1575 |
1576 } while (rev->ready); | |
8371
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1577 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1578 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
|
1579 goto failed; |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1580 } |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1581 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1582 return; |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1583 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1584 failed: |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1585 |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1586 ngx_close_connection(rec->udp); |
eb54227110f0
Resolver: added missing event handling after reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8121
diff
changeset
|
1587 rec->udp = NULL; |
1649 | 1588 } |
1589 | |
1590 | |
1591 static void | |
6367 | 1592 ngx_resolver_tcp_write(ngx_event_t *wev) |
1593 { | |
1594 off_t sent; | |
1595 ssize_t n; | |
1596 ngx_buf_t *b; | |
1597 ngx_resolver_t *r; | |
1598 ngx_connection_t *c; | |
1599 ngx_resolver_connection_t *rec; | |
1600 | |
1601 c = wev->data; | |
1602 rec = c->data; | |
1603 b = rec->write_buf; | |
1604 r = rec->resolver; | |
1605 | |
1606 if (wev->timedout) { | |
1607 goto failed; | |
1608 } | |
1609 | |
1610 sent = c->sent; | |
1611 | |
1612 while (wev->ready && b->pos < b->last) { | |
1613 n = ngx_send(c, b->pos, b->last - b->pos); | |
1614 | |
1615 if (n == NGX_AGAIN) { | |
1616 break; | |
1617 } | |
1618 | |
1619 if (n == NGX_ERROR) { | |
1620 goto failed; | |
1621 } | |
1622 | |
1623 b->pos += n; | |
1624 } | |
1625 | |
1626 if (b->pos != b->start) { | |
1627 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); | |
1628 b->pos = b->start; | |
1629 } | |
1630 | |
1631 if (c->sent != sent) { | |
1632 ngx_add_timer(wev, (ngx_msec_t) (r->tcp_timeout * 1000)); | |
1633 } | |
1634 | |
1635 if (ngx_handle_write_event(wev, 0) != NGX_OK) { | |
1636 goto failed; | |
1637 } | |
1638 | |
1639 return; | |
1640 | |
1641 failed: | |
1642 | |
1643 ngx_close_connection(c); | |
1644 rec->tcp = NULL; | |
1645 } | |
1646 | |
1647 | |
1648 static void | |
1649 ngx_resolver_tcp_read(ngx_event_t *rev) | |
1650 { | |
1651 u_char *p; | |
1652 size_t size; | |
1653 ssize_t n; | |
1654 u_short qlen; | |
1655 ngx_buf_t *b; | |
1656 ngx_resolver_t *r; | |
1657 ngx_connection_t *c; | |
1658 ngx_resolver_connection_t *rec; | |
1659 | |
1660 c = rev->data; | |
1661 rec = c->data; | |
1662 b = rec->read_buf; | |
1663 r = rec->resolver; | |
1664 | |
1665 while (rev->ready) { | |
1666 n = ngx_recv(c, b->last, b->end - b->last); | |
1667 | |
1668 if (n == NGX_AGAIN) { | |
1669 break; | |
1670 } | |
1671 | |
1672 if (n == NGX_ERROR || n == 0) { | |
1673 goto failed; | |
1674 } | |
1675 | |
1676 b->last += n; | |
1677 | |
1678 for ( ;; ) { | |
1679 p = b->pos; | |
1680 size = b->last - p; | |
1681 | |
1682 if (size < 2) { | |
1683 break; | |
1684 } | |
1685 | |
1686 qlen = (u_short) *p++ << 8; | |
1687 qlen += *p++; | |
1688 | |
1689 if (size < (size_t) (2 + qlen)) { | |
1690 break; | |
1691 } | |
1692 | |
1693 ngx_resolver_process_response(r, p, qlen, 1); | |
1694 | |
1695 b->pos += 2 + qlen; | |
1696 } | |
1697 | |
1698 if (b->pos != b->start) { | |
1699 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); | |
1700 b->pos = b->start; | |
1701 } | |
1702 } | |
1703 | |
1704 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
1705 goto failed; | |
1706 } | |
1707 | |
1708 return; | |
1709 | |
1710 failed: | |
1711 | |
1712 ngx_close_connection(c); | |
1713 rec->tcp = NULL; | |
1714 } | |
1715 | |
1716 | |
1717 static void | |
1718 ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, size_t n, | |
1719 ngx_uint_t tcp) | |
1649 | 1720 { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1721 char *err; |
6367 | 1722 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
|
1723 qtype, qclass; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1724 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1725 ngx_uint_t qident6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1726 #endif |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1727 ngx_queue_t *q; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1728 ngx_resolver_qs_t *qs; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1729 ngx_resolver_hdr_t *response; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1730 ngx_resolver_node_t *rn; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1731 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1732 if (n < sizeof(ngx_resolver_hdr_t)) { |
1649 | 1733 goto short_response; |
1734 } | |
1735 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1736 response = (ngx_resolver_hdr_t *) buf; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1737 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1738 ident = (response->ident_hi << 8) + response->ident_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1739 flags = (response->flags_hi << 8) + response->flags_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1740 nqs = (response->nqs_hi << 8) + response->nqs_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1741 nan = (response->nan_hi << 8) + response->nan_lo; |
6367 | 1742 trunc = flags & 0x0200; |
1649 | 1743 |
1744 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
|
1745 "resolver DNS response %ui fl:%04Xi %ui/%ui/%ud/%ud", |
1649 | 1746 ident, flags, nqs, nan, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1747 (response->nns_hi << 8) + response->nns_lo, |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1748 (response->nar_hi << 8) + response->nar_lo); |
1649 | 1749 |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1750 /* response to a standard query */ |
6367 | 1751 if ((flags & 0xf870) != 0x8000 || (trunc && tcp)) { |
1649 | 1752 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
|
1753 "invalid %s DNS response %ui fl:%04Xi", |
6367 | 1754 tcp ? "TCP" : "UDP", ident, flags); |
1649 | 1755 return; |
1756 } | |
1757 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1758 code = flags & 0xf; |
1649 | 1759 |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1760 if (code == NGX_RESOLVE_FORMERR) { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1761 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1762 times = 0; |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1763 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1764 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
|
1765 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
|
1766 q = ngx_queue_next(q)) |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1767 { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1768 rn = ngx_queue_data(q, ngx_resolver_node_t, queue); |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1769 qident = (rn->query[0] << 8) + rn->query[1]; |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1770 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1771 if (qident == ident) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1772 goto dns_error_name; |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1773 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1774 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1775 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1776 if (rn->query6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1777 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
|
1778 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1779 if (qident6 == ident) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1780 goto dns_error_name; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1781 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1782 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1783 #endif |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1784 } |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1785 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1786 goto dns_error; |
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 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1789 if (code > NGX_RESOLVE_REFUSED) { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1790 goto dns_error; |
1649 | 1791 } |
1792 | |
1793 if (nqs != 1) { | |
1794 err = "invalid number of questions in DNS response"; | |
1795 goto done; | |
1796 } | |
1797 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1798 i = sizeof(ngx_resolver_hdr_t); |
1649 | 1799 |
1800 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
|
1801 |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1802 if (buf[i] & 0xc0) { |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1803 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
|
1804 goto done; |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1805 } |
4364b39de407
Resolver: explicit check for compression pointers in question.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8474
diff
changeset
|
1806 |
1649 | 1807 if (buf[i] == '\0') { |
1808 goto found; | |
1809 } | |
1810 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1811 i += 1 + buf[i]; |
1649 | 1812 } |
1813 | |
1814 goto short_response; | |
1815 | |
1816 found: | |
1817 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1818 if (i++ == sizeof(ngx_resolver_hdr_t)) { |
1649 | 1819 err = "zero-length domain name in DNS response"; |
1820 goto done; | |
1821 } | |
1822 | |
1823 if (i + sizeof(ngx_resolver_qs_t) + nan * (2 + sizeof(ngx_resolver_an_t)) | |
1824 > (ngx_uint_t) n) | |
1825 { | |
1826 goto short_response; | |
1827 } | |
1828 | |
1829 qs = (ngx_resolver_qs_t *) &buf[i]; | |
1830 | |
1831 qtype = (qs->type_hi << 8) + qs->type_lo; | |
1832 qclass = (qs->class_hi << 8) + qs->class_lo; | |
1833 | |
1834 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
|
1835 "resolver DNS response qt:%ui cl:%ui", qtype, qclass); |
1649 | 1836 |
1837 if (qclass != 1) { | |
1838 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
|
1839 "unknown query class %ui in DNS response", qclass); |
1649 | 1840 return; |
1841 } | |
1842 | |
1843 switch (qtype) { | |
1844 | |
1845 case NGX_RESOLVE_A: | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1846 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1847 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1848 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1849 |
6367 | 1850 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
|
1851 i + sizeof(ngx_resolver_qs_t)); |
1649 | 1852 |
1853 break; | |
1854 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1855 case NGX_RESOLVE_SRV: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1856 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1857 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
|
1858 i + sizeof(ngx_resolver_qs_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1859 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1860 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1861 |
1649 | 1862 case NGX_RESOLVE_PTR: |
1863 | |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
1864 ngx_resolver_process_ptr(r, buf, n, ident, code, nan); |
1649 | 1865 |
1866 break; | |
1867 | |
1868 default: | |
1869 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
|
1870 "unknown query type %ui in DNS response", qtype); |
1649 | 1871 return; |
1872 } | |
1873 | |
1874 return; | |
1875 | |
1876 short_response: | |
1877 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1878 err = "short DNS response"; |
1649 | 1879 |
1880 done: | |
1881 | |
1882 ngx_log_error(r->log_level, r->log, 0, err); | |
1883 | |
1884 return; | |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1885 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1886 dns_error_name: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1887 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1888 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
|
1889 "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
|
1890 code, ngx_resolver_strerror(code), ident, |
6478
3ef7bb882ad4
Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6460
diff
changeset
|
1891 (size_t) rn->nlen, rn->name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1892 return; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1893 |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1894 dns_error: |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1895 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1896 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
|
1897 "DNS error (%ui: %s), query id:%ui", |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1898 code, ngx_resolver_strerror(code), ident); |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1899 return; |
1649 | 1900 } |
1901 | |
1902 | |
1903 static void | |
6370 | 1904 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
|
1905 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype, |
6367 | 1906 ngx_uint_t nan, ngx_uint_t trunc, ngx_uint_t ans) |
583 | 1907 { |
6367 | 1908 char *err; |
1909 u_char *cname; | |
1910 size_t len; | |
1911 int32_t ttl; | |
1912 uint32_t hash; | |
1913 in_addr_t *addr; | |
1914 ngx_str_t name; | |
6370 | 1915 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
|
1916 #if (NGX_HAVE_INET6) |
6367 | 1917 struct in6_addr *addr6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1918 #endif |
6367 | 1919 ngx_resolver_an_t *an; |
1920 ngx_resolver_ctx_t *ctx, *next; | |
1921 ngx_resolver_node_t *rn; | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1922 ngx_resolver_addr_t *addrs; |
6367 | 1923 ngx_resolver_connection_t *rec; |
1649 | 1924 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1925 if (ngx_resolver_copy(r, &name, buf, |
6370 | 1926 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1927 != NGX_OK) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1928 { |
1649 | 1929 return; |
1930 } | |
1931 | |
1932 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); | |
1933 | |
1934 hash = ngx_crc32_short(name.data, name.len); | |
1935 | |
1936 /* lock name mutex */ | |
1937 | |
1938 rn = ngx_resolver_lookup_name(r, &name, hash); | |
1939 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1940 if (rn == NULL) { |
1649 | 1941 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
|
1942 "unexpected DNS response for %V", &name); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
1943 ngx_resolver_free(r, name.data); |
1649 | 1944 goto failed; |
1945 } | |
1946 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1947 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1948 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1949 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1950 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1951 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1952 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
|
1953 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
|
1954 "unexpected DNS response for %V", &name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1955 ngx_resolver_free(r, name.data); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1956 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1957 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1958 |
6367 | 1959 if (trunc && rn->tcp6) { |
1960 ngx_resolver_free(r, name.data); | |
1961 goto failed; | |
1962 } | |
1963 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1964 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
|
1965 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1966 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1967 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1968 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1969 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1970 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1971 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
|
1972 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
|
1973 "unexpected DNS response for %V", &name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1974 ngx_resolver_free(r, name.data); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1975 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1976 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1977 |
6367 | 1978 if (trunc && rn->tcp) { |
1979 ngx_resolver_free(r, name.data); | |
1980 goto failed; | |
1981 } | |
1982 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1983 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
|
1984 } |
1649 | 1985 |
1986 if (ident != qident) { | |
1987 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
|
1988 "wrong ident %ui in DNS response for %V, expect %ui", |
1649 | 1989 ident, &name, qident); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
1990 ngx_resolver_free(r, name.data); |
1649 | 1991 goto failed; |
1992 } | |
1993 | |
3139 | 1994 ngx_resolver_free(r, name.data); |
1995 | |
6367 | 1996 if (trunc) { |
1997 | |
1998 ngx_queue_remove(&rn->queue); | |
1999 | |
2000 if (rn->waiting == NULL) { | |
2001 ngx_rbtree_delete(&r->name_rbtree, &rn->node); | |
2002 ngx_resolver_free_node(r, rn); | |
2003 goto next; | |
2004 } | |
2005 | |
2006 rec = r->connections.elts; | |
2007 rec = &rec[rn->last_connection]; | |
2008 | |
2009 switch (qtype) { | |
2010 | |
2011 #if (NGX_HAVE_INET6) | |
2012 case NGX_RESOLVE_AAAA: | |
2013 | |
2014 rn->tcp6 = 1; | |
2015 | |
2016 (void) ngx_resolver_send_tcp_query(r, rec, rn->query6, rn->qlen); | |
2017 | |
2018 break; | |
2019 #endif | |
2020 | |
2021 default: /* NGX_RESOLVE_A */ | |
2022 | |
2023 rn->tcp = 1; | |
2024 | |
2025 (void) ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen); | |
2026 } | |
2027 | |
2028 rn->expire = ngx_time() + r->resend_timeout; | |
2029 | |
2030 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue); | |
2031 | |
2032 goto next; | |
2033 } | |
2034 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2035 if (code == 0 && rn->code) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2036 code = rn->code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2037 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2038 |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2039 if (code == 0 && nan == 0) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2040 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2041 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2042 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2043 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2044 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2045 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2046 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2047 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2048 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2049 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2050 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2051 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2052 if (rn->naddrs) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2053 goto export; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2054 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2055 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2056 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2057 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2058 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2059 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2060 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2061 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2062 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2063 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2064 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2065 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2066 if (rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2067 goto export; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2068 } |
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 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2071 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2072 code = NGX_RESOLVE_NXDOMAIN; |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2073 } |
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2074 |
1649 | 2075 if (code) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2076 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2077 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2078 switch (qtype) { |
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 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2081 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2082 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2083 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2084 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2085 rn->code = (u_char) code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2086 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2087 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2088 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2089 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2090 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2091 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2092 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2093 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2094 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2095 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2096 rn->code = (u_char) code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2097 goto next; |
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 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2100 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2101 |
1649 | 2102 next = rn->waiting; |
2103 rn->waiting = NULL; | |
2104 | |
2105 ngx_queue_remove(&rn->queue); | |
2106 | |
2107 ngx_rbtree_delete(&r->name_rbtree, &rn->node); | |
2108 | |
2109 /* unlock name mutex */ | |
2110 | |
2111 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2112 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2113 ctx->state = code; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
2114 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2115 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2116 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2117 ctx->handler(ctx); |
1649 | 2118 } |
2119 | |
5920
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
2120 ngx_resolver_free_node(r, rn); |
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
2121 |
1649 | 2122 return; |
2123 } | |
2124 | |
2125 i = ans; | |
2126 naddrs = 0; | |
2127 cname = NULL; | |
2128 | |
2129 for (a = 0; a < nan; a++) { | |
2130 | |
2131 start = i; | |
2132 | |
6370 | 2133 while (i < n) { |
1649 | 2134 |
2135 if (buf[i] & 0xc0) { | |
2136 i += 2; | |
2137 goto found; | |
2138 } | |
2139 | |
2140 if (buf[i] == 0) { | |
2141 i++; | |
2142 goto test_length; | |
2143 } | |
2144 | |
2145 i += 1 + buf[i]; | |
2146 } | |
2147 | |
2148 goto short_response; | |
2149 | |
2150 test_length: | |
2151 | |
2152 if (i - start < 2) { | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2153 err = "invalid name in DNS response"; |
1649 | 2154 goto invalid; |
2155 } | |
2156 | |
2157 found: | |
2158 | |
6370 | 2159 if (i + sizeof(ngx_resolver_an_t) >= n) { |
1649 | 2160 goto short_response; |
2161 } | |
2162 | |
2163 an = (ngx_resolver_an_t *) &buf[i]; | |
2164 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2165 type = (an->type_hi << 8) + an->type_lo; |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2166 class = (an->class_hi << 8) + an->class_lo; |
1649 | 2167 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
|
2168 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
|
2169 + (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
|
2170 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2171 if (class != 1) { |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2172 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
|
2173 "unexpected RR class %ui in DNS response", class); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2174 goto failed; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2175 } |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2176 |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2177 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
|
2178 ttl = 0; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2179 } |
1649 | 2180 |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2181 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
|
2182 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2183 i += sizeof(ngx_resolver_an_t); |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2184 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2185 switch (type) { |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2186 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2187 case NGX_RESOLVE_A: |
1649 | 2188 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2189 if (qtype != NGX_RESOLVE_A) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2190 err = "unexpected A record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2191 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2192 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2193 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2194 if (len != 4) { |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2195 err = "invalid A record in DNS response"; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2196 goto invalid; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2197 } |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2198 |
6370 | 2199 if (i + 4 > n) { |
1649 | 2200 goto short_response; |
2201 } | |
2202 | |
2203 naddrs++; | |
2204 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2205 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2206 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2207 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2208 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2209 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2210 if (qtype != NGX_RESOLVE_AAAA) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2211 err = "unexpected AAAA record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2212 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2213 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2214 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2215 if (len != 16) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2216 err = "invalid AAAA record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2217 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2218 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2219 |
6370 | 2220 if (i + 16 > n) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2221 goto short_response; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2222 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2223 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2224 naddrs++; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2225 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2226 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2227 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2228 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2229 case NGX_RESOLVE_CNAME: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2230 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2231 cname = &buf[i]; |
1965 | 2232 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2233 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2234 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2235 case NGX_RESOLVE_DNAME: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2236 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2237 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2238 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2239 default: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2240 |
1966 | 2241 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
|
2242 "unexpected RR type %ui in DNS response", type); |
1649 | 2243 } |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2244 |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2245 i += len; |
1649 | 2246 } |
2247 | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2248 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
|
2249 "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
|
2250 naddrs, cname, rn->ttl); |
1649 | 2251 |
2252 if (naddrs) { | |
2253 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2254 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2255 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2256 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2257 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2258 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2259 if (naddrs == 1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2260 addr6 = &rn->u6.addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2261 rn->naddrs6 = 1; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2262 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2263 } else { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2264 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
|
2265 if (addr6 == NULL) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2266 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2267 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2268 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2269 rn->u6.addrs6 = addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2270 rn->naddrs6 = (u_short) naddrs; |
1649 | 2271 } |
2272 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2273 #if (NGX_SUPPRESS_WARN) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2274 addr = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2275 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2276 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2277 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2278 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2279 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2280 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2281 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2282 if (naddrs == 1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2283 addr = &rn->u.addr; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2284 rn->naddrs = 1; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2285 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2286 } else { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2287 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
|
2288 if (addr == NULL) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2289 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2290 } |
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 rn->u.addrs = addr; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2293 rn->naddrs = (u_short) naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2294 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2295 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2296 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2297 addr6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2298 #endif |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2299 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2300 |
6370 | 2301 j = 0; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2302 i = ans; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2303 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2304 for (a = 0; a < nan; a++) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2305 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2306 for ( ;; ) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2307 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2308 if (buf[i] & 0xc0) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2309 i += 2; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2310 break; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2311 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2312 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2313 if (buf[i] == 0) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2314 i++; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2315 break; |
1649 | 2316 } |
2317 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2318 i += 1 + buf[i]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2319 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2320 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2321 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
|
2322 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2323 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
|
2324 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
|
2325 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2326 i += sizeof(ngx_resolver_an_t); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2327 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2328 if (type == NGX_RESOLVE_A) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2329 |
6370 | 2330 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
|
2331 + (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
|
2332 |
6370 | 2333 if (++j == naddrs) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2334 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2335 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2336 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2337 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2338 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2339 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2340 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2341 break; |
1649 | 2342 } |
2343 } | |
2344 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2345 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2346 else if (type == NGX_RESOLVE_AAAA) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2347 |
6370 | 2348 ngx_memcpy(addr6[j].s6_addr, &buf[i], 16); |
2349 | |
2350 if (++j == naddrs) { | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2351 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2352 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2353 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2354 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2355 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2356 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2357 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2358 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2359 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2360 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2361 i += len; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2362 } |
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 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2365 switch (qtype) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2366 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2367 #if (NGX_HAVE_INET6) |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2368 case NGX_RESOLVE_AAAA: |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2369 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2370 if (rn->naddrs6 == (u_short) -1) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2371 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2372 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2373 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2374 break; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2375 #endif |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2376 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2377 default: /* NGX_RESOLVE_A */ |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2378 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2379 if (rn->naddrs == (u_short) -1) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2380 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2381 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2382 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2383 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2384 if (rn->naddrs != (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2385 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2386 && rn->naddrs6 != (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2387 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2388 && rn->naddrs |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2389 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2390 + rn->naddrs6 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2391 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2392 > 0) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2393 { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2394 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2395 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2396 export: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2397 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2398 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2399 naddrs = rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2400 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2401 naddrs += rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2402 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2403 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2404 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
|
2405 addrs = NULL; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2406 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2407 } else { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2408 addrs = ngx_resolver_export(r, rn, 0); |
1649 | 2409 if (addrs == NULL) { |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2410 goto failed; |
1649 | 2411 } |
2412 } | |
2413 | |
2414 ngx_queue_remove(&rn->queue); | |
2415 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2416 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
1649 | 2417 rn->expire = ngx_time() + r->expire; |
2418 | |
2419 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); | |
2420 | |
2421 next = rn->waiting; | |
2422 rn->waiting = NULL; | |
2423 | |
2424 /* unlock name mutex */ | |
2425 | |
2426 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2427 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2428 ctx->state = NGX_OK; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
2429 ctx->valid = rn->valid; |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2430 ctx->naddrs = naddrs; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2431 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2432 if (addrs == NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2433 ctx->addrs = &ctx->addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2434 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
|
2435 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
|
2436 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
|
2437 ctx->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2438 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
|
2439 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2440 } else { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2441 ctx->addrs = addrs; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2442 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2443 |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2444 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2445 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2446 ctx->handler(ctx); |
1649 | 2447 } |
2448 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2449 if (addrs != NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2450 ngx_resolver_free(r, addrs->sockaddr); |
1649 | 2451 ngx_resolver_free(r, addrs); |
2452 } | |
2453 | |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2454 ngx_resolver_free(r, rn->query); |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2455 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2456 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2457 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2458 #endif |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2459 |
1649 | 2460 return; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2461 } |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2462 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2463 if (cname) { |
1649 | 2464 |
2465 /* CNAME only */ | |
2466 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2467 if (rn->naddrs == (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2468 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2469 || rn->naddrs6 == (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2470 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2471 ) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2472 { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2473 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2474 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2475 |
6370 | 2476 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
|
2477 goto failed; |
1649 | 2478 } |
2479 | |
2480 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, | |
2481 "resolver cname:\"%V\"", &name); | |
2482 | |
1741
0829024c924d
fix segfault if response will have CNAME only
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
2483 ngx_queue_remove(&rn->queue); |
0829024c924d
fix segfault if response will have CNAME only
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
2484 |
1649 | 2485 rn->cnlen = (u_short) name.len; |
2486 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
|
2487 |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2488 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
1649 | 2489 rn->expire = ngx_time() + r->expire; |
2490 | |
2491 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); | |
2492 | |
6352
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2493 ngx_resolver_free(r, rn->query); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2494 rn->query = NULL; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2495 #if (NGX_HAVE_INET6) |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2496 rn->query6 = NULL; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2497 #endif |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2498 |
1649 | 2499 ctx = rn->waiting; |
2500 rn->waiting = NULL; | |
2501 | |
2502 if (ctx) { | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2503 |
6352
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2504 if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) { |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2505 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2506 /* unlock name mutex */ |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2507 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2508 do { |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2509 ctx->state = NGX_RESOLVE_NXDOMAIN; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2510 next = ctx->next; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2511 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2512 ctx->handler(ctx); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2513 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2514 ctx = next; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2515 } while (ctx); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2516 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2517 return; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2518 } |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2519 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2520 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
|
2521 next->node = NULL; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2522 } |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2523 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2524 (void) ngx_resolve_name_locked(r, ctx, &name); |
1649 | 2525 } |
2526 | |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2527 /* unlock name mutex */ |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2528 |
1649 | 2529 return; |
2530 } | |
2531 | |
2532 ngx_log_error(r->log_level, r->log, 0, | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2533 "no A or CNAME types in DNS response"); |
1649 | 2534 return; |
2535 | |
2536 short_response: | |
2537 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2538 err = "short DNS response"; |
1649 | 2539 |
2540 invalid: | |
2541 | |
2542 /* unlock name mutex */ | |
2543 | |
2544 ngx_log_error(r->log_level, r->log, 0, err); | |
2545 | |
2546 return; | |
2547 | |
2548 failed: | |
2549 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2550 next: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2551 |
1649 | 2552 /* unlock name mutex */ |
2553 | |
2554 return; | |
2555 } | |
2556 | |
2557 | |
2558 static void | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2559 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
|
2560 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
|
2561 ngx_uint_t trunc, ngx_uint_t ans) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2562 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2563 char *err; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2564 u_char *cname; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2565 size_t len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2566 int32_t ttl; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2567 uint32_t hash; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2568 ngx_str_t name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2569 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
|
2570 ngx_resolver_an_t *an; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2571 ngx_resolver_ctx_t *ctx, *next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2572 ngx_resolver_srv_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2573 ngx_resolver_node_t *rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2574 ngx_resolver_connection_t *rec; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2575 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2576 if (ngx_resolver_copy(r, &name, buf, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2577 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2578 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2579 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2580 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2581 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2582 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2583 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
|
2584 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2585 hash = ngx_crc32_short(name.data, name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2586 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2587 rn = ngx_resolver_lookup_srv(r, &name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2588 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2589 if (rn == NULL || rn->query == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2590 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
|
2591 "unexpected DNS response for %V", &name); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2592 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2593 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2594 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2595 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2596 if (trunc && rn->tcp) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2597 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2598 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2599 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2600 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2601 qident = (rn->query[0] << 8) + rn->query[1]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2602 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2603 if (ident != qident) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2604 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
|
2605 "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
|
2606 ident, &name, qident); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2607 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2608 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2609 } |
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 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2612 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2613 if (trunc) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2614 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2615 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2616 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2617 if (rn->waiting == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2618 ngx_rbtree_delete(&r->srv_rbtree, &rn->node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2619 ngx_resolver_free_node(r, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2620 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2621 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2622 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2623 rec = r->connections.elts; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2624 rec = &rec[rn->last_connection]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2625 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2626 rn->tcp = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2627 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2628 (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
|
2629 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2630 rn->expire = ngx_time() + r->resend_timeout; |
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 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
|
2633 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2634 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2635 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2636 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2637 if (code == 0 && rn->code) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2638 code = rn->code; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2641 if (code == 0 && nan == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2642 code = NGX_RESOLVE_NXDOMAIN; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2645 if (code) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2646 next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2647 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2648 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2649 ngx_queue_remove(&rn->queue); |
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 ngx_rbtree_delete(&r->srv_rbtree, &rn->node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2652 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2653 while (next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2654 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2655 ctx->state = code; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2656 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
|
2657 next = ctx->next; |
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 ctx->handler(ctx); |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2662 ngx_resolver_free_node(r, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2663 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2664 return; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2667 i = ans; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2668 nsrvs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2669 cname = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2670 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2671 for (a = 0; a < nan; a++) { |
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 start = i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2674 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2675 while (i < n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2676 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2677 if (buf[i] & 0xc0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2678 i += 2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2679 goto found; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2680 } |
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 if (buf[i] == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2683 i++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2684 goto test_length; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2685 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2686 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2687 i += 1 + buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2688 } |
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 goto short_response; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2691 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2692 test_length: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2693 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2694 if (i - start < 2) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2695 err = "invalid name DNS response"; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2696 goto invalid; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2697 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2698 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2699 found: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2700 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2701 if (i + sizeof(ngx_resolver_an_t) >= n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2702 goto short_response; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2705 an = (ngx_resolver_an_t *) &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2706 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2707 type = (an->type_hi << 8) + an->type_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2708 class = (an->class_hi << 8) + an->class_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2709 len = (an->len_hi << 8) + an->len_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2710 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
|
2711 + (an->ttl[2] << 8) + (an->ttl[3]); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2712 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2713 if (class != 1) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2714 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
|
2715 "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
|
2716 goto failed; |
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 if (ttl < 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2720 ttl = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2721 } |
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 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
|
2724 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2725 i += sizeof(ngx_resolver_an_t); |
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 switch (type) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2728 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2729 case NGX_RESOLVE_SRV: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2730 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2731 if (i + 6 > n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2732 goto short_response; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2735 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
|
2736 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2737 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2738 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2739 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2740 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2741 nsrvs++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2742 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2743 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2744 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2745 case NGX_RESOLVE_CNAME: |
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 cname = &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2748 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2749 break; |
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 case NGX_RESOLVE_DNAME: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2752 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2753 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2754 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2755 default: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2756 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2757 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
|
2758 "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
|
2759 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2760 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2761 i += len; |
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 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
|
2765 "resolver nsrvs:%ui cname:%p ttl:%uD", |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2766 nsrvs, cname, rn->ttl); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2767 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2768 if (nsrvs) { |
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 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
|
2771 if (srvs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2772 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2775 rn->u.srvs = srvs; |
6460
034329824dd3
Win32: fixed build after 384154fc634f.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6458
diff
changeset
|
2776 rn->nsrvs = (u_short) nsrvs; |
6458
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 j = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2779 i = ans; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2780 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2781 for (a = 0; a < nan; a++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2782 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2783 for ( ;; ) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2784 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2785 if (buf[i] & 0xc0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2786 i += 2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2787 break; |
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 if (buf[i] == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2791 i++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2792 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2793 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2794 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2795 i += 1 + buf[i]; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2798 an = (ngx_resolver_an_t *) &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2799 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2800 type = (an->type_hi << 8) + an->type_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2801 len = (an->len_hi << 8) + an->len_lo; |
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 i += sizeof(ngx_resolver_an_t); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2804 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2805 if (type == NGX_RESOLVE_SRV) { |
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 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
|
2808 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
|
2809 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2810 if (srvs[j].weight == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2811 srvs[j].weight = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2812 } |
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 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
|
2815 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2816 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
|
2817 buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2818 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2819 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2820 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2821 } |
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 j++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2824 } |
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 i += len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2827 } |
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 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
|
2830 ngx_resolver_cmp_srvs); |
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 ngx_resolver_free(r, rn->query); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2833 rn->query = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2834 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2835 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2836 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2837 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
|
2838 rn->expire = ngx_time() + r->expire; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2839 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2840 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
|
2841 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2842 next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2843 rn->waiting = NULL; |
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 while (next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2846 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2847 next = ctx->next; |
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 ngx_resolver_resolve_srv_names(ctx, rn); |
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 return; |
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 rn->nsrvs = 0; |
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 if (cname) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2858 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2859 /* CNAME only */ |
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 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
|
2862 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2865 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
|
2866 "resolver cname:\"%V\"", &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2867 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2868 ngx_queue_remove(&rn->queue); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2869 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2870 rn->cnlen = (u_short) name.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2871 rn->u.cname = name.data; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2872 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2873 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
|
2874 rn->expire = ngx_time() + r->expire; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2875 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2876 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
|
2877 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2878 ngx_resolver_free(r, rn->query); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2879 rn->query = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2880 #if (NGX_HAVE_INET6) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2881 rn->query6 = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2882 #endif |
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 ctx = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2885 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2886 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2887 if (ctx) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2888 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2889 if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2890 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2891 /* unlock name mutex */ |
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 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2894 ctx->state = NGX_RESOLVE_NXDOMAIN; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2895 next = ctx->next; |
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 ctx->handler(ctx); |
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 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2900 } while (ctx); |
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 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2903 } |
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 for (next = ctx; next; next = next->next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2906 next->node = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2907 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2908 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2909 (void) ngx_resolve_name_locked(r, ctx, &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2910 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2911 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2912 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2913 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2914 return; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2917 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
|
2918 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2919 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2920 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2921 short_response: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2922 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2923 err = "short DNS response"; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2924 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2925 invalid: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2926 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2927 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2928 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2929 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
|
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 failed: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2934 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2935 /* unlock name mutex */ |
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 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2938 } |
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 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2942 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
|
2943 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2944 ngx_uint_t i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2945 ngx_resolver_t *r; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2946 ngx_resolver_ctx_t *cctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2947 ngx_resolver_srv_name_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2948 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2949 r = ctx->resolver; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2950 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2951 ctx->node = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2952 ctx->state = NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2953 ctx->valid = rn->valid; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2954 ctx->count = rn->nsrvs; |
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 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
|
2957 if (srvs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2958 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2961 ctx->srvs = srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2962 ctx->nsrvs = rn->nsrvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2963 |
6847
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2964 if (ctx->event && ctx->event->timer_set) { |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2965 ngx_del_timer(ctx->event); |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2966 } |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2967 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
2968 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
|
2969 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
|
2970 if (srvs[i].name.data == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2971 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2974 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
|
2975 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
|
2976 srvs[i].name.len); |
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 cctx = ngx_resolve_start(r, NULL); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2979 if (cctx == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2980 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2981 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2982 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2983 cctx->name = srvs[i].name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2984 cctx->handler = ngx_resolver_srv_names_handler; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2985 cctx->data = ctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2986 cctx->srvs = &srvs[i]; |
6847
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2987 cctx->timeout = ctx->timeout; |
6458
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 srvs[i].priority = rn->u.srvs[i].priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2990 srvs[i].weight = rn->u.srvs[i].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2991 srvs[i].port = rn->u.srvs[i].port; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2992 srvs[i].ctx = cctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2993 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2994 if (ngx_resolve_name(cctx) == NGX_ERROR) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2995 srvs[i].ctx = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2996 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2997 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2998 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2999 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3000 return; |
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 failed: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3003 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3004 ctx->state = NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3005 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
|
3006 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3007 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3008 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3009 |
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 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3012 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
|
3013 { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3014 ngx_uint_t i; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3015 ngx_addr_t *addrs; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3016 ngx_resolver_t *r; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3017 ngx_sockaddr_t *sockaddr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3018 ngx_resolver_ctx_t *ctx; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3019 ngx_resolver_srv_name_t *srv; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3020 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3021 r = cctx->resolver; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3022 ctx = cctx->data; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3023 srv = cctx->srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3024 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3025 ctx->count--; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
3026 ctx->async |= cctx->async; |
6458
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 srv->ctx = NULL; |
6714
c3e3de6d2672
Resolver: introduced state field in ngx_resolver_srv_name_t.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6593
diff
changeset
|
3029 srv->state = cctx->state; |
6458
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 if (cctx->naddrs) { |
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->valid = ngx_min(ctx->valid, cctx->valid); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3034 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3035 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
|
3036 if (addrs == NULL) { |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3037 srv->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3038 goto done; |
6458
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 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3041 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
|
3042 if (sockaddr == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3043 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
|
3044 srv->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3045 goto done; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3046 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3047 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3048 for (i = 0; i < cctx->naddrs; i++) { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3049 addrs[i].sockaddr = &sockaddr[i].sockaddr; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3050 addrs[i].socklen = cctx->addrs[i].socklen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3051 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3052 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
|
3053 addrs[i].socklen); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3054 |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6559
diff
changeset
|
3055 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
|
3056 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3057 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3058 srv->addrs = addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3059 srv->naddrs = cctx->naddrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3060 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3061 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3062 done: |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3063 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3064 ngx_resolve_name_done(cctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3065 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3066 if (ctx->count == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3067 ngx_resolver_report_srv(r, ctx); |
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 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3070 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3071 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3072 static void |
1649 | 3073 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
|
3074 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan) |
1649 | 3075 { |
3076 char *err; | |
3077 size_t len; | |
3078 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
|
3079 int32_t ttl; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3080 ngx_int_t octet; |
1649 | 3081 ngx_str_t name; |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3082 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
|
3083 ngx_queue_t *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3084 ngx_rbtree_t *tree; |
1649 | 3085 ngx_resolver_an_t *an; |
3086 ngx_resolver_ctx_t *ctx, *next; | |
3087 ngx_resolver_node_t *rn; | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3088 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3089 uint32_t hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3090 ngx_int_t digit; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3091 struct in6_addr addr6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3092 #endif |
1649 | 3093 |
6372 | 3094 if (ngx_resolver_copy(r, &name, buf, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3095 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3096 != NGX_OK) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3097 { |
5472
ab493c60d9ff
Resolver: fixes in PTR processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5471
diff
changeset
|
3098 return; |
1649 | 3099 } |
3100 | |
6372 | 3101 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); |
3102 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3103 /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3104 |
1649 | 3105 addr = 0; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3106 i = sizeof(ngx_resolver_hdr_t); |
1649 | 3107 |
3108 for (mask = 0; mask < 32; mask += 8) { | |
3109 len = buf[i++]; | |
3110 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3111 octet = ngx_atoi(&buf[i], len); |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3112 if (octet == NGX_ERROR || octet > 255) { |
1649 | 3113 goto invalid_in_addr_arpa; |
3114 } | |
3115 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3116 addr += octet << mask; |
1649 | 3117 i += len; |
3118 } | |
3119 | |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3120 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
|
3121 i += sizeof("\7in-addr\4arpa"); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3122 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3123 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3124 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3125 rn = ngx_resolver_lookup_addr(r, addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3126 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3127 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3128 expire_queue = &r->addr_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3129 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3130 goto valid; |
1649 | 3131 } |
3132 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3133 invalid_in_addr_arpa: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3134 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3135 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3136 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3137 i = sizeof(ngx_resolver_hdr_t); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3138 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3139 for (octet = 15; octet >= 0; octet--) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3140 if (buf[i++] != '\1') { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3141 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3142 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3143 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3144 digit = ngx_hextoi(&buf[i++], 1); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3145 if (digit == NGX_ERROR) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3146 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3147 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3148 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3149 addr6.s6_addr[octet] = (u_char) digit; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3150 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3151 if (buf[i++] != '\1') { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3152 goto invalid_ip6_arpa; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3155 digit = ngx_hextoi(&buf[i++], 1); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3156 if (digit == NGX_ERROR) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3157 goto invalid_ip6_arpa; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3160 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
|
3161 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3162 |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3163 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
|
3164 i += sizeof("\3ip6\4arpa"); |
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 /* lock addr mutex */ |
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 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
|
3169 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
|
3170 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3171 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3172 expire_queue = &r->addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3173 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3174 goto valid; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3175 } |
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 invalid_ip6_arpa: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3178 #endif |
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 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
|
3181 "invalid in-addr.arpa or ip6.arpa name in DNS response"); |
6372 | 3182 ngx_resolver_free(r, name.data); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3183 return; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3184 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3185 valid: |
1649 | 3186 |
3187 if (rn == NULL || rn->query == NULL) { | |
3188 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
|
3189 "unexpected DNS response for %V", &name); |
6372 | 3190 ngx_resolver_free(r, name.data); |
1649 | 3191 goto failed; |
3192 } | |
3193 | |
3194 qident = (rn->query[0] << 8) + rn->query[1]; | |
3195 | |
3196 if (ident != qident) { | |
3197 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
|
3198 "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
|
3199 ident, &name, qident); |
6372 | 3200 ngx_resolver_free(r, name.data); |
1649 | 3201 goto failed; |
3202 } | |
3203 | |
6372 | 3204 ngx_resolver_free(r, name.data); |
3205 | |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3206 if (code == 0 && nan == 0) { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3207 code = NGX_RESOLVE_NXDOMAIN; |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3208 } |
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3209 |
1649 | 3210 if (code) { |
3211 next = rn->waiting; | |
3212 rn->waiting = NULL; | |
3213 | |
3214 ngx_queue_remove(&rn->queue); | |
3215 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3216 ngx_rbtree_delete(tree, &rn->node); |
1649 | 3217 |
3218 /* unlock addr mutex */ | |
3219 | |
3220 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3221 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3222 ctx->state = code; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
3223 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3224 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3225 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3226 ctx->handler(ctx); |
1649 | 3227 } |
3228 | |
5920
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
3229 ngx_resolver_free_node(r, rn); |
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
3230 |
1649 | 3231 return; |
3232 } | |
3233 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3234 i += sizeof(ngx_resolver_qs_t); |
1649 | 3235 |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3236 for (a = 0; a < nan; a++) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3237 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3238 start = i; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3239 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3240 while (i < n) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3241 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3242 if (buf[i] & 0xc0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3243 i += 2; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3244 goto found; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3245 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3246 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3247 if (buf[i] == 0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3248 i++; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3249 goto test_length; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3250 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3251 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3252 i += 1 + buf[i]; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3253 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3254 |
1649 | 3255 goto short_response; |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3256 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3257 test_length: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3258 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3259 if (i - start < 2) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3260 err = "invalid name in DNS response"; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3261 goto invalid; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3262 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3263 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3264 found: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3265 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3266 if (i + sizeof(ngx_resolver_an_t) >= n) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3267 goto short_response; |
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 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3270 an = (ngx_resolver_an_t *) &buf[i]; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3271 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3272 type = (an->type_hi << 8) + an->type_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3273 class = (an->class_hi << 8) + an->class_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3274 len = (an->len_hi << 8) + an->len_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3275 ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16) |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3276 + (an->ttl[2] << 8) + (an->ttl[3]); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3277 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3278 if (class != 1) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3279 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
|
3280 "unexpected RR class %ui in DNS response", class); |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3281 goto failed; |
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 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3284 if (ttl < 0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3285 ttl = 0; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3286 } |
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 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
|
3289 "resolver qt:%ui cl:%ui len:%uz", |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3290 type, class, len); |
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 i += sizeof(ngx_resolver_an_t); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3293 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3294 switch (type) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3295 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3296 case NGX_RESOLVE_PTR: |
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 goto ptr; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3299 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3300 case NGX_RESOLVE_CNAME: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3301 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3302 break; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3303 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3304 default: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3305 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3306 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
|
3307 "unexpected RR type %ui in DNS response", type); |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3308 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3309 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3310 i += len; |
1649 | 3311 } |
3312 | |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3313 /* unlock addr mutex */ |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3314 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3315 ngx_log_error(r->log_level, r->log, 0, |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3316 "no PTR type in DNS response"); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3317 return; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3318 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3319 ptr: |
1649 | 3320 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3321 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
|
3322 goto failed; |
1649 | 3323 } |
3324 | |
3325 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver an:%V", &name); | |
3326 | |
2486
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3327 if (name.len != (size_t) rn->nlen |
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3328 || ngx_strncmp(name.data, rn->name, name.len) != 0) |
1649 | 3329 { |
2482
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3330 if (rn->nlen) { |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3331 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
|
3332 } |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3333 |
2490
1c87647b7ca5
fix building by msvc, introduced in r2487
Igor Sysoev <igor@sysoev.ru>
parents:
2487
diff
changeset
|
3334 rn->nlen = (u_short) name.len; |
1649 | 3335 rn->name = name.data; |
3336 | |
2486
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3337 name.data = ngx_resolver_dup(r, rn->name, name.len); |
1649 | 3338 if (name.data == NULL) { |
3339 goto failed; | |
3340 } | |
3341 } | |
3342 | |
3343 ngx_queue_remove(&rn->queue); | |
3344 | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
3345 rn->valid = ngx_time() + (r->valid ? r->valid : ttl); |
1649 | 3346 rn->expire = ngx_time() + r->expire; |
3347 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3348 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 3349 |
3350 next = rn->waiting; | |
3351 rn->waiting = NULL; | |
3352 | |
3353 /* unlock addr mutex */ | |
3354 | |
3355 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3356 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3357 ctx->state = NGX_OK; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
3358 ctx->valid = rn->valid; |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3359 ctx->name = name; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3360 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3361 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3362 ctx->handler(ctx); |
1649 | 3363 } |
3364 | |
3365 ngx_resolver_free(r, name.data); | |
3366 | |
3367 return; | |
3368 | |
3369 short_response: | |
3370 | |
3371 err = "short DNS response"; | |
3372 | |
3373 invalid: | |
3374 | |
3375 /* unlock addr mutex */ | |
3376 | |
3377 ngx_log_error(r->log_level, r->log, 0, err); | |
3378 | |
3379 return; | |
3380 | |
3381 failed: | |
3382 | |
3383 /* unlock addr mutex */ | |
3384 | |
3385 return; | |
3386 } | |
3387 | |
3388 | |
3389 static ngx_resolver_node_t * | |
3390 ngx_resolver_lookup_name(ngx_resolver_t *r, ngx_str_t *name, uint32_t hash) | |
3391 { | |
3392 ngx_int_t rc; | |
3393 ngx_rbtree_node_t *node, *sentinel; | |
3394 ngx_resolver_node_t *rn; | |
3395 | |
3396 node = r->name_rbtree.root; | |
3397 sentinel = r->name_rbtree.sentinel; | |
3398 | |
3399 while (node != sentinel) { | |
3400 | |
3401 if (hash < node->key) { | |
3402 node = node->left; | |
3403 continue; | |
3404 } | |
3405 | |
3406 if (hash > node->key) { | |
3407 node = node->right; | |
3408 continue; | |
3409 } | |
3410 | |
3411 /* hash == node->key */ | |
3412 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3413 rn = ngx_resolver_node(node); |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3414 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3415 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
|
3416 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3417 if (rc == 0) { |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3418 return rn; |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3419 } |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3420 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3421 node = (rc < 0) ? node->left : node->right; |
1649 | 3422 } |
3423 | |
3424 /* not found */ | |
3425 | |
3426 return NULL; | |
3427 } | |
3428 | |
3429 | |
3430 static ngx_resolver_node_t * | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3431 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
|
3432 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3433 ngx_int_t rc; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3434 ngx_rbtree_node_t *node, *sentinel; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3435 ngx_resolver_node_t *rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3436 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3437 node = r->srv_rbtree.root; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3438 sentinel = r->srv_rbtree.sentinel; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3439 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3440 while (node != sentinel) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3441 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3442 if (hash < node->key) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3443 node = node->left; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3444 continue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3445 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3446 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3447 if (hash > node->key) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3448 node = node->right; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3449 continue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3450 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3451 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3452 /* hash == node->key */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3453 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3454 rn = ngx_resolver_node(node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3455 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3456 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
|
3457 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3458 if (rc == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3459 return rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3460 } |
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 node = (rc < 0) ? node->left : node->right; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3463 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3464 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3465 /* not found */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3466 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3467 return NULL; |
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 |
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 static ngx_resolver_node_t * |
1649 | 3472 ngx_resolver_lookup_addr(ngx_resolver_t *r, in_addr_t addr) |
3473 { | |
3474 ngx_rbtree_node_t *node, *sentinel; | |
3475 | |
3476 node = r->addr_rbtree.root; | |
3477 sentinel = r->addr_rbtree.sentinel; | |
3478 | |
3479 while (node != sentinel) { | |
3480 | |
3481 if (addr < node->key) { | |
3482 node = node->left; | |
3483 continue; | |
3484 } | |
3485 | |
3486 if (addr > node->key) { | |
3487 node = node->right; | |
3488 continue; | |
3489 } | |
3490 | |
3491 /* addr == node->key */ | |
3492 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3493 return ngx_resolver_node(node); |
1649 | 3494 } |
3495 | |
3496 /* not found */ | |
3497 | |
3498 return NULL; | |
3499 } | |
3500 | |
3501 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3502 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3503 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3504 static ngx_resolver_node_t * |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3505 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
|
3506 uint32_t hash) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3507 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3508 ngx_int_t rc; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3509 ngx_rbtree_node_t *node, *sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3510 ngx_resolver_node_t *rn; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3511 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3512 node = r->addr6_rbtree.root; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3513 sentinel = r->addr6_rbtree.sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3514 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3515 while (node != sentinel) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3516 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3517 if (hash < node->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3518 node = node->left; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3519 continue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3520 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3521 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3522 if (hash > node->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3523 node = node->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3524 continue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3525 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3526 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3527 /* hash == node->key */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3528 |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3529 rn = ngx_resolver_node(node); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3530 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3531 rc = ngx_memcmp(addr, &rn->addr6, 16); |
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 if (rc == 0) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3534 return rn; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3535 } |
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 node = (rc < 0) ? node->left : node->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3538 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3539 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3540 /* not found */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3541 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3542 return NULL; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3545 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3546 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3547 |
1649 | 3548 static void |
3549 ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
3550 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
3551 { | |
3552 ngx_rbtree_node_t **p; | |
3553 ngx_resolver_node_t *rn, *rn_temp; | |
3554 | |
3555 for ( ;; ) { | |
3556 | |
3557 if (node->key < temp->key) { | |
3558 | |
3559 p = &temp->left; | |
3560 | |
3561 } else if (node->key > temp->key) { | |
3562 | |
3563 p = &temp->right; | |
3564 | |
3565 } else { /* node->key == temp->key */ | |
3566 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3567 rn = ngx_resolver_node(node); |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3568 rn_temp = ngx_resolver_node(temp); |
1649 | 3569 |
3143
ab6258e18099
fix resolver cache rbtree comparison
Igor Sysoev <igor@sysoev.ru>
parents:
3139
diff
changeset
|
3570 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
|
3571 < 0) ? &temp->left : &temp->right; |
1649 | 3572 } |
3573 | |
3574 if (*p == sentinel) { | |
3575 break; | |
3576 } | |
3577 | |
3578 temp = *p; | |
3579 } | |
3580 | |
3581 *p = node; | |
3582 node->parent = temp; | |
3583 node->left = sentinel; | |
3584 node->right = sentinel; | |
3585 ngx_rbt_red(node); | |
3586 } | |
3587 | |
3588 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3589 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3590 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3591 static void |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3592 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
|
3593 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
|
3594 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3595 ngx_rbtree_node_t **p; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3596 ngx_resolver_node_t *rn, *rn_temp; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3597 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3598 for ( ;; ) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3599 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3600 if (node->key < temp->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3601 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3602 p = &temp->left; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3603 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3604 } else if (node->key > temp->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3605 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3606 p = &temp->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3607 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3608 } else { /* node->key == temp->key */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3609 |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3610 rn = ngx_resolver_node(node); |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3611 rn_temp = ngx_resolver_node(temp); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3612 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3613 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
|
3614 < 0) ? &temp->left : &temp->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3615 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3616 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3617 if (*p == sentinel) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3618 break; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3621 temp = *p; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3622 } |
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 *p = node; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3625 node->parent = temp; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3626 node->left = sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3627 node->right = sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3628 ngx_rbt_red(node); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3629 } |
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 #endif |
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 |
1649 | 3634 static ngx_int_t |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3635 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
|
3636 ngx_str_t *name) |
1649 | 3637 { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3638 u_char *p, *s; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3639 size_t len, nlen; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3640 ngx_uint_t ident; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3641 ngx_resolver_qs_t *qs; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3642 ngx_resolver_hdr_t *query; |
1649 | 3643 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3644 nlen = name->len ? (1 + name->len + 1) : 1; |
3306
61bdaac6c668
fix resolving an empty name (".")
Igor Sysoev <igor@sysoev.ru>
parents:
3299
diff
changeset
|
3645 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3646 len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t); |
1649 | 3647 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3648 #if (NGX_HAVE_INET6) |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3649 p = ngx_resolver_alloc(r, r->ipv6 ? len * 2 : len); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3650 #else |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3651 p = ngx_resolver_alloc(r, len); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3652 #endif |
1649 | 3653 if (p == NULL) { |
3654 return NGX_ERROR; | |
3655 } | |
3656 | |
3657 rn->qlen = (u_short) len; | |
3658 rn->query = p; | |
3659 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3660 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3661 if (r->ipv6) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3662 rn->query6 = p + len; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3663 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3664 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3665 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3666 query = (ngx_resolver_hdr_t *) p; |
1649 | 3667 |
3668 ident = ngx_random(); | |
3669 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3670 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
|
3671 "resolve: \"%V\" A %i", name, ident & 0xffff); |
1649 | 3672 |
3673 query->ident_hi = (u_char) ((ident >> 8) & 0xff); | |
3674 query->ident_lo = (u_char) (ident & 0xff); | |
3675 | |
3676 /* recursion query */ | |
3677 query->flags_hi = 1; query->flags_lo = 0; | |
3678 | |
3679 /* one question */ | |
3680 query->nqs_hi = 0; query->nqs_lo = 1; | |
3681 query->nan_hi = 0; query->nan_lo = 0; | |
3682 query->nns_hi = 0; query->nns_lo = 0; | |
3683 query->nar_hi = 0; query->nar_lo = 0; | |
3684 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3685 p += sizeof(ngx_resolver_hdr_t) + nlen; |
1649 | 3686 |
3687 qs = (ngx_resolver_qs_t *) p; | |
3688 | |
3689 /* query type */ | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3690 qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_A; |
1649 | 3691 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3692 /* IN query class */ |
1649 | 3693 qs->class_hi = 0; qs->class_lo = 1; |
3694 | |
3695 /* convert "www.example.com" to "\3www\7example\3com\0" */ | |
3696 | |
3697 len = 0; | |
3698 p--; | |
3699 *p-- = '\0'; | |
3700 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3701 if (name->len == 0) { |
4610
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3702 return NGX_DECLINED; |
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3703 } |
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3704 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3705 for (s = name->data + name->len - 1; s >= name->data; s--) { |
1649 | 3706 if (*s != '.') { |
3707 *p = *s; | |
3708 len++; | |
3709 | |
3710 } else { | |
4556
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3711 if (len == 0 || len > 255) { |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3712 return NGX_DECLINED; |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3713 } |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3714 |
1649 | 3715 *p = (u_char) len; |
3716 len = 0; | |
3717 } | |
3718 | |
3719 p--; | |
3720 } | |
3721 | |
4556
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3722 if (len == 0 || len > 255) { |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3723 return NGX_DECLINED; |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3724 } |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3725 |
1649 | 3726 *p = (u_char) len; |
3727 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3728 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3729 if (!r->ipv6) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3730 return NGX_OK; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3731 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3732 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3733 p = rn->query6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3734 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3735 ngx_memcpy(p, rn->query, rn->qlen); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3736 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3737 query = (ngx_resolver_hdr_t *) p; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3738 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3739 ident = ngx_random(); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3740 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3741 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
|
3742 "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
|
3743 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3744 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
|
3745 query->ident_lo = (u_char) (ident & 0xff); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3746 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3747 p += sizeof(ngx_resolver_hdr_t) + nlen; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3748 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3749 qs = (ngx_resolver_qs_t *) p; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3750 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3751 qs->type_lo = NGX_RESOLVE_AAAA; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3752 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3753 |
1649 | 3754 return NGX_OK; |
3755 } | |
3756 | |
3757 | |
3758 static ngx_int_t | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3759 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
|
3760 ngx_str_t *name) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3761 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3762 u_char *p, *s; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3763 size_t len, nlen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3764 ngx_uint_t ident; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3765 ngx_resolver_qs_t *qs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3766 ngx_resolver_hdr_t *query; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3767 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3768 nlen = name->len ? (1 + name->len + 1) : 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3769 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3770 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
|
3771 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3772 p = ngx_resolver_alloc(r, len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3773 if (p == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3774 return NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3775 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3776 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3777 rn->qlen = (u_short) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3778 rn->query = p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3779 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3780 query = (ngx_resolver_hdr_t *) p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3781 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3782 ident = ngx_random(); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3783 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3784 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
|
3785 "resolve: \"%V\" SRV %i", name, ident & 0xffff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3786 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3787 query->ident_hi = (u_char) ((ident >> 8) & 0xff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3788 query->ident_lo = (u_char) (ident & 0xff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3789 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3790 /* recursion query */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3791 query->flags_hi = 1; query->flags_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3792 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3793 /* one question */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3794 query->nqs_hi = 0; query->nqs_lo = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3795 query->nan_hi = 0; query->nan_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3796 query->nns_hi = 0; query->nns_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3797 query->nar_hi = 0; query->nar_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3798 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3799 p += sizeof(ngx_resolver_hdr_t) + nlen; |
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 qs = (ngx_resolver_qs_t *) p; |
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 /* query type */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3804 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
|
3805 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3806 /* IN query class */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3807 qs->class_hi = 0; qs->class_lo = 1; |
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 /* 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
|
3810 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3811 len = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3812 p--; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3813 *p-- = '\0'; |
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 if (name->len == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3816 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3817 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3818 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3819 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
|
3820 if (*s != '.') { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3821 *p = *s; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3822 len++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3823 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3824 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3825 if (len == 0 || len > 255) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3826 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3827 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3828 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3829 *p = (u_char) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3830 len = 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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3833 p--; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3834 } |
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 if (len == 0 || len > 255) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3837 return NGX_DECLINED; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3840 *p = (u_char) len; |
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 return NGX_OK; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3845 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3846 static ngx_int_t |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3847 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
|
3848 ngx_resolver_addr_t *addr) |
1649 | 3849 { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3850 u_char *p, *d; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3851 size_t len; |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3852 in_addr_t inaddr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3853 ngx_int_t n; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3854 ngx_uint_t ident; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3855 ngx_resolver_hdr_t *query; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3856 struct sockaddr_in *sin; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3857 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3858 struct sockaddr_in6 *sin6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3859 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3860 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3861 switch (addr->sockaddr->sa_family) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3862 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3863 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3864 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3865 len = sizeof(ngx_resolver_hdr_t) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3866 + 64 + sizeof(".ip6.arpa.") - 1 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3867 + sizeof(ngx_resolver_qs_t); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3868 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3869 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3870 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3871 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3872 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3873 len = sizeof(ngx_resolver_hdr_t) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3874 + 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
|
3875 + sizeof(ngx_resolver_qs_t); |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
3876 } |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3877 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3878 p = ngx_resolver_alloc(r, len); |
1649 | 3879 if (p == NULL) { |
3880 return NGX_ERROR; | |
3881 } | |
3882 | |
3883 rn->query = p; | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3884 query = (ngx_resolver_hdr_t *) p; |
1649 | 3885 |
3886 ident = ngx_random(); | |
3887 | |
3888 query->ident_hi = (u_char) ((ident >> 8) & 0xff); | |
3889 query->ident_lo = (u_char) (ident & 0xff); | |
3890 | |
3891 /* recursion query */ | |
3892 query->flags_hi = 1; query->flags_lo = 0; | |
3893 | |
3894 /* one question */ | |
3895 query->nqs_hi = 0; query->nqs_lo = 1; | |
3896 query->nan_hi = 0; query->nan_lo = 0; | |
3897 query->nns_hi = 0; query->nns_lo = 0; | |
3898 query->nar_hi = 0; query->nar_lo = 0; | |
3899 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3900 p += sizeof(ngx_resolver_hdr_t); |
1649 | 3901 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3902 switch (addr->sockaddr->sa_family) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3903 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3904 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3905 case AF_INET6: |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3906 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3907 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3908 for (n = 15; n >= 0; n--) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3909 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
|
3910 sin6->sin6_addr.s6_addr[n] & 0xf, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3911 (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
|
3912 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3913 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3914 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
|
3915 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3916 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3917 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3918 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3919 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3920 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3921 sin = (struct sockaddr_in *) addr->sockaddr; |
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3922 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
|
3923 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3924 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
|
3925 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
|
3926 *p = (u_char) (d - &p[1]); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3927 p = d; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3928 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3929 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3930 p = ngx_cpymem(p, "\7in-addr\4arpa\0", 14); |
1649 | 3931 } |
3932 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3933 /* query type "PTR", IN query class */ |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3934 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
|
3935 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3936 rn->qlen = (u_short) (p - rn->query); |
1649 | 3937 |
3938 return NGX_OK; | |
3939 } | |
3940 | |
3941 | |
3942 static ngx_int_t | |
3943 ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src, | |
3944 u_char *last) | |
3945 { | |
3946 char *err; | |
3947 u_char *p, *dst; | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
3948 size_t len; |
1649 | 3949 ngx_uint_t i, n; |
3950 | |
3951 p = src; | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
3952 len = 0; |
1649 | 3953 |
3954 /* | |
3955 * compression pointers allow to create endless loop, so we set limit; | |
3956 * 128 pointers should be enough to store 255-byte name | |
3957 */ | |
3958 | |
3959 for (i = 0; i < 128; i++) { | |
3960 n = *p++; | |
3961 | |
3962 if (n == 0) { | |
3963 goto done; | |
3964 } | |
3965 | |
3966 if (n & 0xc0) { | |
8472
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
3967 if ((n & 0xc0) != 0xc0) { |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
3968 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
|
3969 goto invalid; |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
3970 } |
aa5f8825f24d
Resolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8471
diff
changeset
|
3971 |
8471
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
3972 if (p >= last) { |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
3973 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
|
3974 goto invalid; |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
3975 } |
a093dd4ce154
Resolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8470
diff
changeset
|
3976 |
2314
52987a023486
fix compression pointer for big (>255) DNS responses
Igor Sysoev <igor@sysoev.ru>
parents:
2282
diff
changeset
|
3977 n = ((n & 0x3f) << 8) + *p; |
1649 | 3978 p = &buf[n]; |
3979 | |
3980 } else { | |
3981 len += 1 + n; | |
3982 p = &p[n]; | |
3983 } | |
3984 | |
3985 if (p >= last) { | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3986 err = "name is out of DNS response"; |
1649 | 3987 goto invalid; |
3988 } | |
3989 } | |
3990 | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3991 err = "compression pointers loop in DNS response"; |
1649 | 3992 |
3993 invalid: | |
3994 | |
3995 ngx_log_error(r->log_level, r->log, 0, err); | |
3996 | |
3997 return NGX_ERROR; | |
3998 | |
3999 done: | |
4000 | |
4001 if (name == NULL) { | |
583 | 4002 return NGX_OK; |
4003 } | |
4004 | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
4005 if (len == 0) { |
5764
f166c521b619
Style: use ngx_str_null().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents:
5600
diff
changeset
|
4006 ngx_str_null(name); |
3298
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
4007 return NGX_OK; |
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
4008 } |
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
4009 |
1649 | 4010 dst = ngx_resolver_alloc(r, len); |
4011 if (dst == NULL) { | |
4012 return NGX_ERROR; | |
4013 } | |
4014 | |
4015 name->data = dst; | |
4016 | |
4017 for ( ;; ) { | |
8473
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4018 n = *src++; |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4019 |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4020 if (n == 0) { |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
4021 name->len = dst - name->data - 1; |
8473
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4022 return NGX_OK; |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4023 } |
771743838cbd
Resolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8472
diff
changeset
|
4024 |
4267
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4025 if (n & 0xc0) { |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4026 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
|
4027 src = &buf[n]; |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4028 |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
4029 } else { |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
4030 ngx_strlow(dst, src, n); |
1649 | 4031 dst += n; |
4032 src += n; | |
8474
4ebe1251a8c3
Resolver: simplified ngx_resolver_copy().
Maxim Dounin <mdounin@mdounin.ru>
parents:
8473
diff
changeset
|
4033 *dst++ = '.'; |
1649 | 4034 } |
4035 } | |
4036 } | |
4037 | |
4038 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4039 static ngx_int_t |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4040 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
|
4041 { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4042 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
|
4043 return NGX_OK; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4044 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4045 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4046 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
|
4047 if (ctx->event == NULL) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4048 return NGX_ERROR; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4049 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4050 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4051 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
|
4052 ctx->event->data = ctx; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4053 ctx->event->log = r->log; |
7052
70e65bf8dfd7
Resolver: cancelable resend timer event.
Ruslan Ermilov <ru@nginx.com>
parents:
7051
diff
changeset
|
4054 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
|
4055 ctx->ident = -1; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4056 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4057 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
|
4058 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4059 return NGX_OK; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4060 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4061 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4062 |
1649 | 4063 static void |
4064 ngx_resolver_timeout_handler(ngx_event_t *ev) | |
4065 { | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4066 ngx_resolver_ctx_t *ctx; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4067 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4068 ctx = ev->data; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4069 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4070 ctx->state = NGX_RESOLVE_TIMEDOUT; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4071 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4072 ctx->handler(ctx); |
1649 | 4073 } |
4074 | |
4075 | |
4076 static void | |
4077 ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn) | |
4078 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4079 ngx_uint_t i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4080 |
1649 | 4081 /* lock alloc mutex */ |
4082 | |
4083 if (rn->query) { | |
4084 ngx_resolver_free_locked(r, rn->query); | |
4085 } | |
4086 | |
4087 if (rn->name) { | |
4088 ngx_resolver_free_locked(r, rn->name); | |
4089 } | |
4090 | |
4091 if (rn->cnlen) { | |
4092 ngx_resolver_free_locked(r, rn->u.cname); | |
4093 } | |
4094 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4095 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) { |
1649 | 4096 ngx_resolver_free_locked(r, rn->u.addrs); |
4097 } | |
4098 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4099 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4100 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
|
4101 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
|
4102 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4103 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4104 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4105 if (rn->nsrvs) { |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4106 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
|
4107 if (rn->u.srvs[i].name.data) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4108 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
|
4109 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4110 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4111 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4112 ngx_resolver_free_locked(r, rn->u.srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4113 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4114 |
1649 | 4115 ngx_resolver_free_locked(r, rn); |
4116 | |
4117 /* unlock alloc mutex */ | |
4118 } | |
4119 | |
4120 | |
4121 static void * | |
4122 ngx_resolver_alloc(ngx_resolver_t *r, size_t size) | |
4123 { | |
4124 u_char *p; | |
4125 | |
4126 /* lock alloc mutex */ | |
4127 | |
4128 p = ngx_alloc(size, r->log); | |
4129 | |
4130 /* unlock alloc mutex */ | |
4131 | |
4132 return p; | |
4133 } | |
4134 | |
4135 | |
1903 | 4136 static void * |
1649 | 4137 ngx_resolver_calloc(ngx_resolver_t *r, size_t size) |
4138 { | |
4139 u_char *p; | |
4140 | |
4141 p = ngx_resolver_alloc(r, size); | |
4142 | |
4143 if (p) { | |
4144 ngx_memzero(p, size); | |
4145 } | |
4146 | |
4147 return p; | |
4148 } | |
4149 | |
4150 | |
4151 static void | |
4152 ngx_resolver_free(ngx_resolver_t *r, void *p) | |
4153 { | |
4154 /* lock alloc mutex */ | |
4155 | |
4156 ngx_free(p); | |
4157 | |
4158 /* unlock alloc mutex */ | |
4159 } | |
4160 | |
4161 | |
4162 static void | |
4163 ngx_resolver_free_locked(ngx_resolver_t *r, void *p) | |
4164 { | |
4165 ngx_free(p); | |
4166 } | |
4167 | |
4168 | |
4169 static void * | |
4170 ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size) | |
4171 { | |
4172 void *dst; | |
4173 | |
4174 dst = ngx_resolver_alloc(r, size); | |
4175 | |
4176 if (dst == NULL) { | |
4177 return dst; | |
4178 } | |
4179 | |
4180 ngx_memcpy(dst, src, size); | |
4181 | |
4182 return dst; | |
4183 } | |
4184 | |
4185 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4186 static ngx_resolver_addr_t * |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4187 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
|
4188 ngx_uint_t rotate) |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4189 { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4190 ngx_uint_t d, i, j, n; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4191 in_addr_t *addr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4192 ngx_sockaddr_t *sockaddr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4193 struct sockaddr_in *sin; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4194 ngx_resolver_addr_t *dst; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4195 #if (NGX_HAVE_INET6) |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4196 struct in6_addr *addr6; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4197 struct sockaddr_in6 *sin6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4198 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4199 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4200 n = rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4201 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4202 n += rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4203 #endif |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4204 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4205 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
|
4206 if (dst == NULL) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4207 return NULL; |
4892
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4208 } |
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4209 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4210 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
|
4211 if (sockaddr == NULL) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4212 ngx_resolver_free(r, dst); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4213 return NULL; |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4214 } |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4215 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4216 i = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4217 d = rotate ? ngx_random() % n : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4218 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4219 if (rn->naddrs) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4220 j = rotate ? ngx_random() % rn->naddrs : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4221 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4222 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
|
4223 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4224 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4225 sin = &sockaddr[d].sockaddr_in; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4226 sin->sin_family = AF_INET; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4227 sin->sin_addr.s_addr = addr[j++]; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4228 dst[d].sockaddr = (struct sockaddr *) sin; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4229 dst[d++].socklen = sizeof(struct sockaddr_in); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4230 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4231 if (d == n) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4232 d = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4233 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4234 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4235 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
|
4236 j = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4237 } |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4238 } 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
|
4239 } |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4240 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4241 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4242 if (rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4243 j = rotate ? ngx_random() % rn->naddrs6 : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4244 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4245 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
|
4246 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4247 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4248 sin6 = &sockaddr[d].sockaddr_in6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4249 sin6->sin6_family = AF_INET6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4250 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
|
4251 dst[d].sockaddr = (struct sockaddr *) sin6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4252 dst[d++].socklen = sizeof(struct sockaddr_in6); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4253 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4254 if (d == n) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4255 d = 0; |
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 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4258 if (j == rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4259 j = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4260 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4261 } while (++i < n); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4262 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4263 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4264 |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4265 return dst; |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4266 } |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4267 |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4268 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4269 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4270 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
|
4271 { |
6460
034329824dd3
Win32: fixed build after 384154fc634f.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6458
diff
changeset
|
4272 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
|
4273 ngx_resolver_addr_t *addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4274 ngx_resolver_srv_name_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4275 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4276 srvs = ctx->srvs; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4277 nsrvs = ctx->nsrvs; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4278 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4279 naddrs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4280 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4281 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
|
4282 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
|
4283 ctx->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4284 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
|
4285 |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4286 ctx->handler(ctx); |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4287 return; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4288 } |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4289 |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4290 naddrs += srvs[i].naddrs; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4291 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4292 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4293 if (naddrs == 0) { |
7428
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4294 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
|
4295 |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4296 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
|
4297 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
|
4298 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
|
4299 break; |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4300 } |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4301 } |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4302 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4303 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
|
4304 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4305 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4306 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4307 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4308 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4309 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
|
4310 if (addrs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4311 ctx->state = NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4312 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
|
4313 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4314 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4315 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4316 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4317 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4318 i = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4319 n = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4320 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4321 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4322 nw = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4323 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4324 for (j = i; j < nsrvs; j++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4325 if (srvs[j].priority != srvs[i].priority) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4326 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4327 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4328 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4329 nw += srvs[j].naddrs * srvs[j].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4330 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4331 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4332 if (nw == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4333 goto next_srv; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4334 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4335 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4336 w = ngx_random() % nw; |
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 for (k = i; k < j; k++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4339 if (w < srvs[k].naddrs * srvs[k].weight) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4340 break; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4343 w -= srvs[k].naddrs * srvs[k].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4344 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4345 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4346 for (l = i; l < j; l++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4347 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4348 for (m = 0; m < srvs[k].naddrs; m++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4349 addrs[n].socklen = srvs[k].addrs[m].socklen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4350 addrs[n].sockaddr = srvs[k].addrs[m].sockaddr; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4351 addrs[n].name = srvs[k].name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4352 addrs[n].priority = srvs[k].priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4353 addrs[n].weight = srvs[k].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4354 n++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4355 } |
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 if (++k == j) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4358 k = i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4359 } |
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 next_srv: |
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 i = j; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4365 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4366 } while (i < ctx->nsrvs); |
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 ctx->state = NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4369 ctx->addrs = addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4370 ctx->naddrs = naddrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4371 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4372 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4373 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4374 ngx_resolver_free(r, addrs); |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4377 |
1649 | 4378 char * |
4379 ngx_resolver_strerror(ngx_int_t err) | |
4380 { | |
4381 static char *errors[] = { | |
4382 "Format error", /* FORMERR */ | |
4383 "Server failure", /* SERVFAIL */ | |
4384 "Host not found", /* NXDOMAIN */ | |
4385 "Unimplemented", /* NOTIMP */ | |
4386 "Operation refused" /* REFUSED */ | |
4387 }; | |
4388 | |
4389 if (err > 0 && err < 6) { | |
4390 return errors[err - 1]; | |
4391 } | |
4392 | |
4393 if (err == NGX_RESOLVE_TIMEDOUT) { | |
4394 return "Operation timed out"; | |
4395 } | |
4396 | |
4397 return "Unknown error"; | |
4398 } | |
4399 | |
4400 | |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4401 static u_char * |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4402 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
|
4403 { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4404 u_char *p; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4405 ngx_resolver_connection_t *rec; |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4406 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4407 p = buf; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4408 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4409 if (log->action) { |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4410 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
|
4411 len -= p - buf; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4412 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4413 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4414 rec = log->data; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4415 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4416 if (rec) { |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4417 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
|
4418 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4419 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4420 return p; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4421 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4422 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4423 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
4424 static ngx_int_t |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4425 ngx_udp_connect(ngx_resolver_connection_t *rec) |
1649 | 4426 { |
4427 int rc; | |
4428 ngx_int_t event; | |
4429 ngx_event_t *rev, *wev; | |
4430 ngx_socket_t s; | |
4431 ngx_connection_t *c; | |
4432 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4433 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
|
4434 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4435 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "UDP socket %d", s); |
583 | 4436 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4892
diff
changeset
|
4437 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
|
4438 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
583 | 4439 ngx_socket_n " failed"); |
4440 return NGX_ERROR; | |
4441 } | |
4442 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4443 c = ngx_get_connection(s, &rec->log); |
583 | 4444 |
4445 if (c == NULL) { | |
4446 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
|
4447 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
|
4448 ngx_close_socket_n " failed"); |
583 | 4449 } |
4450 | |
4451 return NGX_ERROR; | |
4452 } | |
4453 | |
1649 | 4454 if (ngx_nonblocking(s) == -1) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4455 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
1649 | 4456 ngx_nonblocking_n " failed"); |
4457 | |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4458 goto failed; |
1649 | 4459 } |
4460 | |
583 | 4461 rev = c->read; |
4462 wev = c->write; | |
4463 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4464 rev->log = &rec->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4465 wev->log = &rec->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4466 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4467 rec->udp = c; |
583 | 4468 |
4469 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
4470 | |
8396
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4471 c->start_time = ngx_current_msec; |
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4472 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4473 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
|
4474 "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
|
4475 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4476 rc = connect(s, rec->sockaddr, rec->socklen); |
1649 | 4477 |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
4478 /* TODO: iocp */ |
583 | 4479 |
4480 if (rc == -1) { | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4481 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
|
4482 "connect() failed"); |
583 | 4483 |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4484 goto failed; |
583 | 4485 } |
4486 | |
1649 | 4487 /* UDP sockets are always ready to write */ |
4488 wev->ready = 1; | |
4489 | |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4490 event = (ngx_event_flags & NGX_USE_CLEAR_EVENT) ? |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4491 /* kqueue, epoll */ NGX_CLEAR_EVENT: |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4492 /* select, poll, /dev/poll */ NGX_LEVEL_EVENT; |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4493 /* eventport event type has no meaning: oneshot only */ |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4494 |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4495 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
|
4496 goto failed; |
583 | 4497 } |
4498 | |
4499 return NGX_OK; | |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4500 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4501 failed: |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4502 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4503 ngx_close_connection(c); |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4504 rec->udp = NULL; |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4505 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4506 return NGX_ERROR; |
583 | 4507 } |
6367 | 4508 |
4509 | |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
4510 static ngx_int_t |
6367 | 4511 ngx_tcp_connect(ngx_resolver_connection_t *rec) |
4512 { | |
4513 int rc; | |
4514 ngx_int_t event; | |
4515 ngx_err_t err; | |
4516 ngx_uint_t level; | |
4517 ngx_socket_t s; | |
4518 ngx_event_t *rev, *wev; | |
4519 ngx_connection_t *c; | |
4520 | |
4521 s = ngx_socket(rec->sockaddr->sa_family, SOCK_STREAM, 0); | |
4522 | |
4523 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "TCP socket %d", s); | |
4524 | |
4525 if (s == (ngx_socket_t) -1) { | |
4526 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4527 ngx_socket_n " failed"); | |
4528 return NGX_ERROR; | |
4529 } | |
4530 | |
4531 c = ngx_get_connection(s, &rec->log); | |
4532 | |
4533 if (c == NULL) { | |
4534 if (ngx_close_socket(s) == -1) { | |
4535 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
|
4536 ngx_close_socket_n " failed"); |
6367 | 4537 } |
4538 | |
4539 return NGX_ERROR; | |
4540 } | |
4541 | |
4542 if (ngx_nonblocking(s) == -1) { | |
4543 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4544 ngx_nonblocking_n " failed"); | |
4545 | |
4546 goto failed; | |
4547 } | |
4548 | |
4549 rev = c->read; | |
4550 wev = c->write; | |
4551 | |
4552 rev->log = &rec->log; | |
4553 wev->log = &rec->log; | |
4554 | |
4555 rec->tcp = c; | |
4556 | |
4557 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
4558 | |
8396
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4559 c->start_time = ngx_current_msec; |
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8371
diff
changeset
|
4560 |
6367 | 4561 if (ngx_add_conn) { |
4562 if (ngx_add_conn(c) == NGX_ERROR) { | |
4563 goto failed; | |
4564 } | |
4565 } | |
4566 | |
4567 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, &rec->log, 0, | |
4568 "connect to %V, fd:%d #%uA", &rec->server, s, c->number); | |
4569 | |
4570 rc = connect(s, rec->sockaddr, rec->socklen); | |
4571 | |
4572 if (rc == -1) { | |
4573 err = ngx_socket_errno; | |
4574 | |
4575 | |
4576 if (err != NGX_EINPROGRESS | |
4577 #if (NGX_WIN32) | |
4578 /* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */ | |
4579 && err != NGX_EAGAIN | |
4580 #endif | |
4581 ) | |
4582 { | |
4583 if (err == NGX_ECONNREFUSED | |
4584 #if (NGX_LINUX) | |
4585 /* | |
4586 * Linux returns EAGAIN instead of ECONNREFUSED | |
4587 * for unix sockets if listen queue is full | |
4588 */ | |
4589 || err == NGX_EAGAIN | |
4590 #endif | |
4591 || err == NGX_ECONNRESET | |
4592 || err == NGX_ENETDOWN | |
4593 || err == NGX_ENETUNREACH | |
4594 || err == NGX_EHOSTDOWN | |
4595 || err == NGX_EHOSTUNREACH) | |
4596 { | |
4597 level = NGX_LOG_ERR; | |
4598 | |
4599 } else { | |
4600 level = NGX_LOG_CRIT; | |
4601 } | |
4602 | |
7275 | 4603 ngx_log_error(level, &rec->log, err, "connect() to %V failed", |
6367 | 4604 &rec->server); |
4605 | |
4606 ngx_close_connection(c); | |
4607 rec->tcp = NULL; | |
4608 | |
4609 return NGX_ERROR; | |
4610 } | |
4611 } | |
4612 | |
4613 if (ngx_add_conn) { | |
4614 if (rc == -1) { | |
4615 | |
4616 /* NGX_EINPROGRESS */ | |
4617 | |
4618 return NGX_AGAIN; | |
4619 } | |
4620 | |
4621 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "connected"); | |
4622 | |
4623 wev->ready = 1; | |
4624 | |
4625 return NGX_OK; | |
4626 } | |
4627 | |
4628 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { | |
4629 | |
4630 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, ngx_socket_errno, | |
4631 "connect(): %d", rc); | |
4632 | |
4633 if (ngx_blocking(s) == -1) { | |
4634 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4635 ngx_blocking_n " failed"); | |
4636 goto failed; | |
4637 } | |
4638 | |
4639 /* | |
4640 * FreeBSD's aio allows to post an operation on non-connected socket. | |
4641 * NT does not support it. | |
4642 * | |
4643 * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT | |
4644 */ | |
4645 | |
4646 rev->ready = 1; | |
4647 wev->ready = 1; | |
4648 | |
4649 return NGX_OK; | |
4650 } | |
4651 | |
4652 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
4653 | |
4654 /* kqueue */ | |
4655 | |
4656 event = NGX_CLEAR_EVENT; | |
4657 | |
4658 } else { | |
4659 | |
4660 /* select, poll, /dev/poll */ | |
4661 | |
4662 event = NGX_LEVEL_EVENT; | |
4663 } | |
4664 | |
4665 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { | |
4666 goto failed; | |
4667 } | |
4668 | |
4669 if (rc == -1) { | |
4670 | |
4671 /* NGX_EINPROGRESS */ | |
4672 | |
4673 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { | |
4674 goto failed; | |
4675 } | |
4676 | |
4677 return NGX_AGAIN; | |
4678 } | |
4679 | |
4680 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "connected"); | |
4681 | |
4682 wev->ready = 1; | |
4683 | |
4684 return NGX_OK; | |
4685 | |
4686 failed: | |
4687 | |
4688 ngx_close_connection(c); | |
4689 rec->tcp = NULL; | |
4690 | |
4691 return NGX_ERROR; | |
4692 } | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4693 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4694 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4695 static ngx_int_t |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4696 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
|
4697 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4698 ngx_int_t p1, p2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4699 ngx_resolver_srv_t *first, *second; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4700 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4701 first = (ngx_resolver_srv_t *) one; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4702 second = (ngx_resolver_srv_t *) two; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4703 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4704 p1 = first->priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4705 p2 = second->priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4706 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4707 return p1 - p2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4708 } |