Merge changes I1250730c,I7d00848c am: e693d49c0a am: 9026fb46cc
am: 9a13aa9ffd
Change-Id: Icc938491a9c4474cc27a4376ef03c954aac461b3
This commit is contained in:
@@ -24,7 +24,7 @@ import android.net.RouteInfo;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
interface INetworkManagementEventObserver {
|
||||
oneway interface INetworkManagementEventObserver {
|
||||
/**
|
||||
* Interface configuration status has changed.
|
||||
*
|
||||
|
||||
@@ -18,10 +18,12 @@ package android.net;
|
||||
import android.net.INetworkMonitorCallbacks;
|
||||
import android.net.dhcp.DhcpServingParamsParcel;
|
||||
import android.net.dhcp.IDhcpServerCallbacks;
|
||||
import android.net.ip.IIpClientCallbacks;
|
||||
|
||||
/** @hide */
|
||||
oneway interface INetworkStackConnector {
|
||||
void makeDhcpServer(in String ifName, in DhcpServingParamsParcel params,
|
||||
in IDhcpServerCallbacks cb);
|
||||
void makeNetworkMonitor(int netId, String name, in INetworkMonitorCallbacks cb);
|
||||
void makeIpClient(in String ifName, in IIpClientCallbacks callbacks);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.dhcp.DhcpServingParamsParcel;
|
||||
import android.net.dhcp.IDhcpServerCallbacks;
|
||||
import android.net.ip.IIpClientCallbacks;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.Process;
|
||||
@@ -83,6 +84,21 @@ public class NetworkStack {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an IpClient on the specified interface.
|
||||
*
|
||||
* <p>The IpClient will be returned asynchronously through the provided callbacks.
|
||||
*/
|
||||
public void makeIpClient(String ifName, IIpClientCallbacks cb) {
|
||||
requestConnector(connector -> {
|
||||
try {
|
||||
connector.makeIpClient(ifName, cb);
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowFromSystemServer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a NetworkMonitor.
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@ java_library {
|
||||
":services-networkstack-shared-srcs",
|
||||
],
|
||||
static_libs: [
|
||||
"dhcp-packet-lib",
|
||||
"services-netlink-lib",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<!-- Launch captive portal app as specific user -->
|
||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||
<uses-permission android:name="android.permission.NETWORK_STACK" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<application
|
||||
android:label="NetworkStack"
|
||||
android:defaultToDeviceProtectedStorage="true"
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package android.net.apf;
|
||||
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ECHO_REQUEST_TYPE;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_NEIGHBOR_ADVERTISEMENT;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ROUTER_ADVERTISEMENT;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ROUTER_SOLICITATION;
|
||||
import static android.net.util.SocketUtils.makePacketSocketAddress;
|
||||
import static android.system.OsConstants.AF_PACKET;
|
||||
import static android.system.OsConstants.ARPHRD_ETHER;
|
||||
@@ -35,6 +31,10 @@ import static com.android.internal.util.BitUtils.getUint16;
|
||||
import static com.android.internal.util.BitUtils.getUint32;
|
||||
import static com.android.internal.util.BitUtils.getUint8;
|
||||
import static com.android.internal.util.BitUtils.uint32;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ECHO_REQUEST_TYPE;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_NEIGHBOR_ADVERTISEMENT;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ROUTER_ADVERTISEMENT;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ROUTER_SOLICITATION;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -46,7 +46,7 @@ import android.net.LinkProperties;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.apf.ApfGenerator.IllegalInstructionException;
|
||||
import android.net.apf.ApfGenerator.Register;
|
||||
import android.net.ip.IpClientCallbacks;
|
||||
import android.net.ip.IpClient.IpClientCallbacksWrapper;
|
||||
import android.net.metrics.ApfProgramEvent;
|
||||
import android.net.metrics.ApfStats;
|
||||
import android.net.metrics.IpConnectivityLog;
|
||||
@@ -337,7 +337,7 @@ public class ApfFilter {
|
||||
private static final int APF_MAX_ETH_TYPE_BLACK_LIST_LEN = 20;
|
||||
|
||||
private final ApfCapabilities mApfCapabilities;
|
||||
private final IpClientCallbacks mIpClientCallback;
|
||||
private final IpClientCallbacksWrapper mIpClientCallback;
|
||||
private final InterfaceParams mInterfaceParams;
|
||||
private final IpConnectivityLog mMetricsLog;
|
||||
|
||||
@@ -378,7 +378,7 @@ public class ApfFilter {
|
||||
|
||||
@VisibleForTesting
|
||||
ApfFilter(Context context, ApfConfiguration config, InterfaceParams ifParams,
|
||||
IpClientCallbacks ipClientCallback, IpConnectivityLog log) {
|
||||
IpClientCallbacksWrapper ipClientCallback, IpConnectivityLog log) {
|
||||
mApfCapabilities = config.apfCapabilities;
|
||||
mIpClientCallback = ipClientCallback;
|
||||
mInterfaceParams = ifParams;
|
||||
@@ -1420,7 +1420,7 @@ public class ApfFilter {
|
||||
* filtering using APF programs.
|
||||
*/
|
||||
public static ApfFilter maybeCreate(Context context, ApfConfiguration config,
|
||||
InterfaceParams ifParams, IpClientCallbacks ipClientCallback) {
|
||||
InterfaceParams ifParams, IpClientCallbacksWrapper ipClientCallback) {
|
||||
if (context == null || config == null || ifParams == null) return null;
|
||||
ApfCapabilities apfCapabilities = config.apfCapabilities;
|
||||
if (apfCapabilities == null) return null;
|
||||
1052
packages/NetworkStack/src/android/net/dhcp/DhcpClient.java
Normal file
1052
packages/NetworkStack/src/android/net/dhcp/DhcpClient.java
Normal file
File diff suppressed because it is too large
Load Diff
1691
packages/NetworkStack/src/android/net/ip/IpClient.java
Normal file
1691
packages/NetworkStack/src/android/net/ip/IpClient.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,47 +16,46 @@
|
||||
|
||||
package android.net.util;
|
||||
|
||||
import static android.net.util.NetworkConstants.ARP_HWTYPE_ETHER;
|
||||
import static android.net.util.NetworkConstants.ARP_PAYLOAD_LEN;
|
||||
import static android.net.util.NetworkConstants.ARP_REPLY;
|
||||
import static android.net.util.NetworkConstants.ARP_REQUEST;
|
||||
import static android.net.util.NetworkConstants.DHCP4_CLIENT_PORT;
|
||||
import static android.net.util.NetworkConstants.ETHER_ADDR_LEN;
|
||||
import static android.net.util.NetworkConstants.ETHER_DST_ADDR_OFFSET;
|
||||
import static android.net.util.NetworkConstants.ETHER_HEADER_LEN;
|
||||
import static android.net.util.NetworkConstants.ETHER_SRC_ADDR_OFFSET;
|
||||
import static android.net.util.NetworkConstants.ETHER_TYPE_ARP;
|
||||
import static android.net.util.NetworkConstants.ETHER_TYPE_IPV4;
|
||||
import static android.net.util.NetworkConstants.ETHER_TYPE_IPV6;
|
||||
import static android.net.util.NetworkConstants.ETHER_TYPE_OFFSET;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_HEADER_MIN_LEN;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ND_OPTION_MIN_LENGTH;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ND_OPTION_MTU;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ND_OPTION_SLLA;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ND_OPTION_TLLA;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_NEIGHBOR_ADVERTISEMENT;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_NEIGHBOR_SOLICITATION;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ROUTER_ADVERTISEMENT;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ROUTER_SOLICITATION;
|
||||
import static android.net.util.NetworkConstants.IPV4_ADDR_LEN;
|
||||
import static android.net.util.NetworkConstants.IPV4_DST_ADDR_OFFSET;
|
||||
import static android.net.util.NetworkConstants.IPV4_FLAGS_OFFSET;
|
||||
import static android.net.util.NetworkConstants.IPV4_FRAGMENT_MASK;
|
||||
import static android.net.util.NetworkConstants.IPV4_HEADER_MIN_LEN;
|
||||
import static android.net.util.NetworkConstants.IPV4_IHL_MASK;
|
||||
import static android.net.util.NetworkConstants.IPV4_PROTOCOL_OFFSET;
|
||||
import static android.net.util.NetworkConstants.IPV4_SRC_ADDR_OFFSET;
|
||||
import static android.net.util.NetworkConstants.IPV6_ADDR_LEN;
|
||||
import static android.net.util.NetworkConstants.IPV6_HEADER_LEN;
|
||||
import static android.net.util.NetworkConstants.IPV6_PROTOCOL_OFFSET;
|
||||
import static android.net.util.NetworkConstants.IPV6_SRC_ADDR_OFFSET;
|
||||
import static android.net.util.NetworkConstants.UDP_HEADER_LEN;
|
||||
import static android.net.util.NetworkConstants.asString;
|
||||
import static android.net.util.NetworkConstants.asUint;
|
||||
import static android.system.OsConstants.IPPROTO_ICMPV6;
|
||||
import static android.system.OsConstants.IPPROTO_UDP;
|
||||
|
||||
import static com.android.server.util.NetworkStackConstants.ARP_HWTYPE_ETHER;
|
||||
import static com.android.server.util.NetworkStackConstants.ARP_PAYLOAD_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.ARP_REPLY;
|
||||
import static com.android.server.util.NetworkStackConstants.ARP_REQUEST;
|
||||
import static com.android.server.util.NetworkStackConstants.DHCP4_CLIENT_PORT;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_ADDR_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_DST_ADDR_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_HEADER_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_SRC_ADDR_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_TYPE_ARP;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_TYPE_IPV4;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_TYPE_IPV6;
|
||||
import static com.android.server.util.NetworkStackConstants.ETHER_TYPE_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_HEADER_MIN_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ND_OPTION_MIN_LENGTH;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ND_OPTION_MTU;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ND_OPTION_SLLA;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ND_OPTION_TLLA;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_NEIGHBOR_ADVERTISEMENT;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_NEIGHBOR_SOLICITATION;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ROUTER_ADVERTISEMENT;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ROUTER_SOLICITATION;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_ADDR_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_DST_ADDR_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_FLAGS_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_FRAGMENT_MASK;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_HEADER_MIN_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_IHL_MASK;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_PROTOCOL_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV4_SRC_ADDR_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV6_ADDR_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV6_HEADER_LEN;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV6_PROTOCOL_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.IPV6_SRC_ADDR_OFFSET;
|
||||
import static com.android.server.util.NetworkStackConstants.UDP_HEADER_LEN;
|
||||
|
||||
import android.net.MacAddress;
|
||||
import android.net.dhcp.DhcpPacket;
|
||||
|
||||
@@ -412,4 +411,25 @@ public class ConnectivityPacketSummary {
|
||||
final String MAC48_FORMAT = "%02x:%02x:%02x:%02x:%02x:%02x";
|
||||
return String.format(MAC48_FORMAT, printableBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to convert an int to a String.
|
||||
*/
|
||||
public static String asString(int i) {
|
||||
return Integer.toString(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to read a byte as an unsigned int.
|
||||
*/
|
||||
public static int asUint(byte b) {
|
||||
return (b & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to read a short as an unsigned int.
|
||||
*/
|
||||
public static int asUint(short s) {
|
||||
return (s & 0xffff);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@ import android.net.dhcp.DhcpServer;
|
||||
import android.net.dhcp.DhcpServingParams;
|
||||
import android.net.dhcp.DhcpServingParamsParcel;
|
||||
import android.net.dhcp.IDhcpServerCallbacks;
|
||||
import android.net.ip.IIpClientCallbacks;
|
||||
import android.net.ip.IpClient;
|
||||
import android.net.shared.PrivateDnsConfig;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.IBinder;
|
||||
@@ -50,7 +52,11 @@ import com.android.server.connectivity.NetworkMonitor;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Android service used to start the network stack when bound to via an intent.
|
||||
@@ -80,6 +86,8 @@ public class NetworkStackService extends Service {
|
||||
private static final int NUM_VALIDATION_LOG_LINES = 20;
|
||||
private final Context mContext;
|
||||
private final ConnectivityManager mCm;
|
||||
@GuardedBy("mIpClients")
|
||||
private final ArrayList<WeakReference<IpClient>> mIpClients = new ArrayList<>();
|
||||
|
||||
private static final int MAX_VALIDATION_LOGS = 10;
|
||||
@GuardedBy("mValidationLogs")
|
||||
@@ -137,6 +145,24 @@ public class NetworkStackService extends Service {
|
||||
cb.onNetworkMonitorCreated(new NetworkMonitorImpl(nm));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeIpClient(String ifName, IIpClientCallbacks cb) throws RemoteException {
|
||||
final IpClient ipClient = new IpClient(mContext, ifName, cb);
|
||||
|
||||
synchronized (mIpClients) {
|
||||
final Iterator<WeakReference<IpClient>> it = mIpClients.iterator();
|
||||
while (it.hasNext()) {
|
||||
final IpClient ipc = it.next().get();
|
||||
if (ipc == null) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
mIpClients.add(new WeakReference<>(ipClient));
|
||||
}
|
||||
|
||||
cb.onIpClientCreated(ipClient.makeConnector());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter fout,
|
||||
@Nullable String[] args) {
|
||||
@@ -145,6 +171,33 @@ public class NetworkStackService extends Service {
|
||||
pw.println("NetworkStack logs:");
|
||||
mLog.dump(fd, pw, args);
|
||||
|
||||
// Dump full IpClient logs for non-GCed clients
|
||||
pw.println();
|
||||
pw.println("Recently active IpClient logs:");
|
||||
final ArrayList<IpClient> ipClients = new ArrayList<>();
|
||||
final HashSet<String> dumpedIpClientIfaces = new HashSet<>();
|
||||
synchronized (mIpClients) {
|
||||
for (WeakReference<IpClient> ipcRef : mIpClients) {
|
||||
final IpClient ipc = ipcRef.get();
|
||||
if (ipc != null) {
|
||||
ipClients.add(ipc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (IpClient ipc : ipClients) {
|
||||
pw.println(ipc.getName());
|
||||
pw.increaseIndent();
|
||||
ipc.dump(fd, pw, args);
|
||||
pw.decreaseIndent();
|
||||
dumpedIpClientIfaces.add(ipc.getInterfaceName());
|
||||
}
|
||||
|
||||
// State machine and connectivity metrics logs are kept for GCed IpClients
|
||||
pw.println();
|
||||
pw.println("Other IpClient logs:");
|
||||
IpClient.dumpAllLogs(fout, dumpedIpClientIfaces);
|
||||
|
||||
pw.println();
|
||||
pw.println("Validation logs (most recent first):");
|
||||
synchronized (mValidationLogs) {
|
||||
|
||||
@@ -31,6 +31,96 @@ public final class NetworkStackConstants {
|
||||
public static final int IPV4_MIN_MTU = 68;
|
||||
public static final int IPV4_MAX_MTU = 65_535;
|
||||
|
||||
/**
|
||||
* Ethernet constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc894
|
||||
* - https://tools.ietf.org/html/rfc2464
|
||||
* - https://tools.ietf.org/html/rfc7042
|
||||
* - http://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
|
||||
* - http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml
|
||||
*/
|
||||
public static final int ETHER_DST_ADDR_OFFSET = 0;
|
||||
public static final int ETHER_SRC_ADDR_OFFSET = 6;
|
||||
public static final int ETHER_ADDR_LEN = 6;
|
||||
public static final int ETHER_TYPE_OFFSET = 12;
|
||||
public static final int ETHER_TYPE_LENGTH = 2;
|
||||
public static final int ETHER_TYPE_ARP = 0x0806;
|
||||
public static final int ETHER_TYPE_IPV4 = 0x0800;
|
||||
public static final int ETHER_TYPE_IPV6 = 0x86dd;
|
||||
public static final int ETHER_HEADER_LEN = 14;
|
||||
|
||||
/**
|
||||
* ARP constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc826
|
||||
* - http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
|
||||
*/
|
||||
public static final int ARP_PAYLOAD_LEN = 28; // For Ethernet+IPv4.
|
||||
public static final int ARP_REQUEST = 1;
|
||||
public static final int ARP_REPLY = 2;
|
||||
public static final int ARP_HWTYPE_RESERVED_LO = 0;
|
||||
public static final int ARP_HWTYPE_ETHER = 1;
|
||||
public static final int ARP_HWTYPE_RESERVED_HI = 0xffff;
|
||||
|
||||
/**
|
||||
* IPv4 constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc791
|
||||
*/
|
||||
public static final int IPV4_HEADER_MIN_LEN = 20;
|
||||
public static final int IPV4_IHL_MASK = 0xf;
|
||||
public static final int IPV4_FLAGS_OFFSET = 6;
|
||||
public static final int IPV4_FRAGMENT_MASK = 0x1fff;
|
||||
public static final int IPV4_PROTOCOL_OFFSET = 9;
|
||||
public static final int IPV4_SRC_ADDR_OFFSET = 12;
|
||||
public static final int IPV4_DST_ADDR_OFFSET = 16;
|
||||
public static final int IPV4_ADDR_LEN = 4;
|
||||
|
||||
/**
|
||||
* IPv6 constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc2460
|
||||
*/
|
||||
public static final int IPV6_ADDR_LEN = 16;
|
||||
public static final int IPV6_HEADER_LEN = 40;
|
||||
public static final int IPV6_PROTOCOL_OFFSET = 6;
|
||||
public static final int IPV6_SRC_ADDR_OFFSET = 8;
|
||||
public static final int IPV6_DST_ADDR_OFFSET = 24;
|
||||
|
||||
/**
|
||||
* ICMPv6 constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc4443
|
||||
* - https://tools.ietf.org/html/rfc4861
|
||||
*/
|
||||
public static final int ICMPV6_HEADER_MIN_LEN = 4;
|
||||
public static final int ICMPV6_ECHO_REPLY_TYPE = 129;
|
||||
public static final int ICMPV6_ECHO_REQUEST_TYPE = 128;
|
||||
public static final int ICMPV6_ROUTER_SOLICITATION = 133;
|
||||
public static final int ICMPV6_ROUTER_ADVERTISEMENT = 134;
|
||||
public static final int ICMPV6_NEIGHBOR_SOLICITATION = 135;
|
||||
public static final int ICMPV6_NEIGHBOR_ADVERTISEMENT = 136;
|
||||
public static final int ICMPV6_ND_OPTION_MIN_LENGTH = 8;
|
||||
public static final int ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR = 8;
|
||||
public static final int ICMPV6_ND_OPTION_SLLA = 1;
|
||||
public static final int ICMPV6_ND_OPTION_TLLA = 2;
|
||||
public static final int ICMPV6_ND_OPTION_MTU = 5;
|
||||
|
||||
/**
|
||||
* UDP constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc768
|
||||
*/
|
||||
public static final int UDP_HEADER_LEN = 8;
|
||||
|
||||
|
||||
/**
|
||||
* DHCP constants.
|
||||
*
|
||||
@@ -38,6 +128,7 @@ public final class NetworkStackConstants {
|
||||
* - https://tools.ietf.org/html/rfc2131
|
||||
*/
|
||||
public static final int INFINITE_LEASE = 0xffffffff;
|
||||
public static final int DHCP4_CLIENT_PORT = 68;
|
||||
|
||||
private NetworkStackConstants() {
|
||||
throw new UnsupportedOperationException("This class is not to be instantiated");
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
android_test {
|
||||
name: "NetworkStackTests",
|
||||
certificate: "platform",
|
||||
srcs: ["src/**/*.java"],
|
||||
resource_dirs: ["res"],
|
||||
static_libs: [
|
||||
"android-support-test",
|
||||
"frameworks-base-testutils",
|
||||
"mockito-target-extended-minus-junit4",
|
||||
"NetworkStackLib",
|
||||
"testables",
|
||||
@@ -26,10 +29,70 @@ android_test {
|
||||
libs: [
|
||||
"android.test.runner",
|
||||
"android.test.base",
|
||||
"android.test.mock",
|
||||
],
|
||||
jni_libs: [
|
||||
// For mockito extended
|
||||
"libdexmakerjvmtiagent",
|
||||
"libstaticjvmtiagent",
|
||||
]
|
||||
}
|
||||
// For ApfTest
|
||||
"libartbase",
|
||||
"libbacktrace",
|
||||
"libbase",
|
||||
"libbinder",
|
||||
"libbinderthreadstate",
|
||||
"libc++",
|
||||
"libcrypto",
|
||||
"libcutils",
|
||||
"libdexfile",
|
||||
"libhidl-gen-utils",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"liblzma",
|
||||
"libnativehelper",
|
||||
"libnetworkstacktestsjni",
|
||||
"libpackagelistparser",
|
||||
"libpcre2",
|
||||
"libprocessgroup",
|
||||
"libselinux",
|
||||
"libui",
|
||||
"libutils",
|
||||
"libvintf",
|
||||
"libvndksupport",
|
||||
"libtinyxml2",
|
||||
"libunwindstack",
|
||||
"libutilscallstack",
|
||||
"libziparchive",
|
||||
"libz",
|
||||
"netd_aidl_interface-cpp",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libnetworkstacktestsjni",
|
||||
srcs: [
|
||||
"jni/**/*.cpp"
|
||||
],
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
include_dirs: [
|
||||
"hardware/google/apf",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbinder",
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libnativehelper",
|
||||
"netd_aidl_interface-cpp",
|
||||
],
|
||||
static_libs: [
|
||||
"libapf",
|
||||
"libpcap",
|
||||
],
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,35 @@
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.server.networkstack.tests">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_LOGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
|
||||
<uses-permission android:name="android.permission.MANAGE_APP_TOKENS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
|
||||
<uses-permission android:name="android.permission.REAL_GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.GET_DETAILED_TASKS" />
|
||||
<uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" />
|
||||
<uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" />
|
||||
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_USERS" />
|
||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
||||
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.PACKET_KEEPALIVE_OFFLOAD" />
|
||||
<uses-permission android:name="android.permission.GET_INTENT_SENDER_INTENT" />
|
||||
<uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" />
|
||||
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.NETWORK_STACK" />
|
||||
|
||||
<application android:debuggable="true">
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package android.net.apf;
|
||||
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ECHO_REQUEST_TYPE;
|
||||
import static android.net.util.NetworkConstants.ICMPV6_ROUTER_ADVERTISEMENT;
|
||||
import static android.system.OsConstants.AF_UNIX;
|
||||
import static android.system.OsConstants.ARPHRD_ETHER;
|
||||
import static android.system.OsConstants.ETH_P_ARP;
|
||||
@@ -28,12 +26,14 @@ import static android.system.OsConstants.IPPROTO_UDP;
|
||||
import static android.system.OsConstants.SOCK_STREAM;
|
||||
|
||||
import static com.android.internal.util.BitUtils.bytesToBEInt;
|
||||
import static com.android.server.util.NetworkStackConstants.ICMPV6_ECHO_REQUEST_TYPE;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -42,10 +42,14 @@ import android.net.LinkProperties;
|
||||
import android.net.apf.ApfFilter.ApfConfiguration;
|
||||
import android.net.apf.ApfGenerator.IllegalInstructionException;
|
||||
import android.net.apf.ApfGenerator.Register;
|
||||
import android.net.ip.IIpClientCallbacks;
|
||||
import android.net.ip.IpClient;
|
||||
import android.net.ip.IpClient.IpClientCallbacksWrapper;
|
||||
import android.net.ip.IpClientCallbacks;
|
||||
import android.net.metrics.IpConnectivityLog;
|
||||
import android.net.metrics.RaEvent;
|
||||
import android.net.util.InterfaceParams;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.ConditionVariable;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
@@ -57,8 +61,9 @@ import android.system.Os;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.frameworks.tests.net.R;
|
||||
import com.android.internal.util.HexDump;
|
||||
import com.android.server.networkstack.tests.R;
|
||||
import com.android.server.util.NetworkStackConstants;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
import libcore.io.Streams;
|
||||
@@ -100,7 +105,7 @@ public class ApfTest {
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
// Load up native shared library containing APF interpreter exposed via JNI.
|
||||
System.loadLibrary("frameworksnettestsjni");
|
||||
System.loadLibrary("networkstacktestsjni");
|
||||
}
|
||||
|
||||
private static final String TAG = "ApfTest";
|
||||
@@ -915,10 +920,14 @@ public class ApfTest {
|
||||
HexDump.toHexString(data, false), result);
|
||||
}
|
||||
|
||||
private class MockIpClientCallback extends IpClientCallbacks {
|
||||
private class MockIpClientCallback extends IpClientCallbacksWrapper {
|
||||
private final ConditionVariable mGotApfProgram = new ConditionVariable();
|
||||
private byte[] mLastApfProgram;
|
||||
|
||||
MockIpClientCallback() {
|
||||
super(mock(IIpClientCallbacks.class), mock(SharedLog.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installPacketFilter(byte[] filter) {
|
||||
mLastApfProgram = filter;
|
||||
@@ -946,7 +955,7 @@ public class ApfTest {
|
||||
private final long mFixedTimeMs = SystemClock.elapsedRealtime();
|
||||
|
||||
public TestApfFilter(Context context, ApfConfiguration config,
|
||||
IpClientCallbacks ipClientCallback, IpConnectivityLog log) throws Exception {
|
||||
IpClientCallbacksWrapper ipClientCallback, IpConnectivityLog log) throws Exception {
|
||||
super(context, config, InterfaceParams.getByName("lo"), ipClientCallback, log);
|
||||
}
|
||||
|
||||
@@ -1075,8 +1084,8 @@ public class ApfTest {
|
||||
private static final byte[] IPV4_ANY_HOST_ADDR = {0, 0, 0, 0};
|
||||
|
||||
// Helper to initialize a default apfFilter.
|
||||
private ApfFilter setupApfFilter(IpClientCallbacks ipClientCallback, ApfConfiguration config)
|
||||
throws Exception {
|
||||
private ApfFilter setupApfFilter(
|
||||
IpClientCallbacksWrapper ipClientCallback, ApfConfiguration config) throws Exception {
|
||||
LinkAddress link = new LinkAddress(InetAddress.getByAddress(MOCK_IPV4_ADDR), 19);
|
||||
LinkProperties lp = new LinkProperties();
|
||||
lp.addLinkAddress(link);
|
||||
@@ -1294,7 +1303,7 @@ public class ApfTest {
|
||||
|
||||
// However, we should still let through all other ICMPv6 types.
|
||||
ByteBuffer raPacket = ByteBuffer.wrap(packet.array().clone());
|
||||
raPacket.put(ICMP6_TYPE_OFFSET, (byte)ICMPV6_ROUTER_ADVERTISEMENT);
|
||||
raPacket.put(ICMP6_TYPE_OFFSET, (byte) NetworkStackConstants.ICMPV6_ROUTER_ADVERTISEMENT);
|
||||
assertPass(ipClientCallback.getApfProgram(), raPacket.array());
|
||||
|
||||
// Now wake up from doze mode to ensure that we no longer drop the packets.
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package android.net.ip;
|
||||
|
||||
import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.eq;
|
||||
@@ -87,7 +90,7 @@ public class IpClientTest {
|
||||
@Mock private INetworkManagementService mNMService;
|
||||
@Mock private INetd mNetd;
|
||||
@Mock private Resources mResources;
|
||||
@Mock private IpClientCallbacks mCb;
|
||||
@Mock private IIpClientCallbacks mCb;
|
||||
@Mock private AlarmManager mAlarm;
|
||||
@Mock private IpClient.Dependencies mDependecies;
|
||||
private MockContentResolver mContentResolver;
|
||||
@@ -209,7 +212,8 @@ public class IpClientTest {
|
||||
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false);
|
||||
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface);
|
||||
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1))
|
||||
.onLinkPropertiesChange(eq(makeEmptyLinkProperties(iface)));
|
||||
.onLinkPropertiesChange(argThat(
|
||||
lp -> fromStableParcelable(lp).equals(makeEmptyLinkProperties(iface))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -254,13 +258,15 @@ public class IpClientTest {
|
||||
mObserver.addressUpdated(iface, new LinkAddress(addresses[lastAddr]));
|
||||
LinkProperties want = linkproperties(links(addresses), routes(prefixes));
|
||||
want.setInterfaceName(iface);
|
||||
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(eq(want));
|
||||
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(argThat(
|
||||
lp -> fromStableParcelable(lp).equals(want)));
|
||||
|
||||
ipc.shutdown();
|
||||
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false);
|
||||
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface);
|
||||
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1))
|
||||
.onLinkPropertiesChange(eq(makeEmptyLinkProperties(iface)));
|
||||
.onLinkPropertiesChange(argThat(
|
||||
lp -> fromStableParcelable(lp).equals(makeEmptyLinkProperties(iface))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -492,11 +498,11 @@ public class IpClientTest {
|
||||
List<String> list3 = Arrays.asList("bar", "baz");
|
||||
List<String> list4 = Arrays.asList("foo", "bar", "baz");
|
||||
|
||||
assertTrue(IpClient.all(list1, (x) -> false));
|
||||
assertFalse(IpClient.all(list2, (x) -> false));
|
||||
assertTrue(IpClient.all(list3, (x) -> true));
|
||||
assertTrue(IpClient.all(list2, (x) -> x.charAt(0) == 'f'));
|
||||
assertFalse(IpClient.all(list4, (x) -> x.charAt(0) == 'f'));
|
||||
assertTrue(InitialConfiguration.all(list1, (x) -> false));
|
||||
assertFalse(InitialConfiguration.all(list2, (x) -> false));
|
||||
assertTrue(InitialConfiguration.all(list3, (x) -> true));
|
||||
assertTrue(InitialConfiguration.all(list2, (x) -> x.charAt(0) == 'f'));
|
||||
assertFalse(InitialConfiguration.all(list4, (x) -> x.charAt(0) == 'f'));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -506,11 +512,11 @@ public class IpClientTest {
|
||||
List<String> list3 = Arrays.asList("bar", "baz");
|
||||
List<String> list4 = Arrays.asList("foo", "bar", "baz");
|
||||
|
||||
assertFalse(IpClient.any(list1, (x) -> true));
|
||||
assertTrue(IpClient.any(list2, (x) -> true));
|
||||
assertTrue(IpClient.any(list2, (x) -> x.charAt(0) == 'f'));
|
||||
assertFalse(IpClient.any(list3, (x) -> x.charAt(0) == 'f'));
|
||||
assertTrue(IpClient.any(list4, (x) -> x.charAt(0) == 'f'));
|
||||
assertFalse(InitialConfiguration.any(list1, (x) -> true));
|
||||
assertTrue(InitialConfiguration.any(list2, (x) -> true));
|
||||
assertTrue(InitialConfiguration.any(list2, (x) -> x.charAt(0) == 'f'));
|
||||
assertFalse(InitialConfiguration.any(list3, (x) -> x.charAt(0) == 'f'));
|
||||
assertTrue(InitialConfiguration.any(list4, (x) -> x.charAt(0) == 'f'));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,7 +100,7 @@ import android.net.netlink.InetDiagMessage;
|
||||
import android.net.shared.NetworkMonitorUtils;
|
||||
import android.net.shared.PrivateDnsConfig;
|
||||
import android.net.util.MultinetworkPolicyTracker;
|
||||
import android.net.util.NetdService;
|
||||
import android.net.shared.NetdService;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
@@ -44,7 +44,7 @@ import android.net.LinkAddress;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.util.NetdService;
|
||||
import android.net.shared.NetdService;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
@@ -62,7 +62,7 @@ import android.net.NetworkUtils;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.TetherStatsParcel;
|
||||
import android.net.UidRange;
|
||||
import android.net.util.NetdService;
|
||||
import android.net.shared.NetdService;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.content.Context;
|
||||
import android.net.ConnectivityMetricsEvent;
|
||||
import android.net.IIpConnectivityMetrics;
|
||||
import android.net.INetdEventCallback;
|
||||
import android.net.ip.IpClient;
|
||||
import android.net.metrics.ApfProgramEvent;
|
||||
import android.net.metrics.IpConnectivityLog;
|
||||
import android.os.Binder;
|
||||
@@ -270,8 +269,6 @@ final public class IpConnectivityMetrics extends SystemService {
|
||||
// Dump the rolling buffer of metrics event and pretty print events using a human readable
|
||||
// format. Also print network dns/connect statistics and default network event time series.
|
||||
static final String CMD_LIST = "list";
|
||||
// Dump all IpClient logs ("ipclient").
|
||||
static final String CMD_IPCLIENT = IpClient.DUMP_ARG;
|
||||
// By default any other argument will fall into the default case which is the equivalent
|
||||
// of calling both the "list" and "ipclient" commands. This includes most notably bug
|
||||
// reports collected by dumpsys.cpp with the "-a" argument.
|
||||
@@ -295,20 +292,9 @@ final public class IpConnectivityMetrics extends SystemService {
|
||||
case CMD_PROTO:
|
||||
cmdListAsProto(pw);
|
||||
return;
|
||||
case CMD_IPCLIENT: {
|
||||
final String[] ipclientArgs = ((args != null) && (args.length > 1))
|
||||
? Arrays.copyOfRange(args, 1, args.length)
|
||||
: null;
|
||||
IpClient.dumpAllLogs(pw, ipclientArgs);
|
||||
return;
|
||||
}
|
||||
case CMD_LIST:
|
||||
cmdList(pw);
|
||||
return;
|
||||
default:
|
||||
cmdList(pw);
|
||||
pw.println("");
|
||||
IpClient.dumpAllLogs(pw, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@ java_library_static {
|
||||
srcs: ["java/**/*.java"],
|
||||
}
|
||||
|
||||
// TODO: move to networking module with DhcpClient and remove lib
|
||||
java_library {
|
||||
name: "dhcp-packet-lib",
|
||||
srcs: [
|
||||
"java/android/net/dhcp/*Packet.java",
|
||||
]
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "services-networkstack-shared-srcs",
|
||||
srcs: [
|
||||
"java/android/net/util/FdEventsReader.java", // TODO: move to NetworkStack with IpClient
|
||||
"java/android/net/ip/InterfaceController.java", // TODO: move to NetworkStack with tethering
|
||||
"java/android/net/util/InterfaceParams.java", // TODO: move to NetworkStack with IpServer
|
||||
"java/android/net/shared/*.java",
|
||||
],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "services-netlink-lib",
|
||||
srcs: [
|
||||
"java/android/net/netlink/*.java",
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -16,8 +16,15 @@
|
||||
|
||||
package android.net.ip;
|
||||
|
||||
import static android.net.shared.IpConfigurationParcelableUtil.fromStableParcelable;
|
||||
import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.DhcpResultsParcelable;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.LinkPropertiesParcelable;
|
||||
import android.net.NetworkStack;
|
||||
import android.net.ip.IIpClientCallbacks;
|
||||
import android.os.ConditionVariable;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
@@ -31,8 +38,8 @@ import java.io.PrintWriter;
|
||||
* @hide
|
||||
*/
|
||||
public class IpClientUtil {
|
||||
// TODO: remove once IpClient dumps are moved to NetworkStack and callers don't need this arg
|
||||
public static final String DUMP_ARG = IpClient.DUMP_ARG;
|
||||
// TODO: remove with its callers
|
||||
public static final String DUMP_ARG = "ipclient";
|
||||
|
||||
/**
|
||||
* Subclass of {@link IpClientCallbacks} allowing clients to block until provisioning is
|
||||
@@ -69,24 +76,129 @@ public class IpClientUtil {
|
||||
*
|
||||
* <p>This is a convenience method to allow clients to use {@link IpClientCallbacks} instead of
|
||||
* {@link IIpClientCallbacks}.
|
||||
* @see {@link NetworkStack#makeIpClient(String, IIpClientCallbacks)}
|
||||
*/
|
||||
public static void makeIpClient(Context context, String ifName, IpClientCallbacks callback) {
|
||||
// TODO: request IpClient asynchronously from NetworkStack.
|
||||
final IpClient ipClient = new IpClient(context, ifName, callback);
|
||||
callback.onIpClientCreated(ipClient.makeConnector());
|
||||
context.getSystemService(NetworkStack.class)
|
||||
.makeIpClient(ifName, new IpClientCallbacksProxy(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new IpClient.
|
||||
*
|
||||
* <p>This is a convenience method to allow clients to use {@link IpClientCallbacksProxy}
|
||||
* instead of {@link IIpClientCallbacks}.
|
||||
* @see {@link NetworkStack#makeIpClient(String, IIpClientCallbacks)}
|
||||
*/
|
||||
public static void makeIpClient(
|
||||
Context context, String ifName, IpClientCallbacksProxy callback) {
|
||||
context.getSystemService(NetworkStack.class)
|
||||
.makeIpClient(ifName, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to relay calls from {@link IIpClientCallbacks} to {@link IpClientCallbacks}.
|
||||
*/
|
||||
public static class IpClientCallbacksProxy extends IIpClientCallbacks.Stub {
|
||||
protected final IpClientCallbacks mCb;
|
||||
|
||||
/**
|
||||
* Create a new IpClientCallbacksProxy.
|
||||
*/
|
||||
public IpClientCallbacksProxy(IpClientCallbacks cb) {
|
||||
mCb = cb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIpClientCreated(IIpClient ipClient) {
|
||||
mCb.onIpClientCreated(ipClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreDhcpAction() {
|
||||
mCb.onPreDhcpAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostDhcpAction() {
|
||||
mCb.onPostDhcpAction();
|
||||
}
|
||||
|
||||
// This is purely advisory and not an indication of provisioning
|
||||
// success or failure. This is only here for callers that want to
|
||||
// expose DHCPv4 results to other APIs (e.g., WifiInfo#setInetAddress).
|
||||
// DHCPv4 or static IPv4 configuration failure or success can be
|
||||
// determined by whether or not the passed-in DhcpResults object is
|
||||
// null or not.
|
||||
@Override
|
||||
public void onNewDhcpResults(DhcpResultsParcelable dhcpResults) {
|
||||
mCb.onNewDhcpResults(fromStableParcelable(dhcpResults));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProvisioningSuccess(LinkPropertiesParcelable newLp) {
|
||||
mCb.onProvisioningSuccess(fromStableParcelable(newLp));
|
||||
}
|
||||
@Override
|
||||
public void onProvisioningFailure(LinkPropertiesParcelable newLp) {
|
||||
mCb.onProvisioningFailure(fromStableParcelable(newLp));
|
||||
}
|
||||
|
||||
// Invoked on LinkProperties changes.
|
||||
@Override
|
||||
public void onLinkPropertiesChange(LinkPropertiesParcelable newLp) {
|
||||
mCb.onLinkPropertiesChange(fromStableParcelable(newLp));
|
||||
}
|
||||
|
||||
// Called when the internal IpReachabilityMonitor (if enabled) has
|
||||
// detected the loss of a critical number of required neighbors.
|
||||
@Override
|
||||
public void onReachabilityLost(String logMsg) {
|
||||
mCb.onReachabilityLost(logMsg);
|
||||
}
|
||||
|
||||
// Called when the IpClient state machine terminates.
|
||||
@Override
|
||||
public void onQuit() {
|
||||
mCb.onQuit();
|
||||
}
|
||||
|
||||
// Install an APF program to filter incoming packets.
|
||||
@Override
|
||||
public void installPacketFilter(byte[] filter) {
|
||||
mCb.installPacketFilter(filter);
|
||||
}
|
||||
|
||||
// Asynchronously read back the APF program & data buffer from the wifi driver.
|
||||
// Due to Wifi HAL limitations, the current implementation only supports dumping the entire
|
||||
// buffer. In response to this request, the driver returns the data buffer asynchronously
|
||||
// by sending an IpClient#EVENT_READ_PACKET_FILTER_COMPLETE message.
|
||||
@Override
|
||||
public void startReadPacketFilter() {
|
||||
mCb.startReadPacketFilter();
|
||||
}
|
||||
|
||||
// If multicast filtering cannot be accomplished with APF, this function will be called to
|
||||
// actuate multicast filtering using another means.
|
||||
@Override
|
||||
public void setFallbackMulticastFilter(boolean enabled) {
|
||||
mCb.setFallbackMulticastFilter(enabled);
|
||||
}
|
||||
|
||||
// Enabled/disable Neighbor Discover offload functionality. This is
|
||||
// called, for example, whenever 464xlat is being started or stopped.
|
||||
@Override
|
||||
public void setNeighborDiscoveryOffload(boolean enable) {
|
||||
mCb.setNeighborDiscoveryOffload(enable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump logs for the specified IpClient.
|
||||
* TODO: remove logging from this method once IpClient logs are dumped in NetworkStack dumpsys,
|
||||
* then remove callers and delete.
|
||||
* TODO: remove callers and delete
|
||||
*/
|
||||
public static void dumpIpClient(
|
||||
IIpClient connector, FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
if (!(connector instanceof IpClient.IpClientConnector)) {
|
||||
pw.println("Invalid connector");
|
||||
return;
|
||||
}
|
||||
((IpClient.IpClientConnector) connector).dumpIpClientLogs(fd, pw, args);
|
||||
pw.println("IpClient logs have moved to dumpsys network_stack");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import android.net.dhcp.IDhcpServer;
|
||||
import android.net.ip.RouterAdvertisementDaemon.RaParams;
|
||||
import android.net.util.InterfaceParams;
|
||||
import android.net.util.InterfaceSet;
|
||||
import android.net.util.NetdService;
|
||||
import android.net.shared.NetdService;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.INetworkManagementService;
|
||||
import android.os.Looper;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.util;
|
||||
package android.net.shared;
|
||||
|
||||
import android.net.INetd;
|
||||
import android.os.RemoteException;
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package android.net.util;
|
||||
|
||||
import static android.net.util.NetworkConstants.ETHER_MTU;
|
||||
import static android.net.util.NetworkConstants.IPV6_MIN_MTU;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
|
||||
import android.net.MacAddress;
|
||||
@@ -44,6 +41,11 @@ public class InterfaceParams {
|
||||
public final MacAddress macAddr;
|
||||
public final int defaultMtu;
|
||||
|
||||
// TODO: move the below to NetworkStackConstants when this class is moved to the NetworkStack.
|
||||
private static final int ETHER_MTU = 1500;
|
||||
private static final int IPV6_MIN_MTU = 1280;
|
||||
|
||||
|
||||
public static InterfaceParams getByName(String name) {
|
||||
final NetworkInterface netif = getNetworkInterfaceByName(name);
|
||||
if (netif == null) return null;
|
||||
|
||||
@@ -28,28 +28,6 @@ package android.net.util;
|
||||
public final class NetworkConstants {
|
||||
private NetworkConstants() { throw new RuntimeException("no instance permitted"); }
|
||||
|
||||
/**
|
||||
* Ethernet constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc894
|
||||
* - https://tools.ietf.org/html/rfc2464
|
||||
* - https://tools.ietf.org/html/rfc7042
|
||||
* - http://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
|
||||
* - http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml
|
||||
*/
|
||||
public static final int ETHER_DST_ADDR_OFFSET = 0;
|
||||
public static final int ETHER_SRC_ADDR_OFFSET = 6;
|
||||
public static final int ETHER_ADDR_LEN = 6;
|
||||
|
||||
public static final int ETHER_TYPE_OFFSET = 12;
|
||||
public static final int ETHER_TYPE_LENGTH = 2;
|
||||
public static final int ETHER_TYPE_ARP = 0x0806;
|
||||
public static final int ETHER_TYPE_IPV4 = 0x0800;
|
||||
public static final int ETHER_TYPE_IPV6 = 0x86dd;
|
||||
|
||||
public static final int ETHER_HEADER_LEN = 14;
|
||||
|
||||
public static final byte FF = asByte(0xff);
|
||||
public static final byte[] ETHER_ADDR_BROADCAST = {
|
||||
FF, FF, FF, FF, FF, FF
|
||||
@@ -57,35 +35,13 @@ public final class NetworkConstants {
|
||||
|
||||
public static final int ETHER_MTU = 1500;
|
||||
|
||||
/**
|
||||
* ARP constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc826
|
||||
* - http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
|
||||
*/
|
||||
public static final int ARP_PAYLOAD_LEN = 28; // For Ethernet+IPv4.
|
||||
public static final int ARP_REQUEST = 1;
|
||||
public static final int ARP_REPLY = 2;
|
||||
public static final int ARP_HWTYPE_RESERVED_LO = 0;
|
||||
public static final int ARP_HWTYPE_ETHER = 1;
|
||||
public static final int ARP_HWTYPE_RESERVED_HI = 0xffff;
|
||||
|
||||
/**
|
||||
* IPv4 constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc791
|
||||
*/
|
||||
public static final int IPV4_HEADER_MIN_LEN = 20;
|
||||
public static final int IPV4_IHL_MASK = 0xf;
|
||||
public static final int IPV4_FLAGS_OFFSET = 6;
|
||||
public static final int IPV4_FRAGMENT_MASK = 0x1fff;
|
||||
public static final int IPV4_PROTOCOL_OFFSET = 9;
|
||||
public static final int IPV4_SRC_ADDR_OFFSET = 12;
|
||||
public static final int IPV4_DST_ADDR_OFFSET = 16;
|
||||
public static final int IPV4_ADDR_BITS = 32;
|
||||
public static final int IPV4_ADDR_LEN = 4;
|
||||
|
||||
/**
|
||||
* IPv6 constants.
|
||||
@@ -93,15 +49,10 @@ public final class NetworkConstants {
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc2460
|
||||
*/
|
||||
public static final int IPV6_HEADER_LEN = 40;
|
||||
public static final int IPV6_PROTOCOL_OFFSET = 6;
|
||||
public static final int IPV6_SRC_ADDR_OFFSET = 8;
|
||||
public static final int IPV6_DST_ADDR_OFFSET = 24;
|
||||
public static final int IPV6_ADDR_BITS = 128;
|
||||
public static final int IPV6_ADDR_LEN = 16;
|
||||
public static final int IPV6_MIN_MTU = 1280;
|
||||
public static final int RFC7421_PREFIX_LENGTH = 64;
|
||||
public static final int RFC6177_MIN_PREFIX_LENGTH = 48;
|
||||
|
||||
/**
|
||||
* ICMP common (v4/v6) constants.
|
||||
@@ -124,45 +75,7 @@ public final class NetworkConstants {
|
||||
* - https://tools.ietf.org/html/rfc792
|
||||
*/
|
||||
public static final int ICMPV4_ECHO_REQUEST_TYPE = 8;
|
||||
|
||||
/**
|
||||
* ICMPv6 constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc4443
|
||||
* - https://tools.ietf.org/html/rfc4861
|
||||
*/
|
||||
public static final int ICMPV6_HEADER_MIN_LEN = 4;
|
||||
public static final int ICMPV6_ECHO_REQUEST_TYPE = 128;
|
||||
public static final int ICMPV6_ECHO_REPLY_TYPE = 129;
|
||||
public static final int ICMPV6_ROUTER_SOLICITATION = 133;
|
||||
public static final int ICMPV6_ROUTER_ADVERTISEMENT = 134;
|
||||
public static final int ICMPV6_NEIGHBOR_SOLICITATION = 135;
|
||||
public static final int ICMPV6_NEIGHBOR_ADVERTISEMENT = 136;
|
||||
|
||||
public static final int ICMPV6_ND_OPTION_MIN_LENGTH = 8;
|
||||
public static final int ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR = 8;
|
||||
public static final int ICMPV6_ND_OPTION_SLLA = 1;
|
||||
public static final int ICMPV6_ND_OPTION_TLLA = 2;
|
||||
public static final int ICMPV6_ND_OPTION_MTU = 5;
|
||||
|
||||
|
||||
/**
|
||||
* UDP constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc768
|
||||
*/
|
||||
public static final int UDP_HEADER_LEN = 8;
|
||||
|
||||
/**
|
||||
* DHCP(v4) constants.
|
||||
*
|
||||
* See also:
|
||||
* - https://tools.ietf.org/html/rfc2131
|
||||
*/
|
||||
public static final int DHCP4_SERVER_PORT = 67;
|
||||
public static final int DHCP4_CLIENT_PORT = 68;
|
||||
|
||||
/**
|
||||
* DNS constants.
|
||||
@@ -176,9 +89,4 @@ public final class NetworkConstants {
|
||||
* Utility functions.
|
||||
*/
|
||||
public static byte asByte(int i) { return (byte) i; }
|
||||
|
||||
public static String asString(int i) { return Integer.toString(i); }
|
||||
|
||||
public static int asUint(byte b) { return (b & 0xff); }
|
||||
public static int asUint(short s) { return (s & 0xffff); }
|
||||
}
|
||||
|
||||
@@ -32,74 +32,6 @@ LOCAL_COMPATIBILITY_SUITE := device-tests
|
||||
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
# These are not normally accessible from apps so they must be explicitly included.
|
||||
LOCAL_JNI_SHARED_LIBRARIES := \
|
||||
android.hidl.token@1.0 \
|
||||
libartbase \
|
||||
libbacktrace \
|
||||
libbase \
|
||||
libbinder \
|
||||
libbinderthreadstate \
|
||||
libc++ \
|
||||
libcrypto \
|
||||
libcutils \
|
||||
libdexfile \
|
||||
libframeworksnettestsjni \
|
||||
libhidl-gen-utils \
|
||||
libhidlbase \
|
||||
libhidltransport \
|
||||
libhwbinder \
|
||||
liblog \
|
||||
liblzma \
|
||||
libnativehelper \
|
||||
libpackagelistparser \
|
||||
libpcre2 \
|
||||
libprocessgroup \
|
||||
libselinux \
|
||||
libui \
|
||||
libutils \
|
||||
libvintf \
|
||||
libvndksupport \
|
||||
libtinyxml2 \
|
||||
libunwindstack \
|
||||
libutilscallstack \
|
||||
libziparchive \
|
||||
libz \
|
||||
netd_aidl_interface-cpp
|
||||
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
#########################################################################
|
||||
# Build JNI Shared Library
|
||||
#########################################################################
|
||||
|
||||
LOCAL_PATH:= $(LOCAL_PATH)/jni
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_CFLAGS := -Wall -Wextra -Werror
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
libpcap \
|
||||
hardware/google/apf
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-cpp-files-under)
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libbinder \
|
||||
liblog \
|
||||
libcutils \
|
||||
libnativehelper \
|
||||
netd_aidl_interface-cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libpcap \
|
||||
libapf
|
||||
|
||||
LOCAL_MODULE := libframeworksnettestsjni
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
Reference in New Issue
Block a user