<p dir="ltr">hello,</p>
<p dir="ltr">is there anything wrong?<br>
could you give me any advice?</p>
<p dir="ltr">Best Regards,<br>
Junpei Yoshino</p>
<div class="gmail_quot<blockquote class=" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Junpei Yoshino <<a href="mailto:junpei.yoshino@gmail.com">junpei.yoshino@gmail.com</a>><br>
# Date 1446723407 -32400<br>
# Thu Nov 05 20:36:47 2015 +0900<br>
# Node ID 59cadccedf402ec325b078cb72a284465639e0fe<br>
# Parent 4ccb37b04454dec6afb9476d085c06aea00adaa0<br>
Http: add proxy_protocol_port variable for rfc6302<br>
<br>
Logging source port is recommended in rfc6302.<br>
use case<br>
logging<br>
sending information by http request headers<br>
<br>
<br>
diff -r 4ccb37b04454 -r 59cadccedf40 src/core/ngx_connection.h<br>
--- a/src/core/ngx_connection.h Fri Oct 30 21:43:30 2015 +0300<br>
+++ b/src/core/ngx_connection.h Thu Nov 05 20:36:47 2015 +0900<br>
@@ -146,6 +146,7 @@<br>
ngx_str_t addr_text;<br>
<br>
ngx_str_t proxy_protocol_addr;<br>
+ ngx_str_t proxy_protocol_port;<br>
<br>
#if (NGX_SSL)<br>
ngx_ssl_connection_t *ssl;<br>
diff -r 4ccb37b04454 -r 59cadccedf40 src/core/ngx_proxy_protocol.c<br>
--- a/src/core/ngx_proxy_protocol.c Fri Oct 30 21:43:30 2015 +0300<br>
+++ b/src/core/ngx_proxy_protocol.c Thu Nov 05 20:36:47 2015 +0900<br>
@@ -13,7 +13,7 @@<br>
ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)<br>
{<br>
size_t len;<br>
- u_char ch, *p, *addr;<br>
+ u_char ch, *p, *addr, *port;<br>
<br>
p = buf;<br>
len = last - buf;<br>
@@ -71,8 +71,56 @@<br>
ngx_memcpy(c->proxy_protocol_addr.data, addr, len);<br>
c->proxy_protocol_addr.len = len;<br>
<br>
+ for ( ;; ) {<br>
+ if (p == last) {<br>
+ goto invalid;<br>
+ }<br>
+<br>
+ ch = *p++;<br>
+<br>
+ if (ch == ' ') {<br>
+ break;<br>
+ }<br>
+<br>
+ if (ch != ':' && ch != '.'<br>
+ && (ch < 'a' || ch > 'f')<br>
+ && (ch < 'A' || ch > 'F')<br>
+ && (ch < '0' || ch > '9'))<br>
+ {<br>
+ goto invalid;<br>
+ }<br>
+ }<br>
+ port = p;<br>
+ for ( ;; ) {<br>
+ if (p == last) {<br>
+ goto invalid;<br>
+ }<br>
+<br>
+ ch = *p++;<br>
+<br>
+ if (ch == ' ') {<br>
+ break;<br>
+ }<br>
+<br>
+ if (ch < '0' || ch > '9')<br>
+ {<br>
+ goto invalid;<br>
+ }<br>
+ }<br>
+ len = p - port - 1;<br>
+ c->proxy_protocol_port.data = ngx_pnalloc(c->pool, len);<br>
+<br>
+ if (c->proxy_protocol_port.data == NULL) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ ngx_memcpy(c->proxy_protocol_port.data, port, len);<br>
+ c->proxy_protocol_port.len = len;<br>
+<br>
ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,<br>
"PROXY protocol address: \"%V\"", &c->proxy_protocol_addr);<br>
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,<br>
+ "PROXY protocol port: \"%V\"", &c->proxy_protocol_port);<br>
<br>
skip:<br>
<br>
diff -r 4ccb37b04454 -r 59cadccedf40 src/http/ngx_http_variables.c<br>
--- a/src/http/ngx_http_variables.c Fri Oct 30 21:43:30 2015 +0300<br>
+++ b/src/http/ngx_http_variables.c Thu Nov 05 20:36:47 2015 +0900<br>
@@ -58,6 +58,8 @@<br>
ngx_http_variable_value_t *v, uintptr_t data);<br>
static ngx_int_t ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,<br>
ngx_http_variable_value_t *v, uintptr_t data);<br>
+static ngx_int_t ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,<br>
+ ngx_http_variable_value_t *v, uintptr_t data);<br>
static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r,<br>
ngx_http_variable_value_t *v, uintptr_t data);<br>
static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r,<br>
@@ -192,6 +194,9 @@<br>
{ ngx_string("proxy_protocol_addr"), NULL,<br>
ngx_http_variable_proxy_protocol_addr, 0, 0, 0 },<br>
<br>
+ { ngx_string("proxy_protocol_port"), NULL,<br>
+ ngx_http_variable_proxy_protocol_port, 0, 0, 0 },<br>
+<br>
{ ngx_string("server_addr"), NULL, ngx_http_variable_server_addr,<br>
0, 0, 0 },<br>
<br>
{ ngx_string("server_port"), NULL, ngx_http_variable_server_port,<br>
0, 0, 0 },<br>
@@ -1250,6 +1255,20 @@<br>
<br>
<br>
static ngx_int_t<br>
+ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,<br>
+ ngx_http_variable_value_t *v, uintptr_t data)<br>
+{<br>
+ v->len = r->connection->proxy_protocol_port.len;<br>
+ v->valid = 1;<br>
+ v->no_cacheable = 0;<br>
+ v->not_found = 0;<br>
+ v->data = r->connection->proxy_protocol_port.data;<br>
+<br>
+ return NGX_OK;<br>
+}<br>
+<br>
+<br>
+static ngx_int_t<br>
ngx_http_variable_server_addr(ngx_http_request_t *r,<br>
ngx_http_variable_value_t *v, uintptr_t data)<br>
{<br>
</div>