Revert "Fix problem with ipv4 over ipv6 on Android"
This reverts commit da2fd2a2b25ee4bd7b383424cb26d51fb6cc7716, as well as follow-up b7227a5a10f233cec04642f15a0233e7355bd340, "Fix handling of partial match for GetVpnUnderlyingAdapterType". Reason for revert: Breaks downstream test. First change's description: > Fix problem with ipv4 over ipv6 on Android > > This patch fixes a problem with using ipv4 over ipv6 > addresses on Android. These addresses are discovered > using 'getifaddr' with interfaces called 'v4-wlan0' or > 'v4-rmnet' but the Android API does not report them. > > This leads to failure when BasicPortAllocator tries > to bind a socket to the ip-address, making the ipv4 > address unusable. > > This solution does the following > 1) Insert BasicNetworkManager as NetworkBinderInterface > rather than AndroidNetworkManager. > > 2) When SocketServer calls BindSocketToNetwork, > BasicNetworkManager first lookup the interface name, > and then calls AndroidNetworkManager. > > 3) AndroidNetworkManager will then first try to bind > using the known ip-addresses, and if it can't find the network > it will instead match the interface names. > > The patch has been tested on real android devices, and works fine. > And everything is disabled by default, and is enabled by field trial. > > My plan is to rollout the feature, checking that it does not introduce > any problems, and if so, enabled for all. > > Bug: webrtc:10707 > Change-Id: I7081ba43d4ce17077acfa5fbab44eda127ac3971 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211003 > Commit-Queue: Jonas Oreland <jonaso@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33422} Second change's description: > 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} TBR=hta@webrtc.org,jonaso@webrtc.org NOTRY=True Bug: webrtc:10707 Change-Id: Ib13127fbf087c7f34ca0ccc6ce1805706f01d19d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211740 Reviewed-by: Taylor <deadbeef@webrtc.org> Commit-Queue: Taylor <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33453}
This commit is contained in:
committed by
Commit Bot
parent
bc1c93dc6e
commit
1e60490ddb
@ -247,8 +247,11 @@ void AndroidNetworkMonitor::Start() {
|
||||
find_network_handle_without_ipv6_temporary_part_ =
|
||||
webrtc::field_trial::IsEnabled(
|
||||
"WebRTC-FindNetworkHandleWithoutIpv6TemporaryPart");
|
||||
bind_using_ifname_ =
|
||||
webrtc::field_trial::IsEnabled("WebRTC-BindUsingInterfaceName");
|
||||
|
||||
// This is kind of magic behavior, but doing this allows the SocketServer to
|
||||
// use this as a NetworkBinder to bind sockets on a particular network when
|
||||
// it creates sockets.
|
||||
network_thread_->socketserver()->set_network_binder(this);
|
||||
|
||||
// Needed for restart after Stop().
|
||||
safety_flag_->SetAlive();
|
||||
@ -282,8 +285,7 @@ void AndroidNetworkMonitor::Stop() {
|
||||
// https://cs.chromium.org/chromium/src/net/udp/udp_socket_posix.cc
|
||||
rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
|
||||
int socket_fd,
|
||||
const rtc::IPAddress& address,
|
||||
const std::string& if_name) {
|
||||
const rtc::IPAddress& address) {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
|
||||
// Android prior to Lollipop didn't have support for binding sockets to
|
||||
@ -301,18 +303,12 @@ rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
|
||||
}
|
||||
|
||||
absl::optional<NetworkHandle> network_handle =
|
||||
FindNetworkHandleFromAddressOrName(address, if_name);
|
||||
FindNetworkHandleFromAddress(address);
|
||||
if (!network_handle) {
|
||||
RTC_LOG(LS_WARNING)
|
||||
<< "BindSocketToNetwork unable to find network handle for"
|
||||
<< " addr: " << address.ToSensitiveString() << " ifname: " << if_name;
|
||||
return rtc::NetworkBindingResult::ADDRESS_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (*network_handle == 0 /* NETWORK_UNSPECIFIED */) {
|
||||
RTC_LOG(LS_WARNING) << "BindSocketToNetwork 0 network handle for"
|
||||
<< " addr: " << address.ToSensitiveString()
|
||||
<< " ifname: " << if_name;
|
||||
return rtc::NetworkBindingResult::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@ -379,19 +375,11 @@ rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
|
||||
// ERR_NETWORK_CHANGED, rather than MapSystemError(ENONET) which gives back
|
||||
// the less descriptive ERR_FAILED.
|
||||
if (rv == 0) {
|
||||
RTC_LOG(LS_VERBOSE) << "BindSocketToNetwork bound network handle for"
|
||||
<< " addr: " << address.ToSensitiveString()
|
||||
<< " ifname: " << if_name;
|
||||
return rtc::NetworkBindingResult::SUCCESS;
|
||||
}
|
||||
|
||||
RTC_LOG(LS_WARNING) << "BindSocketToNetwork got error: " << rv
|
||||
<< " addr: " << address.ToSensitiveString()
|
||||
<< " ifname: " << if_name;
|
||||
if (rv == ENONET) {
|
||||
return rtc::NetworkBindingResult::NETWORK_CHANGED;
|
||||
}
|
||||
|
||||
return rtc::NetworkBindingResult::FAILURE;
|
||||
}
|
||||
|
||||
@ -414,9 +402,8 @@ void AndroidNetworkMonitor::OnNetworkConnected_n(
|
||||
}
|
||||
|
||||
absl::optional<NetworkHandle>
|
||||
AndroidNetworkMonitor::FindNetworkHandleFromAddressOrName(
|
||||
const rtc::IPAddress& ip_address,
|
||||
const std::string& if_name) const {
|
||||
AndroidNetworkMonitor::FindNetworkHandleFromAddress(
|
||||
const rtc::IPAddress& ip_address) const {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
RTC_LOG(LS_INFO) << "Find network handle.";
|
||||
if (find_network_handle_without_ipv6_temporary_part_) {
|
||||
@ -430,31 +417,14 @@ AndroidNetworkMonitor::FindNetworkHandleFromAddressOrName(
|
||||
return absl::make_optional(iter.first);
|
||||
}
|
||||
}
|
||||
return absl::nullopt;
|
||||
} else {
|
||||
auto iter = network_handle_by_address_.find(ip_address);
|
||||
if (iter != network_handle_by_address_.end()) {
|
||||
return absl::make_optional(iter->second);
|
||||
if (iter == network_handle_by_address_.end()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
return absl::make_optional(iter->second);
|
||||
}
|
||||
|
||||
return FindNetworkHandleFromIfname(if_name);
|
||||
}
|
||||
|
||||
absl::optional<NetworkHandle>
|
||||
AndroidNetworkMonitor::FindNetworkHandleFromIfname(
|
||||
const std::string& if_name) const {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
void AndroidNetworkMonitor::OnNetworkDisconnected_n(NetworkHandle handle) {
|
||||
@ -500,18 +470,6 @@ rtc::AdapterType AndroidNetworkMonitor::GetAdapterType(
|
||||
rtc::AdapterType type = (iter == adapter_type_by_name_.end())
|
||||
? 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"
|
||||
if (if_name.find(iter.first) != std::string::npos) {
|
||||
type = iter.second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == rtc::ADAPTER_TYPE_UNKNOWN) {
|
||||
RTC_LOG(LS_WARNING) << "Get an unknown type for the interface " << if_name;
|
||||
}
|
||||
@ -525,17 +483,6 @@ rtc::AdapterType AndroidNetworkMonitor::GetVpnUnderlyingAdapterType(
|
||||
rtc::AdapterType type = (iter == vpn_underlying_adapter_type_by_name_.end())
|
||||
? rtc::ADAPTER_TYPE_UNKNOWN
|
||||
: iter->second;
|
||||
if (type == rtc::ADAPTER_TYPE_UNKNOWN && bind_using_ifname_) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,8 @@ struct NetworkInformation {
|
||||
std::string ToString() const;
|
||||
};
|
||||
|
||||
class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||
class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface,
|
||||
public rtc::NetworkBinderInterface {
|
||||
public:
|
||||
AndroidNetworkMonitor(JNIEnv* env,
|
||||
const JavaRef<jobject>& j_application_context);
|
||||
@ -76,14 +77,9 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||
void Start() override;
|
||||
void Stop() override;
|
||||
|
||||
// Does |this| NetworkMonitorInterface implement BindSocketToNetwork?
|
||||
// Only Android returns true.
|
||||
virtual bool SupportsBindSocketToNetwork() const override { return true; }
|
||||
|
||||
rtc::NetworkBindingResult BindSocketToNetwork(
|
||||
int socket_fd,
|
||||
const rtc::IPAddress& address,
|
||||
const std::string& if_name) override;
|
||||
const rtc::IPAddress& address) override;
|
||||
rtc::AdapterType GetAdapterType(const std::string& if_name) override;
|
||||
rtc::AdapterType GetVpnUnderlyingAdapterType(
|
||||
const std::string& if_name) override;
|
||||
@ -110,9 +106,8 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||
jint preference);
|
||||
|
||||
// Visible for testing.
|
||||
absl::optional<NetworkHandle> FindNetworkHandleFromAddressOrName(
|
||||
const rtc::IPAddress& address,
|
||||
const std::string& ifname) const;
|
||||
absl::optional<NetworkHandle> FindNetworkHandleFromAddress(
|
||||
const rtc::IPAddress& address) const;
|
||||
|
||||
private:
|
||||
void OnNetworkConnected_n(const NetworkInformation& network_info);
|
||||
@ -120,9 +115,6 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||
void OnNetworkPreference_n(NetworkType type,
|
||||
rtc::NetworkPreference preference);
|
||||
|
||||
absl::optional<NetworkHandle> FindNetworkHandleFromIfname(
|
||||
const std::string& ifname) const;
|
||||
|
||||
const int android_sdk_int_;
|
||||
ScopedJavaGlobalRef<jobject> j_application_context_;
|
||||
ScopedJavaGlobalRef<jobject> j_network_monitor_;
|
||||
@ -141,14 +133,6 @@ 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;
|
||||
const rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_
|
||||
RTC_PT_GUARDED_BY(network_thread_);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user