diff src/core/ngx_proxy_protocol.c @ 6561:28c76d9d75b7

Added the $proxy_protocol_port variable.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 23 May 2016 18:44:21 +0300
parents a420cb1c170b
children b3b7e33083ac
line wrap: on
line diff
--- a/src/core/ngx_proxy_protocol.c
+++ b/src/core/ngx_proxy_protocol.c
@@ -12,8 +12,9 @@
 u_char *
 ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)
 {
-    size_t  len;
-    u_char  ch, *p, *addr;
+    size_t     len;
+    u_char     ch, *p, *addr, *port;
+    ngx_int_t  n;
 
     p = buf;
     len = last - buf;
@@ -71,8 +72,40 @@ ngx_proxy_protocol_read(ngx_connection_t
     ngx_memcpy(c->proxy_protocol_addr.data, addr, len);
     c->proxy_protocol_addr.len = len;
 
-    ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
-                   "PROXY protocol address: \"%V\"", &c->proxy_protocol_addr);
+    for ( ;; ) {
+        if (p == last) {
+            goto invalid;
+        }
+
+        if (*p++ == ' ') {
+            break;
+        }
+    }
+
+    port = p;
+
+    for ( ;; ) {
+        if (p == last) {
+            goto invalid;
+        }
+
+        if (*p++ == ' ') {
+            break;
+        }
+    }
+
+    len = p - port - 1;
+
+    n = ngx_atoi(port, len);
+
+    if (n < 0 || n > 65535) {
+        goto invalid;
+    }
+
+    c->proxy_protocol_port = (in_port_t) n;
+
+    ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,
+                   "PROXY protocol address: %V %i", &c->proxy_protocol_addr, n);
 
 skip: