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

Commit f2104b11 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Android (Google) Code Review
Browse files

Merge changes Iddc971c7,If907f49f,I5505bd2c,I110b5800,I9aeb29c2, ...

* changes:
  DHCP: Don't write options longer than 255 bytes.
  DHCP: parsing robustness fixes.
  DHCP: Add a hidden setting to use the legacy DHCP client.
  DHCP: Add a Java DHCP client.
  Add a protectFromVpn method that takes a FileDescriptor
  DHCP: protocol changes.
  DHCP: glue code.
  DHCP: Ethernet/IP packet header changes.
  DHCP: Minor cleanups to the packet code.
  DHCP: Move the packet code to frameworks/base/services.
  DHCP: Add a native method for making a DHCP socket.
  DHCP: Add a superclass for DhcpStateMachine.
  Add two utility methods for IPv4 netmasks.
parents e37628c0 06ac4b8d
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net;

import com.android.internal.util.StateMachine;

/**
 * Interface that must be implemented by DHCP state machines.
 *
 * This is an abstract class instead of a Java interface so that callers can just declare an object
 * of this type and be able to call all the methods defined by either StateMachine or this class.
 *
 * @hide
 */
public abstract class BaseDhcpStateMachine extends StateMachine {
    protected BaseDhcpStateMachine(String tag) {
        super(tag);
    }
    public abstract void registerForPreDhcpNotification();
    public abstract void doQuit();
}
+3 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ import android.util.Log;
 *
 * @hide
 */
public class DhcpStateMachine extends StateMachine {
public class DhcpStateMachine extends BaseDhcpStateMachine {

    private static final String TAG = "DhcpStateMachine";
    private static final boolean DBG = false;
@@ -161,6 +161,7 @@ public class DhcpStateMachine extends StateMachine {
     * This is used by Wifi at this time for the purpose of doing BT-Wifi coex
     * handling during Dhcp
     */
    @Override
    public void registerForPreDhcpNotification() {
        mRegisteredForPreDhcpNotification = true;
    }
@@ -170,6 +171,7 @@ public class DhcpStateMachine extends StateMachine {
     *
     * @hide
     */
    @Override
    public void doQuit() {
        quit();
    }
+51 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.net;

import java.io.FileDescriptor;
import java.net.InetAddress;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Locale;
@@ -138,6 +140,11 @@ public class NetworkUtils {
     */
    public native static String getDhcpError();

    /**
     * Attaches a socket filter that accepts DHCP packets to the given socket.
     */
    public native static void attachDhcpFilter(FileDescriptor fd) throws SocketException;

    /**
     * Binds the current process to the network designated by {@code netId}.  All sockets created
     * in the future (and not explicitly bound via a bound {@link SocketFactory} (see
@@ -170,6 +177,15 @@ public class NetworkUtils {
     */
    public native static int bindSocketToNetwork(int socketfd, int netId);

    /**
     * Protect {@code fd} from VPN connections.  After protecting, data sent through
     * this socket will go directly to the underlying network, so its traffic will not be
     * forwarded through the VPN.
     */
    public static boolean protectFromVpn(FileDescriptor fd) {
        return protectFromVpn(fd.getInt$());
    }

    /**
     * Protect {@code socketfd} from VPN connections.  After protecting, data sent through
     * this socket will go directly to the underlying network, so its traffic will not be
@@ -229,6 +245,25 @@ public class NetworkUtils {
        return Integer.bitCount(netmask);
    }

    /**
     * Convert an IPv4 netmask to a prefix length, checking that the netmask is contiguous.
     * @param netmask as a {@code Inet4Address}.
     * @return the network prefix length
     * @throws IllegalArgumentException the specified netmask was not contiguous.
     * @hide
     */
    public static int netmaskToPrefixLength(Inet4Address netmask) {
        // inetAddressToInt returns an int in *network* byte order.
        int i = Integer.reverseBytes(inetAddressToInt(netmask));
        int prefixLength = Integer.bitCount(i);
        int trailingZeros = Integer.numberOfTrailingZeros(i);
        if (trailingZeros != 32 - prefixLength) {
            throw new IllegalArgumentException("Non-contiguous netmask: " + Integer.toHexString(i));
        }
        return prefixLength;
    }


    /**
     * Create an InetAddress from a string where the string must be a standard
     * representation of a V4 or V6 address.  Avoids doing a DNS lookup on failure
@@ -308,6 +343,22 @@ public class NetworkUtils {
        return netPart;
    }

    /**
     * Returns the implicit netmask of an IPv4 address, as was the custom before 1993.
     */
    public static int getImplicitNetmask(Inet4Address address) {
        int firstByte = address.getAddress()[0] & 0xff;  // Convert to an unsigned value.
        if (firstByte < 128) {
            return 8;
        } else if (firstByte < 192) {
            return 16;
        } else if (firstByte < 224) {
            return 24;
        } else {
            return 32;  // Will likely not end well for other reasons.
        }
    }

    /**
     * Utility method to parse strings such as "192.0.2.5/24" or "2001:db8::cafe:d00d/64".
     * @hide
+0 −74
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.dhcp;

import java.net.InetAddress;
import java.util.List;

/**
 * This class defines the "next steps" which occur after a given DHCP
 * packet has been received.
 */
interface DhcpStateMachine {
    /**
     * Signals that an offer packet has been received with the specified
     * parameters.
     */
    public void onOfferReceived(boolean broadcast, int transactionId,
        byte[] myMac, InetAddress offeredIpAddress,
        InetAddress serverIpAddress);

    /**
     * Signals that a NAK packet has been received.
     */
    public void onNakReceived();

    /**
     * Signals that the final ACK has been received from the server.
     */
    public void onAckReceived(InetAddress myIpAddress, InetAddress myNetMask,
        InetAddress myGateway, List<InetAddress> myDnsServers,
        InetAddress myDhcpServer, int leaseTime);

    /**
     * Signals that a client's DISCOVER packet has been received with the
     * specified parameters.
     */
    public void onDiscoverReceived(boolean broadcast, int transactionId,
        byte[] clientMac, byte[] requestedParameterList);

    /**
     * Signals that a client's REQUEST packet has been received with the
     * specified parameters.
     */
    public void onRequestReceived(boolean broadcast, int transactionId,
        byte[] clientMac, InetAddress requestedIp, byte[] requestedParams,
        String clientHostName);

    /**
     * Signals that a client's INFORM packet has been received with the
     * specified parameters.
     */
    public void onInformReceived(int transactionId, byte[] clientMac,
        InetAddress preassignedIp, byte[] requestedParams);

    /**
     * Signals that a client's DECLINE packet has been received with the
     * specified parameters.
     */
    public void onDeclineReceived(byte[] clientMac, InetAddress declinedIp);
}
+8 −0
Original line number Diff line number Diff line
@@ -5962,6 +5962,14 @@ public final class Settings {
       public static final String HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED =
               "hdmi_control_auto_device_off_enabled";

       /**
        * Whether to use the DHCP client from Lollipop and earlier instead of the newer Android DHCP
        * client.
        * (0 = false, 1 = true)
        * @hide
        */
       public static final String LEGACY_DHCP_CLIENT = "legacy_dhcp_client";

       /**
        * Whether TV will switch to MHL port when a mobile device is plugged in.
        * (0 = false, 1 = true)
Loading