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