Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail.c @ 6806:75dbab4ea930
Events: improved error event handling for UDP sockets.
Normally, the epoll module calls the read and write handlers depending
on whether EPOLLIN and EPOLLOUT are reported by epoll_wait(). No error
processing is done in the module, the handlers are expected to get an
error when doing I/O.
If an error event is reported without EPOLLIN and EPOLLOUT, the module
set both EPOLLIN and EPOLLOUT to ensure the error event is handled at
least in one active handler.
This works well unless the error is delivered along with only one of
EPOLLIN or EPOLLOUT, and the corresponding handler does not do any I/O.
For example, it happened when getting EPOLLERR|EPOLLOUT from
epoll_wait() upon receiving "ICMP port unreachable" while proxying UDP.
As the write handler had nothing to send it was not able to detect and
log an error, and did not switch to the next upstream.
The fix is to unconditionally set EPOLLIN and EPOLLOUT in case of an
error event. In the aforementioned case, this causes the read handler
to be called which does recv() and detects an error.
In addition to the epoll module, analogous changes were made in
devpoll/eventport/poll.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 21 Nov 2016 16:03:42 +0300 |
parents | cebf5fed00bf |
children | 6c13008ad503 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
6 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
1136 | 11 #include <ngx_mail.h> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
12 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
13 |
1136 | 14 static char *ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
15 static ngx_int_t ngx_mail_add_ports(ngx_conf_t *cf, ngx_array_t *ports, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
16 ngx_mail_listen_t *listen); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
17 static char *ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
18 static ngx_int_t ngx_mail_add_addrs(ngx_conf_t *cf, ngx_mail_port_t *mport, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
19 ngx_mail_conf_addr_t *addr); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
20 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
21 static ngx_int_t ngx_mail_add_addrs6(ngx_conf_t *cf, ngx_mail_port_t *mport, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
22 ngx_mail_conf_addr_t *addr); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
23 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
24 static ngx_int_t ngx_mail_cmp_conf_addrs(const void *one, const void *two); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 |
1136 | 27 ngx_uint_t ngx_mail_max_module; |
521 | 28 |
29 | |
1136 | 30 static ngx_command_t ngx_mail_commands[] = { |
31 | |
32 { ngx_string("mail"), | |
33 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
34 ngx_mail_block, | |
35 0, | |
36 0, | |
37 NULL }, | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 ngx_null_command |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 }; |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
577 | 42 |
1136 | 43 static ngx_core_module_t ngx_mail_module_ctx = { |
44 ngx_string("mail"), | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 NULL, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 NULL |
577 | 47 }; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 |
1136 | 50 ngx_module_t ngx_mail_module = { |
509 | 51 NGX_MODULE_V1, |
1136 | 52 &ngx_mail_module_ctx, /* module context */ |
53 ngx_mail_commands, /* module directives */ | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 NGX_CORE_MODULE, /* module type */ |
541 | 55 NULL, /* init master */ |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 NULL, /* init module */ |
541 | 57 NULL, /* init process */ |
58 NULL, /* init thread */ | |
59 NULL, /* exit thread */ | |
60 NULL, /* exit process */ | |
61 NULL, /* exit master */ | |
62 NGX_MODULE_V1_PADDING | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 }; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
64 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
65 |
521 | 66 static char * |
1136 | 67 ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
68 { |
521 | 69 char *rv; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
70 ngx_uint_t i, m, mi, s; |
521 | 71 ngx_conf_t pcf; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
72 ngx_array_t ports; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
73 ngx_mail_listen_t *listen; |
1136 | 74 ngx_mail_module_t *module; |
75 ngx_mail_conf_ctx_t *ctx; | |
76 ngx_mail_core_srv_conf_t **cscfp; | |
77 ngx_mail_core_main_conf_t *cmcf; | |
521 | 78 |
6193
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6173
diff
changeset
|
79 if (*(ngx_mail_conf_ctx_t **) conf) { |
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6173
diff
changeset
|
80 return "is duplicate"; |
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6173
diff
changeset
|
81 } |
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6173
diff
changeset
|
82 |
1136 | 83 /* the main mail context */ |
84 | |
85 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t)); | |
521 | 86 if (ctx == NULL) { |
87 return NGX_CONF_ERROR; | |
88 } | |
89 | |
1136 | 90 *(ngx_mail_conf_ctx_t **) conf = ctx; |
521 | 91 |
5978 | 92 /* count the number of the mail modules and set up their indices */ |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
93 |
6378
0f203a2af17c
Dynamic modules: moved module-related stuff to separate files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6193
diff
changeset
|
94 ngx_mail_max_module = ngx_count_modules(cf->cycle, NGX_MAIL_MODULE); |
521 | 95 |
96 | |
1136 | 97 /* the mail main_conf context, it is the same in the all mail contexts */ |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
98 |
521 | 99 ctx->main_conf = ngx_pcalloc(cf->pool, |
1136 | 100 sizeof(void *) * ngx_mail_max_module); |
521 | 101 if (ctx->main_conf == NULL) { |
102 return NGX_CONF_ERROR; | |
103 } | |
104 | |
105 | |
106 /* | |
1136 | 107 * the mail null srv_conf context, it is used to merge |
521 | 108 * the server{}s' srv_conf's |
109 */ | |
110 | |
1136 | 111 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module); |
521 | 112 if (ctx->srv_conf == NULL) { |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
113 return NGX_CONF_ERROR; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
114 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
115 |
521 | 116 |
117 /* | |
5808
a305a4477af0
Mail: fixed a comment.
Valentin Bartenev <vbart@nginx.com>
parents:
5266
diff
changeset
|
118 * create the main_conf's and the null srv_conf's of the all mail modules |
521 | 119 */ |
120 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
121 for (m = 0; cf->cycle->modules[m]; m++) { |
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
122 if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) { |
521 | 123 continue; |
124 } | |
125 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
126 module = cf->cycle->modules[m]->ctx; |
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
127 mi = cf->cycle->modules[m]->ctx_index; |
521 | 128 |
129 if (module->create_main_conf) { | |
130 ctx->main_conf[mi] = module->create_main_conf(cf); | |
131 if (ctx->main_conf[mi] == NULL) { | |
132 return NGX_CONF_ERROR; | |
133 } | |
134 } | |
135 | |
136 if (module->create_srv_conf) { | |
137 ctx->srv_conf[mi] = module->create_srv_conf(cf); | |
138 if (ctx->srv_conf[mi] == NULL) { | |
139 return NGX_CONF_ERROR; | |
140 } | |
141 } | |
142 } | |
143 | |
144 | |
1136 | 145 /* parse inside the mail{} block */ |
521 | 146 |
147 pcf = *cf; | |
148 cf->ctx = ctx; | |
149 | |
1136 | 150 cf->module_type = NGX_MAIL_MODULE; |
151 cf->cmd_type = NGX_MAIL_MAIN_CONF; | |
521 | 152 rv = ngx_conf_parse(cf, NULL); |
153 | |
154 if (rv != NGX_CONF_OK) { | |
155 *cf = pcf; | |
156 return rv; | |
157 } | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
158 |
521 | 159 |
1136 | 160 /* init mail{} main_conf's, merge the server{}s' srv_conf's */ |
521 | 161 |
1136 | 162 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; |
521 | 163 cscfp = cmcf->servers.elts; |
164 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
165 for (m = 0; cf->cycle->modules[m]; m++) { |
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
166 if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) { |
521 | 167 continue; |
168 } | |
169 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
170 module = cf->cycle->modules[m]->ctx; |
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6378
diff
changeset
|
171 mi = cf->cycle->modules[m]->ctx_index; |
521 | 172 |
1136 | 173 /* init mail{} main_conf's */ |
521 | 174 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
175 cf->ctx = ctx; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
176 |
521 | 177 if (module->init_main_conf) { |
577 | 178 rv = module->init_main_conf(cf, ctx->main_conf[mi]); |
521 | 179 if (rv != NGX_CONF_OK) { |
180 *cf = pcf; | |
181 return rv; | |
182 } | |
183 } | |
184 | |
185 for (s = 0; s < cmcf->servers.nelts; s++) { | |
577 | 186 |
521 | 187 /* merge the server{}s' srv_conf's */ |
577 | 188 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
189 cf->ctx = cscfp[s]->ctx; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
190 |
521 | 191 if (module->merge_srv_conf) { |
192 rv = module->merge_srv_conf(cf, | |
193 ctx->srv_conf[mi], | |
194 cscfp[s]->ctx->srv_conf[mi]); | |
195 if (rv != NGX_CONF_OK) { | |
196 *cf = pcf; | |
197 return rv; | |
198 } | |
199 } | |
200 } | |
201 } | |
202 | |
577 | 203 *cf = pcf; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
204 |
641 | 205 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
206 if (ngx_array_init(&ports, cf->temp_pool, 4, sizeof(ngx_mail_conf_port_t)) |
641 | 207 != NGX_OK) |
208 { | |
209 return NGX_CONF_ERROR; | |
210 } | |
211 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
212 listen = cmcf->listen.elts; |
641 | 213 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
214 for (i = 0; i < cmcf->listen.nelts; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
215 if (ngx_mail_add_ports(cf, &ports, &listen[i]) != NGX_OK) { |
641 | 216 return NGX_CONF_ERROR; |
217 } | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
218 } |
641 | 219 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
220 return ngx_mail_optimize_servers(cf, &ports); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
221 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
222 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
223 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
224 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
225 ngx_mail_add_ports(ngx_conf_t *cf, ngx_array_t *ports, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
226 ngx_mail_listen_t *listen) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
227 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
228 in_port_t p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
229 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
230 struct sockaddr *sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
231 ngx_mail_conf_port_t *port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
232 ngx_mail_conf_addr_t *addr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
233 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
234 sa = &listen->sockaddr.sockaddr; |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6560
diff
changeset
|
235 p = ngx_inet_get_port(sa); |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
236 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
237 port = ports->elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
238 for (i = 0; i < ports->nelts; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
239 if (p == port[i].port && sa->sa_family == port[i].family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
240 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
241 /* a port is already in the port list */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
242 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
243 port = &port[i]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
244 goto found; |
641 | 245 } |
246 } | |
247 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
248 /* add a port to the port list */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
249 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
250 port = ngx_array_push(ports); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
251 if (port == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
252 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
253 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
254 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
255 port->family = sa->sa_family; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
256 port->port = p; |
641 | 257 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
258 if (ngx_array_init(&port->addrs, cf->temp_pool, 2, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
259 sizeof(ngx_mail_conf_addr_t)) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
260 != NGX_OK) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
261 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
262 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
263 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
264 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
265 found: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
266 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
267 addr = ngx_array_push(&port->addrs); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
268 if (addr == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
269 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
270 } |
641 | 271 |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
272 addr->opt = *listen; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
273 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
274 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
275 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
276 |
641 | 277 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
278 static char * |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
279 ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
280 { |
6130 | 281 ngx_uint_t i, p, last, bind_wildcard; |
282 ngx_listening_t *ls; | |
283 ngx_mail_port_t *mport; | |
284 ngx_mail_conf_port_t *port; | |
285 ngx_mail_conf_addr_t *addr; | |
286 ngx_mail_core_srv_conf_t *cscf; | |
641 | 287 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
288 port = ports->elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
289 for (p = 0; p < ports->nelts; p++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
290 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
291 ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
292 sizeof(ngx_mail_conf_addr_t), ngx_mail_cmp_conf_addrs); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
293 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
294 addr = port[p].addrs.elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
295 last = port[p].addrs.nelts; |
641 | 296 |
297 /* | |
298 * if there is the binding to the "*:port" then we need to bind() | |
299 * to the "*:port" only and ignore the other bindings | |
300 */ | |
301 | |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
302 if (addr[last - 1].opt.wildcard) { |
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
303 addr[last - 1].opt.bind = 1; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
304 bind_wildcard = 1; |
641 | 305 |
306 } else { | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
307 bind_wildcard = 0; |
641 | 308 } |
309 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
310 i = 0; |
641 | 311 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
312 while (i < last) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
313 |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
314 if (bind_wildcard && !addr[i].opt.bind) { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
315 i++; |
641 | 316 continue; |
317 } | |
318 | |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
319 ls = ngx_create_listening(cf, &addr[i].opt.sockaddr.sockaddr, |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
320 addr[i].opt.socklen); |
641 | 321 if (ls == NULL) { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
322 return NGX_CONF_ERROR; |
2799
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
323 } |
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
324 |
641 | 325 ls->addr_ntop = 1; |
1136 | 326 ls->handler = ngx_mail_init_connection; |
641 | 327 ls->pool_size = 256; |
328 | |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
329 cscf = addr->opt.ctx->srv_conf[ngx_mail_core_module.ctx_index]; |
6130 | 330 |
331 ls->logp = cscf->error_log; | |
641 | 332 ls->log.data = &ls->addr_text; |
333 ls->log.handler = ngx_accept_log_error; | |
334 | |
6173 | 335 ls->backlog = addr[i].opt.backlog; |
336 | |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
337 ls->keepalive = addr[i].opt.so_keepalive; |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
338 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
339 ls->keepidle = addr[i].opt.tcp_keepidle; |
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
340 ls->keepintvl = addr[i].opt.tcp_keepintvl; |
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
341 ls->keepcnt = addr[i].opt.tcp_keepcnt; |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
342 #endif |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
343 |
6719
cebf5fed00bf
Modules compatibility: removed unneeded IPV6_V6ONLY checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6593
diff
changeset
|
344 #if (NGX_HAVE_INET6) |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
345 ls->ipv6only = addr[i].opt.ipv6only; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
346 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
347 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
348 mport = ngx_palloc(cf->pool, sizeof(ngx_mail_port_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
349 if (mport == NULL) { |
641 | 350 return NGX_CONF_ERROR; |
351 } | |
352 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
353 ls->servers = mport; |
641 | 354 |
6152
3c344ea7d88b
Simplified ngx_http_init_listening().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6142
diff
changeset
|
355 mport->naddrs = i + 1; |
641 | 356 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
357 switch (ls->sockaddr->sa_family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
358 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
359 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
360 if (ngx_mail_add_addrs6(cf, mport, addr) != NGX_OK) { |
641 | 361 return NGX_CONF_ERROR; |
362 } | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
363 break; |
2224 | 364 #endif |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
365 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
366 if (ngx_mail_add_addrs(cf, mport, addr) != NGX_OK) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
367 return NGX_CONF_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
368 } |
641 | 369 break; |
370 } | |
371 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
372 addr++; |
641 | 373 last--; |
374 } | |
375 } | |
376 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
377 return NGX_CONF_OK; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
378 } |
641 | 379 |
380 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
381 static ngx_int_t |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
382 ngx_mail_add_addrs(ngx_conf_t *cf, ngx_mail_port_t *mport, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
383 ngx_mail_conf_addr_t *addr) |
641 | 384 { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
385 u_char *p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
386 size_t len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
387 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
388 ngx_mail_in_addr_t *addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
389 struct sockaddr_in *sin; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
390 u_char buf[NGX_SOCKADDR_STRLEN]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
391 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
392 mport->addrs = ngx_pcalloc(cf->pool, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
393 mport->naddrs * sizeof(ngx_mail_in_addr_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
394 if (mport->addrs == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
395 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
396 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
397 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
398 addrs = mport->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
399 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
400 for (i = 0; i < mport->naddrs; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
401 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
402 sin = &addr[i].opt.sockaddr.sockaddr_in; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
403 addrs[i].addr = sin->sin_addr.s_addr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
404 |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
405 addrs[i].conf.ctx = addr[i].opt.ctx; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
406 #if (NGX_MAIL_SSL) |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
407 addrs[i].conf.ssl = addr[i].opt.ssl; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
408 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
409 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
410 len = ngx_sock_ntop(&addr[i].opt.sockaddr.sockaddr, addr[i].opt.socklen, |
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
411 buf, NGX_SOCKADDR_STRLEN, 1); |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
412 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
413 p = ngx_pnalloc(cf->pool, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
414 if (p == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
415 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
416 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
417 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
418 ngx_memcpy(p, buf, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
419 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
420 addrs[i].conf.addr_text.len = len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
421 addrs[i].conf.addr_text.data = p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
422 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
423 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
424 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
425 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
426 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
427 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
428 #if (NGX_HAVE_INET6) |
641 | 429 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
430 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
431 ngx_mail_add_addrs6(ngx_conf_t *cf, ngx_mail_port_t *mport, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
432 ngx_mail_conf_addr_t *addr) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
433 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
434 u_char *p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
435 size_t len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
436 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
437 ngx_mail_in6_addr_t *addrs6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
438 struct sockaddr_in6 *sin6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
439 u_char buf[NGX_SOCKADDR_STRLEN]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
440 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
441 mport->addrs = ngx_pcalloc(cf->pool, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
442 mport->naddrs * sizeof(ngx_mail_in6_addr_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
443 if (mport->addrs == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
444 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
445 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
446 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
447 addrs6 = mport->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
448 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
449 for (i = 0; i < mport->naddrs; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
450 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
451 sin6 = &addr[i].opt.sockaddr.sockaddr_in6; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
452 addrs6[i].addr6 = sin6->sin6_addr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
453 |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
454 addrs6[i].conf.ctx = addr[i].opt.ctx; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
455 #if (NGX_MAIL_SSL) |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
456 addrs6[i].conf.ssl = addr[i].opt.ssl; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
457 #endif |
641 | 458 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
459 len = ngx_sock_ntop(&addr[i].opt.sockaddr.sockaddr, addr[i].opt.socklen, |
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
460 buf, NGX_SOCKADDR_STRLEN, 1); |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
461 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
462 p = ngx_pnalloc(cf->pool, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
463 if (p == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
464 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
465 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
466 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
467 ngx_memcpy(p, buf, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
468 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
469 addrs6[i].conf.addr_text.len = len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
470 addrs6[i].conf.addr_text.data = p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
471 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
472 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
473 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
474 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
475 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
476 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
477 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
478 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
479 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
480 ngx_mail_cmp_conf_addrs(const void *one, const void *two) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
481 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
482 ngx_mail_conf_addr_t *first, *second; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
483 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
484 first = (ngx_mail_conf_addr_t *) one; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
485 second = (ngx_mail_conf_addr_t *) two; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
486 |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
487 if (first->opt.wildcard) { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
488 /* a wildcard must be the last resort, shift it to the end */ |
641 | 489 return 1; |
490 } | |
491 | |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
492 if (second->opt.wildcard) { |
4817
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
493 /* a wildcard must be the last resort, shift it to the end */ |
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
494 return -1; |
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
495 } |
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
496 |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
497 if (first->opt.bind && !second->opt.bind) { |
641 | 498 /* shift explicit bind()ed addresses to the start */ |
499 return -1; | |
500 } | |
501 | |
6171
f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6152
diff
changeset
|
502 if (!first->opt.bind && second->opt.bind) { |
641 | 503 /* shift explicit bind()ed addresses to the start */ |
504 return 1; | |
505 } | |
506 | |
507 /* do not sort by default */ | |
508 | |
509 return 0; | |
510 } |