[nginx] Realip: take client port from PROXY protocol header.

Dmitry Volyntsev xeioex at nginx.com
Mon May 23 15:45:36 UTC 2016


details:   http://hg.nginx.org/nginx/rev/26feae43987f
branches:  
changeset: 6563:26feae43987f
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon May 23 18:44:22 2016 +0300
description:
Realip: take client port from PROXY protocol header.

Previously, when the client address was changed to the one from
the PROXY protocol header, the client port ($remote_port) was
reset to zero.  Now the client port is also changed to the one
from the PROXY protocol header.

diffstat:

 src/http/modules/ngx_http_realip_module.c |  22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r b13d3a6f0512 -r 26feae43987f src/http/modules/ngx_http_realip_module.c
--- a/src/http/modules/ngx_http_realip_module.c	Mon May 23 18:44:22 2016 +0300
+++ b/src/http/modules/ngx_http_realip_module.c	Mon May 23 18:44:22 2016 +0300
@@ -138,6 +138,10 @@ ngx_http_realip_handler(ngx_http_request
     ngx_list_part_t             *part;
     ngx_table_elt_t             *header;
     ngx_connection_t            *c;
+    struct sockaddr_in          *sin;
+#if (NGX_HAVE_INET6)
+    struct sockaddr_in6         *sin6;
+#endif
     ngx_http_realip_ctx_t       *ctx;
     ngx_http_realip_loc_conf_t  *rlcf;
 
@@ -237,6 +241,24 @@ found:
                                     rlcf->recursive)
         != NGX_DECLINED)
     {
+        if (rlcf->type == NGX_HTTP_REALIP_PROXY) {
+
+            switch (addr.sockaddr->sa_family) {
+
+#if (NGX_HAVE_INET6)
+            case AF_INET6:
+                sin6 = (struct sockaddr_in6 *) addr.sockaddr;
+                sin6->sin6_port = htons(c->proxy_protocol_port);
+                break;
+#endif
+
+            default: /* AF_INET */
+                sin = (struct sockaddr_in *) addr.sockaddr;
+                sin->sin_port = htons(c->proxy_protocol_port);
+                break;
+            }
+        }
+
         return ngx_http_realip_set_addr(r, &addr);
     }
 



More information about the nginx-devel mailing list