Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail.c @ 6038:94ce52db3367
Removed stub implementation of win32 mutexes.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 23 Mar 2015 13:52:47 +0300 |
parents | eb4ba3800c31 |
children | fc99323a3d79 |
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_string("imap"), |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
1136 | 41 ngx_mail_block, |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 0, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 0, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 NULL }, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 ngx_null_command |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 }; |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
577 | 49 |
1136 | 50 static ngx_core_module_t ngx_mail_module_ctx = { |
51 ngx_string("mail"), | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 NULL, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 NULL |
577 | 54 }; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 |
1136 | 57 ngx_module_t ngx_mail_module = { |
509 | 58 NGX_MODULE_V1, |
1136 | 59 &ngx_mail_module_ctx, /* module context */ |
60 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
|
61 NGX_CORE_MODULE, /* module type */ |
541 | 62 NULL, /* init master */ |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 NULL, /* init module */ |
541 | 64 NULL, /* init process */ |
65 NULL, /* init thread */ | |
66 NULL, /* exit thread */ | |
67 NULL, /* exit process */ | |
68 NULL, /* exit master */ | |
69 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
|
70 }; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
71 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
72 |
521 | 73 static char * |
1136 | 74 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
|
75 { |
521 | 76 char *rv; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
77 ngx_uint_t i, m, mi, s; |
521 | 78 ngx_conf_t pcf; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
79 ngx_array_t ports; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
80 ngx_mail_listen_t *listen; |
1136 | 81 ngx_mail_module_t *module; |
82 ngx_mail_conf_ctx_t *ctx; | |
83 ngx_mail_core_srv_conf_t **cscfp; | |
84 ngx_mail_core_main_conf_t *cmcf; | |
521 | 85 |
1136 | 86 if (cmd->name.data[0] == 'i') { |
87 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
88 "the \"imap\" directive is deprecated, " | |
89 "use the \"mail\" directive instead"); | |
90 } | |
521 | 91 |
1136 | 92 /* the main mail context */ |
93 | |
94 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t)); | |
521 | 95 if (ctx == NULL) { |
96 return NGX_CONF_ERROR; | |
97 } | |
98 | |
1136 | 99 *(ngx_mail_conf_ctx_t **) conf = ctx; |
521 | 100 |
5978 | 101 /* 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
|
102 |
1136 | 103 ngx_mail_max_module = 0; |
521 | 104 for (m = 0; ngx_modules[m]; m++) { |
1136 | 105 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 106 continue; |
107 } | |
108 | |
1136 | 109 ngx_modules[m]->ctx_index = ngx_mail_max_module++; |
521 | 110 } |
111 | |
112 | |
1136 | 113 /* 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
|
114 |
521 | 115 ctx->main_conf = ngx_pcalloc(cf->pool, |
1136 | 116 sizeof(void *) * ngx_mail_max_module); |
521 | 117 if (ctx->main_conf == NULL) { |
118 return NGX_CONF_ERROR; | |
119 } | |
120 | |
121 | |
122 /* | |
1136 | 123 * the mail null srv_conf context, it is used to merge |
521 | 124 * the server{}s' srv_conf's |
125 */ | |
126 | |
1136 | 127 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module); |
521 | 128 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
|
129 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
|
130 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
131 |
521 | 132 |
133 /* | |
5808
a305a4477af0
Mail: fixed a comment.
Valentin Bartenev <vbart@nginx.com>
parents:
5266
diff
changeset
|
134 * create the main_conf's and the null srv_conf's of the all mail modules |
521 | 135 */ |
136 | |
137 for (m = 0; ngx_modules[m]; m++) { | |
1136 | 138 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 139 continue; |
140 } | |
141 | |
142 module = ngx_modules[m]->ctx; | |
143 mi = ngx_modules[m]->ctx_index; | |
144 | |
145 if (module->create_main_conf) { | |
146 ctx->main_conf[mi] = module->create_main_conf(cf); | |
147 if (ctx->main_conf[mi] == NULL) { | |
148 return NGX_CONF_ERROR; | |
149 } | |
150 } | |
151 | |
152 if (module->create_srv_conf) { | |
153 ctx->srv_conf[mi] = module->create_srv_conf(cf); | |
154 if (ctx->srv_conf[mi] == NULL) { | |
155 return NGX_CONF_ERROR; | |
156 } | |
157 } | |
158 } | |
159 | |
160 | |
1136 | 161 /* parse inside the mail{} block */ |
521 | 162 |
163 pcf = *cf; | |
164 cf->ctx = ctx; | |
165 | |
1136 | 166 cf->module_type = NGX_MAIL_MODULE; |
167 cf->cmd_type = NGX_MAIL_MAIN_CONF; | |
521 | 168 rv = ngx_conf_parse(cf, NULL); |
169 | |
170 if (rv != NGX_CONF_OK) { | |
171 *cf = pcf; | |
172 return rv; | |
173 } | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
174 |
521 | 175 |
1136 | 176 /* init mail{} main_conf's, merge the server{}s' srv_conf's */ |
521 | 177 |
1136 | 178 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; |
521 | 179 cscfp = cmcf->servers.elts; |
180 | |
181 for (m = 0; ngx_modules[m]; m++) { | |
1136 | 182 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 183 continue; |
184 } | |
185 | |
186 module = ngx_modules[m]->ctx; | |
187 mi = ngx_modules[m]->ctx_index; | |
188 | |
1136 | 189 /* init mail{} main_conf's */ |
521 | 190 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
191 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
|
192 |
521 | 193 if (module->init_main_conf) { |
577 | 194 rv = module->init_main_conf(cf, ctx->main_conf[mi]); |
521 | 195 if (rv != NGX_CONF_OK) { |
196 *cf = pcf; | |
197 return rv; | |
198 } | |
199 } | |
200 | |
201 for (s = 0; s < cmcf->servers.nelts; s++) { | |
577 | 202 |
521 | 203 /* merge the server{}s' srv_conf's */ |
577 | 204 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
205 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
|
206 |
521 | 207 if (module->merge_srv_conf) { |
208 rv = module->merge_srv_conf(cf, | |
209 ctx->srv_conf[mi], | |
210 cscfp[s]->ctx->srv_conf[mi]); | |
211 if (rv != NGX_CONF_OK) { | |
212 *cf = pcf; | |
213 return rv; | |
214 } | |
215 } | |
216 } | |
217 } | |
218 | |
577 | 219 *cf = pcf; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
220 |
641 | 221 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
222 if (ngx_array_init(&ports, cf->temp_pool, 4, sizeof(ngx_mail_conf_port_t)) |
641 | 223 != NGX_OK) |
224 { | |
225 return NGX_CONF_ERROR; | |
226 } | |
227 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
228 listen = cmcf->listen.elts; |
641 | 229 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
230 for (i = 0; i < cmcf->listen.nelts; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
231 if (ngx_mail_add_ports(cf, &ports, &listen[i]) != NGX_OK) { |
641 | 232 return NGX_CONF_ERROR; |
233 } | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
234 } |
641 | 235 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
236 return ngx_mail_optimize_servers(cf, &ports); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
237 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
238 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
239 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
240 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
241 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
|
242 ngx_mail_listen_t *listen) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
243 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
244 in_port_t p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
245 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
246 struct sockaddr *sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
247 struct sockaddr_in *sin; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
248 ngx_mail_conf_port_t *port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
249 ngx_mail_conf_addr_t *addr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
250 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
251 struct sockaddr_in6 *sin6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
252 #endif |
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 sa = (struct sockaddr *) &listen->sockaddr; |
641 | 255 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
256 switch (sa->sa_family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
257 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
258 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
259 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
260 sin6 = (struct sockaddr_in6 *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
261 p = sin6->sin6_port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
262 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
263 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
264 |
4819
49a3fb31a05c
Mail: fixed handling of AF_UNIX addresses in "listen".
Ruslan Ermilov <ru@nginx.com>
parents:
4817
diff
changeset
|
265 #if (NGX_HAVE_UNIX_DOMAIN) |
49a3fb31a05c
Mail: fixed handling of AF_UNIX addresses in "listen".
Ruslan Ermilov <ru@nginx.com>
parents:
4817
diff
changeset
|
266 case AF_UNIX: |
49a3fb31a05c
Mail: fixed handling of AF_UNIX addresses in "listen".
Ruslan Ermilov <ru@nginx.com>
parents:
4817
diff
changeset
|
267 p = 0; |
49a3fb31a05c
Mail: fixed handling of AF_UNIX addresses in "listen".
Ruslan Ermilov <ru@nginx.com>
parents:
4817
diff
changeset
|
268 break; |
49a3fb31a05c
Mail: fixed handling of AF_UNIX addresses in "listen".
Ruslan Ermilov <ru@nginx.com>
parents:
4817
diff
changeset
|
269 #endif |
49a3fb31a05c
Mail: fixed handling of AF_UNIX addresses in "listen".
Ruslan Ermilov <ru@nginx.com>
parents:
4817
diff
changeset
|
270 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
271 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
272 sin = (struct sockaddr_in *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
273 p = sin->sin_port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
274 break; |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
277 port = ports->elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
278 for (i = 0; i < ports->nelts; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
279 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
|
280 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
281 /* a port is already in the port list */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
282 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
283 port = &port[i]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
284 goto found; |
641 | 285 } |
286 } | |
287 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
288 /* add a port to the port list */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
289 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
290 port = ngx_array_push(ports); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
291 if (port == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
292 return NGX_ERROR; |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
295 port->family = sa->sa_family; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
296 port->port = p; |
641 | 297 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
298 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
|
299 sizeof(ngx_mail_conf_addr_t)) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
300 != NGX_OK) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
301 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
302 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
303 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
304 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
305 found: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
306 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
307 addr = ngx_array_push(&port->addrs); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
308 if (addr == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
309 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
310 } |
641 | 311 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
312 addr->sockaddr = (struct sockaddr *) &listen->sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
313 addr->socklen = listen->socklen; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
314 addr->ctx = listen->ctx; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
315 addr->bind = listen->bind; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
316 addr->wildcard = listen->wildcard; |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
317 addr->so_keepalive = listen->so_keepalive; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
318 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
319 addr->tcp_keepidle = listen->tcp_keepidle; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
320 addr->tcp_keepintvl = listen->tcp_keepintvl; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
321 addr->tcp_keepcnt = listen->tcp_keepcnt; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
322 #endif |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
323 #if (NGX_MAIL_SSL) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
324 addr->ssl = listen->ssl; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
325 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
326 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
327 addr->ipv6only = listen->ipv6only; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
328 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
329 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
330 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
331 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
332 |
641 | 333 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
334 static char * |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
335 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
|
336 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
337 ngx_uint_t i, p, last, bind_wildcard; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
338 ngx_listening_t *ls; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
339 ngx_mail_port_t *mport; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
340 ngx_mail_conf_port_t *port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
341 ngx_mail_conf_addr_t *addr; |
641 | 342 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
343 port = ports->elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
344 for (p = 0; p < ports->nelts; p++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
345 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
346 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
|
347 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
|
348 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
349 addr = port[p].addrs.elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
350 last = port[p].addrs.nelts; |
641 | 351 |
352 /* | |
353 * if there is the binding to the "*:port" then we need to bind() | |
354 * to the "*:port" only and ignore the other bindings | |
355 */ | |
356 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
357 if (addr[last - 1].wildcard) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
358 addr[last - 1].bind = 1; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
359 bind_wildcard = 1; |
641 | 360 |
361 } else { | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
362 bind_wildcard = 0; |
641 | 363 } |
364 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
365 i = 0; |
641 | 366 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
367 while (i < last) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
368 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
369 if (bind_wildcard && !addr[i].bind) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
370 i++; |
641 | 371 continue; |
372 } | |
373 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
374 ls = ngx_create_listening(cf, addr[i].sockaddr, addr[i].socklen); |
641 | 375 if (ls == NULL) { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
376 return NGX_CONF_ERROR; |
2799
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
377 } |
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
378 |
641 | 379 ls->addr_ntop = 1; |
1136 | 380 ls->handler = ngx_mail_init_connection; |
641 | 381 ls->pool_size = 256; |
382 | |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
383 /* TODO: error_log directive */ |
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
384 ls->logp = &cf->cycle->new_log; |
641 | 385 ls->log.data = &ls->addr_text; |
386 ls->log.handler = ngx_accept_log_error; | |
387 | |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
388 ls->keepalive = addr[i].so_keepalive; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
389 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
390 ls->keepidle = addr[i].tcp_keepidle; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
391 ls->keepintvl = addr[i].tcp_keepintvl; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
392 ls->keepcnt = addr[i].tcp_keepcnt; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
393 #endif |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
2855
diff
changeset
|
394 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
395 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
396 ls->ipv6only = addr[i].ipv6only; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
397 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
398 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
399 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
|
400 if (mport == NULL) { |
641 | 401 return NGX_CONF_ERROR; |
402 } | |
403 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
404 ls->servers = mport; |
641 | 405 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
406 if (i == last - 1) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
407 mport->naddrs = last; |
641 | 408 |
409 } else { | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
410 mport->naddrs = 1; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
411 i = 0; |
641 | 412 } |
413 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
414 switch (ls->sockaddr->sa_family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
415 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
416 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
417 if (ngx_mail_add_addrs6(cf, mport, addr) != NGX_OK) { |
641 | 418 return NGX_CONF_ERROR; |
419 } | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
420 break; |
2224 | 421 #endif |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
422 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
423 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
|
424 return NGX_CONF_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
425 } |
641 | 426 break; |
427 } | |
428 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
429 addr++; |
641 | 430 last--; |
431 } | |
432 } | |
433 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
434 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
|
435 } |
641 | 436 |
437 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
438 static ngx_int_t |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
439 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
|
440 ngx_mail_conf_addr_t *addr) |
641 | 441 { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
442 u_char *p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
443 size_t len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
444 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
445 ngx_mail_in_addr_t *addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
446 struct sockaddr_in *sin; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
447 u_char buf[NGX_SOCKADDR_STRLEN]; |
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 mport->addrs = ngx_pcalloc(cf->pool, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
450 mport->naddrs * sizeof(ngx_mail_in_addr_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
451 if (mport->addrs == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
452 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
453 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
454 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
455 addrs = mport->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
456 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
457 for (i = 0; i < mport->naddrs; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
458 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
459 sin = (struct sockaddr_in *) addr[i].sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
460 addrs[i].addr = sin->sin_addr.s_addr; |
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 addrs[i].conf.ctx = addr[i].ctx; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
463 #if (NGX_MAIL_SSL) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
464 addrs[i].conf.ssl = addr[i].ssl; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
465 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
466 |
5266 | 467 len = ngx_sock_ntop(addr[i].sockaddr, addr[i].socklen, buf, |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
4819
diff
changeset
|
468 NGX_SOCKADDR_STRLEN, 1); |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
469 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
470 p = ngx_pnalloc(cf->pool, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
471 if (p == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
472 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
473 } |
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 ngx_memcpy(p, buf, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
476 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
477 addrs[i].conf.addr_text.len = len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
478 addrs[i].conf.addr_text.data = p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
479 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
480 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
481 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
482 } |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
485 #if (NGX_HAVE_INET6) |
641 | 486 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
487 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
488 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
|
489 ngx_mail_conf_addr_t *addr) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
490 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
491 u_char *p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
492 size_t len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
493 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
494 ngx_mail_in6_addr_t *addrs6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
495 struct sockaddr_in6 *sin6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
496 u_char buf[NGX_SOCKADDR_STRLEN]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
497 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
498 mport->addrs = ngx_pcalloc(cf->pool, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
499 mport->naddrs * sizeof(ngx_mail_in6_addr_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
500 if (mport->addrs == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
501 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
502 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
503 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
504 addrs6 = mport->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
505 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
506 for (i = 0; i < mport->naddrs; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
507 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
508 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
509 addrs6[i].addr6 = sin6->sin6_addr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
510 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
511 addrs6[i].conf.ctx = addr[i].ctx; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
512 #if (NGX_MAIL_SSL) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
513 addrs6[i].conf.ssl = addr[i].ssl; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
514 #endif |
641 | 515 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
4819
diff
changeset
|
516 len = ngx_sock_ntop(addr[i].sockaddr, addr[i].socklen, buf, |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
4819
diff
changeset
|
517 NGX_SOCKADDR_STRLEN, 1); |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
518 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
519 p = ngx_pnalloc(cf->pool, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
520 if (p == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
521 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
522 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
523 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
524 ngx_memcpy(p, buf, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
525 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
526 addrs6[i].conf.addr_text.len = len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
527 addrs6[i].conf.addr_text.data = p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
528 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
529 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
530 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
531 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
532 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
533 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
534 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
535 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
536 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
537 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
|
538 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
539 ngx_mail_conf_addr_t *first, *second; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
540 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
541 first = (ngx_mail_conf_addr_t *) one; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
542 second = (ngx_mail_conf_addr_t *) two; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
543 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
544 if (first->wildcard) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
545 /* a wildcard must be the last resort, shift it to the end */ |
641 | 546 return 1; |
547 } | |
548 | |
4817
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
549 if (second->wildcard) { |
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
550 /* 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
|
551 return -1; |
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
552 } |
d794e59800ef
Mail: fixed sorting of listen addresses (ticket #187).
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
553 |
641 | 554 if (first->bind && !second->bind) { |
555 /* shift explicit bind()ed addresses to the start */ | |
556 return -1; | |
557 } | |
558 | |
559 if (!first->bind && second->bind) { | |
560 /* shift explicit bind()ed addresses to the start */ | |
561 return 1; | |
562 } | |
563 | |
564 /* do not sort by default */ | |
565 | |
566 return 0; | |
567 } |