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