Klaus Demo nginx / 7336c40
Stream: $proxy_protocol_addr and $proxy_protocol_port. Dmitry Volyntsev 3 years ago
1 changed file(s) with 50 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1616 ngx_stream_variable_value_t *v, uintptr_t data);
1717 static ngx_int_t ngx_stream_variable_remote_port(ngx_stream_session_t *s,
1818 ngx_stream_variable_value_t *v, uintptr_t data);
19 static ngx_int_t ngx_stream_variable_proxy_protocol_addr(
20 ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data);
21 static ngx_int_t ngx_stream_variable_proxy_protocol_port(
22 ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data);
1923 static ngx_int_t ngx_stream_variable_server_addr(ngx_stream_session_t *s,
2024 ngx_stream_variable_value_t *v, uintptr_t data);
2125 static ngx_int_t ngx_stream_variable_server_port(ngx_stream_session_t *s,
5559
5660 { ngx_string("remote_port"), NULL,
5761 ngx_stream_variable_remote_port, 0, 0, 0 },
62
63 { ngx_string("proxy_protocol_addr"), NULL,
64 ngx_stream_variable_proxy_protocol_addr, 0, 0, 0 },
65
66 { ngx_string("proxy_protocol_port"), NULL,
67 ngx_stream_variable_proxy_protocol_port, 0, 0, 0 },
5868
5969 { ngx_string("server_addr"), NULL,
6070 ngx_stream_variable_server_addr, 0, 0, 0 },
407417 }
408418
409419 port = ngx_inet_get_port(s->connection->sockaddr);
420
421 if (port > 0 && port < 65536) {
422 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
423 }
424
425 return NGX_OK;
426 }
427
428
429 static ngx_int_t
430 ngx_stream_variable_proxy_protocol_addr(ngx_stream_session_t *s,
431 ngx_stream_variable_value_t *v, uintptr_t data)
432 {
433 v->len = s->connection->proxy_protocol_addr.len;
434 v->valid = 1;
435 v->no_cacheable = 0;
436 v->not_found = 0;
437 v->data = s->connection->proxy_protocol_addr.data;
438
439 return NGX_OK;
440 }
441
442
443 static ngx_int_t
444 ngx_stream_variable_proxy_protocol_port(ngx_stream_session_t *s,
445 ngx_stream_variable_value_t *v, uintptr_t data)
446 {
447 ngx_uint_t port;
448
449 v->len = 0;
450 v->valid = 1;
451 v->no_cacheable = 0;
452 v->not_found = 0;
453
454 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1);
455 if (v->data == NULL) {
456 return NGX_ERROR;
457 }
458
459 port = s->connection->proxy_protocol_port;
410460
411461 if (port > 0 && port < 65536) {
412462 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;