Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix a MediaRelay issue while processing a SDP without ICE containing …
…an IPv6 connection address, and flexisip has no IPv6 address available.

Previously, an empty connection address was set by the MediaRelay, causing a blank call. Now, the IPv4 address will be used as fallback, which will work if the network provides NAT64 service.
  • Loading branch information
smorlat committed Feb 2, 2021
1 parent d3c7d85 commit 2caed30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/agent.cc
Expand Up @@ -667,6 +667,7 @@ pair<string, string> Agent::getPreferredIp(const string &destination) const {
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_NUMERICHOST;
bool isIpv6;

struct addrinfo *result;
err = getaddrinfo(dest.c_str(), NULL, &hints, &result);
Expand All @@ -681,8 +682,12 @@ pair<string, string> Agent::getPreferredIp(const string &destination) const {
} else {
LOGE("getPreferredIp() getaddrinfo() error while resolving '%s': %s", dest.c_str(), gai_strerror(err));
}
return strchr(dest.c_str(), ':') == NULL ? make_pair(getResolvedPublicIp(), getRtpBindIp())
: make_pair(getResolvedPublicIp(true), getRtpBindIp(true));
isIpv6 = strchr(dest.c_str(), ':') != NULL;
if (getResolvedPublicIp(true).empty()){
// If no IPv6 available, fallback to ipv4 and relay on NAT64.
return make_pair(getResolvedPublicIp(), getRtpBindIp());
}
return isIpv6 ? make_pair(getResolvedPublicIp(), getRtpBindIp()) : make_pair(getResolvedPublicIp(true), getRtpBindIp(true));
}

Agent::Network::Network(const Network &net) : mIP(net.mIP) {
Expand Down
4 changes: 2 additions & 2 deletions src/callcontext-mediarelay.cc
Expand Up @@ -48,8 +48,8 @@ void RelayedCall::enableTelephoneEventDrooping(bool value){

void RelayedCall::setupSpecificRelayTransport(RelayTransport *rt, const char *destHost){
Agent *agent = mServer->getAgent();
bool isIpv6 = (strchr(destHost, ':') != nullptr);
auto relayIps = agent->getPreferredIp(destHost);
bool isIpv6 = strchr(relayIps.first.c_str(), ':') != nullptr;
if (isIpv6){
rt->mIpv6Address = relayIps.first;
rt->mIpv6BindAddress = relayIps.second;
Expand Down Expand Up @@ -97,7 +97,7 @@ void RelayedCall::initChannels ( const std::shared_ptr< SdpModifier >& m, const
rt.mIpv4Address = agent->getResolvedPublicIp(false);
rt.mIpv6BindAddress = agent->getRtpBindIp(true);
rt.mIpv4BindAddress = agent->getRtpBindIp(false);
rt.mPreferredFamily = isIpv6 ? AF_INET6 : AF_INET;
rt.mPreferredFamily = (!rt.mIpv6Address.empty() && isIpv6) ? AF_INET6 : AF_INET;
rt.mDualStackRequired = hasIce && !rt.mIpv6Address.empty();

if (s == NULL) {
Expand Down

0 comments on commit 2caed30

Please sign in to comment.