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

Commit 3e979321 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Set the secs field in the BOOTP header.

We mostly follow RFC 2131, which says that secs is the number of
seconds "since client began address acquisition or renewal
process", and thus set secs to zero on renew. This is different
from our current behaviour, which keeps on counting without
resetting secs to zero on renew.

Bug: 19704592
Change-Id: Ifbb7644094c579be626ffb698eee87047425dbf0
parent c91bc62f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ class DhcpAckPacket extends DhcpPacket {
     */
    private final Inet4Address mSrcIp;

    DhcpAckPacket(int transId, boolean broadcast, Inet4Address serverAddress,
    DhcpAckPacket(int transId, short secs, boolean broadcast, Inet4Address serverAddress,
                  Inet4Address clientIp, byte[] clientMac) {
        super(transId, INADDR_ANY, clientIp, serverAddress, INADDR_ANY, clientMac, broadcast);
        super(transId, secs, INADDR_ANY, clientIp, serverAddress, INADDR_ANY, clientMac, broadcast);
        mBroadcast = broadcast;
        mSrcIp = serverAddress;
    }
+12 −5
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
    private byte[] mHwAddr;
    private PacketSocketAddress mInterfaceBroadcastAddr;
    private int mTransactionId;
    private long mTransactionStartMillis;
    private DhcpResults mDhcpLease;
    private long mDhcpLeaseExpiry;
    private DhcpResults mOffer;
@@ -263,8 +264,9 @@ public class DhcpClient extends BaseDhcpStateMachine {
        }
    }

    private void initTransactionId() {
    private void startNewTransaction() {
        mTransactionId = mRandom.nextInt();
        mTransactionStartMillis = SystemClock.elapsedRealtime();
    }

    private boolean initSockets() {
@@ -340,6 +342,10 @@ public class DhcpClient extends BaseDhcpStateMachine {
        }
    }

    private short getSecs() {
        return (short) ((SystemClock.elapsedRealtime() - mTransactionStartMillis) / 1000);
    }

    private boolean transmitPacket(ByteBuffer buf, String description, Inet4Address to) {
        try {
            if (to.equals(INADDR_BROADCAST)) {
@@ -358,7 +364,8 @@ public class DhcpClient extends BaseDhcpStateMachine {

    private boolean sendDiscoverPacket() {
        ByteBuffer packet = DhcpPacket.buildDiscoverPacket(
                DhcpPacket.ENCAP_L2, mTransactionId, mHwAddr, DO_UNICAST, REQUESTED_PARAMS);
                DhcpPacket.ENCAP_L2, mTransactionId, getSecs(), mHwAddr,
                DO_UNICAST, REQUESTED_PARAMS);
        return transmitPacket(packet, "DHCPDISCOVER", INADDR_BROADCAST);
    }

@@ -369,7 +376,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
        int encap = to.equals(INADDR_BROADCAST) ? DhcpPacket.ENCAP_L2 : DhcpPacket.ENCAP_BOOTP;

        ByteBuffer packet = DhcpPacket.buildRequestPacket(
                encap, mTransactionId, clientAddress,
                encap, mTransactionId, getSecs(), clientAddress,
                DO_UNICAST, mHwAddr, requestedAddress,
                serverAddress, REQUESTED_PARAMS, null);
        String description = "DHCPREQUEST ciaddr=" + clientAddress.getHostAddress() +
@@ -665,7 +672,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
        @Override
        public void enter() {
            super.enter();
            initTransactionId();
            startNewTransaction();
        }

        protected boolean sendPacket() {
@@ -772,7 +779,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
        @Override
        public void enter() {
            super.enter();
            initTransactionId();
            startNewTransaction();
        }

        protected boolean sendPacket() {
+2 −2
Original line number Diff line number Diff line
@@ -26,10 +26,10 @@ class DhcpDeclinePacket extends DhcpPacket {
    /**
     * Generates a DECLINE packet with the specified parameters.
     */
    DhcpDeclinePacket(int transId, Inet4Address clientIp, Inet4Address yourIp,
    DhcpDeclinePacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp,
                      Inet4Address nextIp, Inet4Address relayIp,
                      byte[] clientMac) {
        super(transId, clientIp, yourIp, nextIp, relayIp, clientMac, false);
        super(transId, secs, clientIp, yourIp, nextIp, relayIp, clientMac, false);
    }

    public String toString() {
+2 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ class DhcpDiscoverPacket extends DhcpPacket {
    /**
     * Generates a DISCOVER packet with the specified parameters.
     */
    DhcpDiscoverPacket(int transId, byte[] clientMac, boolean broadcast) {
        super(transId, INADDR_ANY, INADDR_ANY, INADDR_ANY, INADDR_ANY, clientMac, broadcast);
    DhcpDiscoverPacket(int transId, short secs, byte[] clientMac, boolean broadcast) {
        super(transId, secs, INADDR_ANY, INADDR_ANY, INADDR_ANY, INADDR_ANY, clientMac, broadcast);
    }

    public String toString() {
+2 −2
Original line number Diff line number Diff line
@@ -26,10 +26,10 @@ class DhcpInformPacket extends DhcpPacket {
    /**
     * Generates an INFORM packet with the specified parameters.
     */
    DhcpInformPacket(int transId, Inet4Address clientIp, Inet4Address yourIp,
    DhcpInformPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp,
                     Inet4Address nextIp, Inet4Address relayIp,
                     byte[] clientMac) {
        super(transId, clientIp, yourIp, nextIp, relayIp, clientMac, false);
        super(transId, secs, clientIp, yourIp, nextIp, relayIp, clientMac, false);
    }

    public String toString() {
Loading