[svn-commits] file: trunk r410794 - in /trunk: ./ res/res_pjsip_multihomed.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Mar 17 17:47:01 CDT 2014


Author: file
Date: Mon Mar 17 17:46:56 2014
New Revision: 410794

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=410794
Log:
res_pjsip_multihomed: Make address replacement less aggressive.

This change makes the res_pjsip_multihomed module less aggressive when
changing the address in messages. It will now only occur if the transport
in use is bound to the any address OR if the system determined source
address matches the bound address of the transport in use.

Review: https://reviewboard.asterisk.org/r/3369/
........

Merged revisions 410793 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/res/res_pjsip_multihomed.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/res/res_pjsip_multihomed.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_multihomed.c?view=diff&rev=410794&r1=410793&r2=410794
==============================================================================
--- trunk/res/res_pjsip_multihomed.c (original)
+++ trunk/res/res_pjsip_multihomed.c Mon Mar 17 17:46:56 2014
@@ -83,10 +83,31 @@
 	return 0;
 }
 
+/*! \brief Helper function which determines if the existing address has priority over new one */
+static int multihomed_rewrite_header(pj_str_t *source, pjsip_transport *transport)
+{
+	pj_uint32_t loop6[4] = {0, 0, 0, 0};
+
+	/* If the transport is bound to any it should always rewrite */
+	if ((transport->local_addr.addr.sa_family == pj_AF_INET() &&
+		transport->local_addr.ipv4.sin_addr.s_addr == PJ_INADDR_ANY) ||
+		(transport->local_addr.addr.sa_family == pj_AF_INET6() &&
+		!pj_memcmp(&transport->local_addr.ipv6.sin6_addr, loop6, sizeof(loop6)))) {
+		return 1;
+	}
+
+	/* If the transport is explicitly bound but the determined source differs favor the transport */
+	if (!pj_strcmp(source, &transport->local_name.host)) {
+		return 1;
+	}
+
+	return 0;
+}
+
 static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
 {
 	pjsip_tpmgr_fla2_param prm;
-	pjsip_transport *transport;
+	pjsip_transport *transport = NULL;
 	pjsip_cseq_hdr *cseq;
 	pjsip_via_hdr *via;
 
@@ -105,10 +126,20 @@
 	if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||
 		tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP6) {
 		transport = multihomed_get_udp_transport(&prm.ret_addr, prm.ret_port);
-		if (transport && (tdata->tp_info.transport != transport)) {
-			tdata->tp_info.transport = transport;
-		}
-	}
+	}
+
+	/* If no new transport use the one provided by the message */
+	if (!transport) {
+		transport = tdata->tp_info.transport;
+	}
+
+	/* If the message should not be rewritten then abort early */
+	if (!multihomed_rewrite_header(&prm.ret_addr, transport)) {
+		return PJ_SUCCESS;
+	}
+
+	/* Update the transport in case it has changed - we do this now in case we don't want to touch the message above */
+	tdata->tp_info.transport = transport;
 
 	/* If the message needs to be updated with new address do so */
 	if (tdata->msg->type == PJSIP_REQUEST_MSG || !(cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL)) ||




More information about the svn-commits mailing list