Merge "Slightly refactor IPv4 default router interface selection"
am: 701421c6c9
Change-Id: I1c8b9f95c8711c191e0e95cf72a5f4e5a3c3fc53
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.server.connectivity;
|
|||||||
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
||||||
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
||||||
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
|
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
|
||||||
|
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||||
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
|
||||||
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
|
||||||
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
|
||||||
@@ -99,6 +100,7 @@ import com.android.server.net.BaseNetworkObserver;
|
|||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -1302,19 +1304,16 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
protected void setUpstreamNetwork(NetworkState ns) {
|
protected void setUpstreamNetwork(NetworkState ns) {
|
||||||
String iface = null;
|
String iface = null;
|
||||||
if (ns != null && ns.linkProperties != null) {
|
if (ns != null) {
|
||||||
// Find the interface with the default IPv4 route. It may be the
|
// Find the interface with the default IPv4 route. It may be the
|
||||||
// interface described by linkProperties, or one of the interfaces
|
// interface described by linkProperties, or one of the interfaces
|
||||||
// stacked on top of it.
|
// stacked on top of it.
|
||||||
mLog.i("Finding IPv4 upstream interface on: " + ns.linkProperties);
|
mLog.i("Looking for default routes on: " + ns.linkProperties);
|
||||||
RouteInfo ipv4Default = RouteInfo.selectBestRoute(
|
final String iface4 = getIPv4DefaultRouteInterface(ns);
|
||||||
ns.linkProperties.getAllRoutes(), Inet4Address.ANY);
|
final String iface6 = getIPv6DefaultRouteInterface(ns);
|
||||||
if (ipv4Default != null) {
|
mLog.i("IPv4/IPv6 upstream interface(s): " + iface4 + "/" + iface6);
|
||||||
iface = ipv4Default.getInterface();
|
|
||||||
mLog.i("Found interface " + ipv4Default.getInterface());
|
iface = (iface4 != null) ? iface4 : null /* TODO: iface6 */;
|
||||||
} else {
|
|
||||||
mLog.i("No IPv4 upstream interface, giving up.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iface != null) {
|
if (iface != null) {
|
||||||
@@ -1957,6 +1956,31 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
mTetherStates.remove(iface);
|
mTetherStates.remove(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getIPv4DefaultRouteInterface(NetworkState ns) {
|
||||||
|
if (ns == null) return null;
|
||||||
|
return getInterfaceForDestination(ns.linkProperties, Inet4Address.ANY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getIPv6DefaultRouteInterface(NetworkState ns) {
|
||||||
|
if (ns == null) return null;
|
||||||
|
// An upstream network's IPv6 capability is currently only useful if it
|
||||||
|
// can be 64share'd downstream (RFC 7278). For now, that means mobile
|
||||||
|
// upstream networks only.
|
||||||
|
if (ns.networkCapabilities == null ||
|
||||||
|
!ns.networkCapabilities.hasTransport(TRANSPORT_CELLULAR)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getInterfaceForDestination(ns.linkProperties, Inet6Address.ANY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getInterfaceForDestination(LinkProperties lp, InetAddress dst) {
|
||||||
|
final RouteInfo ri = (lp != null)
|
||||||
|
? RouteInfo.selectBestRoute(lp.getAllRoutes(), dst)
|
||||||
|
: null;
|
||||||
|
return (ri != null) ? ri.getInterface() : null;
|
||||||
|
}
|
||||||
|
|
||||||
private static String[] copy(String[] strarray) {
|
private static String[] copy(String[] strarray) {
|
||||||
return Arrays.copyOf(strarray, strarray.length);
|
return Arrays.copyOf(strarray, strarray.length);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user