comparison src/mail/ngx_mail_core_module.c @ 492:98143f74eb3d NGINX_0_7_58

nginx 0.7.58 *) Feature: a "listen" directive of the mail proxy module supports IPv6. *) Feature: the "image_filter_jpeg_quality" directive. *) Feature: the "client_body_in_single_buffer" directive. *) Feature: the $request_body variable. *) Bugfix: in ngx_http_autoindex_module in file name links having a ":" symbol in the name. *) Bugfix: "make upgrade" procedure did not work; the bug had appeared in 0.7.53. Thanks to Denis F. Latypoff.
author Igor Sysoev <http://sysoev.ru>
date Mon, 18 May 2009 00:00:00 +0400
parents 6484cbba0222
children f39b9e29530d
comparison
equal deleted inserted replaced
491:bb2281a3edb6 492:98143f74eb3d
272 272
273 return rv; 273 return rv;
274 } 274 }
275 275
276 276
277 /* AF_INET only */
278
279 static char * 277 static char *
280 ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 278 ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
281 { 279 {
282 ngx_mail_core_srv_conf_t *cscf = conf; 280 ngx_mail_core_srv_conf_t *cscf = conf;
283 281
282 size_t len, off;
283 in_port_t port;
284 ngx_str_t *value; 284 ngx_str_t *value;
285 ngx_url_t u; 285 ngx_url_t u;
286 ngx_uint_t i, m; 286 ngx_uint_t i, m;
287 struct sockaddr *sa;
287 ngx_mail_listen_t *ls; 288 ngx_mail_listen_t *ls;
288 ngx_mail_module_t *module; 289 ngx_mail_module_t *module;
290 struct sockaddr_in *sin;
289 ngx_mail_core_main_conf_t *cmcf; 291 ngx_mail_core_main_conf_t *cmcf;
292 #if (NGX_HAVE_INET6)
293 struct sockaddr_in6 *sin6;
294 #endif
290 295
291 value = cf->args->elts; 296 value = cf->args->elts;
292 297
293 ngx_memzero(&u, sizeof(ngx_url_t)); 298 ngx_memzero(&u, sizeof(ngx_url_t));
294 299
303 } 308 }
304 309
305 return NGX_CONF_ERROR; 310 return NGX_CONF_ERROR;
306 } 311 }
307 312
308 if (u.family != AF_INET) {
309 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "listen supports IPv4 only");
310 return NGX_CONF_ERROR;
311 }
312
313 cmcf = ngx_mail_conf_get_module_main_conf(cf, ngx_mail_core_module); 313 cmcf = ngx_mail_conf_get_module_main_conf(cf, ngx_mail_core_module);
314 314
315 ls = cmcf->listen.elts; 315 ls = cmcf->listen.elts;
316 316
317 for (i = 0; i < cmcf->listen.nelts; i++) { 317 for (i = 0; i < cmcf->listen.nelts; i++) {
318 318
319 if (ls[i].addr != u.addr.in_addr || ls[i].port != u.port) { 319 sa = (struct sockaddr *) ls[i].sockaddr;
320
321 if (sa->sa_family != u.family) {
322 continue;
323 }
324
325 switch (sa->sa_family) {
326
327 #if (NGX_HAVE_INET6)
328 case AF_INET6:
329 off = offsetof(struct sockaddr_in6, sin6_addr);
330 len = 16;
331 sin6 = (struct sockaddr_in6 *) sa;
332 port = sin6->sin6_port;
333 break;
334 #endif
335
336 default: /* AF_INET */
337 off = offsetof(struct sockaddr_in, sin_addr);
338 len = 4;
339 sin = (struct sockaddr_in *) sa;
340 port = sin->sin_port;
341 break;
342 }
343
344 if (ngx_memcmp(ls[i].sockaddr + off, u.sockaddr + off, len) != 0) {
345 continue;
346 }
347
348 if (port != u.port) {
320 continue; 349 continue;
321 } 350 }
322 351
323 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 352 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
324 "duplicate \"%V\" address and port pair", &u.url); 353 "duplicate \"%V\" address and port pair", &u.url);
330 return NGX_CONF_ERROR; 359 return NGX_CONF_ERROR;
331 } 360 }
332 361
333 ngx_memzero(ls, sizeof(ngx_mail_listen_t)); 362 ngx_memzero(ls, sizeof(ngx_mail_listen_t));
334 363
335 ls->addr = u.addr.in_addr; 364 ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen);
336 ls->port = u.port; 365
337 ls->family = u.family; 366 ls->socklen = u.socklen;
367 ls->wildcard = u.wildcard;
338 ls->ctx = cf->ctx; 368 ls->ctx = cf->ctx;
339 369
340 for (m = 0; ngx_modules[m]; m++) { 370 for (m = 0; ngx_modules[m]; m++) {
341 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { 371 if (ngx_modules[m]->type != NGX_MAIL_MODULE) {
342 continue; 372 continue;
359 for (i = 2; i < cf->args->nelts; i++) { 389 for (i = 2; i < cf->args->nelts; i++) {
360 390
361 if (ngx_strcmp(value[i].data, "bind") == 0) { 391 if (ngx_strcmp(value[i].data, "bind") == 0) {
362 ls->bind = 1; 392 ls->bind = 1;
363 continue; 393 continue;
394 }
395
396 if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) {
397 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
398 struct sockaddr *sa;
399 u_char buf[NGX_SOCKADDR_STRLEN];
400
401 sa = (struct sockaddr *) ls->sockaddr;
402
403 if (sa->sa_family == AF_INET6) {
404
405 if (ngx_strcmp(&value[i].data[10], "n") == 0) {
406 ls->ipv6only = 1;
407
408 } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) {
409 ls->ipv6only = 2;
410
411 } else {
412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
413 "invalid ipv6only flags \"%s\"",
414 &value[i].data[9]);
415 return NGX_CONF_ERROR;
416 }
417
418 ls->bind = 1;
419
420 } else {
421 len = ngx_sock_ntop(sa, buf, NGX_SOCKADDR_STRLEN, 1);
422
423 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
424 "ipv6only is not supported "
425 "on addr \"%*s\", ignored", len, buf);
426 }
427
428 continue;
429 #else
430 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
431 "bind ipv6only is not supported "
432 "on this platform");
433 return NGX_CONF_ERROR;
434 #endif
364 } 435 }
365 436
366 if (ngx_strcmp(value[i].data, "ssl") == 0) { 437 if (ngx_strcmp(value[i].data, "ssl") == 0) {
367 #if (NGX_MAIL_SSL) 438 #if (NGX_MAIL_SSL)
368 ls->ssl = 1; 439 ls->ssl = 1;