Welcome! Log In Create A New Profile

Advanced

[PATCH 2 of 2] MAIL: Always log the source port of the client

Quanah Gibson-Mount
April 24, 2014 01:22PM
# HG changeset patch
# User Quanah Gibson-Mount <quanah@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
Subject Author Views Posted

[PATCH 0 of 2] TRAC 531 - Add source port logging for HTTP(S) error logging and all proxied email client connections

Quanah Gibson-Mount 1467 April 24, 2014 01:22PM

[PATCH 2 of 2] MAIL: Always log the source port of the client

Quanah Gibson-Mount 466 April 24, 2014 01:22PM

Re: [PATCH 2 of 2] MAIL: Always log the source port of the client

Maxim Dounin 439 April 24, 2014 01:48PM

Re: [PATCH 2 of 2] MAIL: Always log the source port of the client

Quanah Gibson-Mount 441 April 24, 2014 07:40PM

[PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Quanah Gibson-Mount 524 April 24, 2014 01:22PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Maxim Dounin 467 April 24, 2014 01:38PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Quanah Gibson-Mount 461 April 24, 2014 01:42PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Quanah Gibson-Mount 465 April 24, 2014 01:46PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Maxim Dounin 478 April 24, 2014 01:58PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Quanah Gibson-Mount 449 April 24, 2014 02:08PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Maxim Dounin 438 April 24, 2014 02:28PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Quanah Gibson-Mount 547 April 24, 2014 07:38PM

Re: [PATCH 1 of 2] HTTP: Add client source port to any error that is logged

Maxim Dounin 483 April 25, 2014 07:50AM

Re: [PATCH 0 of 2] TRAC 531 - Add source port logging for HTTP(S) error logging and all proxied email client connections

itpp2012 810 May 23, 2014 02:56PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 159
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready