[asterisk-commits] res/res hep pjsip: Fix reported local IP address when bound ... (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 19 05:23:21 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: res/res_hep_pjsip: Fix reported local IP address when bound to 'any'
......................................................................


res/res_hep_pjsip: Fix reported local IP address when bound to 'any'

When bound to an 'any' address, e.g., 0.0.0.0, PJSIP reports as its
local address the 'any' address, as opposed to the IP address we
actually received the packet on. This can cause some confusion in Homer,
as it will dutifully report what we send it.

This patch uses the PJSIP inspection routines to determine which IP
address we probably received the packet on based on the remote party's
IP address. In the event that this fails, it falls back to the IP
address natively reported by the transport.

Change-Id: I076f835d2aef489e1ee1d01595b211eb2ce62da3
---
M res/res_hep_pjsip.c
1 file changed, 49 insertions(+), 5 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Joshua Colp: Looks good to me, but someone else must approve; Verified



diff --git a/res/res_hep_pjsip.c b/res/res_hep_pjsip.c
index 87d68e3..a19b15f 100644
--- a/res/res_hep_pjsip.c
+++ b/res/res_hep_pjsip.c
@@ -77,13 +77,35 @@
 	pjsip_cid_hdr *cid_hdr;
 	pjsip_from_hdr *from_hdr;
 	pjsip_to_hdr *to_hdr;
+	pjsip_tpmgr_fla2_param prm;
 
 	capture_info = hepv3_create_capture_info(tdata->buf.start, (size_t)(tdata->buf.cur - tdata->buf.start));
 	if (!capture_info) {
 		return PJ_SUCCESS;
 	}
 
-	pj_sockaddr_print(&tdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 3);
+	/* Attempt to determine what IP address will we send this packet out of */
+	pjsip_tpmgr_fla2_param_default(&prm);
+	prm.tp_type = tdata->tp_info.transport->key.type;
+	pj_strset2(&prm.dst_host, tdata->tp_info.dst_name);
+	prm.local_if = PJ_TRUE;
+
+	/* If we can't get the local address use what we have already */
+	if (pjsip_tpmgr_find_local_addr2(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), tdata->pool, &prm) != PJ_SUCCESS) {
+		pj_sockaddr_print(&tdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 3);
+	} else {
+		if (prm.tp_type & PJSIP_TRANSPORT_IPV6) {
+			snprintf(local_buf, sizeof(local_buf), "[%.*s]:%hu",
+				(int)pj_strlen(&prm.ret_addr),
+				pj_strbuf(&prm.ret_addr),
+				prm.ret_port);
+		} else {
+			snprintf(local_buf, sizeof(local_buf), "%.*s:%hu",
+				(int)pj_strlen(&prm.ret_addr),
+				pj_strbuf(&prm.ret_addr),
+				prm.ret_port);
+		}
+	}
 	pj_sockaddr_print(&tdata->tp_info.dst_addr, remote_buf, sizeof(remote_buf), 3);
 
 	cid_hdr = PJSIP_MSG_CID_HDR(tdata->msg);
@@ -115,17 +137,39 @@
 	char remote_buf[256];
 	char *uuid;
 	struct hepv3_capture_info *capture_info;
+	pjsip_tpmgr_fla2_param prm;
 
 	capture_info = hepv3_create_capture_info(&rdata->pkt_info.packet, rdata->pkt_info.len);
 	if (!capture_info) {
 		return PJ_SUCCESS;
 	}
 
-	if (rdata->tp_info.transport->addr_len) {
-		pj_sockaddr_print(&rdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 3);
+	if (!rdata->pkt_info.src_addr_len) {
+		return PJ_SUCCESS;
 	}
-	if (rdata->pkt_info.src_addr_len) {
-		pj_sockaddr_print(&rdata->pkt_info.src_addr, remote_buf, sizeof(remote_buf), 3);
+	pj_sockaddr_print(&rdata->pkt_info.src_addr, remote_buf, sizeof(remote_buf), 3);
+
+	/* Attempt to determine what IP address we probably received this packet on */
+	pjsip_tpmgr_fla2_param_default(&prm);
+	prm.tp_type = rdata->tp_info.transport->key.type;
+	pj_strset2(&prm.dst_host, rdata->pkt_info.src_name);
+	prm.local_if = PJ_TRUE;
+
+	/* If we can't get the local address use what we have already */
+	if (pjsip_tpmgr_find_local_addr2(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), rdata->tp_info.pool, &prm) != PJ_SUCCESS) {
+		pj_sockaddr_print(&rdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 3);
+	} else {
+		if (prm.tp_type & PJSIP_TRANSPORT_IPV6) {
+			snprintf(local_buf, sizeof(local_buf), "[%.*s]:%hu",
+				(int)pj_strlen(&prm.ret_addr),
+				pj_strbuf(&prm.ret_addr),
+				prm.ret_port);
+		} else {
+			snprintf(local_buf, sizeof(local_buf), "%.*s:%hu",
+				(int)pj_strlen(&prm.ret_addr),
+				pj_strbuf(&prm.ret_addr),
+				prm.ret_port);
+		}
 	}
 
 	uuid = assign_uuid(&rdata->msg_info.cid->id, &rdata->msg_info.to->tag, &rdata->msg_info.from->tag);

-- 
To view, visit https://gerrit.asterisk.org/2833
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I076f835d2aef489e1ee1d01595b211eb2ce62da3
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list