summaryrefslogtreecommitdiff
path: root/res/res_pjsip_multihomed.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2014-03-17 22:46:56 +0000
committerJoshua Colp <jcolp@digium.com>2014-03-17 22:46:56 +0000
commit932fb5a6e231c511a74e7a78693cdac1abad7690 (patch)
tree4b193764e01fdd32c728b9c5caa61dec05bd138a /res/res_pjsip_multihomed.c
parented50ef4dc87f16ee32914f1e1d28fe74902d3a83 (diff)
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 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410794 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_multihomed.c')
-rw-r--r--res/res_pjsip_multihomed.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/res/res_pjsip_multihomed.c b/res/res_pjsip_multihomed.c
index e9addd936..ffa3795a9 100644
--- a/res/res_pjsip_multihomed.c
+++ b/res/res_pjsip_multihomed.c
@@ -83,10 +83,31 @@ static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp)
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,11 +126,21 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
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)) ||
pj_strcmp2(&cseq->method.name, "REGISTER")) {