Skip to content
Snippets Groups Projects
Commit 336bb5cf authored by Patrick Rohr's avatar Patrick Rohr
Browse files

TestNetworkService: add support to disable DAD on test interfaces

DscpPolicyTest does not have an IpClient, so it relies on assigning the
LinkAddresses at interface creation. If DAD is enabled, the global
address cannot be used immediately, so the test packet selects the wrong
source address. There is no obvious way to fix this without disabling
DAD as the TestableNetworkCallback receives the LinkProperties update
before the address can be used.

This functionality will also be useful in ethernet tests, which
currently have to block for a long time.

Test: atest DscpPolicyTest
Bug: 235559605
Change-Id: Id7788df5e92ebd8eaf4619a23f44135ea4a2144e
parent 3f8dbf75
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,8 @@ import android.os.ParcelFileDescriptor;
interface ITestNetworkManager
{
TestNetworkInterface createInterface(boolean isTun, boolean hasCarrier, boolean bringUp,
in LinkAddress[] addrs, in @nullable String iface);
boolean disableIpv6ProvisioningDelay, in LinkAddress[] addrs,
in @nullable String iface);
void setCarrierEnabled(in TestNetworkInterface iface, boolean enabled);
......
......@@ -59,6 +59,8 @@ public class TestNetworkManager {
private static final boolean TUN = true;
private static final boolean BRING_UP = true;
private static final boolean CARRIER_UP = true;
// sets disableIpv6ProvisioningDelay to false.
private static final boolean USE_IPV6_PROV_DELAY = false;
private static final LinkAddress[] NO_ADDRS = new LinkAddress[0];
/** @hide */
......@@ -167,8 +169,8 @@ public class TestNetworkManager {
public TestNetworkInterface createTunInterface(@NonNull Collection<LinkAddress> linkAddrs) {
try {
final LinkAddress[] arr = new LinkAddress[linkAddrs.size()];
return mService.createInterface(TUN, CARRIER_UP, BRING_UP, linkAddrs.toArray(arr),
null /* iface */);
return mService.createInterface(TUN, CARRIER_UP, BRING_UP, USE_IPV6_PROV_DELAY,
linkAddrs.toArray(arr), null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
......@@ -186,7 +188,8 @@ public class TestNetworkManager {
@NonNull
public TestNetworkInterface createTapInterface() {
try {
return mService.createInterface(TAP, CARRIER_UP, BRING_UP, NO_ADDRS, null /* iface */);
return mService.createInterface(TAP, CARRIER_UP, BRING_UP, USE_IPV6_PROV_DELAY,
NO_ADDRS, null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
......@@ -204,7 +207,8 @@ public class TestNetworkManager {
@NonNull
public TestNetworkInterface createTapInterface(@NonNull LinkAddress[] linkAddrs) {
try {
return mService.createInterface(TAP, CARRIER_UP, BRING_UP, linkAddrs, null /* iface */);
return mService.createInterface(TAP, CARRIER_UP, BRING_UP, USE_IPV6_PROV_DELAY,
linkAddrs, null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
......@@ -223,7 +227,8 @@ public class TestNetworkManager {
@NonNull
public TestNetworkInterface createTapInterface(boolean bringUp) {
try {
return mService.createInterface(TAP, CARRIER_UP, bringUp, NO_ADDRS, null /* iface */);
return mService.createInterface(TAP, CARRIER_UP, bringUp, USE_IPV6_PROV_DELAY,
NO_ADDRS, null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
......@@ -245,7 +250,8 @@ public class TestNetworkManager {
@NonNull
public TestNetworkInterface createTapInterface(boolean bringUp, @NonNull String iface) {
try {
return mService.createInterface(TAP, CARRIER_UP, bringUp, NO_ADDRS, iface);
return mService.createInterface(TAP, CARRIER_UP, bringUp, USE_IPV6_PROV_DELAY,
NO_ADDRS, iface);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
......@@ -264,7 +270,49 @@ public class TestNetworkManager {
@NonNull
public TestNetworkInterface createTapInterface(boolean carrierUp, boolean bringUp) {
try {
return mService.createInterface(TAP, carrierUp, bringUp, NO_ADDRS, null /* iface */);
return mService.createInterface(TAP, carrierUp, bringUp, USE_IPV6_PROV_DELAY, NO_ADDRS,
null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Create a tap interface for testing purposes.
*
* @param carrierUp whether the created interface has a carrier or not.
* @param bringUp whether to bring up the interface before returning it.
* @param disableIpv6ProvisioningDelay whether to disable DAD and RS delay.
* @hide
*/
@RequiresPermission(Manifest.permission.MANAGE_TEST_NETWORKS)
@NonNull
public TestNetworkInterface createTapInterface(boolean carrierUp, boolean bringUp,
boolean disableIpv6ProvisioningDelay) {
try {
return mService.createInterface(TAP, carrierUp, bringUp, disableIpv6ProvisioningDelay,
NO_ADDRS, null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Create a tap interface for testing purposes.
*
* @param disableIpv6ProvisioningDelay whether to disable DAD and RS delay.
* @param linkAddrs an array of LinkAddresses to assign to the TAP interface
* @return A TestNetworkInterface representing the underlying TAP interface. Close the contained
* ParcelFileDescriptor to tear down the TAP interface.
* @hide
*/
@RequiresPermission(Manifest.permission.MANAGE_TEST_NETWORKS)
@NonNull
public TestNetworkInterface createTapInterface(boolean disableIpv6ProvisioningDelay,
@NonNull LinkAddress[] linkAddrs) {
try {
return mService.createInterface(TAP, CARRIER_UP, BRING_UP, disableIpv6ProvisioningDelay,
linkAddrs, null /* iface */);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
......
......@@ -120,7 +120,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
*/
@Override
public TestNetworkInterface createInterface(boolean isTun, boolean hasCarrier, boolean bringUp,
LinkAddress[] linkAddrs, @Nullable String iface) {
boolean disableIpv6ProvisioningDelay, LinkAddress[] linkAddrs, @Nullable String iface) {
enforceTestNetworkPermissions(mContext);
Objects.requireNonNull(linkAddrs, "missing linkAddrs");
......@@ -137,6 +137,14 @@ class TestNetworkService extends ITestNetworkManager.Stub {
try {
ParcelFileDescriptor tunIntf = ParcelFileDescriptor.adoptFd(
nativeCreateTunTap(isTun, hasCarrier, interfaceName));
// Disable DAD and remove router_solicitation_delay before assigning link addresses.
if (disableIpv6ProvisioningDelay) {
mNetd.setProcSysNet(
INetd.IPV6, INetd.CONF, interfaceName, "router_solicitation_delay", "0");
mNetd.setProcSysNet(INetd.IPV6, INetd.CONF, interfaceName, "dad_transmits", "0");
}
for (LinkAddress addr : linkAddrs) {
mNetd.interfaceAddAddress(
interfaceName,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment