Skip to content

Commit

Permalink
mobile: Allow ConnectivityManager to handle getifaddrs failures (envo…
Browse files Browse the repository at this point in the history
…yproxy#32286)

ConnectivityManager's enumerateInterfaces relies on getifaddrs. However,
getifaddrs could fail for a number of reasons. Instead of
RELEASE_ASSERT'ing, which causes crashes, we log the failure and return
an empty vector of interfaces, similar to how if there is no support for
getifaddrs.

Signed-off-by: Ali Beyad <[email protected]>
  • Loading branch information
abeyad authored Feb 9, 2024
1 parent 9406790 commit cfbc5eb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mobile/library/common/network/connectivity_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ InterfacePair ConnectivityManagerImpl::getActiveAlternateInterface(envoy_network
return std::make_pair("", nullptr);
}

// TODO(abeyad): pass OsSysCallsImpl in as a class dependency instead of directly using
// Api::OsSysCallsSingleton. That'll make it easier to create tests that mock out the
// sys calls behavior.
std::vector<InterfacePair>
ConnectivityManagerImpl::enumerateInterfaces([[maybe_unused]] unsigned short family,
[[maybe_unused]] unsigned int select_flags,
Expand All @@ -421,7 +424,10 @@ ConnectivityManagerImpl::enumerateInterfaces([[maybe_unused]] unsigned short fam

Api::InterfaceAddressVector interface_addresses{};
const Api::SysCallIntResult rc = Api::OsSysCallsSingleton::get().getifaddrs(interface_addresses);
RELEASE_ASSERT(!rc.return_value_, fmt::format("getiffaddrs error: {}", rc.errno_));
if (rc.return_value_ != 0) {
ENVOY_LOG_EVERY_POW_2(warn, "getifaddrs error: {}", rc.errno_);
return pairs;
}

for (const auto& interface_address : interface_addresses) {
const auto family_version = family == AF_INET ? Envoy::Network::Address::IpVersion::v4
Expand Down

0 comments on commit cfbc5eb

Please sign in to comment.