annotate src/core/ngx_resolver.c @ 542:2b9e388c61f1 NGINX_0_8_23

nginx 0.8.23 *) Security: now SSL/TLS renegotiation is disabled. Thanks to Maxim Dounin. *) Bugfix: listen unix domain socket did not inherit while online upgrade. *) Bugfix: the "unix:" parameter of the "set_real_ip_from" directive did not without yet another directive with any IP address. *) Bugfix: segmentation fault and infinite looping in resolver. *) Bugfix: in resolver. Thanks to Artem Bokhan.
author Igor Sysoev <http://sysoev.ru>
date Wed, 11 Nov 2009 00:00:00 +0300
parents c04fa65fe604
children 40c366b3535c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_event.h>
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 #define NGX_RESOLVER_UDP_SIZE 4096
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 typedef struct {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 u_char ident_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 u_char ident_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18 u_char flags_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 u_char flags_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 u_char nqs_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 u_char nqs_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 u_char nan_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23 u_char nan_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 u_char nns_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 u_char nns_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 u_char nar_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 u_char nar_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 } ngx_resolver_query_t;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 typedef struct {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 u_char type_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 u_char type_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 u_char class_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 u_char class_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 } ngx_resolver_qs_t;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 typedef struct {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 u_char type_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 u_char type_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 u_char class_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 u_char class_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 u_char ttl[4];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 u_char len_hi;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 u_char len_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 } ngx_resolver_an_t;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 ngx_int_t ngx_udp_connect(ngx_udp_connection_t *uc);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
53 static void ngx_resolver_cleanup(void *data);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
54 static void ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 static ngx_int_t ngx_resolve_name_locked(ngx_resolver_t *r,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 ngx_resolver_ctx_t *ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 static void ngx_resolver_expire(ngx_resolver_t *r, ngx_rbtree_t *tree,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 ngx_queue_t *queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 static ngx_int_t ngx_resolver_send_query(ngx_resolver_t *r,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 ngx_resolver_node_t *rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 static ngx_int_t ngx_resolver_create_name_query(ngx_resolver_node_t *rn,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 ngx_resolver_ctx_t *ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 static ngx_int_t ngx_resolver_create_addr_query(ngx_resolver_node_t *rn,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 ngx_resolver_ctx_t *ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 static void ngx_resolver_resend_handler(ngx_event_t *ev);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 static time_t ngx_resolver_resend(ngx_resolver_t *r, ngx_rbtree_t *tree,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 ngx_queue_t *queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 static void ngx_resolver_read_response(ngx_event_t *rev);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 static void ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 size_t n);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 static void ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n,
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
72 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, ngx_uint_t ans);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 static void ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
74 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 static ngx_resolver_node_t *ngx_resolver_lookup_name(ngx_resolver_t *r,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 ngx_str_t *name, uint32_t hash);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 static ngx_resolver_node_t *ngx_resolver_lookup_addr(ngx_resolver_t *r,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 in_addr_t addr);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 static void ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 static ngx_int_t ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 u_char *buf, u_char *src, u_char *last);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 static void ngx_resolver_timeout_handler(ngx_event_t *ev);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 static void ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 static void *ngx_resolver_alloc(ngx_resolver_t *r, size_t size);
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
86 static void *ngx_resolver_calloc(ngx_resolver_t *r, size_t size);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 static void ngx_resolver_free(ngx_resolver_t *r, void *p);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 static void *ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 /* STUB: ngx_peer_addr_t * */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 ngx_resolver_t *
540
c04fa65fe604 nginx 0.8.22
Igor Sysoev <http://sysoev.ru>
parents: 528
diff changeset
95 ngx_resolver_create(ngx_conf_t *cf, ngx_addr_t *addr)
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 ngx_resolver_t *r;
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
98 ngx_pool_cleanup_t *cln;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 ngx_udp_connection_t *uc;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
101 cln = ngx_pool_cleanup_add(cf->pool, 0);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
102 if (cln == NULL) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
103 return NULL;
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
104 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
105
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
106 cln->handler = ngx_resolver_cleanup;
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
107
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
108 r = ngx_calloc(sizeof(ngx_resolver_t), cf->log);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 if (r == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 return NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
113 cln->data = r;
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
114
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
115 r->event = ngx_calloc(sizeof(ngx_event_t), cf->log);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 if (r->event == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 return NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
120 ngx_rbtree_init(&r->name_rbtree, &r->name_sentinel,
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
121 ngx_resolver_rbtree_insert_value);
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
122
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
123 ngx_rbtree_init(&r->addr_rbtree, &r->addr_sentinel,
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
124 ngx_rbtree_insert_value);
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
125
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
126 ngx_queue_init(&r->name_resend_queue);
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
127 ngx_queue_init(&r->addr_resend_queue);
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
128
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
129 ngx_queue_init(&r->name_expire_queue);
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
130 ngx_queue_init(&r->addr_expire_queue);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 r->event->handler = ngx_resolver_resend_handler;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 r->event->data = r;
484
ed5e10fb40fc nginx 0.7.54
Igor Sysoev <http://sysoev.ru>
parents: 442
diff changeset
134 r->event->log = &cf->cycle->new_log;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 r->ident = -1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 r->resend_timeout = 5;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 r->expire = 30;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 r->valid = 300;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140
484
ed5e10fb40fc nginx 0.7.54
Igor Sysoev <http://sysoev.ru>
parents: 442
diff changeset
141 r->log = &cf->cycle->new_log;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142 r->log_level = NGX_LOG_ALERT;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
144 if (addr) {
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
145 uc = ngx_calloc(sizeof(ngx_udp_connection_t), cf->log);
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
146 if (uc == NULL) {
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
147 return NULL;
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
148 }
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
149
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
150 r->udp_connection = uc;
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
151
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
152 uc->sockaddr = addr->sockaddr;
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
153 uc->socklen = addr->socklen;
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
154 uc->server = addr->name;
484
ed5e10fb40fc nginx 0.7.54
Igor Sysoev <http://sysoev.ru>
parents: 442
diff changeset
155 uc->log = &cf->cycle->new_log;
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
156 }
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 return r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
162 static void
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
163 ngx_resolver_cleanup(void *data)
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
164 {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
165 ngx_resolver_t *r = data;
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
166
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
167 if (r) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
168 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
169 "cleanup resolver");
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
170
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
171 ngx_resolver_cleanup_tree(r, &r->name_rbtree);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
172
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
173 ngx_resolver_cleanup_tree(r, &r->addr_rbtree);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
174
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
175 if (r->event) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
176 ngx_free(r->event);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
177 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
178
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
179 if (r->udp_connection) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
180 if (r->udp_connection->connection) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
181 ngx_close_connection(r->udp_connection->connection);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
182 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
183
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
184 ngx_free(r->udp_connection);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
185 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
186
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
187 ngx_free(r);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
188 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
189 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
190
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
191
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
192 static void
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
193 ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree)
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
194 {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
195 ngx_resolver_ctx_t *ctx, *next;
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
196 ngx_resolver_node_t *rn;
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
197
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
198 while (tree->root != tree->sentinel) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
199
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
200 rn = (ngx_resolver_node_t *) ngx_rbtree_min(tree->root, tree->sentinel);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
201
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
202 ngx_queue_remove(&rn->queue);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
203
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
204 for (ctx = rn->waiting; ctx; ctx = next) {
376
edf1cb6c328e nginx 0.7.0
Igor Sysoev <http://sysoev.ru>
parents: 372
diff changeset
205 next = ctx->next;
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
206
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
207 if (ctx->event) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
208 ngx_resolver_free(r, ctx->event);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
209 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
210
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
211 ngx_resolver_free(r, ctx);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
212 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
213
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
214 ngx_rbtree_delete(tree, &rn->node);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
215
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
216 ngx_resolver_free_node(r, rn);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
217 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
218 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
219
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
220
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 ngx_resolver_ctx_t *
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 ngx_resolve_start(ngx_resolver_t *r, ngx_resolver_ctx_t *temp)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224 in_addr_t addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225 ngx_resolver_ctx_t *ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227 if (temp) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 addr = ngx_inet_addr(temp->name.data, temp->name.len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 if (addr != INADDR_NONE) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231 temp->resolver = r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 temp->state = NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 temp->naddrs = 1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 temp->addrs = &temp->addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 temp->addr = addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 temp->quick = 1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 return temp;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
242 if (r->udp_connection == NULL) {
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
243 return NGX_NO_RESOLVER;
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
244 }
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
245
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246 ctx = ngx_resolver_calloc(r, sizeof(ngx_resolver_ctx_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 if (ctx) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 ctx->resolver = r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 return ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256 ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 ngx_resolve_name(ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 ngx_int_t rc;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 ngx_resolver_t *r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262 r = ctx->resolver;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 "resolve: \"%V\"", &ctx->name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 if (ctx->quick) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 /* lock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 rc = ngx_resolve_name_locked(r, ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 if (rc == NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 if (rc == NGX_AGAIN) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
286 /* NGX_ERROR */
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288 if (ctx->event) {
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
289 ngx_resolver_free(r, ctx->event);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
292 ngx_resolver_free(r, ctx);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299 ngx_resolve_name_done(ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
301 uint32_t hash;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 ngx_resolver_t *r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 ngx_resolver_ctx_t *w, **p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 r = ctx->resolver;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
308 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309 "resolve name done: %i", ctx->state);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
310
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311 if (ctx->quick) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315 if (ctx->event && ctx->event->timer_set) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316 ngx_del_timer(ctx->event);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
318
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319 /* lock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323 hash = ngx_crc32_short(ctx->name.data, ctx->name.len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
324
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325 rn = ngx_resolver_lookup_name(r, &ctx->name, hash);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 if (rn) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328 p = &rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329 w = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 while (w) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 if (w == ctx) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333 *p = w->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335 goto done;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
336 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338 p = &w->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 w = w->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
342
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 ngx_log_error(NGX_LOG_ALERT, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344 "could not cancel %V resolving", &ctx->name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
345 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
347 done:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349 ngx_resolver_expire(r, &r->name_rbtree, &r->name_expire_queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
351 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
352
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
353 /* lock alloc mutex */
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
354
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
355 if (ctx->event) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
356 ngx_resolver_free_locked(r, ctx->event);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
357 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
358
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
359 ngx_resolver_free_locked(r, ctx);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
360
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
361 /* unlock alloc mutex */
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365 /* NGX_RESOLVE_A only */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 static ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368 ngx_resolve_name_locked(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
370 uint32_t hash;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
371 in_addr_t addr, *addrs;
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
372 ngx_int_t rc;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 ngx_uint_t naddrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374 ngx_resolver_ctx_t *next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
376
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
377 hash = ngx_crc32_short(ctx->name.data, ctx->name.len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
378
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
379 rn = ngx_resolver_lookup_name(r, &ctx->name, hash);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381 if (rn) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
382
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
383 if (rn->valid >= ngx_time()) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
384
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
385 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
386
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389 rn->expire = ngx_time() + r->expire;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
390
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393 naddrs = rn->naddrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
394
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
395 if (naddrs) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
396
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397 /* NGX_RESOLVE_A answer */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399 if (naddrs != 1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400 addr = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401 addrs = ngx_resolver_dup(r, rn->u.addrs,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402 naddrs * sizeof(in_addr_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403 if (addrs == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
405 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 addr = rn->u.addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409 addrs = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
411
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412 ctx->next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413 rn->waiting = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
416
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417 do {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418 ctx->state = NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419 ctx->naddrs = naddrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420 ctx->addrs = (naddrs == 1) ? &ctx->addr : addrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421 ctx->addr = addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422 next = ctx->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426 ctx = next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
427 } while (ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429 if (addrs) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430 ngx_resolver_free(r, addrs);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
431 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
436 /* NGX_RESOLVE_CNAME */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
438 if (ctx->recursion++ < NGX_RESOLVER_MAX_RECURSION) {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
439
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
440 ctx->name.len = rn->cnlen;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
441 ctx->name.data = rn->u.cname;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
442
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
443 return ngx_resolve_name_locked(r, ctx);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
444 }
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
445
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
446 ctx->next = rn->waiting;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
447 rn->waiting = NULL;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
448
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
449 /* unlock name mutex */
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
450
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
451 do {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
452 ctx->state = NGX_RESOLVE_NXDOMAIN;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
453 next = ctx->next;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
454
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
455 ctx->handler(ctx);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
456
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
457 ctx = next;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
458 } while (ctx);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
459
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
460 return NGX_OK;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 if (rn->waiting) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
464
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465 ctx->next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466 rn->waiting = ctx;
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
467 ctx->state = NGX_AGAIN;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
468
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
469 return NGX_AGAIN;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
471
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
472 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
473
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
474 /* lock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
475
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
476 ngx_resolver_free_locked(r, rn->query);
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
477 rn->query = NULL;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
478
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
479 if (rn->cnlen) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
480 ngx_resolver_free_locked(r, rn->u.cname);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
481 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
482
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
483 if (rn->naddrs > 1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
484 ngx_resolver_free_locked(r, rn->u.addrs);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
486
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
487 /* unlock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
488
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
489 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
491 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
492 if (rn == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
494 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496 rn->name = ngx_resolver_dup(r, ctx->name.data, ctx->name.len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497 if (rn->name == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498 ngx_resolver_free(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
501
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
502 rn->node.key = hash;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
503 rn->nlen = (u_short) ctx->name.len;
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
504 rn->query = NULL;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
505
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
506 ngx_rbtree_insert(&r->name_rbtree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
507 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
508
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
509 rc = ngx_resolver_create_name_query(rn, ctx);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
510
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
511 if (rc == NGX_ERROR) {
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
513 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
514
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
515 if (rc == NGX_DECLINED) {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
516 ngx_rbtree_delete(&r->name_rbtree, &rn->node);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
517
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
518 ngx_resolver_free(r, rn->query);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
519 ngx_resolver_free(r, rn->name);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
520 ngx_resolver_free(r, rn);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
521
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
522 ctx->state = NGX_RESOLVE_NXDOMAIN;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
523 ctx->handler(ctx);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
524
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
525 return NGX_OK;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
526 }
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
527
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
528 if (ngx_resolver_send_query(r, rn) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
529 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
530 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
531
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
532 if (ctx->event == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
533 ctx->event = ngx_resolver_calloc(r, sizeof(ngx_event_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
534 if (ctx->event == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
535 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
536 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
537
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
538 ctx->event->handler = ngx_resolver_timeout_handler;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
539 ctx->event->data = ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
540 ctx->event->log = r->log;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
541 ctx->ident = -1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
542
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
543 ngx_add_timer(ctx->event, ctx->timeout);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
544 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546 if (ngx_queue_empty(&r->name_resend_queue)) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547 ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
548 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
549
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
550 rn->expire = ngx_time() + r->resend_timeout;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
551
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
552 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
553
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
554 rn->cnlen = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
555 rn->naddrs = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
556 rn->valid = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
557 rn->waiting = ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
558
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
559 ctx->state = NGX_AGAIN;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
560
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
561 return NGX_AGAIN;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
562
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
563 failed:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
564
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
565 ngx_rbtree_delete(&r->name_rbtree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
566
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
567 if (rn->query) {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
568 ngx_resolver_free(r, rn->query);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
569 }
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
570
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
571 ngx_resolver_free(r, rn->name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
572
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
573 ngx_resolver_free(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
574
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
575 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
576 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
577
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
578
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
580 ngx_resolve_addr(ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
581 {
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
582 u_char *name;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
583 ngx_resolver_t *r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
584 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
585
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586 r = ctx->resolver;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
588 ctx->addr = ntohl(ctx->addr);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
589
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
590 /* lock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
591
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
592 rn = ngx_resolver_lookup_addr(r, ctx->addr);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
593
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
594 if (rn) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
595
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
596 if (rn->valid >= ngx_time()) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
597
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
598 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
599
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
600 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
601
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
602 rn->expire = ngx_time() + r->expire;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
603
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
604 ngx_queue_insert_head(&r->addr_expire_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
605
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
606 name = ngx_resolver_dup(r, rn->name, rn->nlen);
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
607 if (name == NULL) {
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
608 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
609 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
610
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
611 ctx->name.len = rn->nlen;
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
612 ctx->name.data = name;
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
613
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
614 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
615
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
616 ctx->state = NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
617
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
618 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
619
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
620 ngx_resolver_free(r, name);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
621
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
622 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
623 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
624
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
625 if (rn->waiting) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
626
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
627 ctx->next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
628 rn->waiting = ctx;
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
629 ctx->state = NGX_AGAIN;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
631 /* unlock addr mutex */
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
632
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
633 return NGX_OK;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
634 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
635
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
637
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
638 ngx_resolver_free(r, rn->query);
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
639 rn->query = NULL;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
640
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
641 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
642 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643 if (rn == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
644 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
645 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
646
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
647 rn->node.key = ctx->addr;
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
648 rn->query = NULL;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
649
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650 ngx_rbtree_insert(&r->addr_rbtree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
651 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
652
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
653 if (ngx_resolver_create_addr_query(rn, ctx) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
654 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
655 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
656
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
657 if (ngx_resolver_send_query(r, rn) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
658 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
659 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
660
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
661 ctx->event = ngx_resolver_calloc(r, sizeof(ngx_event_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
662 if (ctx->event == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
663 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
664 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
665
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
666 ctx->event->handler = ngx_resolver_timeout_handler;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
667 ctx->event->data = ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
668 ctx->event->log = r->log;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
669 ctx->ident = -1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
670
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
671 ngx_add_timer(ctx->event, ctx->timeout);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
672
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
673 if (ngx_queue_empty(&r->addr_resend_queue)) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
674 ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
675 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
676
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
677 rn->expire = ngx_time() + r->resend_timeout;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
678
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
679 ngx_queue_insert_head(&r->addr_resend_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
680
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
681 rn->cnlen = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
682 rn->naddrs = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
683 rn->name = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
684 rn->nlen = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
685 rn->valid = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
686 rn->waiting = ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
687
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
688 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
689
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
690 ctx->state = NGX_AGAIN;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
691
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
692 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
693
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694 failed:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 if (rn) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697 ngx_rbtree_delete(&r->addr_rbtree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
699 if (rn->query) {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
700 ngx_resolver_free(r, rn->query);
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
701 }
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
702
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
703 ngx_resolver_free(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
704 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
705
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
706 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
707
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
708 if (ctx->event) {
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
709 ngx_resolver_free(r, ctx->event);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
710 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
711
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
712 ngx_resolver_free(r, ctx);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
713
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
714 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
715 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
716
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
717
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
718 void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
719 ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
720 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
721 in_addr_t addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
722 ngx_resolver_t *r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
723 ngx_resolver_ctx_t *w, **p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
724 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
725
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
726 r = ctx->resolver;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
728 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
729 "resolve addr done: %i", ctx->state);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
730
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731 if (ctx->event && ctx->event->timer_set) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
732 ngx_del_timer(ctx->event);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
733 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
734
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
735 /* lock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
736
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
737 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
738
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
739 rn = ngx_resolver_lookup_addr(r, ctx->addr);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
740
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
741 if (rn) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
742 p = &rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
743 w = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
744
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
745 while (w) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
746 if (w == ctx) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
747 *p = w->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
748
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
749 goto done;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
750 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
751
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
752 p = &w->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
753 w = w->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
754 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
755 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
756
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
757 addr = ntohl(ctx->addr);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
758
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
759 ngx_log_error(NGX_LOG_ALERT, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760 "could not cancel %ud.%ud.%ud.%ud resolving",
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
761 (addr >> 24) & 0xff, (addr >> 16) & 0xff,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
762 (addr >> 8) & 0xff, addr & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
763 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
764
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
765 done:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
766
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
767 ngx_resolver_expire(r, &r->addr_rbtree, &r->addr_expire_queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
768
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
769 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
770
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
771 /* lock alloc mutex */
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
772
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
773 if (ctx->event) {
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
774 ngx_resolver_free_locked(r, ctx->event);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
775 }
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
776
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
777 ngx_resolver_free_locked(r, ctx);
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
778
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
779 /* unlock alloc mutex */
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
780 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
781
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
782
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784 ngx_resolver_expire(ngx_resolver_t *r, ngx_rbtree_t *tree, ngx_queue_t *queue)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
785 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
786 time_t now;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
787 ngx_uint_t i;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
788 ngx_queue_t *q;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
791 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver expire");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
792
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
793 now = ngx_time();
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
794
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
795 for (i = 0; i < 2; i++) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
796 if (ngx_queue_empty(queue)) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
797 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
798 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
799
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
800 q = ngx_queue_last(queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
801
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802 rn = ngx_queue_data(q, ngx_resolver_node_t, queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
803
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
804 if (now <= rn->expire) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
805 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
806 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
808 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
809 "resolver expire \"%*s\"", (size_t) rn->nlen, rn->name);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
810
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
811 ngx_queue_remove(q);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
812
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
813 ngx_rbtree_delete(tree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 ngx_resolver_free_node(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
816 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
817 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
818
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
819
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
820 static ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
821 ngx_resolver_send_query(ngx_resolver_t *r, ngx_resolver_node_t *rn)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
822 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
823 ssize_t n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824 ngx_udp_connection_t *uc;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
825
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
826 uc = r->udp_connection;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
827
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
828 if (uc->connection == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
829 if (ngx_udp_connect(uc) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
830 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
831 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
832
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
833 uc->connection->data = r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834 uc->connection->read->handler = ngx_resolver_read_response;
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
835 uc->connection->read->resolver = 1;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
836 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
837
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
838 n = ngx_send(uc->connection, rn->query, rn->qlen);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
839
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
840 if (n == -1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
841 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
842 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
843
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
844 if ((size_t) n != (size_t) rn->qlen) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
845 ngx_log_error(NGX_LOG_CRIT, uc->log, 0, "send() incomplete");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
846 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
850 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
851
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
852
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
853 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
854 ngx_resolver_resend_handler(ngx_event_t *ev)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
855 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
856 time_t timer, atimer, ntimer;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
857 ngx_resolver_t *r;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
858
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
859 r = ev->data;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
860
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
861 ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
862 "resolver resend handler");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
863
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
864 /* lock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
865
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
866 ntimer = ngx_resolver_resend(r, &r->name_rbtree, &r->name_resend_queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
867
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
868 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
869
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
870 /* lock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
871
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
872 atimer = ngx_resolver_resend(r, &r->addr_rbtree, &r->addr_resend_queue);
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
873
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
874 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
875
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
876 if (ntimer == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
877 timer = atimer;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
878
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
879 } else if (atimer == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
880 timer = ntimer;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
881
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
882 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
883 timer = (atimer < ntimer) ? atimer : ntimer;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
884 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
885
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
886 if (timer) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
887 ngx_add_timer(r->event, (ngx_msec_t) (timer * 1000));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
888 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
889 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
890
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
891
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
892 static time_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
893 ngx_resolver_resend(ngx_resolver_t *r, ngx_rbtree_t *tree, ngx_queue_t *queue)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
894 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
895 time_t now;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
896 ngx_queue_t *q;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
897 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
898
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
899 now = ngx_time();
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
900
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
901 for ( ;; ) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
902 if (ngx_queue_empty(queue)) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
903 return 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
904 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
905
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
906 q = ngx_queue_last(queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
907
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
908 rn = ngx_queue_data(q, ngx_resolver_node_t, queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
909
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
910 if (now < rn->expire) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
911 return rn->expire - now;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
912 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
913
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
914 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
915 "resolver resend \"%*s\" %p",
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
916 (size_t) rn->nlen, rn->name, rn->waiting);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
917
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
918 ngx_queue_remove(q);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
919
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
920 if (rn->waiting) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
921
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
922 if (ngx_resolver_send_query(r, rn) == NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
923
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
924 rn->expire = now + r->resend_timeout;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
925
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
926 ngx_queue_insert_head(queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
927 }
364
a39aab45a53f nginx 0.6.26
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
928
a39aab45a53f nginx 0.6.26
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
929 continue;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
930 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
931
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
932 ngx_rbtree_delete(tree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
933
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
934 ngx_resolver_free_node(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
935 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
936 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
937
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
938
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
939 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
940 ngx_resolver_read_response(ngx_event_t *rev)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
941 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
942 ssize_t n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
943 ngx_connection_t *c;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
944 u_char buf[NGX_RESOLVER_UDP_SIZE];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
945
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
946 c = rev->data;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
947
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
948 do {
354
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
949 n = ngx_udp_recv(c, buf, NGX_RESOLVER_UDP_SIZE);
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
950
583decdb82a4 nginx 0.6.21
Igor Sysoev <http://sysoev.ru>
parents: 350
diff changeset
951 if (n < 0) {
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
952 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
953 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
954
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
955 ngx_resolver_process_response(c->data, buf, n);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
956
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
957 } while (rev->ready);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
958 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
959
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
960
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
961 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
962 ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf, size_t n)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
963 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
964 char *err;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
965 size_t len;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
966 ngx_uint_t i, times, ident, qident, flags, code, nqs, nan,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
967 qtype, qclass;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
968 ngx_queue_t *q;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
969 ngx_resolver_qs_t *qs;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
970 ngx_resolver_node_t *rn;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
971 ngx_resolver_query_t *query;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
972
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
973 if ((size_t) n < sizeof(ngx_resolver_query_t)) {
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
974 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
975 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
976
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
977 query = (ngx_resolver_query_t *) buf;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
978
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
979 ident = (query->ident_hi << 8) + query->ident_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
980 flags = (query->flags_hi << 8) + query->flags_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
981 nqs = (query->nqs_hi << 8) + query->nqs_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
982 nan = (query->nan_hi << 8) + query->nan_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
983
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
984 ngx_log_debug6(NGX_LOG_DEBUG_CORE, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
985 "resolver DNS response %ui fl:%04Xui %ui/%ui/%ui/%ui",
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
986 ident, flags, nqs, nan,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
987 (query->nns_hi << 8) + query->nns_lo,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
988 (query->nar_hi << 8) + query->nar_lo);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
989
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
990 if (!(flags & 0x8000)) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
991 ngx_log_error(r->log_level, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
992 "invalid DNS response %ui fl:%04Xui", ident, flags);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
993 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
994 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
995
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
996 code = flags & 0x7f;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
997
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
998 if (code == NGX_RESOLVE_FORMERR) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
999
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1000 times = 0;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1001
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1002 for (q = ngx_queue_head(&r->name_resend_queue);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1003 q != ngx_queue_sentinel(&r->name_resend_queue) || times++ < 100;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1004 q = ngx_queue_next(q))
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1005 {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1006 rn = ngx_queue_data(q, ngx_resolver_node_t, queue);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1007 qident = (rn->query[0] << 8) + rn->query[1];
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1008
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1009 if (qident == ident) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1010 ngx_log_error(r->log_level, r->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1011 "DNS error (%ui: %s), query id:%ui, name:\"%*s\"",
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1012 code, ngx_resolver_strerror(code), ident,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1013 rn->nlen, rn->name);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1014 return;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1015 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1016 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1017
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1018 goto dns_error;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1019 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1020
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1021 if (code > NGX_RESOLVE_REFUSED) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1022 goto dns_error;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1023 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1024
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1025 if (nqs != 1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1026 err = "invalid number of questions in DNS response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1027 goto done;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1028 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1029
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1030 i = sizeof(ngx_resolver_query_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1031
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1032 while (i < (ngx_uint_t) n) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1033 if (buf[i] == '\0') {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1034 goto found;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1035 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1036
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1037 len = buf[i];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1038 i += 1 + len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1039 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1040
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1041 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1042
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1043 found:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1044
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1045 if (i++ == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1046 err = "zero-length domain name in DNS response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1047 goto done;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1048 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1049
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1050 if (i + sizeof(ngx_resolver_qs_t) + nan * (2 + sizeof(ngx_resolver_an_t))
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1051 > (ngx_uint_t) n)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1052 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1053 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1054 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1055
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1056 qs = (ngx_resolver_qs_t *) &buf[i];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1057
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1058 qtype = (qs->type_hi << 8) + qs->type_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1059 qclass = (qs->class_hi << 8) + qs->class_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1060
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1061 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1062 "resolver DNS response qt:%ui cl:%ui", qtype, qclass);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1063
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1064 if (qclass != 1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1065 ngx_log_error(r->log_level, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1066 "unknown query class %ui in DNS response", qclass);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1067 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1068 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1069
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1070 switch (qtype) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1071
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1072 case NGX_RESOLVE_A:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1073
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1074 ngx_resolver_process_a(r, buf, n, ident, code, nan,
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1075 i + sizeof(ngx_resolver_qs_t));
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1076
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1077 break;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1078
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1079 case NGX_RESOLVE_PTR:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1080
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1081 ngx_resolver_process_ptr(r, buf, n, ident, code, nan);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1082
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1083 break;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1084
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1085 default:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1086 ngx_log_error(r->log_level, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1087 "unknown query type %ui in DNS response", qtype);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1088 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1089 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1090
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1091 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1092
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1093 short_response:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1094
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1095 err = "short dns response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1096
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1097 done:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1098
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1099 ngx_log_error(r->log_level, r->log, 0, err);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1100
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1101 return;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1102
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1103 dns_error:
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1104
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1105 ngx_log_error(r->log_level, r->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1106 "DNS error (%ui: %s), query id:%ui",
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1107 code, ngx_resolver_strerror(code), ident);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 376
diff changeset
1108 return;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1109 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1110
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1111
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1112 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1113 ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t last,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1114 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, ngx_uint_t ans)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1115 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1116 char *err;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1117 u_char *cname;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1118 size_t len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1119 uint32_t hash;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1120 in_addr_t addr, *addrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1121 ngx_str_t name;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1122 ngx_uint_t qtype, qident, naddrs, a, i, n, start;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1123 ngx_resolver_an_t *an;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1124 ngx_resolver_ctx_t *ctx, *next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1125 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1126
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1127 if (ngx_resolver_copy(r, &name, buf, &buf[12], &buf[last]) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1128 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1129 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1130
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1131 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1132
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1133 hash = ngx_crc32_short(name.data, name.len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1134
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1135 /* lock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1136
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1137 rn = ngx_resolver_lookup_name(r, &name, hash);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1138
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1139 if (rn == NULL || rn->query == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1140 ngx_log_error(r->log_level, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1141 "unexpected response for %V", &name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1142 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1143 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1144
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1145 qident = (rn->query[0] << 8) + rn->query[1];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1146
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1147 if (ident != qident) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1148 ngx_log_error(r->log_level, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1149 "wrong ident %ui response for %V, expect %ui",
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1150 ident, &name, qident);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1151 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1152 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1153
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1154 ngx_resolver_free(r, name.data);
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1155
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1156 if (code == 0 && nan == 0) {
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1157 code = 3; /* NXDOMAIN */
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1158 }
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1159
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1160 if (code) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1161 next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1162 rn->waiting = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1163
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1164 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1165
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1166 ngx_rbtree_delete(&r->name_rbtree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1167
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1168 ngx_resolver_free_node(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1169
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1170 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1171
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1172 while (next) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1173 ctx = next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1174 ctx->state = code;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1175 next = ctx->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1176
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1177 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1178 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1179
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1180 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1181 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1182
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1183 i = ans;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1184 naddrs = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1185 addr = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1186 addrs = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1187 cname = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1188 qtype = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1189
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1190 for (a = 0; a < nan; a++) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1191
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1192 start = i;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1193
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1194 while (i < last) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1195
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1196 if (buf[i] & 0xc0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1197 i += 2;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1198 goto found;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1199 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1200
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1201 if (buf[i] == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1202 i++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1203 goto test_length;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1204 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1205
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1206 i += 1 + buf[i];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1207 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1208
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1209 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1210
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1211 test_length:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1212
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1213 if (i - start < 2) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1214 err = "invalid name in dns response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1215 goto invalid;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1216 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1217
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1218 found:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1219
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1220 if (i + sizeof(ngx_resolver_an_t) >= last) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1221 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1222 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1223
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1224 an = (ngx_resolver_an_t *) &buf[i];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1225
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1226 qtype = (an->type_hi << 8) + an->type_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1227 len = (an->len_hi << 8) + an->len_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1228
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1229 if (qtype == NGX_RESOLVE_A) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1230
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1231 i += sizeof(ngx_resolver_an_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1232
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1233 if (i + len > last) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1234 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1235 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1236
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1237 addr = htonl((buf[i] << 24) + (buf[i + 1] << 16)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1238 + (buf[i + 2] << 8) + (buf[i + 3]));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1239
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1240 naddrs++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1241
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1242 i += len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1243
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1244 } else if (qtype == NGX_RESOLVE_CNAME) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1245 cname = &buf[i] + sizeof(ngx_resolver_an_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1246 i += sizeof(ngx_resolver_an_t) + len;
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1247
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1248 } else if (qtype == NGX_RESOLVE_DNAME) {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1249 i += sizeof(ngx_resolver_an_t) + len;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1250
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1251 } else {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1252 ngx_log_error(r->log_level, r->log, 0,
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1253 "unexpected qtype %ui", qtype);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1254 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1255 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1256
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1257 ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1258 "resolver naddrs:%ui cname:%p", naddrs, cname);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1259
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1260 if (naddrs) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1261
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1262 if (naddrs == 1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1263 rn->u.addr = addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1264
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1265 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1266
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1267 addrs = ngx_resolver_alloc(r, naddrs * sizeof(in_addr_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1268 if (addrs == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1269 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1270 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1271
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1272 n = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1273 i = ans;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1274
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1275 for (a = 0; a < nan; a++) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1276
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1277 for ( ;; ) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1278
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1279 if (buf[i] & 0xc0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1280 i += 2;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1281 goto ok;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1282 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1283
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1284 if (buf[i] == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1285 i++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1286 goto ok;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1287 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1288
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1289 i += 1 + buf[i];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1290 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1291
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1292 ok:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1293
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1294 an = (ngx_resolver_an_t *) &buf[i];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1295
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1296 qtype = (an->type_hi << 8) + an->type_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1297 len = (an->len_hi << 8) + an->len_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1298
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1299 i += sizeof(ngx_resolver_an_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1300
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1301 if (qtype == NGX_RESOLVE_A) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1302
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1303 addrs[n++] = htonl((buf[i] << 24) + (buf[i + 1] << 16)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1304 + (buf[i + 2] << 8) + (buf[i + 3]));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1305
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1306 if (n == naddrs) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1307 break;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1308 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1309 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1310
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1311 i += len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1312 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1313
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1314 rn->u.addrs = addrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1315
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1316 addrs = ngx_resolver_dup(r, rn->u.addrs,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1317 naddrs * sizeof(in_addr_t));
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1318 if (addrs == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1319 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1320 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1321 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1322
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1323 rn->naddrs = (u_short) naddrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1324
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1325 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1326
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1327 rn->valid = ngx_time() + r->valid;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1328 rn->expire = ngx_time() + r->expire;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1329
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1330 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1331
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1332 next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1333 rn->waiting = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1334
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1335 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1336
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1337 while (next) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1338 ctx = next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1339 ctx->state = NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1340 ctx->naddrs = naddrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1341 ctx->addrs = (naddrs == 1) ? &ctx->addr : addrs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1342 ctx->addr = addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1343 next = ctx->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1344
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1345 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1346 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1347
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1348 if (naddrs > 1) {
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1349 ngx_resolver_free(r, addrs);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1350 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1351
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1352 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1353
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1354 } else if (cname) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1355
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1356 /* CNAME only */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1357
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1358 if (ngx_resolver_copy(r, &name, buf, cname, &buf[last]) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1359 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1360 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1361
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1362 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1363 "resolver cname:\"%V\"", &name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1364
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1365 ngx_queue_remove(&rn->queue);
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1366
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1367 rn->cnlen = (u_short) name.len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1368 rn->u.cname = name.data;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1369 rn->valid = ngx_time() + r->valid;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1370 rn->expire = ngx_time() + r->expire;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1371
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1372 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1373
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1374 ctx = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1375 rn->waiting = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1376
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1377 if (ctx) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1378 ctx->name = name;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1379
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1380 (void) ngx_resolve_name_locked(r, ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1381 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1382
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1383 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1384 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1385
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1386 ngx_log_error(r->log_level, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1387 "no A or CNAME types in DNS responses, unknown query type: %ui",
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1388 qtype);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1389 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1390
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1391 short_response:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1392
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1393 err = "short dns response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1394
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1395 invalid:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1396
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1397 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1398
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1399 ngx_log_error(r->log_level, r->log, 0, err);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1400
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1401 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1402
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1403 failed:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1404
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1405 /* unlock name mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1406
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1407 ngx_resolver_free(r, name.data);
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1408
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1409 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1410 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1411
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1412
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1413 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1414 ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1415 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan)
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1416 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1417 char *err;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1418 size_t len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1419 in_addr_t addr;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1420 ngx_int_t digit;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1421 ngx_str_t name;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1422 ngx_uint_t i, mask, qtype, qclass, qident;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1423 ngx_resolver_an_t *an;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1424 ngx_resolver_ctx_t *ctx, *next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1425 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1426
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1427 if (ngx_resolver_copy(r, NULL, buf, &buf[12], &buf[n]) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1428 goto invalid_in_addr_arpa;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1429 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1430
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1431 addr = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1432 i = 12;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1433
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1434 for (mask = 0; mask < 32; mask += 8) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1435 len = buf[i++];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1436
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1437 digit = ngx_atoi(&buf[i], len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1438 if (digit == NGX_ERROR || digit > 255) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1439 goto invalid_in_addr_arpa;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1440 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1441
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1442 addr += digit << mask;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1443 i += len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1444 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1445
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1446 if (ngx_strcmp(&buf[i], "\7in-addr\4arpa") != 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1447 goto invalid_in_addr_arpa;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1448 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1449
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1450 /* lock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1451
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1452 rn = ngx_resolver_lookup_addr(r, addr);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1453
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1454 if (rn == NULL || rn->query == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1455 ngx_log_error(r->log_level, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1456 "unexpected response for %ud.%ud.%ud.%ud",
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1457 (addr >> 24) & 0xff, (addr >> 16) & 0xff,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1458 (addr >> 8) & 0xff, addr & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1459 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1460 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1461
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1462 qident = (rn->query[0] << 8) + rn->query[1];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1463
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1464 if (ident != qident) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1465 ngx_log_error(r->log_level, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1466 "wrong ident %ui response for %ud.%ud.%ud.%ud, expect %ui",
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1467 ident, (addr >> 24) & 0xff, (addr >> 16) & 0xff,
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1468 (addr >> 8) & 0xff, addr & 0xff, qident);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1469 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1470 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1471
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1472 if (code == 0 && nan == 0) {
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1473 code = 3; /* NXDOMAIN */
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1474 }
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 354
diff changeset
1475
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1476 if (code) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1477 next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1478 rn->waiting = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1479
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1480 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1481
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1482 ngx_rbtree_delete(&r->addr_rbtree, &rn->node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1483
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1484 ngx_resolver_free_node(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1485
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1486 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1487
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1488 while (next) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1489 ctx = next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1490 ctx->state = code;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1491 next = ctx->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1492
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1493 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1494 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1495
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1496 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1497 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1498
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1499 i += sizeof("\7in-addr\4arpa") + sizeof(ngx_resolver_qs_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1500
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1501 if (i + 2 + sizeof(ngx_resolver_an_t) > (ngx_uint_t) n) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1502 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1503 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1504
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1505 /* compression pointer to "XX.XX.XX.XX.in-addr.arpa */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1506
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1507 if (buf[i] != 0xc0 || buf[i + 1] != 0x0c) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1508 err = "invalid in-addr.arpa name in DNS response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1509 goto invalid;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1510 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1511
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1512 an = (ngx_resolver_an_t *) &buf[i + 2];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1513
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1514 qtype = (an->type_hi << 8) + an->type_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1515 qclass = (an->class_hi << 8) + an->class_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1516 len = (an->len_hi << 8) + an->len_lo;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1517
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1518 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0,
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1519 "resolver qt:%ui cl:%ui len:%uz", qtype, qclass, len);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1520
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1521 i += 2 + sizeof(ngx_resolver_an_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1522
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1523 if (i + len > (ngx_uint_t) n) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1524 goto short_response;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1525 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1526
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1527 if (ngx_resolver_copy(r, &name, buf, &buf[i], &buf[n]) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1528 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1529 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1530
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1531 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver an:%V", &name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1532
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1533 if (name.len != (size_t) rn->nlen
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1534 || ngx_strncmp(name.data, rn->name, name.len) != 0)
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1535 {
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1536 if (rn->nlen) {
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1537 ngx_resolver_free(r, rn->name);
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1538 }
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1539
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1540 rn->nlen = (u_short) name.len;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1541 rn->name = name.data;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1542
442
670af56a1158 nginx 0.7.33
Igor Sysoev <http://sysoev.ru>
parents: 420
diff changeset
1543 name.data = ngx_resolver_dup(r, rn->name, name.len);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1544 if (name.data == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1545 goto failed;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1546 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1547 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1548
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1549 ngx_queue_remove(&rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1550
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1551 rn->valid = ngx_time() + r->valid;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1552 rn->expire = ngx_time() + r->expire;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1553
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1554 ngx_queue_insert_head(&r->addr_expire_queue, &rn->queue);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1555
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1556 next = rn->waiting;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1557 rn->waiting = NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1558
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1559 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1560
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1561 while (next) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1562 ctx = next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1563 ctx->state = NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1564 ctx->name = name;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1565 next = ctx->next;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1566
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1567 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1568 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1569
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1570 ngx_resolver_free(r, name.data);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1571
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1572 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1573
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1574 invalid_in_addr_arpa:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1575
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1576 ngx_log_error(r->log_level, r->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1577 "invalid in-addr.arpa name in DNS response");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1578 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1579
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1580 short_response:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1581
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1582 err = "short DNS response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1583
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1584 invalid:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1585
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1586 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1587
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1588 ngx_log_error(r->log_level, r->log, 0, err);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1589
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1590 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1591
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1592 failed:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1593
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1594 /* unlock addr mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1595
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1596 return;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1597 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1598
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1599
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1600 static ngx_resolver_node_t *
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1601 ngx_resolver_lookup_name(ngx_resolver_t *r, ngx_str_t *name, uint32_t hash)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1602 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1603 ngx_int_t rc;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1604 ngx_rbtree_node_t *node, *sentinel;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1605 ngx_resolver_node_t *rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1606
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1607 node = r->name_rbtree.root;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1608 sentinel = r->name_rbtree.sentinel;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1609
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1610 while (node != sentinel) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1611
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1612 if (hash < node->key) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1613 node = node->left;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1614 continue;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1615 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1616
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1617 if (hash > node->key) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1618 node = node->right;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1619 continue;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1620 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1621
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1622 /* hash == node->key */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1623
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1624 do {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1625 rn = (ngx_resolver_node_t *) node;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1626
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1627 rc = ngx_memn2cmp(name->data, rn->name, name->len, rn->nlen);
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1628
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1629 if (rc == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1630 return rn;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1631 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1632
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1633 node = (rc < 0) ? node->left : node->right;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1634
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1635 } while (node != sentinel && hash == node->key);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1636
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1637 break;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1638 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1639
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1640 /* not found */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1641
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1642 return NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1643 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1644
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1645
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1646 static ngx_resolver_node_t *
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1647 ngx_resolver_lookup_addr(ngx_resolver_t *r, in_addr_t addr)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1648 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1649 ngx_rbtree_node_t *node, *sentinel;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1650
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1651 node = r->addr_rbtree.root;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1652 sentinel = r->addr_rbtree.sentinel;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1653
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1654 while (node != sentinel) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1655
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1656 if (addr < node->key) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1657 node = node->left;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1658 continue;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1659 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1660
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1661 if (addr > node->key) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1662 node = node->right;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1663 continue;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1664 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1665
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1666 /* addr == node->key */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1667
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1668 return (ngx_resolver_node_t *) node;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1669 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1670
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1671 /* not found */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1672
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1673 return NULL;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1674 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1675
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1676
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1677 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1678 ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1679 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1680 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1681 ngx_rbtree_node_t **p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1682 ngx_resolver_node_t *rn, *rn_temp;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1683
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1684 for ( ;; ) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1685
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1686 if (node->key < temp->key) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1687
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1688 p = &temp->left;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1689
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1690 } else if (node->key > temp->key) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1691
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1692 p = &temp->right;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1693
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1694 } else { /* node->key == temp->key */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1695
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1696 rn = (ngx_resolver_node_t *) node;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1697 rn_temp = (ngx_resolver_node_t *) temp;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1698
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1699 p = (ngx_memn2cmp(rn->name, rn_temp->name, rn->nlen, rn_temp->nlen)
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 484
diff changeset
1700 < 0) ? &temp->left : &temp->right;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1701 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1702
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1703 if (*p == sentinel) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1704 break;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1705 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1706
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1707 temp = *p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1708 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1709
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1710 *p = node;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1711 node->parent = temp;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1712 node->left = sentinel;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1713 node->right = sentinel;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1714 ngx_rbt_red(node);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1715 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1716
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1717
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1718 static ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1719 ngx_resolver_create_name_query(ngx_resolver_node_t *rn, ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1720 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1721 u_char *p, *s;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1722 size_t len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1723 ngx_uint_t ident;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1724 ngx_resolver_qs_t *qs;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1725 ngx_resolver_query_t *query;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1726
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1727 len = sizeof(ngx_resolver_query_t)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1728 + 1 + ctx->name.len + 1 + sizeof(ngx_resolver_qs_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1729
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1730 p = ngx_resolver_calloc(ctx->resolver, len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1731 if (p == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1732 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1733 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1734
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1735 rn->qlen = (u_short) len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1736 rn->query = p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1737
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1738 query = (ngx_resolver_query_t *) p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1739
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1740 ident = ngx_random();
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1741
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1742 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->resolver->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1743 "resolve: \"%V\" %i", &ctx->name, ident & 0xffff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1744
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1745 query->ident_hi = (u_char) ((ident >> 8) & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1746 query->ident_lo = (u_char) (ident & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1747
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1748 /* recursion query */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1749 query->flags_hi = 1; query->flags_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1750
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1751 /* one question */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1752 query->nqs_hi = 0; query->nqs_lo = 1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1753 query->nan_hi = 0; query->nan_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1754 query->nns_hi = 0; query->nns_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1755 query->nar_hi = 0; query->nar_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1756
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1757 p += sizeof(ngx_resolver_query_t)
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1758 + ctx->name.len ? (1 + ctx->name.len + 1) : 1;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1759
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1760 qs = (ngx_resolver_qs_t *) p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1761
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1762 /* query type */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1763 qs->type_hi = 0; qs->type_lo = (u_char) ctx->type;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1764
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1765 /* IP query class */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1766 qs->class_hi = 0; qs->class_lo = 1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1767
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1768 /* convert "www.example.com" to "\3www\7example\3com\0" */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1769
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1770 len = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1771 p--;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1772 *p-- = '\0';
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1773
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1774 for (s = ctx->name.data + ctx->name.len - 1; s >= ctx->name.data; s--) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1775 if (*s != '.') {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1776 *p = *s;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1777 len++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1778
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1779 } else {
372
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1780 if (len == 0) {
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1781 return NGX_DECLINED;
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1782 }
6639b93e81b2 nginx 0.6.30
Igor Sysoev <http://sysoev.ru>
parents: 366
diff changeset
1783
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1784 *p = (u_char) len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1785 len = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1786 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1787
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1788 p--;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1789 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1790
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1791 *p = (u_char) len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1792
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1793 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1794 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1795
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1796
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1797 /* AF_INET only */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1798
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1799 static ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1800 ngx_resolver_create_addr_query(ngx_resolver_node_t *rn, ngx_resolver_ctx_t *ctx)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1801 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1802 u_char *p, *d;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1803 size_t len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1804 ngx_int_t n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1805 ngx_uint_t ident;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1806 ngx_resolver_query_t *query;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1807
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1808 len = sizeof(ngx_resolver_query_t)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1809 + sizeof(".255.255.255.255.in-addr.arpa.") - 1
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1810 + sizeof(ngx_resolver_qs_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1811
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1812 p = ngx_resolver_calloc(ctx->resolver, len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1813 if (p == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1814 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1815 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1816
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1817 rn->query = p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1818 query = (ngx_resolver_query_t *) p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1819
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1820 ident = ngx_random();
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1821
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1822 query->ident_hi = (u_char) ((ident >> 8) & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1823 query->ident_lo = (u_char) (ident & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1824
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1825 /* recursion query */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1826 query->flags_hi = 1; query->flags_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1827
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1828 /* one question */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1829 query->nqs_hi = 0; query->nqs_lo = 1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1830 query->nan_hi = 0; query->nan_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1831 query->nns_hi = 0; query->nns_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1832 query->nar_hi = 0; query->nar_lo = 0;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1833
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1834 p += sizeof(ngx_resolver_query_t);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1835
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1836 for (n = 0; n < 32; n += 8){
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1837 d = ngx_sprintf(&p[1], "%ud", (ctx->addr >> n) & 0xff);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1838 *p = (u_char) (d - &p[1]);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1839 p = d;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1840 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1841
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1842 /* query type "PTR", IP query class */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1843 ngx_memcpy(p, "\7in-addr\4arpa\0\0\14\0\1", 18);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1844
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1845 rn->qlen = (u_short)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1846 (p + sizeof("\7in-addr\4arpa") + sizeof(ngx_resolver_qs_t)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1847 - rn->query);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1848
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1849 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1850 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1851
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1852
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1853 static ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1854 ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1855 u_char *last)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1856 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1857 char *err;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1858 u_char *p, *dst;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1859 ssize_t len;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1860 ngx_uint_t i, n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1861
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1862 p = src;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1863 len = -1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1864
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1865 /*
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1866 * compression pointers allow to create endless loop, so we set limit;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1867 * 128 pointers should be enough to store 255-byte name
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1868 */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1869
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1870 for (i = 0; i < 128; i++) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1871 n = *p++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1872
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1873 if (n == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1874 goto done;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1875 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1876
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1877 if (n & 0xc0) {
420
ad0a34a8efa6 nginx 0.7.22
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1878 n = ((n & 0x3f) << 8) + *p;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1879 p = &buf[n];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1880
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1881 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1882 len += 1 + n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1883 p = &p[n];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1884 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1885
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1886 if (p >= last) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1887 err = "name is out of response";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1888 goto invalid;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1889 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1890 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1891
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1892 err = "compression pointers loop";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1893
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1894 invalid:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1895
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1896 ngx_log_error(r->log_level, r->log, 0, err);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1897
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1898 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1899
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1900 done:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1901
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1902 if (name == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1903 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1904 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1905
542
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1906 if (len == -1) {
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1907 name->len = 0;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1908 name->data = NULL;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1909 return NGX_OK;
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1910 }
2b9e388c61f1 nginx 0.8.23
Igor Sysoev <http://sysoev.ru>
parents: 540
diff changeset
1911
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1912 dst = ngx_resolver_alloc(r, len);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1913 if (dst == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1914 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1915 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1916
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1917 name->data = dst;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1918
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1919 n = *src++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1920
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1921 for ( ;; ) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1922 if (n != 0xc0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1923 ngx_memcpy(dst, src, n);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1924 dst += n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1925 src += n;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1926
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1927 n = *src++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1928
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1929 if (n != 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1930 *dst++ = '.';
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1931 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1932
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1933 } else {
420
ad0a34a8efa6 nginx 0.7.22
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1934 n = ((n & 0x3f) << 8) + *src;
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1935 src = &buf[n];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1936
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1937 n = *src++;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1938 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1939
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1940 if (n == 0) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1941 name->len = dst - name->data;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1942 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1943 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1944 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1945 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1946
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1947
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1948 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1949 ngx_resolver_timeout_handler(ngx_event_t *ev)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1950 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1951 ngx_resolver_ctx_t *ctx;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1952
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1953 ctx = ev->data;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1954
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1955 ctx->state = NGX_RESOLVE_TIMEDOUT;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1956
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1957 ctx->handler(ctx);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1958 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1959
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1960
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1961 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1962 ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1963 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1964 /* lock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1965
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1966 if (rn->query) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1967 ngx_resolver_free_locked(r, rn->query);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1968 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1969
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1970 if (rn->name) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1971 ngx_resolver_free_locked(r, rn->name);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1972 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1973
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1974 if (rn->cnlen) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1975 ngx_resolver_free_locked(r, rn->u.cname);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1976 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1977
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1978 if (rn->naddrs > 1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1979 ngx_resolver_free_locked(r, rn->u.addrs);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1980 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1981
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1982 ngx_resolver_free_locked(r, rn);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1983
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1984 /* unlock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1985 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1986
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1987
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1988 static void *
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1989 ngx_resolver_alloc(ngx_resolver_t *r, size_t size)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1990 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1991 u_char *p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1992
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1993 /* lock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1994
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1995 p = ngx_alloc(size, r->log);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1996
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1997 /* unlock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1998
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1999 return p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2000 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2001
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2002
366
babd3d9efb62 nginx 0.6.27
Igor Sysoev <http://sysoev.ru>
parents: 364
diff changeset
2003 static void *
350
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2004 ngx_resolver_calloc(ngx_resolver_t *r, size_t size)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2005 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2006 u_char *p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2007
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2008 p = ngx_resolver_alloc(r, size);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2009
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2010 if (p) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2011 ngx_memzero(p, size);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2012 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2013
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2014 return p;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2015 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2016
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2017
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2018 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2019 ngx_resolver_free(ngx_resolver_t *r, void *p)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2020 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2021 /* lock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2022
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2023 ngx_free(p);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2024
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2025 /* unlock alloc mutex */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2026 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2027
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2028
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2029 static void
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2030 ngx_resolver_free_locked(ngx_resolver_t *r, void *p)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2031 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2032 ngx_free(p);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2033 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2034
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2035
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2036 static void *
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2037 ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2038 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2039 void *dst;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2040
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2041 dst = ngx_resolver_alloc(r, size);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2042
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2043 if (dst == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2044 return dst;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2045 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2046
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2047 ngx_memcpy(dst, src, size);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2048
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2049 return dst;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2050 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2051
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2052
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2053 char *
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2054 ngx_resolver_strerror(ngx_int_t err)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2055 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2056 static char *errors[] = {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2057 "Format error", /* FORMERR */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2058 "Server failure", /* SERVFAIL */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2059 "Host not found", /* NXDOMAIN */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2060 "Unimplemented", /* NOTIMP */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2061 "Operation refused" /* REFUSED */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2062 };
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2063
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2064 if (err > 0 && err < 6) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2065 return errors[err - 1];
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2066 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2067
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2068 if (err == NGX_RESOLVE_TIMEDOUT) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2069 return "Operation timed out";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2070 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2071
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2072 return "Unknown error";
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2073 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2074
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2075
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2076 ngx_int_t
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2077 ngx_udp_connect(ngx_udp_connection_t *uc)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2078 {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2079 int rc;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2080 ngx_int_t event;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2081 ngx_event_t *rev, *wev;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2082 ngx_socket_t s;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2083 ngx_connection_t *c;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2084
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2085 s = ngx_socket(AF_INET, SOCK_DGRAM, 0);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2086
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2087 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, uc->log, 0, "UDP socket %d", s);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2088
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2089 if (s == -1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2090 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2091 ngx_socket_n " failed");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2092 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2093 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2094
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2095 c = ngx_get_connection(s, uc->log);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2096
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2097 if (c == NULL) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2098 if (ngx_close_socket(s) == -1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2099 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2100 ngx_close_socket_n "failed");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2101 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2102
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2103 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2104 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2105
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2106 if (ngx_nonblocking(s) == -1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2107 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2108 ngx_nonblocking_n " failed");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2109
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2110 ngx_free_connection(c);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2111
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2112 if (ngx_close_socket(s) == -1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2113 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2114 ngx_close_socket_n " failed");
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2115 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2116
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2117 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2118 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2119
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2120 rev = c->read;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2121 wev = c->write;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2122
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2123 rev->log = uc->log;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2124 wev->log = uc->log;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2125
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2126 uc->connection = c;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2127
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2128 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2129
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2130 #if (NGX_THREADS)
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2131
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2132 /* TODO: lock event when call completion handler */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2133
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2134 rev->lock = &c->lock;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2135 wev->lock = &c->lock;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2136 rev->own_lock = &c->lock;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2137 wev->own_lock = &c->lock;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2138
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2139 #endif
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2140
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2141 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, uc->log, 0,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2142 "connect to %V, fd:%d #%d", &uc->server, s, c->number);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2143
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2144 rc = connect(s, uc->sockaddr, uc->socklen);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2145
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2146 /* TODO: aio, iocp */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2147
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2148 if (rc == -1) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2149 ngx_log_error(NGX_LOG_CRIT, uc->log, ngx_socket_errno,
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2150 "connect() to %V failed", &uc->server);
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2151
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2152 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2153 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2154
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2155 /* UDP sockets are always ready to write */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2156 wev->ready = 1;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2157
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2158 if (ngx_add_event) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2159
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2160 event = (ngx_event_flags & NGX_USE_CLEAR_EVENT) ?
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2161 /* kqueue, epoll */ NGX_CLEAR_EVENT:
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2162 /* select, poll, /dev/poll */ NGX_LEVEL_EVENT;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2163 /* eventport event type has no meaning: oneshot only */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2164
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2165 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2166 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2167 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2168
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2169 } else {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2170 /* rtsig */
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2171
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2172 if (ngx_add_conn(c) == NGX_ERROR) {
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2173 return NGX_ERROR;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2174 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2175 }
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2176
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2177 return NGX_OK;
5a1bb0129dff nginx 0.6.19
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2178 }