From abb70339ea5b5e5ad4d0c0a8b8cfd0c92cf93329 Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Tue, 28 Aug 2018 14:00:37 +0900 Subject: Try to set the hop limit to something suitable for 64share Introduce hopLimit into RaParams so in future the value can be passed in from the control plane up in Tethering. Test: as follows - built, flashed, booted - runtest frameworks-net passes Bug: 32163131 Change-Id: I8d2f056dcd55d76e89199db1196754fb690250e8 --- .../android/net/ip/RouterAdvertisementDaemon.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/services/net/java/android/net/ip/RouterAdvertisementDaemon.java b/services/net/java/android/net/ip/RouterAdvertisementDaemon.java index 8fbc01ea4493..9d686efcb2ab 100644 --- a/services/net/java/android/net/ip/RouterAdvertisementDaemon.java +++ b/services/net/java/android/net/ip/RouterAdvertisementDaemon.java @@ -119,13 +119,23 @@ public class RouterAdvertisementDaemon { private volatile UnicastResponder mUnicastResponder; public static class RaParams { + // Tethered traffic will have the hop limit properly decremented. + // Consequently, set the hoplimit greater by one than the upstream + // unicast hop limit. + // + // TODO: Dynamically pass down the IPV6_UNICAST_HOPS value from the + // upstream interface for more correct behaviour. + static final byte DEFAULT_HOPLIMIT = 65; + public boolean hasDefaultRoute; + public byte hopLimit; public int mtu; public HashSet prefixes; public HashSet dnses; public RaParams() { hasDefaultRoute = false; + hopLimit = DEFAULT_HOPLIMIT; mtu = IPV6_MIN_MTU; prefixes = new HashSet(); dnses = new HashSet(); @@ -133,6 +143,7 @@ public class RouterAdvertisementDaemon { public RaParams(RaParams other) { hasDefaultRoute = other.hasDefaultRoute; + hopLimit = other.hopLimit; mtu = other.mtu; prefixes = (HashSet) other.prefixes.clone(); dnses = (HashSet) other.dnses.clone(); @@ -273,10 +284,12 @@ public class RouterAdvertisementDaemon { final ByteBuffer ra = ByteBuffer.wrap(mRA); ra.order(ByteOrder.BIG_ENDIAN); + final boolean haveRaParams = (mRaParams != null); boolean shouldSendRA = false; try { - putHeader(ra, mRaParams != null && mRaParams.hasDefaultRoute); + putHeader(ra, haveRaParams && mRaParams.hasDefaultRoute, + haveRaParams ? mRaParams.hopLimit : RaParams.DEFAULT_HOPLIMIT); putSlla(ra, mInterface.macAddr.toByteArray()); mRaLength = ra.position(); @@ -287,7 +300,7 @@ public class RouterAdvertisementDaemon { // // putExpandedFlagsOption(ra); - if (mRaParams != null) { + if (haveRaParams) { putMtu(ra, mRaParams.mtu); mRaLength = ra.position(); @@ -348,7 +361,7 @@ public class RouterAdvertisementDaemon { private static byte asByte(int value) { return (byte) value; } private static short asShort(int value) { return (short) value; } - private static void putHeader(ByteBuffer ra, boolean hasDefaultRoute) { + private static void putHeader(ByteBuffer ra, boolean hasDefaultRoute, byte hopLimit) { /** Router Advertisement Message Format @@ -366,11 +379,10 @@ public class RouterAdvertisementDaemon { | Options ... +-+-+-+-+-+-+-+-+-+-+-+- */ - final byte DEFAULT_HOPLIMIT = 64; ra.put(ICMPV6_ND_ROUTER_ADVERT) .put(asByte(0)) .putShort(asShort(0)) - .put(DEFAULT_HOPLIMIT) + .put(hopLimit) // RFC 4191 "high" preference, iff. advertising a default route. .put(hasDefaultRoute ? asByte(0x08) : asByte(0)) .putShort(hasDefaultRoute ? asShort(DEFAULT_LIFETIME) : asShort(0)) -- cgit v1.2.3-59-g8ed1b