Mercurial > hg > nginx-quic
annotate src/core/ngx_resolver.h @ 6432:cf3e75cfa951
Added variables support to server_tokens.
It can now be set to "off" conditionally, e.g. using the map
directive.
An empty value will disable the emission of the Server: header
and the signature in error messages generated by nginx.
Any other value is treated as "on", meaning that full nginx
version is emitted in the Server: header and error messages
generated by nginx.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 15 Mar 2016 13:36:19 +0300 |
parents | 5a16d40c63de |
children | c94aba230a5a |
rev | line source |
---|---|
1649 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
1649 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 #ifndef _NGX_RESOLVER_H_INCLUDED_ | |
13 #define _NGX_RESOLVER_H_INCLUDED_ | |
14 | |
15 | |
16 #define NGX_RESOLVE_A 1 | |
17 #define NGX_RESOLVE_CNAME 5 | |
18 #define NGX_RESOLVE_PTR 12 | |
19 #define NGX_RESOLVE_MX 15 | |
20 #define NGX_RESOLVE_TXT 16 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
21 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
22 #define NGX_RESOLVE_AAAA 28 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
23 #endif |
1965 | 24 #define NGX_RESOLVE_DNAME 39 |
1649 | 25 |
26 #define NGX_RESOLVE_FORMERR 1 | |
27 #define NGX_RESOLVE_SERVFAIL 2 | |
28 #define NGX_RESOLVE_NXDOMAIN 3 | |
29 #define NGX_RESOLVE_NOTIMP 4 | |
30 #define NGX_RESOLVE_REFUSED 5 | |
31 #define NGX_RESOLVE_TIMEDOUT NGX_ETIMEDOUT | |
32 | |
33 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
34 #define NGX_NO_RESOLVER (void *) -1 |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
35 |
1969 | 36 #define NGX_RESOLVER_MAX_RECURSION 50 |
37 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
38 |
6367 | 39 typedef struct ngx_resolver_s ngx_resolver_t; |
40 | |
41 | |
1649 | 42 typedef struct { |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6364
diff
changeset
|
43 ngx_connection_t *udp; |
6367 | 44 ngx_connection_t *tcp; |
1649 | 45 struct sockaddr *sockaddr; |
46 socklen_t socklen; | |
47 ngx_str_t server; | |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3269
diff
changeset
|
48 ngx_log_t log; |
6367 | 49 ngx_buf_t *read_buf; |
50 ngx_buf_t *write_buf; | |
51 ngx_resolver_t *resolver; | |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6364
diff
changeset
|
52 } ngx_resolver_connection_t; |
1649 | 53 |
54 | |
55 typedef struct ngx_resolver_ctx_s ngx_resolver_ctx_t; | |
56 | |
57 typedef void (*ngx_resolver_handler_pt)(ngx_resolver_ctx_t *ctx); | |
58 | |
59 | |
60 typedef struct { | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
61 ngx_rbtree_node_t node; |
1649 | 62 ngx_queue_t queue; |
63 | |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
64 /* PTR: resolved name, A: name to resolve */ |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
65 u_char *name; |
1649 | 66 |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
67 #if (NGX_HAVE_INET6) |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
68 /* PTR: IPv6 address to resolve (IPv4 address is in rbtree node key) */ |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
69 struct in6_addr addr6; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
70 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
71 |
1649 | 72 u_short nlen; |
73 u_short qlen; | |
74 | |
75 u_char *query; | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
76 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
77 u_char *query6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
78 #endif |
1649 | 79 |
80 union { | |
81 in_addr_t addr; | |
82 in_addr_t *addrs; | |
83 u_char *cname; | |
84 } u; | |
85 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
86 u_char code; |
1649 | 87 u_short naddrs; |
88 u_short cnlen; | |
89 | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
90 #if (NGX_HAVE_INET6) |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
91 union { |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
92 struct in6_addr addr6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
93 struct in6_addr *addrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
94 } u6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
95 |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
96 u_short naddrs6; |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
97 #endif |
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
98 |
1649 | 99 time_t expire; |
100 time_t valid; | |
5477
98876ce2a7fd
Resolver: implemented IPv6 name to address resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5476
diff
changeset
|
101 uint32_t ttl; |
1649 | 102 |
6367 | 103 unsigned tcp:1; |
104 #if (NGX_HAVE_INET6) | |
105 unsigned tcp6:1; | |
106 #endif | |
107 | |
6366
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
108 ngx_uint_t last_connection; |
2e5c027f2a98
Resolver: per-request DNS server balancer.
Roman Arutyunyan <arut@nginx.com>
parents:
6365
diff
changeset
|
109 |
1649 | 110 ngx_resolver_ctx_t *waiting; |
111 } ngx_resolver_node_t; | |
112 | |
113 | |
6367 | 114 struct ngx_resolver_s { |
1649 | 115 /* has to be pointer because of "incomplete type" */ |
116 ngx_event_t *event; | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
117 void *dummy; |
1649 | 118 ngx_log_t *log; |
119 | |
5921
5004210e8c78
Resolver: fixed debug event logging.
Ruslan Ermilov <ru@nginx.com>
parents:
5478
diff
changeset
|
120 /* event ident must be after 3 pointers as in ngx_connection_t */ |
1649 | 121 ngx_int_t ident; |
122 | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
123 /* simple round robin DNS peers balancer */ |
6365
d35b4d590b2d
Resolver: renamed UDP-specific structures, fields and variables.
Roman Arutyunyan <arut@nginx.com>
parents:
6364
diff
changeset
|
124 ngx_array_t connections; |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
125 ngx_uint_t last_connection; |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
126 |
1649 | 127 ngx_rbtree_t name_rbtree; |
128 ngx_rbtree_node_t name_sentinel; | |
129 | |
130 ngx_rbtree_t addr_rbtree; | |
131 ngx_rbtree_node_t addr_sentinel; | |
132 | |
133 ngx_queue_t name_resend_queue; | |
134 ngx_queue_t addr_resend_queue; | |
135 | |
136 ngx_queue_t name_expire_queue; | |
137 ngx_queue_t addr_expire_queue; | |
138 | |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
139 #if (NGX_HAVE_INET6) |
5478
3cb3175a6fef
The "ipv6=" boolean parameter of the "resolver" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
140 ngx_uint_t ipv6; /* unsigned ipv6:1; */ |
5476
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
141 ngx_rbtree_t addr6_rbtree; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
142 ngx_rbtree_node_t addr6_sentinel; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
143 ngx_queue_t addr6_resend_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
144 ngx_queue_t addr6_expire_queue; |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
145 #endif |
950c9ed3e66f
Resolver: implemented IPv6 address to name resolving.
Ruslan Ermilov <ru@nginx.com>
parents:
5475
diff
changeset
|
146 |
1649 | 147 time_t resend_timeout; |
6367 | 148 time_t tcp_timeout; |
1649 | 149 time_t expire; |
150 time_t valid; | |
151 | |
152 ngx_uint_t log_level; | |
6367 | 153 }; |
1649 | 154 |
155 | |
156 struct ngx_resolver_ctx_s { | |
157 ngx_resolver_ctx_t *next; | |
158 ngx_resolver_t *resolver; | |
6364
69977457e1a6
Resolver: removed unused field from ngx_resolver_ctx_t.
Roman Arutyunyan <arut@nginx.com>
parents:
6351
diff
changeset
|
159 ngx_resolver_node_t *node; |
1649 | 160 |
6348
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
161 /* event ident must be after 3 pointers as in ngx_connection_t */ |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
162 ngx_int_t ident; |
7316c57e4fe7
Resolver: fixed crashes in timeout handler.
Ruslan Ermilov <ru@nginx.com>
parents:
5921
diff
changeset
|
163 |
1649 | 164 ngx_int_t state; |
165 ngx_str_t name; | |
166 | |
167 ngx_uint_t naddrs; | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
168 ngx_addr_t *addrs; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
169 ngx_addr_t addr; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
170 struct sockaddr_in sin; |
1649 | 171 |
172 ngx_resolver_handler_pt handler; | |
173 void *data; | |
174 ngx_msec_t timeout; | |
175 | |
176 ngx_uint_t quick; /* unsigned quick:1; */ | |
1969 | 177 ngx_uint_t recursion; |
1649 | 178 ngx_event_t *event; |
179 }; | |
180 | |
181 | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
182 ngx_resolver_t *ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
183 ngx_uint_t n); |
1649 | 184 ngx_resolver_ctx_t *ngx_resolve_start(ngx_resolver_t *r, |
185 ngx_resolver_ctx_t *temp); | |
186 ngx_int_t ngx_resolve_name(ngx_resolver_ctx_t *ctx); | |
187 void ngx_resolve_name_done(ngx_resolver_ctx_t *ctx); | |
188 ngx_int_t ngx_resolve_addr(ngx_resolver_ctx_t *ctx); | |
189 void ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx); | |
190 char *ngx_resolver_strerror(ngx_int_t err); | |
191 | |
192 | |
193 #endif /* _NGX_RESOLVER_H_INCLUDED_ */ |