From 48279e08ee4a038bc4e6deceb916e5ac186b7802 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 31 Oct 2019 09:03:17 +0100 Subject: [PATCH] core: tcp - set src/dst address before parsing haproxy headers - the connection ip and port are preserved in this way --- src/core/tcp_main.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c index 403c0c6adfb..9687cbd4b81 100644 --- a/src/core/tcp_main.c +++ b/src/core/tcp_main.c @@ -1215,31 +1215,29 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su, c->rcv.src_su=*su; + su2ip_addr(&c->rcv.src_ip, su); + c->rcv.src_port=su_getport(su); + if (likely(local_addr)){ + su2ip_addr(&c->rcv.dst_ip, local_addr); + c->rcv.dst_port=su_getport(local_addr); + }else if (ba){ + c->rcv.dst_ip=ba->address; + c->rcv.dst_port=ba->port_no; + } + c->rcv.bind_address=ba; + atomic_set(&c->refcnt, 0); local_timer_init(&c->timer, tcpconn_main_timeout, c, 0); + if (unlikely(ksr_tcp_accept_haproxy && state == S_CONN_ACCEPT)) { ret = tcpconn_read_haproxy(c); - if (ret == -1) { LM_ERR("invalid PROXY protocol header\n"); goto error; } else if (ret == 1) { LM_DBG("PROXY protocol did not override IP addresses\n"); - goto read_ip_info; - } - } else { -read_ip_info: - su2ip_addr(&c->rcv.src_ip, su); - c->rcv.src_port=su_getport(su); - if (likely(local_addr)){ - su2ip_addr(&c->rcv.dst_ip, local_addr); - c->rcv.dst_port=su_getport(local_addr); - }else if (ba){ - c->rcv.dst_ip=ba->address; - c->rcv.dst_port=ba->port_no; } } - c->rcv.bind_address=ba; print_ip("tcpconn_new: new tcp connection: ", &c->rcv.src_ip, "\n"); LM_DBG("on port %d, type %d\n", c->rcv.src_port, type); init_tcp_req(&c->req, (char*)c+sizeof(struct tcp_connection), rd_b_size);