Mercurial > hg > nginx
annotate src/mail/ngx_mail.c @ 4089:e27670e1ab70
mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 12 Sep 2011 09:38:04 +0000 |
parents | a96a8c916b0c |
children | c4513d4dd024 4919fb357a5d |
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 |
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
|
4 */ |
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 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
1136 | 10 #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
|
11 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
12 |
1136 | 13 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
|
14 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
|
15 ngx_mail_listen_t *listen); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
16 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
|
17 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
|
18 ngx_mail_conf_addr_t *addr); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
19 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
20 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
|
21 ngx_mail_conf_addr_t *addr); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
22 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
23 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
|
24 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
1136 | 26 ngx_uint_t ngx_mail_max_module; |
521 | 27 |
28 | |
1136 | 29 static ngx_command_t ngx_mail_commands[] = { |
30 | |
31 { ngx_string("mail"), | |
32 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
33 ngx_mail_block, | |
34 0, | |
35 0, | |
36 NULL }, | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 { ngx_string("imap"), |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
1136 | 40 ngx_mail_block, |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 0, |
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 NULL }, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 ngx_null_command |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 }; |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 |
577 | 48 |
1136 | 49 static ngx_core_module_t ngx_mail_module_ctx = { |
50 ngx_string("mail"), | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 NULL, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 NULL |
577 | 53 }; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
1136 | 56 ngx_module_t ngx_mail_module = { |
509 | 57 NGX_MODULE_V1, |
1136 | 58 &ngx_mail_module_ctx, /* module context */ |
59 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
|
60 NGX_CORE_MODULE, /* module type */ |
541 | 61 NULL, /* init master */ |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 NULL, /* init module */ |
541 | 63 NULL, /* init process */ |
64 NULL, /* init thread */ | |
65 NULL, /* exit thread */ | |
66 NULL, /* exit process */ | |
67 NULL, /* exit master */ | |
68 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
|
69 }; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
70 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
71 |
521 | 72 static char * |
1136 | 73 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
|
74 { |
521 | 75 char *rv; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
76 ngx_uint_t i, m, mi, s; |
521 | 77 ngx_conf_t pcf; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
78 ngx_array_t ports; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
79 ngx_mail_listen_t *listen; |
1136 | 80 ngx_mail_module_t *module; |
81 ngx_mail_conf_ctx_t *ctx; | |
82 ngx_mail_core_srv_conf_t **cscfp; | |
83 ngx_mail_core_main_conf_t *cmcf; | |
521 | 84 |
1136 | 85 if (cmd->name.data[0] == 'i') { |
86 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
87 "the \"imap\" directive is deprecated, " | |
88 "use the \"mail\" directive instead"); | |
89 } | |
521 | 90 |
1136 | 91 /* the main mail context */ |
92 | |
93 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t)); | |
521 | 94 if (ctx == NULL) { |
95 return NGX_CONF_ERROR; | |
96 } | |
97 | |
1136 | 98 *(ngx_mail_conf_ctx_t **) conf = ctx; |
521 | 99 |
100 /* count the number of the http 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
|
101 |
1136 | 102 ngx_mail_max_module = 0; |
521 | 103 for (m = 0; ngx_modules[m]; m++) { |
1136 | 104 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 105 continue; |
106 } | |
107 | |
1136 | 108 ngx_modules[m]->ctx_index = ngx_mail_max_module++; |
521 | 109 } |
110 | |
111 | |
1136 | 112 /* 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
|
113 |
521 | 114 ctx->main_conf = ngx_pcalloc(cf->pool, |
1136 | 115 sizeof(void *) * ngx_mail_max_module); |
521 | 116 if (ctx->main_conf == NULL) { |
117 return NGX_CONF_ERROR; | |
118 } | |
119 | |
120 | |
121 /* | |
1136 | 122 * the mail null srv_conf context, it is used to merge |
521 | 123 * the server{}s' srv_conf's |
124 */ | |
125 | |
1136 | 126 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module); |
521 | 127 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
|
128 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
|
129 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
130 |
521 | 131 |
132 /* | |
133 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
1136 | 134 * 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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
265 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
266 sin = (struct sockaddr_in *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
267 p = sin->sin_port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
268 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
269 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
270 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
271 port = ports->elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
272 for (i = 0; i < ports->nelts; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
273 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
|
274 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
275 /* a port is already in the port list */ |
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 = &port[i]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
278 goto found; |
641 | 279 } |
280 } | |
281 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
282 /* add a port to the port list */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
283 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
284 port = ngx_array_push(ports); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
285 if (port == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
286 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
287 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
288 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
289 port->family = sa->sa_family; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
290 port->port = p; |
641 | 291 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
292 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
|
293 sizeof(ngx_mail_conf_addr_t)) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
294 != NGX_OK) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
295 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
296 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
297 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
298 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
299 found: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
300 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
301 addr = ngx_array_push(&port->addrs); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
302 if (addr == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
303 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
304 } |
641 | 305 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
306 addr->sockaddr = (struct sockaddr *) &listen->sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
307 addr->socklen = listen->socklen; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
308 addr->ctx = listen->ctx; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
309 addr->bind = listen->bind; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
310 addr->wildcard = listen->wildcard; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
311 #if (NGX_MAIL_SSL) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
312 addr->ssl = listen->ssl; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
313 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
314 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
315 addr->ipv6only = listen->ipv6only; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
316 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
317 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
318 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
319 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
320 |
641 | 321 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
322 static char * |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
323 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
|
324 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
325 ngx_uint_t i, p, last, bind_wildcard; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
326 ngx_listening_t *ls; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
327 ngx_mail_port_t *mport; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
328 ngx_mail_conf_port_t *port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
329 ngx_mail_conf_addr_t *addr; |
641 | 330 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
331 port = ports->elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
332 for (p = 0; p < ports->nelts; p++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
333 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
334 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
|
335 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
|
336 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
337 addr = port[p].addrs.elts; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
338 last = port[p].addrs.nelts; |
641 | 339 |
340 /* | |
341 * if there is the binding to the "*:port" then we need to bind() | |
342 * to the "*:port" only and ignore the other bindings | |
343 */ | |
344 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
345 if (addr[last - 1].wildcard) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
346 addr[last - 1].bind = 1; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
347 bind_wildcard = 1; |
641 | 348 |
349 } else { | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
350 bind_wildcard = 0; |
641 | 351 } |
352 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
353 i = 0; |
641 | 354 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
355 while (i < last) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
356 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
357 if (bind_wildcard && !addr[i].bind) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
358 i++; |
641 | 359 continue; |
360 } | |
361 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
362 ls = ngx_create_listening(cf, addr[i].sockaddr, addr[i].socklen); |
641 | 363 if (ls == NULL) { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
364 return NGX_CONF_ERROR; |
2799
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
365 } |
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
366 |
641 | 367 ls->addr_ntop = 1; |
1136 | 368 ls->handler = ngx_mail_init_connection; |
641 | 369 ls->pool_size = 256; |
370 | |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
371 /* 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
|
372 ls->logp = &cf->cycle->new_log; |
641 | 373 ls->log.data = &ls->addr_text; |
374 ls->log.handler = ngx_accept_log_error; | |
375 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
376 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
377 ls->ipv6only = addr[i].ipv6only; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
378 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
379 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
380 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
|
381 if (mport == NULL) { |
641 | 382 return NGX_CONF_ERROR; |
383 } | |
384 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
385 ls->servers = mport; |
641 | 386 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
387 if (i == last - 1) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
388 mport->naddrs = last; |
641 | 389 |
390 } else { | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
391 mport->naddrs = 1; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
392 i = 0; |
641 | 393 } |
394 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
395 switch (ls->sockaddr->sa_family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
396 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
397 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
398 if (ngx_mail_add_addrs6(cf, mport, addr) != NGX_OK) { |
641 | 399 return NGX_CONF_ERROR; |
400 } | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
401 break; |
2224 | 402 #endif |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
403 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
404 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
|
405 return NGX_CONF_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
406 } |
641 | 407 break; |
408 } | |
409 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
410 addr++; |
641 | 411 last--; |
412 } | |
413 } | |
414 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
415 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
|
416 } |
641 | 417 |
418 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
419 static ngx_int_t |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
420 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
|
421 ngx_mail_conf_addr_t *addr) |
641 | 422 { |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
423 u_char *p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
424 size_t len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
425 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
426 ngx_mail_in_addr_t *addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
427 struct sockaddr_in *sin; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
428 u_char buf[NGX_SOCKADDR_STRLEN]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
429 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
430 mport->addrs = ngx_pcalloc(cf->pool, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
431 mport->naddrs * sizeof(ngx_mail_in_addr_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
432 if (mport->addrs == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
433 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
434 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
435 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
436 addrs = mport->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
437 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
438 for (i = 0; i < mport->naddrs; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
439 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
440 sin = (struct sockaddr_in *) addr[i].sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
441 addrs[i].addr = sin->sin_addr.s_addr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
442 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
443 addrs[i].conf.ctx = addr[i].ctx; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
444 #if (NGX_MAIL_SSL) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
445 addrs[i].conf.ssl = addr[i].ssl; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
446 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
447 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
448 len = ngx_sock_ntop(addr[i].sockaddr, buf, NGX_SOCKADDR_STRLEN, 1); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
449 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
450 p = ngx_pnalloc(cf->pool, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
451 if (p == 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 ngx_memcpy(p, buf, len); |
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 addrs[i].conf.addr_text.len = len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
458 addrs[i].conf.addr_text.data = p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
459 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
460 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
461 return NGX_OK; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
462 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
463 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
464 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
465 #if (NGX_HAVE_INET6) |
641 | 466 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
467 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
468 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
|
469 ngx_mail_conf_addr_t *addr) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
470 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
471 u_char *p; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
472 size_t len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
473 ngx_uint_t i; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
474 ngx_mail_in6_addr_t *addrs6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
475 struct sockaddr_in6 *sin6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
476 u_char buf[NGX_SOCKADDR_STRLEN]; |
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 mport->addrs = ngx_pcalloc(cf->pool, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
479 mport->naddrs * sizeof(ngx_mail_in6_addr_t)); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
480 if (mport->addrs == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
481 return NGX_ERROR; |
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 addrs6 = mport->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
485 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
486 for (i = 0; i < mport->naddrs; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
487 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
488 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
489 addrs6[i].addr6 = sin6->sin6_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 addrs6[i].conf.ctx = addr[i].ctx; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
492 #if (NGX_MAIL_SSL) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
493 addrs6[i].conf.ssl = addr[i].ssl; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
494 #endif |
641 | 495 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
496 len = ngx_sock_ntop(addr[i].sockaddr, buf, NGX_SOCKADDR_STRLEN, 1); |
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 p = ngx_pnalloc(cf->pool, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
499 if (p == NULL) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
500 return NGX_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
501 } |
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 ngx_memcpy(p, buf, len); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
504 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
505 addrs6[i].conf.addr_text.len = len; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
506 addrs6[i].conf.addr_text.data = p; |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
509 return NGX_OK; |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
512 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
513 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
514 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
515 static ngx_int_t |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
516 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
|
517 { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
518 ngx_mail_conf_addr_t *first, *second; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
519 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
520 first = (ngx_mail_conf_addr_t *) one; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
521 second = (ngx_mail_conf_addr_t *) two; |
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 if (first->wildcard) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
524 /* a wildcard must be the last resort, shift it to the end */ |
641 | 525 return 1; |
526 } | |
527 | |
528 if (first->bind && !second->bind) { | |
529 /* shift explicit bind()ed addresses to the start */ | |
530 return -1; | |
531 } | |
532 | |
533 if (!first->bind && second->bind) { | |
534 /* shift explicit bind()ed addresses to the start */ | |
535 return 1; | |
536 } | |
537 | |
538 /* do not sort by default */ | |
539 | |
540 return 0; | |
541 } |