From 7f2b3dabcde6b3682d290cb30ac5aa38f0d80cf6 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 17 Oct 2023 13:23:26 +0900 Subject: [PATCH] Reapply "Simplify addRoutesToLocalNetwork calls" This reverts commit 316346be6e99f32aa73b8dbb4de8d434a50cd3e1. Change-Id: I86977f6e7a5451d037c7ea6fee5c4bc7082935ff --- .../net/ip/RouterAdvertisementDaemonTest.java | 17 ++++++++--------- .../com/android/net/module/util/NetdUtils.java | 8 +++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java b/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java index 328e3fb61c..dac5b63fe2 100644 --- a/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java +++ b/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java @@ -16,8 +16,6 @@ package android.net.ip; -import static android.net.RouteInfo.RTN_UNICAST; - import static com.android.net.module.util.NetworkStackConstants.ETHER_HEADER_LEN; import static com.android.net.module.util.NetworkStackConstants.ETHER_TYPE_IPV6; import static com.android.net.module.util.NetworkStackConstants.ICMPV6_ND_OPTION_MTU; @@ -42,12 +40,13 @@ import android.content.Context; import android.net.INetd; import android.net.IpPrefix; import android.net.MacAddress; -import android.net.RouteInfo; import android.net.ip.RouterAdvertisementDaemon.RaParams; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; +import android.os.RemoteException; +import android.os.ServiceSpecificException; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; @@ -55,7 +54,6 @@ import androidx.test.runner.AndroidJUnit4; import com.android.net.module.util.InterfaceParams; import com.android.net.module.util.Ipv6Utils; -import com.android.net.module.util.NetdUtils; import com.android.net.module.util.Struct; import com.android.net.module.util.structs.EthernetHeader; import com.android.net.module.util.structs.Icmpv6Header; @@ -80,7 +78,6 @@ import java.net.Inet6Address; import java.net.InetAddress; import java.nio.ByteBuffer; import java.util.HashSet; -import java.util.List; @RunWith(AndroidJUnit4.class) @SmallTest @@ -332,10 +329,12 @@ public final class RouterAdvertisementDaemonTest { // Add a default route "fe80::/64 -> ::" to local network, otherwise, device will fail to // send the unicast RA out due to the ENETUNREACH error(No route to the peer's link-local // address is present). - final String iface = mTetheredParams.name; - final RouteInfo linkLocalRoute = - new RouteInfo(new IpPrefix("fe80::/64"), null, iface, RTN_UNICAST); - NetdUtils.addRoutesToLocalNetwork(sNetd, iface, List.of(linkLocalRoute)); + try { + sNetd.networkAddRoute(INetd.LOCAL_NET_ID, mTetheredParams.name, + "fe80::/64", INetd.NEXTHOP_NONE); + } catch (RemoteException | ServiceSpecificException e) { + throw new IllegalStateException(e); + } final ByteBuffer rs = createRsPacket("fe80::1122:3344:5566:7788"); mTetheredPacketReader.sendResponse(rs); diff --git a/staticlibs/client-libs/netd/com/android/net/module/util/NetdUtils.java b/staticlibs/client-libs/netd/com/android/net/module/util/NetdUtils.java index 98fda56547..ea18d3794e 100644 --- a/staticlibs/client-libs/netd/com/android/net/module/util/NetdUtils.java +++ b/staticlibs/client-libs/netd/com/android/net/module/util/NetdUtils.java @@ -159,9 +159,11 @@ public class NetdUtils { throws RemoteException, ServiceSpecificException { netd.tetherInterfaceAdd(iface); networkAddInterface(netd, iface, maxAttempts, pollingIntervalMs); - List routes = new ArrayList<>(); - routes.add(new RouteInfo(dest, null, iface, RTN_UNICAST)); - addRoutesToLocalNetwork(netd, iface, routes); + // Activate a route to dest and IPv6 link local. + modifyRoute(netd, ModifyOperation.ADD, INetd.LOCAL_NET_ID, + new RouteInfo(dest, null, iface, RTN_UNICAST)); + modifyRoute(netd, ModifyOperation.ADD, INetd.LOCAL_NET_ID, + new RouteInfo(new IpPrefix("fe80::/64"), null, iface, RTN_UNICAST)); } /**