Mercurial > hg > nginx-quic
annotate src/core/ngx_resolver.c @ 8264:5247461c17e1 quic
QUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104).
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 22 Dec 2020 12:04:16 +0300 |
parents | 8fe7ebe5adc4 |
children | eb54227110f0 |
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 | |
1566 if (n < 0) { | |
1649 | 1567 return; |
1568 } | |
1569 | |
6367 | 1570 ngx_resolver_process_response(rec->resolver, buf, n, 0); |
1649 | 1571 |
1572 } while (rev->ready); | |
1573 } | |
1574 | |
1575 | |
1576 static void | |
6367 | 1577 ngx_resolver_tcp_write(ngx_event_t *wev) |
1578 { | |
1579 off_t sent; | |
1580 ssize_t n; | |
1581 ngx_buf_t *b; | |
1582 ngx_resolver_t *r; | |
1583 ngx_connection_t *c; | |
1584 ngx_resolver_connection_t *rec; | |
1585 | |
1586 c = wev->data; | |
1587 rec = c->data; | |
1588 b = rec->write_buf; | |
1589 r = rec->resolver; | |
1590 | |
1591 if (wev->timedout) { | |
1592 goto failed; | |
1593 } | |
1594 | |
1595 sent = c->sent; | |
1596 | |
1597 while (wev->ready && b->pos < b->last) { | |
1598 n = ngx_send(c, b->pos, b->last - b->pos); | |
1599 | |
1600 if (n == NGX_AGAIN) { | |
1601 break; | |
1602 } | |
1603 | |
1604 if (n == NGX_ERROR) { | |
1605 goto failed; | |
1606 } | |
1607 | |
1608 b->pos += n; | |
1609 } | |
1610 | |
1611 if (b->pos != b->start) { | |
1612 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); | |
1613 b->pos = b->start; | |
1614 } | |
1615 | |
1616 if (c->sent != sent) { | |
1617 ngx_add_timer(wev, (ngx_msec_t) (r->tcp_timeout * 1000)); | |
1618 } | |
1619 | |
1620 if (ngx_handle_write_event(wev, 0) != NGX_OK) { | |
1621 goto failed; | |
1622 } | |
1623 | |
1624 return; | |
1625 | |
1626 failed: | |
1627 | |
1628 ngx_close_connection(c); | |
1629 rec->tcp = NULL; | |
1630 } | |
1631 | |
1632 | |
1633 static void | |
1634 ngx_resolver_tcp_read(ngx_event_t *rev) | |
1635 { | |
1636 u_char *p; | |
1637 size_t size; | |
1638 ssize_t n; | |
1639 u_short qlen; | |
1640 ngx_buf_t *b; | |
1641 ngx_resolver_t *r; | |
1642 ngx_connection_t *c; | |
1643 ngx_resolver_connection_t *rec; | |
1644 | |
1645 c = rev->data; | |
1646 rec = c->data; | |
1647 b = rec->read_buf; | |
1648 r = rec->resolver; | |
1649 | |
1650 while (rev->ready) { | |
1651 n = ngx_recv(c, b->last, b->end - b->last); | |
1652 | |
1653 if (n == NGX_AGAIN) { | |
1654 break; | |
1655 } | |
1656 | |
1657 if (n == NGX_ERROR || n == 0) { | |
1658 goto failed; | |
1659 } | |
1660 | |
1661 b->last += n; | |
1662 | |
1663 for ( ;; ) { | |
1664 p = b->pos; | |
1665 size = b->last - p; | |
1666 | |
1667 if (size < 2) { | |
1668 break; | |
1669 } | |
1670 | |
1671 qlen = (u_short) *p++ << 8; | |
1672 qlen += *p++; | |
1673 | |
1674 if (size < (size_t) (2 + qlen)) { | |
1675 break; | |
1676 } | |
1677 | |
1678 ngx_resolver_process_response(r, p, qlen, 1); | |
1679 | |
1680 b->pos += 2 + qlen; | |
1681 } | |
1682 | |
1683 if (b->pos != b->start) { | |
1684 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); | |
1685 b->pos = b->start; | |
1686 } | |
1687 } | |
1688 | |
1689 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
1690 goto failed; | |
1691 } | |
1692 | |
1693 return; | |
1694 | |
1695 failed: | |
1696 | |
1697 ngx_close_connection(c); | |
1698 rec->tcp = NULL; | |
1699 } | |
1700 | |
1701 | |
1702 static void | |
1703 ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, size_t n, | |
1704 ngx_uint_t tcp) | |
1649 | 1705 { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1706 char *err; |
6367 | 1707 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
|
1708 qtype, qclass; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1709 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1710 ngx_uint_t qident6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1711 #endif |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1712 ngx_queue_t *q; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1713 ngx_resolver_qs_t *qs; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1714 ngx_resolver_hdr_t *response; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1715 ngx_resolver_node_t *rn; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1716 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1717 if (n < sizeof(ngx_resolver_hdr_t)) { |
1649 | 1718 goto short_response; |
1719 } | |
1720 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1721 response = (ngx_resolver_hdr_t *) buf; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1722 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1723 ident = (response->ident_hi << 8) + response->ident_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1724 flags = (response->flags_hi << 8) + response->flags_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1725 nqs = (response->nqs_hi << 8) + response->nqs_lo; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1726 nan = (response->nan_hi << 8) + response->nan_lo; |
6367 | 1727 trunc = flags & 0x0200; |
1649 | 1728 |
1729 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
|
1730 "resolver DNS response %ui fl:%04Xi %ui/%ui/%ud/%ud", |
1649 | 1731 ident, flags, nqs, nan, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1732 (response->nns_hi << 8) + response->nns_lo, |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1733 (response->nar_hi << 8) + response->nar_lo); |
1649 | 1734 |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1735 /* response to a standard query */ |
6367 | 1736 if ((flags & 0xf870) != 0x8000 || (trunc && tcp)) { |
1649 | 1737 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
|
1738 "invalid %s DNS response %ui fl:%04Xi", |
6367 | 1739 tcp ? "TCP" : "UDP", ident, flags); |
1649 | 1740 return; |
1741 } | |
1742 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1743 code = flags & 0xf; |
1649 | 1744 |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1745 if (code == NGX_RESOLVE_FORMERR) { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1746 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1747 times = 0; |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1748 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1749 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
|
1750 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
|
1751 q = ngx_queue_next(q)) |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1752 { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1753 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
|
1754 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
|
1755 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1756 if (qident == ident) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1757 goto dns_error_name; |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1758 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1759 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1760 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1761 if (rn->query6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1762 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
|
1763 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1764 if (qident6 == ident) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1765 goto dns_error_name; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1766 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1767 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1768 #endif |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1769 } |
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 goto dns_error; |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1772 } |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1773 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1774 if (code > NGX_RESOLVE_REFUSED) { |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1775 goto dns_error; |
1649 | 1776 } |
1777 | |
1778 if (nqs != 1) { | |
1779 err = "invalid number of questions in DNS response"; | |
1780 goto done; | |
1781 } | |
1782 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1783 i = sizeof(ngx_resolver_hdr_t); |
1649 | 1784 |
1785 while (i < (ngx_uint_t) n) { | |
1786 if (buf[i] == '\0') { | |
1787 goto found; | |
1788 } | |
1789 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1790 i += 1 + buf[i]; |
1649 | 1791 } |
1792 | |
1793 goto short_response; | |
1794 | |
1795 found: | |
1796 | |
5470
aebdca7e8f8f
Resolver: fixed response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5469
diff
changeset
|
1797 if (i++ == sizeof(ngx_resolver_hdr_t)) { |
1649 | 1798 err = "zero-length domain name in DNS response"; |
1799 goto done; | |
1800 } | |
1801 | |
1802 if (i + sizeof(ngx_resolver_qs_t) + nan * (2 + sizeof(ngx_resolver_an_t)) | |
1803 > (ngx_uint_t) n) | |
1804 { | |
1805 goto short_response; | |
1806 } | |
1807 | |
1808 qs = (ngx_resolver_qs_t *) &buf[i]; | |
1809 | |
1810 qtype = (qs->type_hi << 8) + qs->type_lo; | |
1811 qclass = (qs->class_hi << 8) + qs->class_lo; | |
1812 | |
1813 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
|
1814 "resolver DNS response qt:%ui cl:%ui", qtype, qclass); |
1649 | 1815 |
1816 if (qclass != 1) { | |
1817 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
|
1818 "unknown query class %ui in DNS response", qclass); |
1649 | 1819 return; |
1820 } | |
1821 | |
1822 switch (qtype) { | |
1823 | |
1824 case NGX_RESOLVE_A: | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1825 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1826 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1827 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1828 |
6367 | 1829 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
|
1830 i + sizeof(ngx_resolver_qs_t)); |
1649 | 1831 |
1832 break; | |
1833 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1834 case NGX_RESOLVE_SRV: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1835 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1836 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
|
1837 i + sizeof(ngx_resolver_qs_t)); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1838 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1839 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1840 |
1649 | 1841 case NGX_RESOLVE_PTR: |
1842 | |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
1843 ngx_resolver_process_ptr(r, buf, n, ident, code, nan); |
1649 | 1844 |
1845 break; | |
1846 | |
1847 default: | |
1848 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
|
1849 "unknown query type %ui in DNS response", qtype); |
1649 | 1850 return; |
1851 } | |
1852 | |
1853 return; | |
1854 | |
1855 short_response: | |
1856 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1857 err = "short DNS response"; |
1649 | 1858 |
1859 done: | |
1860 | |
1861 ngx_log_error(r->log_level, r->log, 0, err); | |
1862 | |
1863 return; | |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1864 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1865 dns_error_name: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1866 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1867 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
|
1868 "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
|
1869 code, ngx_resolver_strerror(code), ident, |
6478
3ef7bb882ad4
Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6460
diff
changeset
|
1870 (size_t) rn->nlen, rn->name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1871 return; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1872 |
2282
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1873 dns_error: |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1874 |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1875 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
|
1876 "DNS error (%ui: %s), query id:%ui", |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1877 code, ngx_resolver_strerror(code), ident); |
ec97eb9a8038
show name for a FORMERR DNS response
Igor Sysoev <igor@sysoev.ru>
parents:
2281
diff
changeset
|
1878 return; |
1649 | 1879 } |
1880 | |
1881 | |
1882 static void | |
6370 | 1883 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
|
1884 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype, |
6367 | 1885 ngx_uint_t nan, ngx_uint_t trunc, ngx_uint_t ans) |
583 | 1886 { |
6367 | 1887 char *err; |
1888 u_char *cname; | |
1889 size_t len; | |
1890 int32_t ttl; | |
1891 uint32_t hash; | |
1892 in_addr_t *addr; | |
1893 ngx_str_t name; | |
6370 | 1894 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
|
1895 #if (NGX_HAVE_INET6) |
6367 | 1896 struct in6_addr *addr6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1897 #endif |
6367 | 1898 ngx_resolver_an_t *an; |
1899 ngx_resolver_ctx_t *ctx, *next; | |
1900 ngx_resolver_node_t *rn; | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
1901 ngx_resolver_addr_t *addrs; |
6367 | 1902 ngx_resolver_connection_t *rec; |
1649 | 1903 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1904 if (ngx_resolver_copy(r, &name, buf, |
6370 | 1905 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1906 != NGX_OK) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
1907 { |
1649 | 1908 return; |
1909 } | |
1910 | |
1911 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); | |
1912 | |
1913 hash = ngx_crc32_short(name.data, name.len); | |
1914 | |
1915 /* lock name mutex */ | |
1916 | |
1917 rn = ngx_resolver_lookup_name(r, &name, hash); | |
1918 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1919 if (rn == NULL) { |
1649 | 1920 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
|
1921 "unexpected DNS response for %V", &name); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
1922 ngx_resolver_free(r, name.data); |
1649 | 1923 goto failed; |
1924 } | |
1925 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1926 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1927 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1928 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1929 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1930 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1931 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
|
1932 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
|
1933 "unexpected DNS response for %V", &name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1934 ngx_resolver_free(r, name.data); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1935 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1936 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1937 |
6367 | 1938 if (trunc && rn->tcp6) { |
1939 ngx_resolver_free(r, name.data); | |
1940 goto failed; | |
1941 } | |
1942 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1943 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
|
1944 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1945 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1946 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1947 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1948 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1949 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1950 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
|
1951 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
|
1952 "unexpected DNS response for %V", &name); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1953 ngx_resolver_free(r, name.data); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1954 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1955 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1956 |
6367 | 1957 if (trunc && rn->tcp) { |
1958 ngx_resolver_free(r, name.data); | |
1959 goto failed; | |
1960 } | |
1961 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
1962 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
|
1963 } |
1649 | 1964 |
1965 if (ident != qident) { | |
1966 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
|
1967 "wrong ident %ui in DNS response for %V, expect %ui", |
1649 | 1968 ident, &name, qident); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
1969 ngx_resolver_free(r, name.data); |
1649 | 1970 goto failed; |
1971 } | |
1972 | |
3139 | 1973 ngx_resolver_free(r, name.data); |
1974 | |
6367 | 1975 if (trunc) { |
1976 | |
1977 ngx_queue_remove(&rn->queue); | |
1978 | |
1979 if (rn->waiting == NULL) { | |
1980 ngx_rbtree_delete(&r->name_rbtree, &rn->node); | |
1981 ngx_resolver_free_node(r, rn); | |
1982 goto next; | |
1983 } | |
1984 | |
1985 rec = r->connections.elts; | |
1986 rec = &rec[rn->last_connection]; | |
1987 | |
1988 switch (qtype) { | |
1989 | |
1990 #if (NGX_HAVE_INET6) | |
1991 case NGX_RESOLVE_AAAA: | |
1992 | |
1993 rn->tcp6 = 1; | |
1994 | |
1995 (void) ngx_resolver_send_tcp_query(r, rec, rn->query6, rn->qlen); | |
1996 | |
1997 break; | |
1998 #endif | |
1999 | |
2000 default: /* NGX_RESOLVE_A */ | |
2001 | |
2002 rn->tcp = 1; | |
2003 | |
2004 (void) ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen); | |
2005 } | |
2006 | |
2007 rn->expire = ngx_time() + r->resend_timeout; | |
2008 | |
2009 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue); | |
2010 | |
2011 goto next; | |
2012 } | |
2013 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2014 if (code == 0 && rn->code) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2015 code = rn->code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2016 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2017 |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2018 if (code == 0 && nan == 0) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2019 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2020 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2021 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2022 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2023 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2024 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2025 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2026 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2027 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2028 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2029 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2030 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2031 if (rn->naddrs) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2032 goto export; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2033 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2034 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2035 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2036 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2037 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2038 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2039 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2040 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2041 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2042 goto next; |
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 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2045 if (rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2046 goto export; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2047 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2048 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2049 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2050 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2051 code = NGX_RESOLVE_NXDOMAIN; |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2052 } |
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
2053 |
1649 | 2054 if (code) { |
5477
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 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2057 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2058 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2059 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2060 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2061 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2062 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2063 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2064 rn->code = (u_char) code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2065 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2066 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2067 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2068 break; |
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 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2071 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2072 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2073 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2074 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2075 rn->code = (u_char) code; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2076 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2077 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2078 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2079 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2080 |
1649 | 2081 next = rn->waiting; |
2082 rn->waiting = NULL; | |
2083 | |
2084 ngx_queue_remove(&rn->queue); | |
2085 | |
2086 ngx_rbtree_delete(&r->name_rbtree, &rn->node); | |
2087 | |
2088 /* unlock name mutex */ | |
2089 | |
2090 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2091 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2092 ctx->state = code; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
2093 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2094 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2095 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2096 ctx->handler(ctx); |
1649 | 2097 } |
2098 | |
5920
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
2099 ngx_resolver_free_node(r, rn); |
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
2100 |
1649 | 2101 return; |
2102 } | |
2103 | |
2104 i = ans; | |
2105 naddrs = 0; | |
2106 cname = NULL; | |
2107 | |
2108 for (a = 0; a < nan; a++) { | |
2109 | |
2110 start = i; | |
2111 | |
6370 | 2112 while (i < n) { |
1649 | 2113 |
2114 if (buf[i] & 0xc0) { | |
2115 i += 2; | |
2116 goto found; | |
2117 } | |
2118 | |
2119 if (buf[i] == 0) { | |
2120 i++; | |
2121 goto test_length; | |
2122 } | |
2123 | |
2124 i += 1 + buf[i]; | |
2125 } | |
2126 | |
2127 goto short_response; | |
2128 | |
2129 test_length: | |
2130 | |
2131 if (i - start < 2) { | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2132 err = "invalid name in DNS response"; |
1649 | 2133 goto invalid; |
2134 } | |
2135 | |
2136 found: | |
2137 | |
6370 | 2138 if (i + sizeof(ngx_resolver_an_t) >= n) { |
1649 | 2139 goto short_response; |
2140 } | |
2141 | |
2142 an = (ngx_resolver_an_t *) &buf[i]; | |
2143 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2144 type = (an->type_hi << 8) + an->type_lo; |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2145 class = (an->class_hi << 8) + an->class_lo; |
1649 | 2146 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
|
2147 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
|
2148 + (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
|
2149 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2150 if (class != 1) { |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2151 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
|
2152 "unexpected RR class %ui in DNS response", class); |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2153 goto failed; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2154 } |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2155 |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2156 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
|
2157 ttl = 0; |
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2158 } |
1649 | 2159 |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2160 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
|
2161 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2162 i += sizeof(ngx_resolver_an_t); |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2163 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2164 switch (type) { |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2165 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2166 case NGX_RESOLVE_A: |
1649 | 2167 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2168 if (qtype != NGX_RESOLVE_A) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2169 err = "unexpected A record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2170 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2171 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2172 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2173 if (len != 4) { |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2174 err = "invalid A record in DNS response"; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2175 goto invalid; |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2176 } |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2177 |
6370 | 2178 if (i + 4 > n) { |
1649 | 2179 goto short_response; |
2180 } | |
2181 | |
2182 naddrs++; | |
2183 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2184 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2185 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2186 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2187 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2188 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2189 if (qtype != NGX_RESOLVE_AAAA) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2190 err = "unexpected AAAA 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 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2194 if (len != 16) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2195 err = "invalid AAAA record in DNS response"; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2196 goto invalid; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2197 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2198 |
6370 | 2199 if (i + 16 > n) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2200 goto short_response; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2201 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2202 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2203 naddrs++; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2204 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2205 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2206 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2207 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2208 case NGX_RESOLVE_CNAME: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2209 |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2210 cname = &buf[i]; |
1965 | 2211 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2212 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2213 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2214 case NGX_RESOLVE_DNAME: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2215 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2216 break; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2217 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2218 default: |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2219 |
1966 | 2220 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
|
2221 "unexpected RR type %ui in DNS response", type); |
1649 | 2222 } |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2223 |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2224 i += len; |
1649 | 2225 } |
2226 | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
2227 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
|
2228 "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
|
2229 naddrs, cname, rn->ttl); |
1649 | 2230 |
2231 if (naddrs) { | |
2232 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2233 switch (qtype) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2234 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2235 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2236 case NGX_RESOLVE_AAAA: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2237 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2238 if (naddrs == 1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2239 addr6 = &rn->u6.addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2240 rn->naddrs6 = 1; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2241 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2242 } else { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2243 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
|
2244 if (addr6 == NULL) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2245 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2246 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2247 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2248 rn->u6.addrs6 = addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2249 rn->naddrs6 = (u_short) naddrs; |
1649 | 2250 } |
2251 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2252 #if (NGX_SUPPRESS_WARN) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2253 addr = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2254 #endif |
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 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2257 #endif |
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 default: /* NGX_RESOLVE_A */ |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2260 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2261 if (naddrs == 1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2262 addr = &rn->u.addr; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2263 rn->naddrs = 1; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2264 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2265 } else { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2266 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
|
2267 if (addr == NULL) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2268 goto failed; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2269 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2270 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2271 rn->u.addrs = addr; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2272 rn->naddrs = (u_short) naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2273 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2274 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2275 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2276 addr6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2277 #endif |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2278 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2279 |
6370 | 2280 j = 0; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2281 i = ans; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2282 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2283 for (a = 0; a < nan; a++) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2284 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2285 for ( ;; ) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2286 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2287 if (buf[i] & 0xc0) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2288 i += 2; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2289 break; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2290 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2291 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2292 if (buf[i] == 0) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2293 i++; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2294 break; |
1649 | 2295 } |
2296 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2297 i += 1 + buf[i]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2298 } |
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 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
|
2301 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2302 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
|
2303 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
|
2304 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2305 i += sizeof(ngx_resolver_an_t); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2306 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2307 if (type == NGX_RESOLVE_A) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2308 |
6370 | 2309 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
|
2310 + (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
|
2311 |
6370 | 2312 if (++j == naddrs) { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2313 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2314 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2315 if (rn->naddrs6 == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2316 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2317 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2318 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2319 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2320 break; |
1649 | 2321 } |
2322 } | |
2323 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2324 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2325 else if (type == NGX_RESOLVE_AAAA) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2326 |
6370 | 2327 ngx_memcpy(addr6[j].s6_addr, &buf[i], 16); |
2328 | |
2329 if (++j == naddrs) { | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2330 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2331 if (rn->naddrs == (u_short) -1) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2332 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2333 } |
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 break; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2336 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2337 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2338 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2339 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2340 i += len; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2341 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2342 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2343 |
5768
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2344 switch (qtype) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2345 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2346 #if (NGX_HAVE_INET6) |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2347 case NGX_RESOLVE_AAAA: |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2348 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2349 if (rn->naddrs6 == (u_short) -1) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2350 rn->naddrs6 = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2351 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2352 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2353 break; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2354 #endif |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2355 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2356 default: /* NGX_RESOLVE_A */ |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2357 |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2358 if (rn->naddrs == (u_short) -1) { |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2359 rn->naddrs = 0; |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2360 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2361 } |
70a0408cca7b
Resolver: fixed resend on malformed responses.
Ruslan Ermilov <ru@nginx.com>
parents:
5764
diff
changeset
|
2362 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2363 if (rn->naddrs != (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2364 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2365 && rn->naddrs6 != (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2366 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2367 && rn->naddrs |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2368 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2369 + rn->naddrs6 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2370 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2371 > 0) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2372 { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2373 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2374 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2375 export: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2376 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2377 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2378 naddrs = rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2379 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2380 naddrs += rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2381 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2382 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2383 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
|
2384 addrs = NULL; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2385 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2386 } else { |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2387 addrs = ngx_resolver_export(r, rn, 0); |
1649 | 2388 if (addrs == NULL) { |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2389 goto failed; |
1649 | 2390 } |
2391 } | |
2392 | |
2393 ngx_queue_remove(&rn->queue); | |
2394 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2395 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
1649 | 2396 rn->expire = ngx_time() + r->expire; |
2397 | |
2398 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); | |
2399 | |
2400 next = rn->waiting; | |
2401 rn->waiting = NULL; | |
2402 | |
2403 /* unlock name mutex */ | |
2404 | |
2405 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2406 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2407 ctx->state = NGX_OK; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
2408 ctx->valid = rn->valid; |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2409 ctx->naddrs = naddrs; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2410 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2411 if (addrs == NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2412 ctx->addrs = &ctx->addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2413 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
|
2414 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
|
2415 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
|
2416 ctx->sin.sin_family = AF_INET; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2417 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
|
2418 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2419 } else { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2420 ctx->addrs = addrs; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2421 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2422 |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2423 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2424 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
2425 ctx->handler(ctx); |
1649 | 2426 } |
2427 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2428 if (addrs != NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
2429 ngx_resolver_free(r, addrs->sockaddr); |
1649 | 2430 ngx_resolver_free(r, addrs); |
2431 } | |
2432 | |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2433 ngx_resolver_free(r, rn->query); |
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2434 rn->query = NULL; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2435 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2436 rn->query6 = NULL; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2437 #endif |
4619
3171ec7d0d05
Resolver: protection from duplicate responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4610
diff
changeset
|
2438 |
1649 | 2439 return; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2440 } |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2441 |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2442 if (cname) { |
1649 | 2443 |
2444 /* CNAME only */ | |
2445 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2446 if (rn->naddrs == (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2447 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2448 || rn->naddrs6 == (u_short) -1 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2449 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2450 ) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2451 { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2452 goto next; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2453 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2454 |
6370 | 2455 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
|
2456 goto failed; |
1649 | 2457 } |
2458 | |
2459 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, | |
2460 "resolver cname:\"%V\"", &name); | |
2461 | |
1741
0829024c924d
fix segfault if response will have CNAME only
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
2462 ngx_queue_remove(&rn->queue); |
0829024c924d
fix segfault if response will have CNAME only
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
2463 |
1649 | 2464 rn->cnlen = (u_short) name.len; |
2465 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
|
2466 |
5485
8958656a8060
Resolver: use minimum TTL for caching (ticket #329).
Ruslan Ermilov <ru@nginx.com>
parents:
5479
diff
changeset
|
2467 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl); |
1649 | 2468 rn->expire = ngx_time() + r->expire; |
2469 | |
2470 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); | |
2471 | |
6352
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2472 ngx_resolver_free(r, rn->query); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2473 rn->query = NULL; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2474 #if (NGX_HAVE_INET6) |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2475 rn->query6 = NULL; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2476 #endif |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2477 |
1649 | 2478 ctx = rn->waiting; |
2479 rn->waiting = NULL; | |
2480 | |
2481 if (ctx) { | |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2482 |
6352
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2483 if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) { |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2484 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2485 /* unlock name mutex */ |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2486 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2487 do { |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2488 ctx->state = NGX_RESOLVE_NXDOMAIN; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2489 next = ctx->next; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2490 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2491 ctx->handler(ctx); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2492 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2493 ctx = next; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2494 } while (ctx); |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2495 |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2496 return; |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2497 } |
ff9b32c0e141
Resolver: limited CNAME recursion.
Ruslan Ermilov <ru@nginx.com>
parents:
6351
diff
changeset
|
2498 |
6351
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2499 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
|
2500 next->node = NULL; |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2501 } |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2502 |
497d0cff8ace
Resolver: fixed use-after-free memory accesses with CNAME.
Roman Arutyunyan <arut@nginx.com>
parents:
6350
diff
changeset
|
2503 (void) ngx_resolve_name_locked(r, ctx, &name); |
1649 | 2504 } |
2505 | |
5471
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2506 /* unlock name mutex */ |
9c96782d9d05
Resolver: fixes in A processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5470
diff
changeset
|
2507 |
1649 | 2508 return; |
2509 } | |
2510 | |
2511 ngx_log_error(r->log_level, r->log, 0, | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2512 "no A or CNAME types in DNS response"); |
1649 | 2513 return; |
2514 | |
2515 short_response: | |
2516 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
2517 err = "short DNS response"; |
1649 | 2518 |
2519 invalid: | |
2520 | |
2521 /* unlock name mutex */ | |
2522 | |
2523 ngx_log_error(r->log_level, r->log, 0, err); | |
2524 | |
2525 return; | |
2526 | |
2527 failed: | |
2528 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2529 next: |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
2530 |
1649 | 2531 /* unlock name mutex */ |
2532 | |
2533 return; | |
2534 } | |
2535 | |
2536 | |
2537 static void | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2538 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
|
2539 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
|
2540 ngx_uint_t trunc, ngx_uint_t ans) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2541 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2542 char *err; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2543 u_char *cname; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2544 size_t len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2545 int32_t ttl; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2546 uint32_t hash; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2547 ngx_str_t name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2548 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
|
2549 ngx_resolver_an_t *an; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2550 ngx_resolver_ctx_t *ctx, *next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2551 ngx_resolver_srv_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2552 ngx_resolver_node_t *rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2553 ngx_resolver_connection_t *rec; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2554 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2555 if (ngx_resolver_copy(r, &name, buf, |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2556 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2557 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2558 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2559 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2560 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2561 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2562 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
|
2563 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2564 hash = ngx_crc32_short(name.data, name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2565 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2566 rn = ngx_resolver_lookup_srv(r, &name, hash); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2567 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2568 if (rn == NULL || rn->query == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2569 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
|
2570 "unexpected DNS response for %V", &name); |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2571 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2572 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2573 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2574 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2575 if (trunc && rn->tcp) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2576 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2577 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2578 } |
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 qident = (rn->query[0] << 8) + rn->query[1]; |
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 if (ident != qident) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2583 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
|
2584 "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
|
2585 ident, &name, qident); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2586 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2587 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2590 ngx_resolver_free(r, name.data); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2591 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2592 if (trunc) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2593 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2594 ngx_queue_remove(&rn->queue); |
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 (rn->waiting == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2597 ngx_rbtree_delete(&r->srv_rbtree, &rn->node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2598 ngx_resolver_free_node(r, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2599 return; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2602 rec = r->connections.elts; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2603 rec = &rec[rn->last_connection]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2604 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2605 rn->tcp = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2606 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2607 (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
|
2608 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2609 rn->expire = ngx_time() + r->resend_timeout; |
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_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
|
2612 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2613 return; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2616 if (code == 0 && rn->code) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2617 code = rn->code; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2618 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2619 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2620 if (code == 0 && nan == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2621 code = NGX_RESOLVE_NXDOMAIN; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2624 if (code) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2625 next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2626 rn->waiting = NULL; |
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 ngx_queue_remove(&rn->queue); |
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 ngx_rbtree_delete(&r->srv_rbtree, &rn->node); |
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 while (next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2633 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2634 ctx->state = code; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2635 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
|
2636 next = ctx->next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2637 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2638 ctx->handler(ctx); |
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 ngx_resolver_free_node(r, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2642 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2643 return; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2646 i = ans; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2647 nsrvs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2648 cname = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2649 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2650 for (a = 0; a < nan; a++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2651 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2652 start = i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2653 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2654 while (i < n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2655 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2656 if (buf[i] & 0xc0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2657 i += 2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2658 goto found; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2659 } |
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 if (buf[i] == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2662 i++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2663 goto test_length; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2664 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2665 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2666 i += 1 + buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2667 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2668 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2669 goto short_response; |
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 test_length: |
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 if (i - start < 2) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2674 err = "invalid name DNS response"; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2675 goto invalid; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2678 found: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2679 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2680 if (i + sizeof(ngx_resolver_an_t) >= n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2681 goto short_response; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2682 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2683 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2684 an = (ngx_resolver_an_t *) &buf[i]; |
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 type = (an->type_hi << 8) + an->type_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2687 class = (an->class_hi << 8) + an->class_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2688 len = (an->len_hi << 8) + an->len_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2689 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
|
2690 + (an->ttl[2] << 8) + (an->ttl[3]); |
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 if (class != 1) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2693 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
|
2694 "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
|
2695 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2696 } |
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 if (ttl < 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2699 ttl = 0; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2702 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
|
2703 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2704 i += sizeof(ngx_resolver_an_t); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2705 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2706 switch (type) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2707 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2708 case NGX_RESOLVE_SRV: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2709 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2710 if (i + 6 > n) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2711 goto short_response; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2714 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
|
2715 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2716 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2717 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2720 nsrvs++; |
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 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2723 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2724 case NGX_RESOLVE_CNAME: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2725 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2726 cname = &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2727 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2728 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2729 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2730 case NGX_RESOLVE_DNAME: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2731 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2732 break; |
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 default: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2735 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2736 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
|
2737 "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
|
2738 } |
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 i += len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2741 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2742 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2743 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
|
2744 "resolver nsrvs:%ui cname:%p ttl:%uD", |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2745 nsrvs, cname, rn->ttl); |
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 if (nsrvs) { |
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 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
|
2750 if (srvs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2751 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2754 rn->u.srvs = srvs; |
6460
034329824dd3
Win32: fixed build after 384154fc634f.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6458
diff
changeset
|
2755 rn->nsrvs = (u_short) nsrvs; |
6458
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 j = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2758 i = ans; |
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 for (a = 0; a < nan; a++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2761 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2762 for ( ;; ) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2763 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2764 if (buf[i] & 0xc0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2765 i += 2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2766 break; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2769 if (buf[i] == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2770 i++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2771 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2772 } |
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 i += 1 + buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2775 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2776 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2777 an = (ngx_resolver_an_t *) &buf[i]; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2778 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2779 type = (an->type_hi << 8) + an->type_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2780 len = (an->len_hi << 8) + an->len_lo; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2781 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2782 i += sizeof(ngx_resolver_an_t); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2783 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2784 if (type == NGX_RESOLVE_SRV) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2785 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2786 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
|
2787 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
|
2788 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2789 if (srvs[j].weight == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2790 srvs[j].weight = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2791 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2792 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2793 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
|
2794 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2795 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
|
2796 buf + n) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2797 != NGX_OK) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2798 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2799 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2800 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2801 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2802 j++; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2803 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2804 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2805 i += len; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2808 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
|
2809 ngx_resolver_cmp_srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2810 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2811 ngx_resolver_free(r, rn->query); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2812 rn->query = NULL; |
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 ngx_queue_remove(&rn->queue); |
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 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
|
2817 rn->expire = ngx_time() + r->expire; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2818 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2819 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
|
2820 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2821 next = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2822 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2823 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2824 while (next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2825 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2826 next = ctx->next; |
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 ngx_resolver_resolve_srv_names(ctx, rn); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2829 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2830 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2831 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2832 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2833 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2834 rn->nsrvs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2835 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2836 if (cname) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2837 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2838 /* CNAME only */ |
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 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
|
2841 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2842 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2843 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2844 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
|
2845 "resolver cname:\"%V\"", &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2846 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2847 ngx_queue_remove(&rn->queue); |
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 rn->cnlen = (u_short) name.len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2850 rn->u.cname = name.data; |
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 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
|
2853 rn->expire = ngx_time() + r->expire; |
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 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
|
2856 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2857 ngx_resolver_free(r, rn->query); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2858 rn->query = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2859 #if (NGX_HAVE_INET6) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2860 rn->query6 = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2861 #endif |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2862 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2863 ctx = rn->waiting; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2864 rn->waiting = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2865 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2866 if (ctx) { |
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 if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) { |
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 /* unlock name mutex */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2871 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2872 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2873 ctx->state = NGX_RESOLVE_NXDOMAIN; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2874 next = ctx->next; |
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 ctx->handler(ctx); |
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 ctx = next; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2879 } while (ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2880 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2881 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2882 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2883 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2884 for (next = ctx; next; next = next->next) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2885 next->node = 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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2888 (void) ngx_resolve_name_locked(r, ctx, &name); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2889 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2890 |
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 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2894 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2895 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2896 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
|
2897 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2898 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2899 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2900 short_response: |
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 err = "short DNS response"; |
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 invalid: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2905 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2906 /* unlock name mutex */ |
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 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
|
2909 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2910 return; |
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 failed: |
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 /* unlock name mutex */ |
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 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2917 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2918 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2919 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2920 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2921 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
|
2922 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2923 ngx_uint_t i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2924 ngx_resolver_t *r; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2925 ngx_resolver_ctx_t *cctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2926 ngx_resolver_srv_name_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2927 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2928 r = ctx->resolver; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2929 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2930 ctx->node = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2931 ctx->state = NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2932 ctx->valid = rn->valid; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2933 ctx->count = rn->nsrvs; |
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 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
|
2936 if (srvs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2937 goto failed; |
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 ctx->srvs = srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2941 ctx->nsrvs = rn->nsrvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2942 |
6847
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2943 if (ctx->event && ctx->event->timer_set) { |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2944 ngx_del_timer(ctx->event); |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2945 } |
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2946 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
2947 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
|
2948 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
|
2949 if (srvs[i].name.data == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2950 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2951 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2952 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2953 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
|
2954 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
|
2955 srvs[i].name.len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2956 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2957 cctx = ngx_resolve_start(r, NULL); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2958 if (cctx == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2959 goto failed; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2962 cctx->name = srvs[i].name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2963 cctx->handler = ngx_resolver_srv_names_handler; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2964 cctx->data = ctx; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2965 cctx->srvs = &srvs[i]; |
6847
d72b38376092
Resolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6846
diff
changeset
|
2966 cctx->timeout = ctx->timeout; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2967 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2968 srvs[i].priority = rn->u.srvs[i].priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2969 srvs[i].weight = rn->u.srvs[i].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2970 srvs[i].port = rn->u.srvs[i].port; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2971 srvs[i].ctx = cctx; |
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 if (ngx_resolve_name(cctx) == NGX_ERROR) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2974 srvs[i].ctx = NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2975 goto failed; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2976 } |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2979 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2980 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2981 failed: |
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 ctx->state = NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2984 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
|
2985 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2986 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2987 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2988 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2989 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2990 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
2991 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
|
2992 { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
2993 ngx_uint_t i; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
2994 ngx_addr_t *addrs; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
2995 ngx_resolver_t *r; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
2996 ngx_sockaddr_t *sockaddr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
2997 ngx_resolver_ctx_t *ctx; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
2998 ngx_resolver_srv_name_t *srv; |
6458
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 r = cctx->resolver; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3001 ctx = cctx->data; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3002 srv = cctx->srvs; |
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->count--; |
7040
d49b74a683b1
Resolver: added the "async" flag to resolver context.
Roman Arutyunyan <arut@nginx.com>
parents:
7039
diff
changeset
|
3005 ctx->async |= cctx->async; |
6458
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 srv->ctx = NULL; |
6714
c3e3de6d2672
Resolver: introduced state field in ngx_resolver_srv_name_t.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6593
diff
changeset
|
3008 srv->state = cctx->state; |
6458
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 if (cctx->naddrs) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3011 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3012 ctx->valid = ngx_min(ctx->valid, cctx->valid); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3013 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3014 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
|
3015 if (addrs == NULL) { |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3016 srv->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3017 goto done; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3018 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3019 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3020 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
|
3021 if (sockaddr == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3022 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
|
3023 srv->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3024 goto done; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3025 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3026 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3027 for (i = 0; i < cctx->naddrs; i++) { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3028 addrs[i].sockaddr = &sockaddr[i].sockaddr; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3029 addrs[i].socklen = cctx->addrs[i].socklen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3030 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
3031 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
|
3032 addrs[i].socklen); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3033 |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6559
diff
changeset
|
3034 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
|
3035 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3036 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3037 srv->addrs = addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3038 srv->naddrs = cctx->naddrs; |
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 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3041 done: |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
3042 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3043 ngx_resolve_name_done(cctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3044 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3045 if (ctx->count == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3046 ngx_resolver_report_srv(r, ctx); |
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 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3049 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3050 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3051 static void |
1649 | 3052 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
|
3053 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan) |
1649 | 3054 { |
3055 char *err; | |
3056 size_t len; | |
3057 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
|
3058 int32_t ttl; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3059 ngx_int_t octet; |
1649 | 3060 ngx_str_t name; |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3061 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
|
3062 ngx_queue_t *expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3063 ngx_rbtree_t *tree; |
1649 | 3064 ngx_resolver_an_t *an; |
3065 ngx_resolver_ctx_t *ctx, *next; | |
3066 ngx_resolver_node_t *rn; | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3067 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3068 uint32_t hash; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3069 ngx_int_t digit; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3070 struct in6_addr addr6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3071 #endif |
1649 | 3072 |
6372 | 3073 if (ngx_resolver_copy(r, &name, buf, |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3074 buf + sizeof(ngx_resolver_hdr_t), buf + n) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3075 != NGX_OK) |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3076 { |
5472
ab493c60d9ff
Resolver: fixes in PTR processing.
Ruslan Ermilov <ru@nginx.com>
parents:
5471
diff
changeset
|
3077 return; |
1649 | 3078 } |
3079 | |
6372 | 3080 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name); |
3081 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3082 /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3083 |
1649 | 3084 addr = 0; |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3085 i = sizeof(ngx_resolver_hdr_t); |
1649 | 3086 |
3087 for (mask = 0; mask < 32; mask += 8) { | |
3088 len = buf[i++]; | |
3089 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3090 octet = ngx_atoi(&buf[i], len); |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3091 if (octet == NGX_ERROR || octet > 255) { |
1649 | 3092 goto invalid_in_addr_arpa; |
3093 } | |
3094 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3095 addr += octet << mask; |
1649 | 3096 i += len; |
3097 } | |
3098 | |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3099 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
|
3100 i += sizeof("\7in-addr\4arpa"); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3101 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3102 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3103 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3104 rn = ngx_resolver_lookup_addr(r, addr); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3105 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3106 tree = &r->addr_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3107 expire_queue = &r->addr_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3108 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3109 goto valid; |
1649 | 3110 } |
3111 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3112 invalid_in_addr_arpa: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3113 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3114 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3115 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3116 i = sizeof(ngx_resolver_hdr_t); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3117 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3118 for (octet = 15; octet >= 0; octet--) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3119 if (buf[i++] != '\1') { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3120 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3121 } |
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 digit = ngx_hextoi(&buf[i++], 1); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3124 if (digit == NGX_ERROR) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3125 goto invalid_ip6_arpa; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3128 addr6.s6_addr[octet] = (u_char) digit; |
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 if (buf[i++] != '\1') { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3131 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3132 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3133 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3134 digit = ngx_hextoi(&buf[i++], 1); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3135 if (digit == NGX_ERROR) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3136 goto invalid_ip6_arpa; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3137 } |
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 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
|
3140 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3141 |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3142 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
|
3143 i += sizeof("\3ip6\4arpa"); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3144 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3145 /* lock addr mutex */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3146 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3147 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
|
3148 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
|
3149 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3150 tree = &r->addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3151 expire_queue = &r->addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3152 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3153 goto valid; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3156 invalid_ip6_arpa: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3157 #endif |
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 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
|
3160 "invalid in-addr.arpa or ip6.arpa name in DNS response"); |
6372 | 3161 ngx_resolver_free(r, name.data); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3162 return; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3163 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3164 valid: |
1649 | 3165 |
3166 if (rn == NULL || rn->query == NULL) { | |
3167 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
|
3168 "unexpected DNS response for %V", &name); |
6372 | 3169 ngx_resolver_free(r, name.data); |
1649 | 3170 goto failed; |
3171 } | |
3172 | |
3173 qident = (rn->query[0] << 8) + rn->query[1]; | |
3174 | |
3175 if (ident != qident) { | |
3176 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
|
3177 "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
|
3178 ident, &name, qident); |
6372 | 3179 ngx_resolver_free(r, name.data); |
1649 | 3180 goto failed; |
3181 } | |
3182 | |
6372 | 3183 ngx_resolver_free(r, name.data); |
3184 | |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3185 if (code == 0 && nan == 0) { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3186 code = NGX_RESOLVE_NXDOMAIN; |
1742
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3187 } |
268b81386fe4
no answers in DNS response should be NXDOMAIN
Igor Sysoev <igor@sysoev.ru>
parents:
1741
diff
changeset
|
3188 |
1649 | 3189 if (code) { |
3190 next = rn->waiting; | |
3191 rn->waiting = NULL; | |
3192 | |
3193 ngx_queue_remove(&rn->queue); | |
3194 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3195 ngx_rbtree_delete(tree, &rn->node); |
1649 | 3196 |
3197 /* unlock addr mutex */ | |
3198 | |
3199 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3200 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3201 ctx->state = code; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
3202 ctx->valid = ngx_time() + (r->valid ? r->valid : 10); |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3203 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3204 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3205 ctx->handler(ctx); |
1649 | 3206 } |
3207 | |
5920
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
3208 ngx_resolver_free_node(r, rn); |
7420068c4d4b
Resolver: fixed use-after-free memory access.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
3209 |
1649 | 3210 return; |
3211 } | |
3212 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3213 i += sizeof(ngx_resolver_qs_t); |
1649 | 3214 |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3215 for (a = 0; a < nan; a++) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3216 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3217 start = i; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3218 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3219 while (i < n) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3220 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3221 if (buf[i] & 0xc0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3222 i += 2; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3223 goto found; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3224 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3225 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3226 if (buf[i] == 0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3227 i++; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3228 goto test_length; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3229 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3230 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3231 i += 1 + buf[i]; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3232 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3233 |
1649 | 3234 goto short_response; |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3235 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3236 test_length: |
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 if (i - start < 2) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3239 err = "invalid name in DNS response"; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3240 goto invalid; |
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 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3243 found: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3244 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3245 if (i + sizeof(ngx_resolver_an_t) >= n) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3246 goto short_response; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3247 } |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3248 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3249 an = (ngx_resolver_an_t *) &buf[i]; |
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 type = (an->type_hi << 8) + an->type_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3252 class = (an->class_hi << 8) + an->class_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3253 len = (an->len_hi << 8) + an->len_lo; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3254 ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16) |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3255 + (an->ttl[2] << 8) + (an->ttl[3]); |
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 if (class != 1) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3258 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
|
3259 "unexpected RR class %ui in DNS response", class); |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3260 goto failed; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3261 } |
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 if (ttl < 0) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3264 ttl = 0; |
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 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3267 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
|
3268 "resolver qt:%ui cl:%ui len:%uz", |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3269 type, class, len); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3270 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3271 i += sizeof(ngx_resolver_an_t); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3272 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3273 switch (type) { |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3274 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3275 case NGX_RESOLVE_PTR: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3276 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3277 goto ptr; |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3278 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3279 case NGX_RESOLVE_CNAME: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3280 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3281 break; |
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 default: |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3284 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3285 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
|
3286 "unexpected RR type %ui in DNS response", type); |
6371
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 |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3289 i += len; |
1649 | 3290 } |
3291 | |
6371
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3292 /* unlock addr mutex */ |
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 ngx_log_error(r->log_level, r->log, 0, |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3295 "no PTR type in DNS response"); |
33c4d319f08f
Resolver: improved PTR response processing.
Ruslan Ermilov <ru@nginx.com>
parents:
6370
diff
changeset
|
3296 return; |
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 ptr: |
1649 | 3299 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3300 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
|
3301 goto failed; |
1649 | 3302 } |
3303 | |
3304 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver an:%V", &name); | |
3305 | |
2486
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3306 if (name.len != (size_t) rn->nlen |
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3307 || ngx_strncmp(name.data, rn->name, name.len) != 0) |
1649 | 3308 { |
2482
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3309 if (rn->nlen) { |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3310 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
|
3311 } |
30ec8c5ac75b
fix reverse resolving cache: it stored zero length names
Igor Sysoev <igor@sysoev.ru>
parents:
2314
diff
changeset
|
3312 |
2490
1c87647b7ca5
fix building by msvc, introduced in r2487
Igor Sysoev <igor@sysoev.ru>
parents:
2487
diff
changeset
|
3313 rn->nlen = (u_short) name.len; |
1649 | 3314 rn->name = name.data; |
3315 | |
2486
8de5dc3e7001
use length of uncompressed name
Igor Sysoev <igor@sysoev.ru>
parents:
2484
diff
changeset
|
3316 name.data = ngx_resolver_dup(r, rn->name, name.len); |
1649 | 3317 if (name.data == NULL) { |
3318 goto failed; | |
3319 } | |
3320 } | |
3321 | |
3322 ngx_queue_remove(&rn->queue); | |
3323 | |
4295
05031fce7ce8
Now nginx uses TTL of a DNS response when calculating cache validity.
Ruslan Ermilov <ru@nginx.com>
parents:
4267
diff
changeset
|
3324 rn->valid = ngx_time() + (r->valid ? r->valid : ttl); |
1649 | 3325 rn->expire = ngx_time() + r->expire; |
3326 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3327 ngx_queue_insert_head(expire_queue, &rn->queue); |
1649 | 3328 |
3329 next = rn->waiting; | |
3330 rn->waiting = NULL; | |
3331 | |
3332 /* unlock addr mutex */ | |
3333 | |
3334 while (next) { | |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3335 ctx = next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3336 ctx->state = NGX_OK; |
6456
c94aba230a5a
Resolver: introduced valid field in resolver responses.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6372
diff
changeset
|
3337 ctx->valid = rn->valid; |
5474
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3338 ctx->name = name; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3339 next = ctx->next; |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3340 |
b43b02bb54db
Resolver: fixed indentation.
Ruslan Ermilov <ru@nginx.com>
parents:
5472
diff
changeset
|
3341 ctx->handler(ctx); |
1649 | 3342 } |
3343 | |
3344 ngx_resolver_free(r, name.data); | |
3345 | |
3346 return; | |
3347 | |
3348 short_response: | |
3349 | |
3350 err = "short DNS response"; | |
3351 | |
3352 invalid: | |
3353 | |
3354 /* unlock addr mutex */ | |
3355 | |
3356 ngx_log_error(r->log_level, r->log, 0, err); | |
3357 | |
3358 return; | |
3359 | |
3360 failed: | |
3361 | |
3362 /* unlock addr mutex */ | |
3363 | |
3364 return; | |
3365 } | |
3366 | |
3367 | |
3368 static ngx_resolver_node_t * | |
3369 ngx_resolver_lookup_name(ngx_resolver_t *r, ngx_str_t *name, uint32_t hash) | |
3370 { | |
3371 ngx_int_t rc; | |
3372 ngx_rbtree_node_t *node, *sentinel; | |
3373 ngx_resolver_node_t *rn; | |
3374 | |
3375 node = r->name_rbtree.root; | |
3376 sentinel = r->name_rbtree.sentinel; | |
3377 | |
3378 while (node != sentinel) { | |
3379 | |
3380 if (hash < node->key) { | |
3381 node = node->left; | |
3382 continue; | |
3383 } | |
3384 | |
3385 if (hash > node->key) { | |
3386 node = node->right; | |
3387 continue; | |
3388 } | |
3389 | |
3390 /* hash == node->key */ | |
3391 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3392 rn = ngx_resolver_node(node); |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3393 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3394 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
|
3395 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3396 if (rc == 0) { |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3397 return rn; |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3398 } |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3399 |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4496
diff
changeset
|
3400 node = (rc < 0) ? node->left : node->right; |
1649 | 3401 } |
3402 | |
3403 /* not found */ | |
3404 | |
3405 return NULL; | |
3406 } | |
3407 | |
3408 | |
3409 static ngx_resolver_node_t * | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3410 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
|
3411 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3412 ngx_int_t rc; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3413 ngx_rbtree_node_t *node, *sentinel; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3414 ngx_resolver_node_t *rn; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3415 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3416 node = r->srv_rbtree.root; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3417 sentinel = r->srv_rbtree.sentinel; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3418 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3419 while (node != sentinel) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3420 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3421 if (hash < node->key) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3422 node = node->left; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3423 continue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3424 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3425 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3426 if (hash > node->key) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3427 node = node->right; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3428 continue; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3429 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3430 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3431 /* hash == node->key */ |
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 rn = ngx_resolver_node(node); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3434 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3435 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
|
3436 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3437 if (rc == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3438 return rn; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3441 node = (rc < 0) ? node->left : node->right; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3442 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3443 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3444 /* not found */ |
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 return NULL; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3447 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3448 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3449 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3450 static ngx_resolver_node_t * |
1649 | 3451 ngx_resolver_lookup_addr(ngx_resolver_t *r, in_addr_t addr) |
3452 { | |
3453 ngx_rbtree_node_t *node, *sentinel; | |
3454 | |
3455 node = r->addr_rbtree.root; | |
3456 sentinel = r->addr_rbtree.sentinel; | |
3457 | |
3458 while (node != sentinel) { | |
3459 | |
3460 if (addr < node->key) { | |
3461 node = node->left; | |
3462 continue; | |
3463 } | |
3464 | |
3465 if (addr > node->key) { | |
3466 node = node->right; | |
3467 continue; | |
3468 } | |
3469 | |
3470 /* addr == node->key */ | |
3471 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3472 return ngx_resolver_node(node); |
1649 | 3473 } |
3474 | |
3475 /* not found */ | |
3476 | |
3477 return NULL; | |
3478 } | |
3479 | |
3480 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3481 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3482 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3483 static ngx_resolver_node_t * |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3484 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
|
3485 uint32_t hash) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3486 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3487 ngx_int_t rc; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3488 ngx_rbtree_node_t *node, *sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3489 ngx_resolver_node_t *rn; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3490 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3491 node = r->addr6_rbtree.root; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3492 sentinel = r->addr6_rbtree.sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3493 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3494 while (node != sentinel) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3495 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3496 if (hash < node->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3497 node = node->left; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3498 continue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3499 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3500 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3501 if (hash > node->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3502 node = node->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3503 continue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3504 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3505 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3506 /* hash == node->key */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3507 |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3508 rn = ngx_resolver_node(node); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3509 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3510 rc = ngx_memcmp(addr, &rn->addr6, 16); |
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 if (rc == 0) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3513 return rn; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3516 node = (rc < 0) ? node->left : node->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3517 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3518 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3519 /* not found */ |
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 return NULL; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3522 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3523 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3524 #endif |
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 |
1649 | 3527 static void |
3528 ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
3529 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
3530 { | |
3531 ngx_rbtree_node_t **p; | |
3532 ngx_resolver_node_t *rn, *rn_temp; | |
3533 | |
3534 for ( ;; ) { | |
3535 | |
3536 if (node->key < temp->key) { | |
3537 | |
3538 p = &temp->left; | |
3539 | |
3540 } else if (node->key > temp->key) { | |
3541 | |
3542 p = &temp->right; | |
3543 | |
3544 } else { /* node->key == temp->key */ | |
3545 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3546 rn = ngx_resolver_node(node); |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3547 rn_temp = ngx_resolver_node(temp); |
1649 | 3548 |
3143
ab6258e18099
fix resolver cache rbtree comparison
Igor Sysoev <igor@sysoev.ru>
parents:
3139
diff
changeset
|
3549 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
|
3550 < 0) ? &temp->left : &temp->right; |
1649 | 3551 } |
3552 | |
3553 if (*p == sentinel) { | |
3554 break; | |
3555 } | |
3556 | |
3557 temp = *p; | |
3558 } | |
3559 | |
3560 *p = node; | |
3561 node->parent = temp; | |
3562 node->left = sentinel; | |
3563 node->right = sentinel; | |
3564 ngx_rbt_red(node); | |
3565 } | |
3566 | |
3567 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3568 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3569 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3570 static void |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3571 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
|
3572 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
|
3573 { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3574 ngx_rbtree_node_t **p; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3575 ngx_resolver_node_t *rn, *rn_temp; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3576 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3577 for ( ;; ) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3578 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3579 if (node->key < temp->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3580 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3581 p = &temp->left; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3582 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3583 } else if (node->key > temp->key) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3584 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3585 p = &temp->right; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3586 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3587 } else { /* node->key == temp->key */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3588 |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3589 rn = ngx_resolver_node(node); |
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5920
diff
changeset
|
3590 rn_temp = ngx_resolver_node(temp); |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3591 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3592 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
|
3593 < 0) ? &temp->left : &temp->right; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3596 if (*p == sentinel) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3597 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3598 } |
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 temp = *p; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3603 *p = node; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3604 node->parent = temp; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3605 node->left = sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3606 node->right = sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3607 ngx_rbt_red(node); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3608 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3609 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3610 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3611 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3612 |
1649 | 3613 static ngx_int_t |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3614 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
|
3615 ngx_str_t *name) |
1649 | 3616 { |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3617 u_char *p, *s; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3618 size_t len, nlen; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3619 ngx_uint_t ident; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3620 ngx_resolver_qs_t *qs; |
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3621 ngx_resolver_hdr_t *query; |
1649 | 3622 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3623 nlen = name->len ? (1 + name->len + 1) : 1; |
3306
61bdaac6c668
fix resolving an empty name (".")
Igor Sysoev <igor@sysoev.ru>
parents:
3299
diff
changeset
|
3624 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3625 len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t); |
1649 | 3626 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3627 #if (NGX_HAVE_INET6) |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3628 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
|
3629 #else |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3630 p = ngx_resolver_alloc(r, len); |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3631 #endif |
1649 | 3632 if (p == NULL) { |
3633 return NGX_ERROR; | |
3634 } | |
3635 | |
3636 rn->qlen = (u_short) len; | |
3637 rn->query = p; | |
3638 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3639 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3640 if (r->ipv6) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3641 rn->query6 = p + len; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3642 } |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3643 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3644 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3645 query = (ngx_resolver_hdr_t *) p; |
1649 | 3646 |
3647 ident = ngx_random(); | |
3648 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3649 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
|
3650 "resolve: \"%V\" A %i", name, ident & 0xffff); |
1649 | 3651 |
3652 query->ident_hi = (u_char) ((ident >> 8) & 0xff); | |
3653 query->ident_lo = (u_char) (ident & 0xff); | |
3654 | |
3655 /* recursion query */ | |
3656 query->flags_hi = 1; query->flags_lo = 0; | |
3657 | |
3658 /* one question */ | |
3659 query->nqs_hi = 0; query->nqs_lo = 1; | |
3660 query->nan_hi = 0; query->nan_lo = 0; | |
3661 query->nns_hi = 0; query->nns_lo = 0; | |
3662 query->nar_hi = 0; query->nar_lo = 0; | |
3663 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3664 p += sizeof(ngx_resolver_hdr_t) + nlen; |
1649 | 3665 |
3666 qs = (ngx_resolver_qs_t *) p; | |
3667 | |
3668 /* query type */ | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3669 qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_A; |
1649 | 3670 |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3671 /* IN query class */ |
1649 | 3672 qs->class_hi = 0; qs->class_lo = 1; |
3673 | |
3674 /* convert "www.example.com" to "\3www\7example\3com\0" */ | |
3675 | |
3676 len = 0; | |
3677 p--; | |
3678 *p-- = '\0'; | |
3679 | |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3680 if (name->len == 0) { |
4610
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3681 return NGX_DECLINED; |
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3682 } |
778d2cc03e22
Fixed segmentation fault in ngx_resolver_create_name_query().
Ruslan Ermilov <ru@nginx.com>
parents:
4556
diff
changeset
|
3683 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3684 for (s = name->data + name->len - 1; s >= name->data; s--) { |
1649 | 3685 if (*s != '.') { |
3686 *p = *s; | |
3687 len++; | |
3688 | |
3689 } else { | |
4556
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3690 if (len == 0 || len > 255) { |
1961
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3691 return NGX_DECLINED; |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3692 } |
99b9feacccb4
return NXDOMAIN for ".." in host name
Igor Sysoev <igor@sysoev.ru>
parents:
1960
diff
changeset
|
3693 |
1649 | 3694 *p = (u_char) len; |
3695 len = 0; | |
3696 } | |
3697 | |
3698 p--; | |
3699 } | |
3700 | |
4556
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3701 if (len == 0 || len > 255) { |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3702 return NGX_DECLINED; |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3703 } |
1bddc91e78d6
Resolver: added missing sanity checking when creating name queries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4497
diff
changeset
|
3704 |
1649 | 3705 *p = (u_char) len; |
3706 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3707 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3708 if (!r->ipv6) { |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3709 return NGX_OK; |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3710 } |
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
3711 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3712 p = rn->query6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3713 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3714 ngx_memcpy(p, rn->query, rn->qlen); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3715 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3716 query = (ngx_resolver_hdr_t *) p; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3717 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3718 ident = ngx_random(); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3719 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3720 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
|
3721 "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
|
3722 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3723 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
|
3724 query->ident_lo = (u_char) (ident & 0xff); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3725 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3726 p += sizeof(ngx_resolver_hdr_t) + nlen; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3727 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3728 qs = (ngx_resolver_qs_t *) p; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3729 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3730 qs->type_lo = NGX_RESOLVE_AAAA; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3731 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
3732 |
1649 | 3733 return NGX_OK; |
3734 } | |
3735 | |
3736 | |
3737 static ngx_int_t | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3738 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
|
3739 ngx_str_t *name) |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3740 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3741 u_char *p, *s; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3742 size_t len, nlen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3743 ngx_uint_t ident; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3744 ngx_resolver_qs_t *qs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3745 ngx_resolver_hdr_t *query; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3746 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3747 nlen = name->len ? (1 + name->len + 1) : 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3748 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3749 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
|
3750 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3751 p = ngx_resolver_alloc(r, len); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3752 if (p == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3753 return NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3754 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3755 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3756 rn->qlen = (u_short) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3757 rn->query = p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3758 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3759 query = (ngx_resolver_hdr_t *) p; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3760 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3761 ident = ngx_random(); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3762 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3763 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
|
3764 "resolve: \"%V\" SRV %i", name, ident & 0xffff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3765 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3766 query->ident_hi = (u_char) ((ident >> 8) & 0xff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3767 query->ident_lo = (u_char) (ident & 0xff); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3768 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3769 /* recursion query */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3770 query->flags_hi = 1; query->flags_lo = 0; |
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 /* one question */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3773 query->nqs_hi = 0; query->nqs_lo = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3774 query->nan_hi = 0; query->nan_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3775 query->nns_hi = 0; query->nns_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3776 query->nar_hi = 0; query->nar_lo = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3777 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3778 p += sizeof(ngx_resolver_hdr_t) + nlen; |
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 qs = (ngx_resolver_qs_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 /* query type */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3783 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
|
3784 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3785 /* IN query class */ |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3786 qs->class_hi = 0; qs->class_lo = 1; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3787 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3788 /* 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
|
3789 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3790 len = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3791 p--; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3792 *p-- = '\0'; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3793 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3794 if (name->len == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3795 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3796 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3797 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3798 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
|
3799 if (*s != '.') { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3800 *p = *s; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3801 len++; |
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 } else { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3804 if (len == 0 || len > 255) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3805 return NGX_DECLINED; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3806 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3807 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3808 *p = (u_char) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3809 len = 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 |
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 } |
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 (len == 0 || len > 255) { |
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 *p = (u_char) len; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3820 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3821 return NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3822 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3823 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3824 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
3825 static ngx_int_t |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3826 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
|
3827 ngx_resolver_addr_t *addr) |
1649 | 3828 { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3829 u_char *p, *d; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3830 size_t len; |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3831 in_addr_t inaddr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3832 ngx_int_t n; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3833 ngx_uint_t ident; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3834 ngx_resolver_hdr_t *query; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3835 struct sockaddr_in *sin; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3836 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3837 struct sockaddr_in6 *sin6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3838 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3839 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3840 switch (addr->sockaddr->sa_family) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3841 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3842 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3843 case AF_INET6: |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3844 len = sizeof(ngx_resolver_hdr_t) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3845 + 64 + sizeof(".ip6.arpa.") - 1 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3846 + sizeof(ngx_resolver_qs_t); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3847 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3848 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3849 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3850 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3851 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3852 len = sizeof(ngx_resolver_hdr_t) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3853 + 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
|
3854 + sizeof(ngx_resolver_qs_t); |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
3855 } |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3856 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3857 p = ngx_resolver_alloc(r, len); |
1649 | 3858 if (p == NULL) { |
3859 return NGX_ERROR; | |
3860 } | |
3861 | |
3862 rn->query = p; | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3863 query = (ngx_resolver_hdr_t *) p; |
1649 | 3864 |
3865 ident = ngx_random(); | |
3866 | |
3867 query->ident_hi = (u_char) ((ident >> 8) & 0xff); | |
3868 query->ident_lo = (u_char) (ident & 0xff); | |
3869 | |
3870 /* recursion query */ | |
3871 query->flags_hi = 1; query->flags_lo = 0; | |
3872 | |
3873 /* one question */ | |
3874 query->nqs_hi = 0; query->nqs_lo = 1; | |
3875 query->nan_hi = 0; query->nan_lo = 0; | |
3876 query->nns_hi = 0; query->nns_lo = 0; | |
3877 query->nar_hi = 0; query->nar_lo = 0; | |
3878 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3879 p += sizeof(ngx_resolver_hdr_t); |
1649 | 3880 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3881 switch (addr->sockaddr->sa_family) { |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3882 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3883 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3884 case AF_INET6: |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3885 sin6 = (struct sockaddr_in6 *) addr->sockaddr; |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3886 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3887 for (n = 15; n >= 0; n--) { |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3888 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
|
3889 sin6->sin6_addr.s6_addr[n] & 0xf, |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3890 (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
|
3891 } |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3892 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3893 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
|
3894 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3895 break; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3896 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3897 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3898 default: /* AF_INET */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3899 |
6350
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3900 sin = (struct sockaddr_in *) addr->sockaddr; |
a5767988c022
Resolver: changed the ngx_resolver_create_*_query() arguments.
Roman Arutyunyan <arut@nginx.com>
parents:
6349
diff
changeset
|
3901 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
|
3902 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3903 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
|
3904 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
|
3905 *p = (u_char) (d - &p[1]); |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3906 p = d; |
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 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3909 p = ngx_cpymem(p, "\7in-addr\4arpa\0", 14); |
1649 | 3910 } |
3911 | |
5468
5c410d6ca7dd
Resolver: improved code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
3912 /* query type "PTR", IN query class */ |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3913 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
|
3914 |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
3915 rn->qlen = (u_short) (p - rn->query); |
1649 | 3916 |
3917 return NGX_OK; | |
3918 } | |
3919 | |
3920 | |
3921 static ngx_int_t | |
3922 ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src, | |
3923 u_char *last) | |
3924 { | |
3925 char *err; | |
3926 u_char *p, *dst; | |
3927 ssize_t len; | |
3928 ngx_uint_t i, n; | |
3929 | |
3930 p = src; | |
3931 len = -1; | |
3932 | |
3933 /* | |
3934 * compression pointers allow to create endless loop, so we set limit; | |
3935 * 128 pointers should be enough to store 255-byte name | |
3936 */ | |
3937 | |
3938 for (i = 0; i < 128; i++) { | |
3939 n = *p++; | |
3940 | |
3941 if (n == 0) { | |
3942 goto done; | |
3943 } | |
3944 | |
3945 if (n & 0xc0) { | |
2314
52987a023486
fix compression pointer for big (>255) DNS responses
Igor Sysoev <igor@sysoev.ru>
parents:
2282
diff
changeset
|
3946 n = ((n & 0x3f) << 8) + *p; |
1649 | 3947 p = &buf[n]; |
3948 | |
3949 } else { | |
3950 len += 1 + n; | |
3951 p = &p[n]; | |
3952 } | |
3953 | |
3954 if (p >= last) { | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3955 err = "name is out of DNS response"; |
1649 | 3956 goto invalid; |
3957 } | |
3958 } | |
3959 | |
8121
8fe7ebe5adc4
Resolver: improved error messages (ticket #2024).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7566
diff
changeset
|
3960 err = "compression pointers loop in DNS response"; |
1649 | 3961 |
3962 invalid: | |
3963 | |
3964 ngx_log_error(r->log_level, r->log, 0, err); | |
3965 | |
3966 return NGX_ERROR; | |
3967 | |
3968 done: | |
3969 | |
3970 if (name == NULL) { | |
583 | 3971 return NGX_OK; |
3972 } | |
3973 | |
3298
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
3974 if (len == -1) { |
5764
f166c521b619
Style: use ngx_str_null().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents:
5600
diff
changeset
|
3975 ngx_str_null(name); |
3298
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
3976 return NGX_OK; |
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
3977 } |
847ab5a32307
fix "PTR ." case in address resolver
Igor Sysoev <igor@sysoev.ru>
parents:
3297
diff
changeset
|
3978 |
1649 | 3979 dst = ngx_resolver_alloc(r, len); |
3980 if (dst == NULL) { | |
3981 return NGX_ERROR; | |
3982 } | |
3983 | |
3984 name->data = dst; | |
3985 | |
3986 n = *src++; | |
3987 | |
3988 for ( ;; ) { | |
4267
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
3989 if (n & 0xc0) { |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
3990 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
|
3991 src = &buf[n]; |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
3992 |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
3993 n = *src++; |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
3994 |
768212ca0745
Fixed compression pointer processing in DNS response greater than 255 bytes.
Igor Sysoev <igor@sysoev.ru>
parents:
4225
diff
changeset
|
3995 } else { |
5479
c0d6eae5a1c5
Resolver: lookups are case-insensitive.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
3996 ngx_strlow(dst, src, n); |
1649 | 3997 dst += n; |
3998 src += n; | |
3999 | |
4000 n = *src++; | |
4001 | |
4002 if (n != 0) { | |
4003 *dst++ = '.'; | |
4004 } | |
4005 } | |
4006 | |
4007 if (n == 0) { | |
4008 name->len = dst - name->data; | |
4009 return NGX_OK; | |
4010 } | |
4011 } | |
4012 } | |
4013 | |
4014 | |
7051
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4015 static ngx_int_t |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4016 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
|
4017 { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4018 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
|
4019 return NGX_OK; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4020 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4021 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4022 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
|
4023 if (ctx->event == NULL) { |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4024 return NGX_ERROR; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4025 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4026 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4027 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
|
4028 ctx->event->data = ctx; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4029 ctx->event->log = r->log; |
7052
70e65bf8dfd7
Resolver: cancelable resend timer event.
Ruslan Ermilov <ru@nginx.com>
parents:
7051
diff
changeset
|
4030 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
|
4031 ctx->ident = -1; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4032 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4033 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
|
4034 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4035 return NGX_OK; |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4036 } |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4037 |
137c5be7df09
Resolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7048
diff
changeset
|
4038 |
1649 | 4039 static void |
4040 ngx_resolver_timeout_handler(ngx_event_t *ev) | |
4041 { | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4042 ngx_resolver_ctx_t *ctx; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4043 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4044 ctx = ev->data; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4045 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4046 ctx->state = NGX_RESOLVE_TIMEDOUT; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4047 |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6347
diff
changeset
|
4048 ctx->handler(ctx); |
1649 | 4049 } |
4050 | |
4051 | |
4052 static void | |
4053 ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn) | |
4054 { | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4055 ngx_uint_t i; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4056 |
1649 | 4057 /* lock alloc mutex */ |
4058 | |
4059 if (rn->query) { | |
4060 ngx_resolver_free_locked(r, rn->query); | |
4061 } | |
4062 | |
4063 if (rn->name) { | |
4064 ngx_resolver_free_locked(r, rn->name); | |
4065 } | |
4066 | |
4067 if (rn->cnlen) { | |
4068 ngx_resolver_free_locked(r, rn->u.cname); | |
4069 } | |
4070 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4071 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) { |
1649 | 4072 ngx_resolver_free_locked(r, rn->u.addrs); |
4073 } | |
4074 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4075 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4076 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
|
4077 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
|
4078 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4079 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4080 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4081 if (rn->nsrvs) { |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4082 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
|
4083 if (rn->u.srvs[i].name.data) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4084 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
|
4085 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4086 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4087 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4088 ngx_resolver_free_locked(r, rn->u.srvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4089 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4090 |
1649 | 4091 ngx_resolver_free_locked(r, rn); |
4092 | |
4093 /* unlock alloc mutex */ | |
4094 } | |
4095 | |
4096 | |
4097 static void * | |
4098 ngx_resolver_alloc(ngx_resolver_t *r, size_t size) | |
4099 { | |
4100 u_char *p; | |
4101 | |
4102 /* lock alloc mutex */ | |
4103 | |
4104 p = ngx_alloc(size, r->log); | |
4105 | |
4106 /* unlock alloc mutex */ | |
4107 | |
4108 return p; | |
4109 } | |
4110 | |
4111 | |
1903 | 4112 static void * |
1649 | 4113 ngx_resolver_calloc(ngx_resolver_t *r, size_t size) |
4114 { | |
4115 u_char *p; | |
4116 | |
4117 p = ngx_resolver_alloc(r, size); | |
4118 | |
4119 if (p) { | |
4120 ngx_memzero(p, size); | |
4121 } | |
4122 | |
4123 return p; | |
4124 } | |
4125 | |
4126 | |
4127 static void | |
4128 ngx_resolver_free(ngx_resolver_t *r, void *p) | |
4129 { | |
4130 /* lock alloc mutex */ | |
4131 | |
4132 ngx_free(p); | |
4133 | |
4134 /* unlock alloc mutex */ | |
4135 } | |
4136 | |
4137 | |
4138 static void | |
4139 ngx_resolver_free_locked(ngx_resolver_t *r, void *p) | |
4140 { | |
4141 ngx_free(p); | |
4142 } | |
4143 | |
4144 | |
4145 static void * | |
4146 ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size) | |
4147 { | |
4148 void *dst; | |
4149 | |
4150 dst = ngx_resolver_alloc(r, size); | |
4151 | |
4152 if (dst == NULL) { | |
4153 return dst; | |
4154 } | |
4155 | |
4156 ngx_memcpy(dst, src, size); | |
4157 | |
4158 return dst; | |
4159 } | |
4160 | |
4161 | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4162 static ngx_resolver_addr_t * |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4163 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
|
4164 ngx_uint_t rotate) |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4165 { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4166 ngx_uint_t d, i, j, n; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4167 in_addr_t *addr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4168 ngx_sockaddr_t *sockaddr; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4169 struct sockaddr_in *sin; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4170 ngx_resolver_addr_t *dst; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4171 #if (NGX_HAVE_INET6) |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4172 struct in6_addr *addr6; |
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4173 struct sockaddr_in6 *sin6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4174 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4175 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4176 n = rn->naddrs; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4177 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4178 n += rn->naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4179 #endif |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4180 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4181 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
|
4182 if (dst == NULL) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4183 return NULL; |
4892
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4184 } |
063ac68d89dc
Resolver: added missing memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4871
diff
changeset
|
4185 |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4186 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
|
4187 if (sockaddr == NULL) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4188 ngx_resolver_free(r, dst); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5474
diff
changeset
|
4189 return NULL; |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4190 } |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4191 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4192 i = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4193 d = rotate ? ngx_random() % n : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4194 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4195 if (rn->naddrs) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4196 j = rotate ? ngx_random() % rn->naddrs : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4197 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4198 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
|
4199 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4200 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4201 sin = &sockaddr[d].sockaddr_in; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4202 sin->sin_family = AF_INET; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4203 sin->sin_addr.s_addr = addr[j++]; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4204 dst[d].sockaddr = (struct sockaddr *) sin; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4205 dst[d++].socklen = sizeof(struct sockaddr_in); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4206 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4207 if (d == n) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4208 d = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4209 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4210 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4211 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
|
4212 j = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4213 } |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6847
diff
changeset
|
4214 } 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
|
4215 } |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4216 |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4217 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4218 if (rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4219 j = rotate ? ngx_random() % rn->naddrs6 : 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4220 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4221 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
|
4222 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4223 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6509
diff
changeset
|
4224 sin6 = &sockaddr[d].sockaddr_in6; |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4225 sin6->sin6_family = AF_INET6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4226 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
|
4227 dst[d].sockaddr = (struct sockaddr *) sin6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4228 dst[d++].socklen = sizeof(struct sockaddr_in6); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4229 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4230 if (d == n) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4231 d = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4232 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4233 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4234 if (j == rn->naddrs6) { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4235 j = 0; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4236 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4237 } while (++i < n); |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4238 } |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4239 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
4240 |
4871
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4241 return dst; |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4242 } |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4243 |
c85cefbdaafe
Resolver: cached addresses are returned with random rotation now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4784
diff
changeset
|
4244 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4245 static void |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4246 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
|
4247 { |
6460
034329824dd3
Win32: fixed build after 384154fc634f.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6458
diff
changeset
|
4248 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
|
4249 ngx_resolver_addr_t *addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4250 ngx_resolver_srv_name_t *srvs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4251 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4252 srvs = ctx->srvs; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4253 nsrvs = ctx->nsrvs; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4254 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4255 naddrs = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4256 |
7048
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4257 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
|
4258 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
|
4259 ctx->state = NGX_ERROR; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4260 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
|
4261 |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4262 ctx->handler(ctx); |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4263 return; |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4264 } |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4265 |
80224192163c
Resolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan <arut@nginx.com>
parents:
7040
diff
changeset
|
4266 naddrs += srvs[i].naddrs; |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4267 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4268 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4269 if (naddrs == 0) { |
7428
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4270 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
|
4271 |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4272 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
|
4273 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
|
4274 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
|
4275 break; |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4276 } |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4277 } |
cbc5dee8d5d2
Resolver: report SRV resolve failure if all A resolves failed.
Roman Arutyunyan <arut@nginx.com>
parents:
7312
diff
changeset
|
4278 |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4279 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
|
4280 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4281 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4282 return; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4283 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4284 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4285 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
|
4286 if (addrs == NULL) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4287 ctx->state = NGX_ERROR; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4288 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
|
4289 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4290 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4291 return; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4294 i = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4295 n = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4296 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4297 do { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4298 nw = 0; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4299 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4300 for (j = i; j < nsrvs; j++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4301 if (srvs[j].priority != srvs[i].priority) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4302 break; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4303 } |
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 nw += srvs[j].naddrs * srvs[j].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4306 } |
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 if (nw == 0) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4309 goto next_srv; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4310 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4311 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4312 w = ngx_random() % nw; |
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 for (k = i; k < j; k++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4315 if (w < srvs[k].naddrs * srvs[k].weight) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4316 break; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4319 w -= srvs[k].naddrs * srvs[k].weight; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4322 for (l = i; l < j; l++) { |
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 (m = 0; m < srvs[k].naddrs; m++) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4325 addrs[n].socklen = srvs[k].addrs[m].socklen; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4326 addrs[n].sockaddr = srvs[k].addrs[m].sockaddr; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4327 addrs[n].name = srvs[k].name; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4328 addrs[n].priority = srvs[k].priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4329 addrs[n].weight = srvs[k].weight; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4330 n++; |
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 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4333 if (++k == j) { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4334 k = i; |
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 } |
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 next_srv: |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4339 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4340 i = j; |
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 } while (i < ctx->nsrvs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4343 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4344 ctx->state = NGX_OK; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4345 ctx->addrs = addrs; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4346 ctx->naddrs = naddrs; |
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 ctx->handler(ctx); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4349 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4350 ngx_resolver_free(r, addrs); |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4351 } |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4352 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4353 |
1649 | 4354 char * |
4355 ngx_resolver_strerror(ngx_int_t err) | |
4356 { | |
4357 static char *errors[] = { | |
4358 "Format error", /* FORMERR */ | |
4359 "Server failure", /* SERVFAIL */ | |
4360 "Host not found", /* NXDOMAIN */ | |
4361 "Unimplemented", /* NOTIMP */ | |
4362 "Operation refused" /* REFUSED */ | |
4363 }; | |
4364 | |
4365 if (err > 0 && err < 6) { | |
4366 return errors[err - 1]; | |
4367 } | |
4368 | |
4369 if (err == NGX_RESOLVE_TIMEDOUT) { | |
4370 return "Operation timed out"; | |
4371 } | |
4372 | |
4373 return "Unknown error"; | |
4374 } | |
4375 | |
4376 | |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4377 static u_char * |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4378 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
|
4379 { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4380 u_char *p; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4381 ngx_resolver_connection_t *rec; |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4382 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4383 p = buf; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4384 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4385 if (log->action) { |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4386 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
|
4387 len -= p - buf; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4388 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4389 |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4390 rec = log->data; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4391 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4392 if (rec) { |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4393 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
|
4394 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4395 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4396 return p; |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4397 } |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4398 |
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4399 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
4400 static ngx_int_t |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4401 ngx_udp_connect(ngx_resolver_connection_t *rec) |
1649 | 4402 { |
4403 int rc; | |
4404 ngx_int_t event; | |
4405 ngx_event_t *rev, *wev; | |
4406 ngx_socket_t s; | |
4407 ngx_connection_t *c; | |
4408 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4409 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
|
4410 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4411 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "UDP socket %d", s); |
583 | 4412 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4892
diff
changeset
|
4413 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
|
4414 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
583 | 4415 ngx_socket_n " failed"); |
4416 return NGX_ERROR; | |
4417 } | |
4418 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4419 c = ngx_get_connection(s, &rec->log); |
583 | 4420 |
4421 if (c == NULL) { | |
4422 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
|
4423 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
|
4424 ngx_close_socket_n " failed"); |
583 | 4425 } |
4426 | |
4427 return NGX_ERROR; | |
4428 } | |
4429 | |
1649 | 4430 if (ngx_nonblocking(s) == -1) { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4431 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, |
1649 | 4432 ngx_nonblocking_n " failed"); |
4433 | |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4434 goto failed; |
1649 | 4435 } |
4436 | |
583 | 4437 rev = c->read; |
4438 wev = c->write; | |
4439 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4440 rev->log = &rec->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4441 wev->log = &rec->log; |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4442 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4443 rec->udp = c; |
583 | 4444 |
4445 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
4446 | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4447 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
|
4448 "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
|
4449 |
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4450 rc = connect(s, rec->sockaddr, rec->socklen); |
1649 | 4451 |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
4452 /* TODO: iocp */ |
583 | 4453 |
4454 if (rc == -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_CRIT, &rec->log, ngx_socket_errno, |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3376
diff
changeset
|
4456 "connect() failed"); |
583 | 4457 |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4458 goto failed; |
583 | 4459 } |
4460 | |
1649 | 4461 /* UDP sockets are always ready to write */ |
4462 wev->ready = 1; | |
4463 | |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4464 event = (ngx_event_flags & NGX_USE_CLEAR_EVENT) ? |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4465 /* kqueue, epoll */ NGX_CLEAR_EVENT: |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4466 /* select, poll, /dev/poll */ NGX_LEVEL_EVENT; |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4467 /* eventport event type has no meaning: oneshot only */ |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4468 |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4469 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
|
4470 goto failed; |
583 | 4471 } |
4472 | |
4473 return NGX_OK; | |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4474 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4475 failed: |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4476 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4477 ngx_close_connection(c); |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6352
diff
changeset
|
4478 rec->udp = NULL; |
5582
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4479 |
545a4d393e2f
Resolver: properly handle connect() failures.
Ruslan Ermilov <ru@nginx.com>
parents:
5505
diff
changeset
|
4480 return NGX_ERROR; |
583 | 4481 } |
6367 | 4482 |
4483 | |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6860
diff
changeset
|
4484 static ngx_int_t |
6367 | 4485 ngx_tcp_connect(ngx_resolver_connection_t *rec) |
4486 { | |
4487 int rc; | |
4488 ngx_int_t event; | |
4489 ngx_err_t err; | |
4490 ngx_uint_t level; | |
4491 ngx_socket_t s; | |
4492 ngx_event_t *rev, *wev; | |
4493 ngx_connection_t *c; | |
4494 | |
4495 s = ngx_socket(rec->sockaddr->sa_family, SOCK_STREAM, 0); | |
4496 | |
4497 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "TCP socket %d", s); | |
4498 | |
4499 if (s == (ngx_socket_t) -1) { | |
4500 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4501 ngx_socket_n " failed"); | |
4502 return NGX_ERROR; | |
4503 } | |
4504 | |
4505 c = ngx_get_connection(s, &rec->log); | |
4506 | |
4507 if (c == NULL) { | |
4508 if (ngx_close_socket(s) == -1) { | |
4509 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
|
4510 ngx_close_socket_n " failed"); |
6367 | 4511 } |
4512 | |
4513 return NGX_ERROR; | |
4514 } | |
4515 | |
4516 if (ngx_nonblocking(s) == -1) { | |
4517 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4518 ngx_nonblocking_n " failed"); | |
4519 | |
4520 goto failed; | |
4521 } | |
4522 | |
4523 rev = c->read; | |
4524 wev = c->write; | |
4525 | |
4526 rev->log = &rec->log; | |
4527 wev->log = &rec->log; | |
4528 | |
4529 rec->tcp = c; | |
4530 | |
4531 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
4532 | |
4533 if (ngx_add_conn) { | |
4534 if (ngx_add_conn(c) == NGX_ERROR) { | |
4535 goto failed; | |
4536 } | |
4537 } | |
4538 | |
4539 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, &rec->log, 0, | |
4540 "connect to %V, fd:%d #%uA", &rec->server, s, c->number); | |
4541 | |
4542 rc = connect(s, rec->sockaddr, rec->socklen); | |
4543 | |
4544 if (rc == -1) { | |
4545 err = ngx_socket_errno; | |
4546 | |
4547 | |
4548 if (err != NGX_EINPROGRESS | |
4549 #if (NGX_WIN32) | |
4550 /* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */ | |
4551 && err != NGX_EAGAIN | |
4552 #endif | |
4553 ) | |
4554 { | |
4555 if (err == NGX_ECONNREFUSED | |
4556 #if (NGX_LINUX) | |
4557 /* | |
4558 * Linux returns EAGAIN instead of ECONNREFUSED | |
4559 * for unix sockets if listen queue is full | |
4560 */ | |
4561 || err == NGX_EAGAIN | |
4562 #endif | |
4563 || err == NGX_ECONNRESET | |
4564 || err == NGX_ENETDOWN | |
4565 || err == NGX_ENETUNREACH | |
4566 || err == NGX_EHOSTDOWN | |
4567 || err == NGX_EHOSTUNREACH) | |
4568 { | |
4569 level = NGX_LOG_ERR; | |
4570 | |
4571 } else { | |
4572 level = NGX_LOG_CRIT; | |
4573 } | |
4574 | |
7275 | 4575 ngx_log_error(level, &rec->log, err, "connect() to %V failed", |
6367 | 4576 &rec->server); |
4577 | |
4578 ngx_close_connection(c); | |
4579 rec->tcp = NULL; | |
4580 | |
4581 return NGX_ERROR; | |
4582 } | |
4583 } | |
4584 | |
4585 if (ngx_add_conn) { | |
4586 if (rc == -1) { | |
4587 | |
4588 /* NGX_EINPROGRESS */ | |
4589 | |
4590 return NGX_AGAIN; | |
4591 } | |
4592 | |
4593 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "connected"); | |
4594 | |
4595 wev->ready = 1; | |
4596 | |
4597 return NGX_OK; | |
4598 } | |
4599 | |
4600 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { | |
4601 | |
4602 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &rec->log, ngx_socket_errno, | |
4603 "connect(): %d", rc); | |
4604 | |
4605 if (ngx_blocking(s) == -1) { | |
4606 ngx_log_error(NGX_LOG_ALERT, &rec->log, ngx_socket_errno, | |
4607 ngx_blocking_n " failed"); | |
4608 goto failed; | |
4609 } | |
4610 | |
4611 /* | |
4612 * FreeBSD's aio allows to post an operation on non-connected socket. | |
4613 * NT does not support it. | |
4614 * | |
4615 * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT | |
4616 */ | |
4617 | |
4618 rev->ready = 1; | |
4619 wev->ready = 1; | |
4620 | |
4621 return NGX_OK; | |
4622 } | |
4623 | |
4624 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
4625 | |
4626 /* kqueue */ | |
4627 | |
4628 event = NGX_CLEAR_EVENT; | |
4629 | |
4630 } else { | |
4631 | |
4632 /* select, poll, /dev/poll */ | |
4633 | |
4634 event = NGX_LEVEL_EVENT; | |
4635 } | |
4636 | |
4637 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { | |
4638 goto failed; | |
4639 } | |
4640 | |
4641 if (rc == -1) { | |
4642 | |
4643 /* NGX_EINPROGRESS */ | |
4644 | |
4645 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { | |
4646 goto failed; | |
4647 } | |
4648 | |
4649 return NGX_AGAIN; | |
4650 } | |
4651 | |
4652 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, &rec->log, 0, "connected"); | |
4653 | |
4654 wev->ready = 1; | |
4655 | |
4656 return NGX_OK; | |
4657 | |
4658 failed: | |
4659 | |
4660 ngx_close_connection(c); | |
4661 rec->tcp = NULL; | |
4662 | |
4663 return NGX_ERROR; | |
4664 } | |
6458
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4665 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4666 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4667 static ngx_int_t |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4668 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
|
4669 { |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4670 ngx_int_t p1, p2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4671 ngx_resolver_srv_t *first, *second; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4672 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4673 first = (ngx_resolver_srv_t *) one; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4674 second = (ngx_resolver_srv_t *) two; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4675 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4676 p1 = first->priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4677 p2 = second->priority; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4678 |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4679 return p1 - p2; |
384154fc634f
Resolver: added support for SRV records.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6457
diff
changeset
|
4680 } |