Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abb70339 authored by Erik Kline's avatar Erik Kline
Browse files

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
parent 90d5e7b1
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -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<IpPrefix> prefixes;
        public HashSet<Inet6Address> dnses;

        public RaParams() {
            hasDefaultRoute = false;
            hopLimit = DEFAULT_HOPLIMIT;
            mtu = IPV6_MIN_MTU;
            prefixes = new HashSet<IpPrefix>();
            dnses = new HashSet<Inet6Address>();
@@ -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))