<div dir="ltr">Hi,<div><br></div><div>Can anybody check this patch?</div><div>I'm eager to use this feature.</div><div class="gmail_extra"><br><div class="gmail_quote">2015-12-08 9:35 GMT+09:00 junpei yoshino <span dir="ltr"><<a href="mailto:junpei.yoshino@gmail.com" target="_blank">junpei.yoshino@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I made merged patch.<br>
<span class=""><br>
# HG changeset patch<br>
# User Junpei Yoshino <<a href="mailto:junpei.yoshino@gmail.com">junpei.yoshino@gmail.com</a>><br>
# Date 1449499172 -32400<br>
# Mon Dec 07 23:39:32 2015 +0900<br>
</span># Node ID f4cd90a03eca5c330f51ac4ba2673e64348c622e<br>
# Parent 29f35e60840b8eed2927dd3495ef2d8e524862f7<br>
<span class="">Http: add proxy_protocol_port variable for rfc6302<br>
<br>
</span>diff -r 29f35e60840b -r f4cd90a03eca src/core/ngx_connection.h<br>
--- a/src/core/ngx_connection.h Mon Dec 07 16:30:48 2015 +0300<br>
<span class="">+++ b/src/core/ngx_connection.h Mon Dec 07 23:39:32 2015 +0900<br>
</span>@@ -146,6 +146,7 @@<br>
ngx_str_t addr_text;<br>
<br>
ngx_str_t proxy_protocol_addr;<br>
<span class="">+ ngx_int_t proxy_protocol_port;<br>
<br>
#if (NGX_SSL)<br>
ngx_ssl_connection_t *ssl;<br>
</span>diff -r 29f35e60840b -r f4cd90a03eca src/core/ngx_proxy_protocol.c<br>
--- a/src/core/ngx_proxy_protocol.c Mon Dec 07 16:30:48 2015 +0300<br>
<span class="">+++ b/src/core/ngx_proxy_protocol.c Mon Dec 07 23:39:32 2015 +0900<br>
</span><span class="">@@ -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>
</span>@@ -71,8 +71,40 @@<br>
<span class=""> ngx_memcpy(c->proxy_protocol_addr.data, addr, len);<br>
c->proxy_protocol_addr.len = len;<br>
<br>
</span><span class="">- ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,<br>
- "PROXY protocol address: \"%V\"", &c->proxy_protocol_addr);<br>
</span><span class="">+ for ( ;; ) {<br>
+ if (p == last) {<br>
+ goto invalid;<br>
+ }<br>
+<br>
+ ch = *p++;<br>
+<br>
+ if (ch == ' ') {<br>
+ break;<br>
+ }<br>
+ }<br>
</span>+ port = p;<br>
<span class="">+ for ( ;; ) {<br>
+ if (p == last) {<br>
+ goto invalid;<br>
+ }<br>
+<br>
+ ch = *p++;<br>
+<br>
+ if (ch == ' ') {<br>
+ break;<br>
+ }<br>
+<br>
</span>+ if (ch < '0' || ch > '9')<br>
<span class="">+ {<br>
+ goto invalid;<br>
+ }<br>
+ }<br>
</span>+ len = p - port - 1;<br>
<span class="">+ c->proxy_protocol_port = ngx_atoi(port,len);<br>
</span>+<br>
<span class="">+ ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,<br>
+ "PROXY protocol address: \"%V\", PROXY protocol<br>
port: \"%d\"",<br>
+ &c->proxy_protocol_addr, c->proxy_protocol_port);<br>
<br>
skip:<br>
<br>
</span>diff -r 29f35e60840b -r f4cd90a03eca src/http/ngx_http_variables.c<br>
--- a/src/http/ngx_http_variables.c Mon Dec 07 16:30:48 2015 +0300<br>
<span class="">+++ b/src/http/ngx_http_variables.c Mon Dec 07 23:39:32 2015 +0900<br>
</span><span class="">@@ -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>
</span>@@ -1250,6 +1255,29 @@<br>
<span class=""><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>
</span><span class="">+ ngx_int_t port = r->connection->proxy_protocol_port;<br>
+<br>
+ v->len = 0;<br>
</span><span class="">+ v->valid = 1;<br>
+ v->no_cacheable = 0;<br>
+ v->not_found = 0;<br>
</span><span class="">+ v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);<br>
+<br>
+ if (v->data == NULL) {<br>
+ return NGX_ERROR;<br>
+ }<br>
+ if (port > 0 && port < 65536) {<br>
+ v->len = ngx_sprintf(v->data, "%ui", port) - v->data;<br>
+ }<br>
</span><span class="">+<br>
+ return NGX_OK;<br>
+}<br>
+<br>
+<br>
+static ngx_int_t<br>
</span> ngx_http_variable_server_addr(ngx_http_request_t *r,<br>
ngx_http_variable_value_t *v, uintptr_t data)<br>
{<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Tue, Dec 8, 2015 at 12:56 AM, junpei yoshino<br>
<<a href="mailto:junpei.yoshino@gmail.com">junpei.yoshino@gmail.com</a>> wrote:<br>
> Hello.<br>
><br>
> I wrote additional patch.<br>
><br>
> # HG changeset patch<br>
> # User Junpei Yoshino <<a href="mailto:junpei.yoshino@gmail.com">junpei.yoshino@gmail.com</a>><br>
> # Date 1449499172 -32400<br>
> # Mon Dec 07 23:39:32 2015 +0900<br>
> # Node ID e2984af905ff8cf523b22860620a9f3ff22d555a<br>
> # Parent 59cadccedf402ec325b078cb72a284465639e0fe<br>
> Change definition of proxy_protocol_port<br>
><br>
> diff -r 59cadccedf40 -r e2984af905ff src/core/ngx_connection.h<br>
> --- a/src/core/ngx_connection.h Thu Nov 05 20:36:47 2015 +0900<br>
> +++ b/src/core/ngx_connection.h Mon Dec 07 23:39:32 2015 +0900<br>
> @@ -146,7 +146,7 @@<br>
> ngx_str_t addr_text;<br>
><br>
> ngx_str_t proxy_protocol_addr;<br>
> - ngx_str_t proxy_protocol_port;<br>
> + ngx_int_t proxy_protocol_port;<br>
><br>
> #if (NGX_SSL)<br>
> ngx_ssl_connection_t *ssl;<br>
> diff -r 59cadccedf40 -r e2984af905ff src/core/ngx_proxy_protocol.c<br>
> --- a/src/core/ngx_proxy_protocol.c Thu Nov 05 20:36:47 2015 +0900<br>
> +++ b/src/core/ngx_proxy_protocol.c Mon Dec 07 23:39:32 2015 +0900<br>
> @@ -81,14 +81,6 @@<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>
> @@ -108,19 +100,11 @@<br>
> }<br>
> }<br>
> len = p - port - 1;<br>
> - c->proxy_protocol_port.data = ngx_pnalloc(c->pool, len);<br>
> + c->proxy_protocol_port = ngx_atoi(port,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>
> + ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,<br>
> + "PROXY protocol address: \"%V\", PROXY protocol<br>
> port: \"%d\"",<br>
> + &c->proxy_protocol_addr, c->proxy_protocol_port);<br>
><br>
> skip:<br>
><br>
> diff -r 59cadccedf40 -r e2984af905ff src/http/ngx_http_variables.c<br>
> --- a/src/http/ngx_http_variables.c Thu Nov 05 20:36:47 2015 +0900<br>
> +++ b/src/http/ngx_http_variables.c Mon Dec 07 23:39:32 2015 +0900<br>
> @@ -1258,11 +1258,20 @@<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>
> + ngx_int_t port = r->connection->proxy_protocol_port;<br>
> +<br>
> + v->len = 0;<br>
> v->valid = 1;<br>
> v->no_cacheable = 0;<br>
> v->not_found = 0;<br>
> - v->data = r->connection->proxy_protocol_port.data;<br>
> + v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);<br>
> +<br>
> + if (v->data == NULL) {<br>
> + return NGX_ERROR;<br>
> + }<br>
> + if (port > 0 && port < 65536) {<br>
> + v->len = ngx_sprintf(v->data, "%ui", port) - v->data;<br>
> + }<br>
><br>
> return NGX_OK;<br>
> }<br>
><br>
><br>
> On Mon, Dec 7, 2015 at 11:51 AM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:<br>
>> Hello!<br>
>><br>
>> On Mon, Dec 07, 2015 at 12:14:38AM +0900, junpei yoshino wrote:<br>
>><br>
>>> > but we need someone to do the rest of the work.<br>
>>><br>
>>> Could I contribute it?<br>
>>> At first, I will revise this patch along your review.<br>
>><br>
>> It may be a bit too many for someone with small nginx coding<br>
>> experience, but you may try to.<br>
>><br>
>> --<br>
>> Maxim Dounin<br>
>> <a href="http://nginx.org/" rel="noreferrer" target="_blank">http://nginx.org/</a><br>
>><br>
>> _______________________________________________<br>
>> nginx-devel mailing list<br>
>> <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
>> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
><br>
><br>
><br>
> --<br>
> <a href="mailto:junpei.yoshino@gmail.com">junpei.yoshino@gmail.com</a><br>
<br>
<br>
<br>
--<br>
<a href="mailto:junpei.yoshino@gmail.com">junpei.yoshino@gmail.com</a><br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Tomoya KABE<br>Mail : <a href="mailto:limit.usus@gmail.com" target="_blank">limit.usus@gmail.com</a><br></div>
</div></div>