comparison src/stream/ngx_stream_variables.c @ 7590:06b01840bd42

Core: moved PROXY protocol fields out of ngx_connection_t. Now a new structure ngx_proxy_protocol_t holds these fields. This allows to add more PROXY protocol fields in the future without modifying the connection structure.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 21 Oct 2019 18:06:19 +0300
parents 0b1eb40de6da
children 89adf49fe76a
comparison
equal deleted inserted replaced
7589:486d2e0b1b6f 7590:06b01840bd42
555 555
556 static ngx_int_t 556 static ngx_int_t
557 ngx_stream_variable_proxy_protocol_addr(ngx_stream_session_t *s, 557 ngx_stream_variable_proxy_protocol_addr(ngx_stream_session_t *s,
558 ngx_stream_variable_value_t *v, uintptr_t data) 558 ngx_stream_variable_value_t *v, uintptr_t data)
559 { 559 {
560 v->len = s->connection->proxy_protocol_addr.len; 560 ngx_proxy_protocol_t *pp;
561 v->valid = 1; 561
562 v->no_cacheable = 0; 562 pp = s->connection->proxy_protocol;
563 v->not_found = 0; 563 if (pp == NULL) {
564 v->data = s->connection->proxy_protocol_addr.data; 564 v->not_found = 1;
565 return NGX_OK;
566 }
567
568 v->len = pp->src_addr.len;
569 v->valid = 1;
570 v->no_cacheable = 0;
571 v->not_found = 0;
572 v->data = pp->src_addr.data;
565 573
566 return NGX_OK; 574 return NGX_OK;
567 } 575 }
568 576
569 577
570 static ngx_int_t 578 static ngx_int_t
571 ngx_stream_variable_proxy_protocol_port(ngx_stream_session_t *s, 579 ngx_stream_variable_proxy_protocol_port(ngx_stream_session_t *s,
572 ngx_stream_variable_value_t *v, uintptr_t data) 580 ngx_stream_variable_value_t *v, uintptr_t data)
573 { 581 {
574 ngx_uint_t port; 582 ngx_uint_t port;
583 ngx_proxy_protocol_t *pp;
584
585 pp = s->connection->proxy_protocol;
586 if (pp == NULL) {
587 v->not_found = 1;
588 return NGX_OK;
589 }
575 590
576 v->len = 0; 591 v->len = 0;
577 v->valid = 1; 592 v->valid = 1;
578 v->no_cacheable = 0; 593 v->no_cacheable = 0;
579 v->not_found = 0; 594 v->not_found = 0;
581 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1); 596 v->data = ngx_pnalloc(s->connection->pool, sizeof("65535") - 1);
582 if (v->data == NULL) { 597 if (v->data == NULL) {
583 return NGX_ERROR; 598 return NGX_ERROR;
584 } 599 }
585 600
586 port = s->connection->proxy_protocol_port; 601 port = pp->src_port;
587 602
588 if (port > 0 && port < 65536) { 603 if (port > 0 && port < 65536) {
589 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; 604 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
590 } 605 }
591 606