[PATCH]add proxy_protocol_port variable for rfc6302

junpei yoshino junpei.yoshino at gmail.com
Mon Dec 7 15:56:07 UTC 2015


Hello.

I wrote additional patch.

# HG changeset patch
# User Junpei Yoshino <junpei.yoshino at gmail.com>
# Date 1449499172 -32400
#      Mon Dec 07 23:39:32 2015 +0900
# Node ID e2984af905ff8cf523b22860620a9f3ff22d555a
# Parent  59cadccedf402ec325b078cb72a284465639e0fe
Change definition of  proxy_protocol_port

diff -r 59cadccedf40 -r e2984af905ff src/core/ngx_connection.h
--- a/src/core/ngx_connection.h Thu Nov 05 20:36:47 2015 +0900
+++ b/src/core/ngx_connection.h Mon Dec 07 23:39:32 2015 +0900
@@ -146,7 +146,7 @@
     ngx_str_t           addr_text;

     ngx_str_t           proxy_protocol_addr;
-    ngx_str_t           proxy_protocol_port;
+    ngx_int_t           proxy_protocol_port;

 #if (NGX_SSL)
     ngx_ssl_connection_t  *ssl;
diff -r 59cadccedf40 -r e2984af905ff src/core/ngx_proxy_protocol.c
--- a/src/core/ngx_proxy_protocol.c     Thu Nov 05 20:36:47 2015 +0900
+++ b/src/core/ngx_proxy_protocol.c     Mon Dec 07 23:39:32 2015 +0900
@@ -81,14 +81,6 @@
         if (ch == ' ') {
             break;
         }
-
-        if (ch != ':' && ch != '.'
-            && (ch < 'a' || ch > 'f')
-            && (ch < 'A' || ch > 'F')
-            && (ch < '0' || ch > '9'))
-        {
-            goto invalid;
-        }
     }
     port = p;
     for ( ;; ) {
@@ -108,19 +100,11 @@
         }
     }
     len = p - port - 1;
-    c->proxy_protocol_port.data = ngx_pnalloc(c->pool, len);
+    c->proxy_protocol_port = ngx_atoi(port,len);

-    if (c->proxy_protocol_port.data == NULL) {
-        return NULL;
-    }
-
-    ngx_memcpy(c->proxy_protocol_port.data, port, len);
-    c->proxy_protocol_port.len = len;
-
-    ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
-                   "PROXY protocol address: \"%V\"", &c->proxy_protocol_addr);
-    ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
-                   "PROXY protocol port: \"%V\"", &c->proxy_protocol_port);
+    ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,
+                   "PROXY protocol address: \"%V\", PROXY protocol
port: \"%d\"",
+                   &c->proxy_protocol_addr, c->proxy_protocol_port);

 skip:

diff -r 59cadccedf40 -r e2984af905ff src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c     Thu Nov 05 20:36:47 2015 +0900
+++ b/src/http/ngx_http_variables.c     Mon Dec 07 23:39:32 2015 +0900
@@ -1258,11 +1258,20 @@
 ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data)
 {
-    v->len = r->connection->proxy_protocol_port.len;
+    ngx_int_t port = r->connection->proxy_protocol_port;
+
+    v->len = 0;
     v->valid = 1;
     v->no_cacheable = 0;
     v->not_found = 0;
-    v->data = r->connection->proxy_protocol_port.data;
+    v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
+
+    if (v->data == NULL) {
+        return NGX_ERROR;
+    }
+    if (port > 0 && port < 65536) {
+        v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
+    }

     return NGX_OK;
 }


On Mon, Dec 7, 2015 at 11:51 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> Hello!
>
> On Mon, Dec 07, 2015 at 12:14:38AM +0900, junpei yoshino wrote:
>
>> > but we need someone to do the rest of the work.
>>
>> Could I contribute it?
>> At first, I will revise this patch along your review.
>
> It may be a bit too many for someone with small nginx coding
> experience, but you may try to.
>
> --
> Maxim Dounin
> http://nginx.org/
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel



-- 
junpei.yoshino at gmail.com



More information about the nginx-devel mailing list