aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_proxy_protocol.c
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2016-05-23 18:44:21 +0300
committerDmitry Volyntsev <xeioex@nginx.com>2016-05-23 18:44:21 +0300
commitf56cf3ddc7740ea94e41457cd1f1fd47b97cdb3d (patch)
tree70e2c3bc7ed26b91ec8c33b49002097842dd2342 /src/core/ngx_proxy_protocol.c
parent5b267a55bc27f35f38d6d04d2f6284ed4d6156c0 (diff)
downloadnginx-f56cf3ddc7740ea94e41457cd1f1fd47b97cdb3d.tar.gz
nginx-f56cf3ddc7740ea94e41457cd1f1fd47b97cdb3d.zip
Added the $proxy_protocol_port variable.
Diffstat (limited to 'src/core/ngx_proxy_protocol.c')
-rw-r--r--src/core/ngx_proxy_protocol.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/core/ngx_proxy_protocol.c b/src/core/ngx_proxy_protocol.c
index f347e7f43..3e54d4255 100644
--- 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 *c, u_char *buf, u_char *last)
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: