Welcome! Log In Create A New Profile

Advanced

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

Quanah Gibson-Mount
April 24, 2014 01:22PM
# HG changeset patch
# User Quanah Gibson-Mount <quanah@zimbra.com>
# Date 1398357557 18000
# Node ID 4b7d2e503c06758330aabcc21ffbbab77f09568e
# Parent 1b0c55d38d0b7ba69dcad79760a3fadc30696a9d
HTTP: Add client source port to any error that is logged
For TRAC ticket 531

diff -r 1b0c55d38d0b -r 4b7d2e503c06 src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c Thu Apr 24 16:54:23 2014 +0400
+++ b/src/http/ngx_http_request.c Thu Apr 24 11:39:17 2014 -0500
@@ -3548,6 +3548,11 @@
u_char *p;
ngx_http_request_t *r;
ngx_http_log_ctx_t *ctx;
+ ngx_uint_t remote_port=0;
+ struct sockaddr_in *sin;
+#if (NGX_HAVE_INET6)
+ struct sockaddr_in6 *sin6;
+#endif

if (log->action) {
p = ngx_snprintf(buf, len, " while %s", log->action);
@@ -3557,15 +3562,32 @@

ctx = log->data;

- p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text);
- len -= p - buf;
-
r = ctx->request;
-
if (r) {
+ switch (r->connection->sockaddr->sa_family) {
+ #if (NGX_HAVE_INET6)
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
+ remote_port = ntohs(sin6->sin6_port);
+ break;
+ #endif
+
+ default: /* AF_INET */
+ sin = (struct sockaddr_in *) r->connection->sockaddr;
+ remote_port = ntohs(sin->sin_port);
+ break;
+ }
+
+ if (remote_port && remote_port < 65536) {
+ p = ngx_snprintf(buf, len, ", client: %V:%ui", &ctx->connection->addr_text,remote_port);
+ } else {
+ p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text);
+ }
+ len -= p - buf;
+
return r->log_handler(r, ctx->current_request, p, len);
-
} else {
+ p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text);
p = ngx_snprintf(p, len, ", server: %V",
&ctx->connection->listening->addr_text);
}

_______________________________________________
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 523 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 809 May 23, 2014 02:56PM



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

Online Users

Guests: 135
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