From e4051fbb937e5917bbe39b4de37bf4258446918a Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> Date: Tue, 27 Jan 2015 18:07:24 -0500 Subject: [PATCH] upnp: don't use empty upnp address In the case that getting the external address via UPnP fails, don't try to use the empty address to prevent pjsip assert crashes. Refs #64829 Change-Id: Ibd21dab96a1b79ec852a70506dfe7db587b9add6 --- daemon/src/ice_transport.cpp | 26 +++++++++++++++----------- daemon/src/ringdht/ringaccount.cpp | 3 +++ daemon/src/sip/sipaccount.cpp | 5 ++++- daemon/src/sip/sipvoiplink.cpp | 12 +++++++++--- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/daemon/src/ice_transport.cpp b/daemon/src/ice_transport.cpp index 2b83fba7f2..2020ed70d6 100644 --- a/daemon/src/ice_transport.cpp +++ b/daemon/src/ice_transport.cpp @@ -472,18 +472,22 @@ IceTransport::selectUPnPIceCandidates() * add candidate with that port and public IP */ IpAddr publicIP = upnp_->getExternalIP(); - for(unsigned comp_id = 0; comp_id < component_count_; comp_id++) { - RING_DBG("UPnP : Opening port(s) for Ice comp %d and adding candidate with public IP.", comp_id); - std::vector<IpAddr> candidates = getLocalCandidatesAddr(comp_id); - for(IpAddr addr : candidates) { - uint16_t port = addr.getPort(); - uint16_t port_used; - if (upnp_->addAnyMapping(port, upnp::PortType::UDP, true, &port_used)) { - publicIP.setPort(port_used); - addCandidate(comp_id, publicIP); - } else - RING_WARN("UPnP : Could not create a port mapping for the ICE candidae."); + if (publicIP) { + for(unsigned comp_id = 0; comp_id < component_count_; comp_id++) { + RING_DBG("UPnP : Opening port(s) for Ice comp %d and adding candidate with public IP.", comp_id); + std::vector<IpAddr> candidates = getLocalCandidatesAddr(comp_id); + for(IpAddr addr : candidates) { + uint16_t port = addr.getPort(); + uint16_t port_used; + if (upnp_->addAnyMapping(port, upnp::PortType::UDP, true, &port_used)) { + publicIP.setPort(port_used); + addCandidate(comp_id, publicIP); + } else + RING_WARN("UPnP : Could not create a port mapping for the ICE candidae."); + } } + } else { + RING_WARN("UPnP : Could not determine public IP for ICE candidates."); } } } diff --git a/daemon/src/ringdht/ringaccount.cpp b/daemon/src/ringdht/ringaccount.cpp index b94087a5a3..cbdb671129 100644 --- a/daemon/src/ringdht/ringaccount.cpp +++ b/daemon/src/ringdht/ringaccount.cpp @@ -240,6 +240,9 @@ RingAccount::createOutgoingCall(const std::shared_ptr<SIPCall>& call, const std: getPublishedIpAddress() : localAddress; } + /* fallback on local address */ + if (not addrSdp) addrSdp = localAddress; + // Initialize the session using ULAW as default codec in case of early media // The session should be ready to receive media once the first INVITE is sent, before // the session initialization is completed diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index e17405f8da..2cbd92b08a 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -239,6 +239,9 @@ SIPAccount::newOutgoingCall(const std::string& id, const std::string& toUrl) getPublishedIpAddress() : localAddress; } + /* fallback on local address */ + if (not addrSdp) addrSdp = localAddress; + // Initialize the session using ULAW as default codec in case of early media // The session should be ready to receive media once the first INVITE is sent, before // the session initialization is completed @@ -1419,7 +1422,7 @@ SIPAccount::getContactHeader(pjsip_transport* t) hostname_, address, port); - if (getUseUPnP()) { + if (getUseUPnP() and getUPnPIpAddress()) { address = getUPnPIpAddress().toString(); port = publishedPortUsed_; useUPnPAddressPortInVIA(); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index ca0b471e6a..511f70186d 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -326,6 +326,9 @@ transaction_request_cb(pjsip_rx_data *rdata) ? account->getPublishedIpAddress() : addrToUse; } + /* fallback on local address */ + if (not addrSdp) addrSdp = addrToUse; + call->setConnectionState(Call::PROGRESSING); call->setPeerNumber(peerNumber); call->setDisplayName(displayName); @@ -892,6 +895,7 @@ sdp_create_offer_cb(pjsip_inv_session *inv, pjmedia_sdp_session **p_offer) // FIXME : for now, use the same address family as the SIP transport auto family = pjsip_transport_type_get_af(account.getTransportType()); + IpAddr addrToUse = ip_utils::getInterfaceAddr(account.getLocalInterface(), family); IpAddr address; if (account.getUseUPnP()) { @@ -899,11 +903,13 @@ sdp_create_offer_cb(pjsip_inv_session *inv, pjmedia_sdp_session **p_offer) address = account.getPublishedSameasLocal() ? account.getUPnPIpAddress() : account.getPublishedIpAddress(); } else { - address = account.getPublishedSameasLocal() - ? IpAddr(ip_utils::getInterfaceAddr(account.getLocalInterface(), family)) - : account.getPublishedIpAddress(); + address = account.getPublishedSameasLocal() ? + addrToUse : account.getPublishedIpAddress(); } + /* fallback on local address */ + if (not address) address = addrToUse; + call->setCallMediaLocal(address); auto& localSDP = call->getSDP(); -- GitLab