[asterisk-commits] file: branch file/pimp_sip_nat r382152 - /team/file/pimp_sip_nat/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 27 07:31:39 CST 2013


Author: file
Date: Wed Feb 27 07:31:34 2013
New Revision: 382152

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382152
Log:
Modify the Via header as well, for implementations where rport is but a distant dream.

Modified:
    team/file/pimp_sip_nat/res/res_sip_nat.c

Modified: team/file/pimp_sip_nat/res/res_sip_nat.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_nat/res/res_sip_nat.c?view=diff&rev=382152&r1=382151&r2=382152
==============================================================================
--- team/file/pimp_sip_nat/res/res_sip_nat.c (original)
+++ team/file/pimp_sip_nat/res/res_sip_nat.c Wed Feb 27 07:31:34 2013
@@ -106,8 +106,9 @@
 	RAII_VAR(struct ao2_container *, transports, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
 	struct request_transport_details details = { 0, };
-	pjsip_sip_uri *uri = NULL;
+	pjsip_via_hdr *via = NULL;
 	struct ast_sockaddr addr = { { 0, } };
+	pjsip_sip_uri *uri;
 
 	/* If a transport selector is in use we know the transport or factory, so explicitly find it */
 	if (tdata->tp_sel.type == PJSIP_TPSELECTOR_TRANSPORT) {
@@ -128,12 +129,9 @@
 			return PJ_SUCCESS;
 		}
 
-		if (!(uri = nat_get_contact_sip_uri(tdata))) {
-			return PJ_SUCCESS;
-		}
-
-		details.local_address = uri->host;
-		details.local_port = uri->port;
+		via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
+		details.local_address = via->sent_by.host;
+		details.local_port = via->sent_by.port;
 	}
 
 	if (!(transports = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "transport", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL)) ||
@@ -146,14 +144,26 @@
 	ast_sockaddr_set_port(&addr, tdata->tp_info.dst_port);
 
 	/* See if where we are sending this request is local or not, and if not that we can get a Contact URI to modify */
-	if ((ast_apply_ha(transport->localnet, &addr) != AST_SENSE_ALLOW) || (!uri && !(uri = nat_get_contact_sip_uri(tdata)))) {
+	if (ast_apply_ha(transport->localnet, &addr) != AST_SENSE_ALLOW) {
 		return PJ_SUCCESS;
 	}
 
+	if (!via) {
+		via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
+	}
+
+	/* Update the via header with the external address */
+	pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport->external_address));
+	if (transport->external_signaling_port) {
+		via->sent_by.port = transport->external_signaling_port;
+	}
+
 	/* Update the contact header with the external address */
-	pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport->external_address));
-	if (transport->external_signaling_port) {
-		uri->port = transport->external_signaling_port;
+	if ((uri = nat_get_contact_sip_uri(tdata))) {
+		uri->host = via->sent_by.host;
+		if (transport->external_signaling_port) {
+			uri->port = transport->external_signaling_port;
+		}
 	}
 
 	return PJ_SUCCESS;




More information about the asterisk-commits mailing list