Mercurial > hg > nginx-quic
annotate src/core/ngx_resolver.h @ 4569:1db899642518
Upstream: reject upstreams without normal servers.
Such upstreams cause CPU hog later in the code as number of peers isn't
expected to be 0. Currently this may happen either if there are only backup
servers defined in an upstream block, or if server with ipv6 address used
in an upstream block.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 02 Apr 2012 21:29:35 +0000 |
parents | d620f497c50f |
children | 07dd5bd222ac |
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 | |
1965 | 21 #define NGX_RESOLVE_DNAME 39 |
1649 | 22 |
23 #define NGX_RESOLVE_FORMERR 1 | |
24 #define NGX_RESOLVE_SERVFAIL 2 | |
25 #define NGX_RESOLVE_NXDOMAIN 3 | |
26 #define NGX_RESOLVE_NOTIMP 4 | |
27 #define NGX_RESOLVE_REFUSED 5 | |
28 #define NGX_RESOLVE_TIMEDOUT NGX_ETIMEDOUT | |
29 | |
30 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
31 #define NGX_NO_RESOLVER (void *) -1 |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
32 |
1969 | 33 #define NGX_RESOLVER_MAX_RECURSION 50 |
34 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1649
diff
changeset
|
35 |
1649 | 36 typedef struct { |
37 ngx_connection_t *connection; | |
38 struct sockaddr *sockaddr; | |
39 socklen_t socklen; | |
40 ngx_str_t server; | |
3408
71193a456616
add context to a resolver log
Igor Sysoev <igor@sysoev.ru>
parents:
3269
diff
changeset
|
41 ngx_log_t log; |
1649 | 42 } ngx_udp_connection_t; |
43 | |
44 | |
45 typedef struct ngx_resolver_ctx_s ngx_resolver_ctx_t; | |
46 | |
47 typedef void (*ngx_resolver_handler_pt)(ngx_resolver_ctx_t *ctx); | |
48 | |
49 | |
50 typedef struct { | |
51 ngx_rbtree_node_t node; | |
52 ngx_queue_t queue; | |
53 | |
54 /* PTR: resolved name, A: name to resolve */ | |
55 u_char *name; | |
56 | |
57 u_short nlen; | |
58 u_short qlen; | |
59 | |
60 u_char *query; | |
61 | |
62 union { | |
63 in_addr_t addr; | |
64 in_addr_t *addrs; | |
65 u_char *cname; | |
66 } u; | |
67 | |
68 u_short naddrs; | |
69 u_short cnlen; | |
70 | |
71 time_t expire; | |
72 time_t valid; | |
73 | |
74 ngx_resolver_ctx_t *waiting; | |
75 } ngx_resolver_node_t; | |
76 | |
77 | |
78 typedef struct { | |
79 /* has to be pointer because of "incomplete type" */ | |
80 ngx_event_t *event; | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
81 void *dummy; |
1649 | 82 ngx_log_t *log; |
83 | |
84 /* ident must be after 3 pointers */ | |
85 ngx_int_t ident; | |
86 | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
87 /* simple round robin DNS peers balancer */ |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
88 ngx_array_t udp_connections; |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
89 ngx_uint_t last_connection; |
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
90 |
1649 | 91 ngx_rbtree_t name_rbtree; |
92 ngx_rbtree_node_t name_sentinel; | |
93 | |
94 ngx_rbtree_t addr_rbtree; | |
95 ngx_rbtree_node_t addr_sentinel; | |
96 | |
97 ngx_queue_t name_resend_queue; | |
98 ngx_queue_t addr_resend_queue; | |
99 | |
100 ngx_queue_t name_expire_queue; | |
101 ngx_queue_t addr_expire_queue; | |
102 | |
103 time_t resend_timeout; | |
104 time_t expire; | |
105 time_t valid; | |
106 | |
107 ngx_uint_t log_level; | |
108 } ngx_resolver_t; | |
109 | |
110 | |
111 struct ngx_resolver_ctx_s { | |
112 ngx_resolver_ctx_t *next; | |
113 ngx_resolver_t *resolver; | |
114 ngx_udp_connection_t *udp_connection; | |
115 | |
116 /* ident must be after 3 pointers */ | |
117 ngx_int_t ident; | |
118 | |
119 ngx_int_t state; | |
120 ngx_int_t type; | |
121 ngx_str_t name; | |
122 | |
123 ngx_uint_t naddrs; | |
124 in_addr_t *addrs; | |
125 in_addr_t addr; | |
126 | |
127 ngx_resolver_handler_pt handler; | |
128 void *data; | |
129 ngx_msec_t timeout; | |
130 | |
131 ngx_uint_t quick; /* unsigned quick:1; */ | |
1969 | 132 ngx_uint_t recursion; |
1649 | 133 ngx_event_t *event; |
134 }; | |
135 | |
136 | |
4225
016352c19049
Support of several servers in the "resolver" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3408
diff
changeset
|
137 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
|
138 ngx_uint_t n); |
1649 | 139 ngx_resolver_ctx_t *ngx_resolve_start(ngx_resolver_t *r, |
140 ngx_resolver_ctx_t *temp); | |
141 ngx_int_t ngx_resolve_name(ngx_resolver_ctx_t *ctx); | |
142 void ngx_resolve_name_done(ngx_resolver_ctx_t *ctx); | |
143 ngx_int_t ngx_resolve_addr(ngx_resolver_ctx_t *ctx); | |
144 void ngx_resolve_addr_done(ngx_resolver_ctx_t *ctx); | |
145 char *ngx_resolver_strerror(ngx_int_t err); | |
146 | |
147 | |
148 #endif /* _NGX_RESOLVER_H_INCLUDED_ */ |