Module: kamailio
Branch: master
Commit: 2bb8598edef41470f45bccb7a4b4715eed647a44
URL: 
https://github.com/kamailio/kamailio/commit/2bb8598edef41470f45bccb7a4b4715eed647a44

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2019-10-28T10:23:40+01:00

core: tcp - keep original connection info for haproxy tunnels

---

Modified: src/core/ip_addr.h
Modified: src/core/tcp_conn.h
Modified: src/core/tcp_main.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/2bb8598edef41470f45bccb7a4b4715eed647a44.diff
Patch: 
https://github.com/kamailio/kamailio/commit/2bb8598edef41470f45bccb7a4b4715eed647a44.patch

---

diff --git a/src/core/ip_addr.h b/src/core/ip_addr.h
index 0d26e7e756..9a7b67ac5d 100644
--- a/src/core/ip_addr.h
+++ b/src/core/ip_addr.h
@@ -172,6 +172,15 @@ typedef struct dest_info {
 } dest_info_t;
 
 
+typedef struct ksr_coninfo {
+       ip_addr_t src_ip;
+       ip_addr_t dst_ip;
+       unsigned short src_port; /* host byte order */
+       unsigned short dst_port; /* host byte order */
+       int proto;
+       socket_info_t *csocket;
+} ksr_coninfo_t;
+
 typedef struct sr_net_info {
        str data;
        receive_info_t* rcv;
diff --git a/src/core/tcp_conn.h b/src/core/tcp_conn.h
index a428c43f1f..d9a69b6929 100644
--- a/src/core/tcp_conn.h
+++ b/src/core/tcp_conn.h
@@ -200,6 +200,7 @@ typedef struct tcp_connection {
                         * reply-ing */
        int reader_pid; /* pid of the active reader process */
        struct receive_info rcv; /* src & dst ip, ports, proto a.s.o*/
+       ksr_coninfo_t cinfo; /* connection info (e.g., for haproxy ) */
        struct tcp_req req; /* request data */
        atomic_t refcnt;
        enum sip_protos type; /* PROTO_TCP or a protocol over it, e.g. TLS */
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index 99d33ee719..403c0c6adf 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -1021,6 +1021,14 @@ int tcpconn_read_haproxy(struct tcp_connection *c) {
                bytes = recv(c->s, &hdr, sizeof(hdr), MSG_PEEK);
        } while (bytes == -1 && (errno == EINTR || errno == EAGAIN));
 
+       /* copy original tunnel address details */
+       memcpy(&c->cinfo.src_ip, &c->rcv.src_ip, sizeof(ip_addr_t));
+       memcpy(&c->cinfo.dst_ip, &c->rcv.dst_ip, sizeof(ip_addr_t));
+       c->cinfo.src_port = c->rcv.src_port;
+       c->cinfo.dst_port = c->rcv.dst_port;
+       c->cinfo.proto = (int)c->rcv.proto;
+       c->cinfo.csocket = c->rcv.bind_address;
+
        src_ip = &c->rcv.src_ip;
        dst_ip = &c->rcv.dst_ip;
 


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to