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