Fix handling of partial match for GetVpnUnderlyingAdapterType

This is a followup to https://webrtc-review.googlesource.com/c/src/+/211003
and fixes the problem pointed out by deadbeef@, thanks!

Bug: webrtc:10707
Change-Id: I8dea842b25ba15416353ce4002356183087873c7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211344
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33436}
This commit is contained in:
Jonas Oreland 2021-03-11 12:52:52 +01:00 committed by Commit Bot
parent fd1e9d1af4
commit b7227a5a10
3 changed files with 28 additions and 1 deletions

View file

@ -149,5 +149,19 @@ TEST_F(AndroidNetworkMonitorTest, TestFindNetworkHandleUsingIfName) {
EXPECT_EQ(ipv6_handle, *network_handle2);
}
TEST_F(AndroidNetworkMonitorTest, TestUnderlyingVpnType) {
ScopedFieldTrials field_trials("WebRTC-BindUsingInterfaceName/Enabled/");
jni::NetworkHandle ipv4_handle = 100;
rtc::IPAddress ipv4_address(kTestIpv4Address);
jni::NetworkInformation net_info =
CreateNetworkInformation("wlan0", ipv4_handle, ipv4_address);
net_info.type = jni::NETWORK_VPN;
net_info.underlying_type_for_vpn = jni::NETWORK_WIFI;
network_monitor_->SetNetworkInfos({net_info});
EXPECT_EQ(rtc::ADAPTER_TYPE_WIFI,
network_monitor_->GetVpnUnderlyingAdapterType("v4-wlan0"));
}
} // namespace test
} // namespace webrtc

View file

@ -436,6 +436,8 @@ AndroidNetworkMonitor::FindNetworkHandleFromIfname(
if (bind_using_ifname_) {
for (auto const& iter : network_info_by_handle_) {
if (if_name.find(iter.second.interface_name) != std::string::npos) {
// Use partial match so that e.g if_name="v4-wlan0" is matched
// agains iter.first="wlan0"
return absl::make_optional(iter.first);
}
}
@ -490,6 +492,8 @@ rtc::AdapterType AndroidNetworkMonitor::GetAdapterType(
if (type == rtc::ADAPTER_TYPE_UNKNOWN && bind_using_ifname_) {
for (auto const& iter : adapter_type_by_name_) {
// Use partial match so that e.g if_name="v4-wlan0" is matched
// agains iter.first="wlan0"
if (if_name.find(iter.first) != std::string::npos) {
type = iter.second;
break;
@ -511,7 +515,9 @@ rtc::AdapterType AndroidNetworkMonitor::GetVpnUnderlyingAdapterType(
? rtc::ADAPTER_TYPE_UNKNOWN
: iter->second;
if (type == rtc::ADAPTER_TYPE_UNKNOWN && bind_using_ifname_) {
for (auto const& iter : adapter_type_by_name_) {
// Use partial match so that e.g if_name="v4-wlan0" is matched
// agains iter.first="wlan0"
for (auto const& iter : vpn_underlying_adapter_type_by_name_) {
if (if_name.find(iter.first) != std::string::npos) {
type = iter.second;
break;

View file

@ -139,6 +139,13 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
bool find_network_handle_without_ipv6_temporary_part_
RTC_GUARDED_BY(network_thread_) = false;
bool surface_cellular_types_ RTC_GUARDED_BY(network_thread_) = false;
// NOTE: if bind_using_ifname_ is TRUE
// then the adapter name is used with substring matching as follows:
// An adapater name repored by android as 'wlan0'
// will be matched with 'v4-wlan0' ("v4-wlan0".find("wlan0") != npos).
// This applies to adapter_type_by_name_, vpn_underlying_adapter_type_by_name_
// and FindNetworkHandleFromIfname.
bool bind_using_ifname_ RTC_GUARDED_BY(network_thread_) = true;
};