aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2016-09-06 21:28:16 +0300
committerDmitry Volyntsev <xeioex@nginx.com>2016-09-06 21:28:16 +0300
commit7336c4008ff2271f3cf199ba34dffe5e68797c25 (patch)
treec51a9b218b274ca3e1b2b9888afc31fbd3cc6e7e
parentabd1b0a76d0ef6655d17caf90bea8937802fd5da (diff)
downloadnginx-7336c4008ff2271f3cf199ba34dffe5e68797c25.tar.gz
nginx-7336c4008ff2271f3cf199ba34dffe5e68797c25.zip
Stream: $proxy_protocol_addr and $proxy_protocol_port.
-rw-r--r--src/stream/ngx_stream_variables.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/stream/ngx_stream_variables.c b/src/stream/ngx_stream_variables.c
index 5fa3ec992..aa5361d18 100644
--- a/src/stream/ngx_stream_variables.c
+++ b/src/stream/ngx_stream_variables.c
@@ -17,6 +17,10 @@ static ngx_int_t ngx_stream_variable_remote_addr(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_stream_variable_remote_port(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_variable_proxy_protocol_addr(
+ ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_variable_proxy_protocol_port(
+ ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_stream_variable_server_addr(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_stream_variable_server_port(ngx_stream_session_t *s,
@@ -57,6 +61,12 @@ static ngx_stream_variable_t ngx_stream_core_variables[] = {
{ ngx_string("remote_port"), NULL,
ngx_stream_variable_remote_port, 0, 0, 0 },
+ { ngx_string("proxy_protocol_addr"), NULL,
+ ngx_stream_variable_proxy_protocol_addr, 0, 0, 0 },
+
+ { ngx_string("proxy_protocol_port"), NULL,
+ ngx_stream_variable_proxy_protocol_port, 0, 0, 0 },
+
{ ngx_string("server_addr"), NULL,
ngx_stream_variable_server_addr, 0, 0, 0 },
@@ -418,6 +428,46 @@ ngx_stream_variable_remote_port(ngx_stream_session_t *s,
static ngx_int_t
+ngx_stream_variable_proxy_protocol_addr(ngx_stream_session_t *s,
+ ngx_stream_variable_value_t *v, uintptr_t data)
+{
+ v->len = s->connection->proxy_protocol_addr.len;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ v->data = s->connection->proxy_protocol_addr.data;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
+ngx_stream_variable_proxy_protocol_port(ngx_stream_session_t *s,
+ ngx_stream_variable_value_t *v, uintptr_t data)
+{
+ ngx_uint_t port;
+
+ v->len = 0;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1);
+ if (v->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ port = s->connection->proxy_protocol_port;
+
+ if (port > 0 && port < 65536) {
+ v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
+ }
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_stream_variable_server_addr(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data)
{