Mail: IPv6 backends (ticket #323).

This commit is contained in:
Ruslan Ermilov 2013-03-25 13:38:59 +00:00
parent 2fd8b271c4
commit 4f2d6513dc

View File

@ -460,6 +460,9 @@ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
ngx_int_t rc, port, n;
ngx_addr_t *peer;
struct sockaddr_in *sin;
#if (NGX_HAVE_INET6)
struct sockaddr_in6 *sin6;
#endif
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
"mail auth http process headers");
@ -772,17 +775,26 @@ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
return;
}
/* AF_INET only */
rc = ngx_parse_addr(s->connection->pool, peer,
ctx->addr.data, ctx->addr.len);
sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in));
if (sin == NULL) {
switch (rc) {
case NGX_OK:
break;
case NGX_DECLINED:
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
"auth http server %V sent invalid server "
"address:\"%V\"",
ctx->peer.name, &ctx->addr);
/* fall through */
default:
ngx_destroy_pool(ctx->pool);
ngx_mail_session_internal_server_error(s);
return;
}
sin->sin_family = AF_INET;
port = ngx_atoi(ctx->port.data, ctx->port.len);
if (port == NGX_ERROR || port < 1 || port > 65535) {
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
@ -794,22 +806,21 @@ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
return;
}
switch (peer->sockaddr->sa_family) {
#if (NGX_HAVE_INET6)
case AF_INET6:
sin6 = (struct sockaddr_in6 *) peer->sockaddr;
sin6->sin6_port = htons((in_port_t) port);
break;
#endif
default: /* AF_INET */
sin = (struct sockaddr_in *) peer->sockaddr;
sin->sin_port = htons((in_port_t) port);
sin->sin_addr.s_addr = ngx_inet_addr(ctx->addr.data, ctx->addr.len);
if (sin->sin_addr.s_addr == INADDR_NONE) {
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
"auth http server %V sent invalid server "
"address:\"%V\"",
ctx->peer.name, &ctx->addr);
ngx_destroy_pool(ctx->pool);
ngx_mail_session_internal_server_error(s);
return;
break;
}
peer->sockaddr = (struct sockaddr *) sin;
peer->socklen = sizeof(struct sockaddr_in);
len = ctx->addr.len + 1 + ctx->port.len;
peer->name.len = len;