comparison 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
comparison
equal deleted inserted replaced
6560:c90cf79d0e1d 6561:28c76d9d75b7
10 10
11 11
12 u_char * 12 u_char *
13 ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last) 13 ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)
14 { 14 {
15 size_t len; 15 size_t len;
16 u_char ch, *p, *addr; 16 u_char ch, *p, *addr, *port;
17 ngx_int_t n;
17 18
18 p = buf; 19 p = buf;
19 len = last - buf; 20 len = last - buf;
20 21
21 if (len < 8 || ngx_strncmp(p, "PROXY ", 6) != 0) { 22 if (len < 8 || ngx_strncmp(p, "PROXY ", 6) != 0) {
69 } 70 }
70 71
71 ngx_memcpy(c->proxy_protocol_addr.data, addr, len); 72 ngx_memcpy(c->proxy_protocol_addr.data, addr, len);
72 c->proxy_protocol_addr.len = len; 73 c->proxy_protocol_addr.len = len;
73 74
74 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, 75 for ( ;; ) {
75 "PROXY protocol address: \"%V\"", &c->proxy_protocol_addr); 76 if (p == last) {
77 goto invalid;
78 }
79
80 if (*p++ == ' ') {
81 break;
82 }
83 }
84
85 port = p;
86
87 for ( ;; ) {
88 if (p == last) {
89 goto invalid;
90 }
91
92 if (*p++ == ' ') {
93 break;
94 }
95 }
96
97 len = p - port - 1;
98
99 n = ngx_atoi(port, len);
100
101 if (n < 0 || n > 65535) {
102 goto invalid;
103 }
104
105 c->proxy_protocol_port = (in_port_t) n;
106
107 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,
108 "PROXY protocol address: %V %i", &c->proxy_protocol_addr, n);
76 109
77 skip: 110 skip:
78 111
79 for ( /* void */ ; p < last - 1; p++) { 112 for ( /* void */ ; p < last - 1; p++) {
80 if (p[0] == CR && p[1] == LF) { 113 if (p[0] == CR && p[1] == LF) {