Browse code

core: tcp - add alias for cinfo dst IP

Federico Cabiddu authored on 18/10/2021 12:02:25
Showing 1 changed files
... ...
@@ -1478,7 +1478,12 @@ inline static struct tcp_connection*  tcpconn_add(struct tcp_connection *c)
1478 1478
 		 * the second alias is for (peer_ip, peer_port, local_addr, 0) -- for
1479 1479
 		 *  finding any conenction to peer_ip, peer_port from local_addr 
1480 1480
 		 * the third alias is for (peer_ip, peer_port, local_addr, local_port) 
1481
-		 *   -- for finding if a fully specified connection exists */
1481
+		 *   -- for finding if a fully specified connection exists 
1482
+		 * the fourth alias is for (peer_ip, peer_port, cinfo_addr, 0) -- for
1483
+		 *  finding any connection to peer_ip, peer_port from address stored into cinfo (e.g. when proxy protocol is used)
1484
+		 * the fifth alias is for (peer_ip, peer_port, cinfo_addr, cinfo_port) 
1485
+		 *   -- for finding if a fully specified connection exists using address
1486
+		 *      and port stored into cinfo*/
1482 1487
 		_tcpconn_add_alias_unsafe(c, c->rcv.src_port, &zero_ip, 0,
1483 1488
 													new_conn_alias_flags);
1484 1489
 		if (likely(c->rcv.dst_ip.af && ! ip_addr_any(&c->rcv.dst_ip))){
... ...
@@ -1487,6 +1492,14 @@ inline static struct tcp_connection*  tcpconn_add(struct tcp_connection *c)
1487 1492
 			_tcpconn_add_alias_unsafe(c, c->rcv.src_port, &c->rcv.dst_ip,
1488 1493
 									c->rcv.dst_port, new_conn_alias_flags);
1489 1494
 		}
1495
+		if (unlikely(c->cinfo.dst_ip.af && ! ip_addr_any(&c->cinfo.dst_ip) &&
1496
+									! ip_addr_cmp(&c->rcv.dst_ip, &c->cinfo.dst_ip))){
1497
+			_tcpconn_add_alias_unsafe(c, c->rcv.src_port, &c->cinfo.dst_ip, 0,
1498
+													new_conn_alias_flags);
1499
+			_tcpconn_add_alias_unsafe(c, c->rcv.src_port, &c->cinfo.dst_ip, c->cinfo.dst_port,
1500
+													new_conn_alias_flags);
1501
+		}
1502
+
1490 1503
 		/* ignore add_alias errors, there are some valid cases when one
1491 1504
 		 *  of the add_alias would fail (e.g. first add_alias for 2 connections
1492 1505
 		 *   with the same destination but different src. ip*/
... ...
@@ -1604,7 +1617,8 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port,
1604 1617
 					((l_port==0) || (l_port==a->parent->rcv.dst_port)) &&
1605 1618
 					(ip_addr_cmp(ip, &a->parent->rcv.src_ip)) &&
1606 1619
 					(is_local_ip_any ||
1607
-						ip_addr_cmp(l_ip, &a->parent->rcv.dst_ip))
1620
+						ip_addr_cmp(l_ip, &a->parent->rcv.dst_ip) ||
1621
+						ip_addr_cmp(l_ip, &a->parent->cinfo.dst_ip))
1608 1622
 			   ) {
1609 1623
 				LM_DBG("found connection by peer address (id: %d)\n",
1610 1624
 						a->parent->id);