forked from chronolaw/annotated_nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngx_resolver.h
242 lines (177 loc) · 6.22 KB
/
ngx_resolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#include <ngx_config.h>
#include <ngx_core.h>
#ifndef _NGX_RESOLVER_H_INCLUDED_
#define _NGX_RESOLVER_H_INCLUDED_
#define NGX_RESOLVE_A 1
#define NGX_RESOLVE_CNAME 5
#define NGX_RESOLVE_PTR 12
#define NGX_RESOLVE_MX 15
#define NGX_RESOLVE_TXT 16
#if (NGX_HAVE_INET6)
#define NGX_RESOLVE_AAAA 28
#endif
#define NGX_RESOLVE_SRV 33
#define NGX_RESOLVE_DNAME 39
#define NGX_RESOLVE_FORMERR 1
#define NGX_RESOLVE_SERVFAIL 2
#define NGX_RESOLVE_NXDOMAIN 3
#define NGX_RESOLVE_NOTIMP 4
#define NGX_RESOLVE_REFUSED 5
#define NGX_RESOLVE_TIMEDOUT NGX_ETIMEDOUT
#define NGX_NO_RESOLVER (void *) -1
#define NGX_RESOLVER_MAX_RECURSION 50
typedef struct ngx_resolver_s ngx_resolver_t;
typedef struct {
ngx_connection_t *udp;
ngx_connection_t *tcp;
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t server;
ngx_log_t log;
ngx_buf_t *read_buf;
ngx_buf_t *write_buf;
ngx_resolver_t *resolver;
} ngx_resolver_connection_t;
typedef struct ngx_resolver_ctx_s ngx_resolver_ctx_t;
typedef void (*ngx_resolver_handler_pt)(ngx_resolver_ctx_t *ctx);
typedef struct {
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_str_t name;
u_short priority;
u_short weight;
} ngx_resolver_addr_t;
typedef struct {
ngx_str_t name;
u_short priority;
u_short weight;
u_short port;
} ngx_resolver_srv_t;
typedef struct {
ngx_str_t name;
u_short priority;
u_short weight;
u_short port;
ngx_resolver_ctx_t *ctx;
ngx_int_t state;
ngx_uint_t naddrs;
ngx_addr_t *addrs;
} ngx_resolver_srv_name_t;
typedef struct {
ngx_rbtree_node_t node;
ngx_queue_t queue;
/* PTR: resolved name, A: name to resolve */
u_char *name;
#if (NGX_HAVE_INET6)
/* PTR: IPv6 address to resolve (IPv4 address is in rbtree node key) */
struct in6_addr addr6;
#endif
u_short nlen;
u_short qlen;
u_char *query;
#if (NGX_HAVE_INET6)
u_char *query6;
#endif
union {
in_addr_t addr;
in_addr_t *addrs;
u_char *cname;
ngx_resolver_srv_t *srvs;
} u;
u_char code;
u_short naddrs;
u_short nsrvs;
u_short cnlen;
#if (NGX_HAVE_INET6)
union {
struct in6_addr addr6;
struct in6_addr *addrs6;
} u6;
u_short naddrs6;
#endif
time_t expire;
time_t valid;
uint32_t ttl;
unsigned tcp:1;
#if (NGX_HAVE_INET6)
unsigned tcp6:1;
#endif
ngx_uint_t last_connection;
ngx_resolver_ctx_t *waiting;
} ngx_resolver_node_t;
struct ngx_resolver_s {
/* has to be pointer because of "incomplete type" */
ngx_event_t *event;
void *dummy;
ngx_log_t *log;
/* event ident must be after 3 pointers as in ngx_connection_t */
ngx_int_t ident;
/* simple round robin DNS peers balancer */
ngx_array_t connections;
ngx_uint_t last_connection;
ngx_rbtree_t name_rbtree;
ngx_rbtree_node_t name_sentinel;
ngx_rbtree_t srv_rbtree;
ngx_rbtree_node_t srv_sentinel;
ngx_rbtree_t addr_rbtree;
ngx_rbtree_node_t addr_sentinel;
ngx_queue_t name_resend_queue;
ngx_queue_t srv_resend_queue;
ngx_queue_t addr_resend_queue;
ngx_queue_t name_expire_queue;
ngx_queue_t srv_expire_queue;
ngx_queue_t addr_expire_queue;
unsigned ipv4:1;
#if (NGX_HAVE_INET6)
unsigned ipv6:1;
ngx_rbtree_t addr6_rbtree;
ngx_rbtree_node_t addr6_sentinel;
ngx_queue_t addr6_resend_queue;
ngx_queue_t addr6_expire_queue;
#endif
time_t resend_timeout;
time_t tcp_timeout;
time_t expire;
time_t valid;
ngx_uint_t log_level;
};
struct ngx_resolver_ctx_s {
ngx_resolver_ctx_t *next;
ngx_resolver_t *resolver;
ngx_resolver_node_t *node;
/* event ident must be after 3 pointers as in ngx_connection_t */
ngx_int_t ident;
ngx_int_t state;
ngx_str_t name;
ngx_str_t service;
time_t valid;
ngx_uint_t naddrs;
ngx_resolver_addr_t *addrs;
ngx_resolver_addr_t addr;
struct sockaddr_in sin;
ngx_uint_t count;
ngx_uint_t nsrvs;
ngx_resolver_srv_name_t *srvs;
ngx_resolver_handler_pt handler;
void *data;
ngx_msec_t timeout;
unsigned quick:1;
unsigned async:1;
unsigned cancelable:1;
ngx_uint_t recursion;
ngx_event_t *event;
};
ngx_resolver_t *ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names,
ngx_uint_t n);
ngx_resolver_ctx_t *ngx_resolve_start(ngx_resolver_t *r,
ngx_resolver_ctx_t *temp);
ngx_int_t ngx_resolve_name(ngx_resolver_ctx_t *ctx);
void ngx_resolve_name_done(ngx_resolver_ctx_t *ctx);
ngx_int_t ngx_resolve_addr(ngx_resolver_ctx_t *ctx);
void ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx);
char *ngx_resolver_strerror(ngx_int_t err);
#endif /* _NGX_RESOLVER_H_INCLUDED_ */