# HG changeset patch # User Quanah Gibson-Mount <qua...@zimbra.com> # Date 1398359069 18000 # Node ID 3c908c40acd15c8df020f95309b98d45f2b5e5de # Parent 4b7d2e503c06758330aabcc21ffbbab77f09568e MAIL: Always log the source port of the client For TRAC 531
diff -r 4b7d2e503c06 -r 3c908c40acd1 src/mail/ngx_mail.h --- a/src/mail/ngx_mail.h Thu Apr 24 11:39:17 2014 -0500 +++ b/src/mail/ngx_mail.h Thu Apr 24 12:04:29 2014 -0500 @@ -253,6 +253,7 @@ typedef struct { ngx_str_t *client; + ngx_uint_t client_port; ngx_mail_session_t *session; } ngx_mail_log_ctx_t; diff -r 4b7d2e503c06 -r 3c908c40acd1 src/mail/ngx_mail_handler.c --- a/src/mail/ngx_mail_handler.c Thu Apr 24 11:39:17 2014 -0500 +++ b/src/mail/ngx_mail_handler.c Thu Apr 24 12:04:29 2014 -0500 @@ -24,6 +24,7 @@ { ngx_uint_t i; ngx_mail_port_t *port; + ngx_uint_t remote_port=0; struct sockaddr *sa; struct sockaddr_in *sin; ngx_mail_log_ctx_t *ctx; @@ -127,8 +128,26 @@ c->data = s; s->connection = c; - ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %V connected to %V", + switch (c->sockaddr->sa_family) { +#if (NGX_HAVE_INET6) + case AF_INET6: + sin6 = (struct sockaddr_in6 *) c->sockaddr; + remote_port = ntohs(sin6->sin6_port); + break; +#endif + default: + sin = (struct sockaddr_in *) c->sockaddr; + remote_port = ntohs(sin->sin_port); + break; + } + + if (remote_port && remote_port < 65536) { + ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %V:%ui connected to %V", + c->number, &c->addr_text, remote_port, s->addr_text); + } else { + ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %V connected to %V", c->number, &c->addr_text, s->addr_text); + } ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t)); if (ctx == NULL) { @@ -137,6 +156,7 @@ } ctx->client = &c->addr_text; + ctx->client_port = remote_port; ctx->session = s; c->log->connection = c->number; @@ -750,7 +770,11 @@ ctx = log->data; - p = ngx_snprintf(buf, len, ", client: %V", ctx->client); + if (ctx->client_port && ctx->client_port < 65536) { + p = ngx_snprintf(buf, len, ", client: %V:%ui", ctx->client, ctx->client_port); + } else { + p = ngx_snprintf(buf, len, ", client: %V", ctx->client, ctx->client_port); + } len -= p - buf; buf = p; _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel