Merge "Replace InterfaceParams with ifName in DhcpServer"
This commit is contained in:
@@ -39,7 +39,6 @@ import android.annotation.Nullable;
|
||||
import android.net.MacAddress;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.util.InterfaceParams;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -85,7 +84,7 @@ public class DhcpServer {
|
||||
@NonNull
|
||||
private final ServerHandler mHandler;
|
||||
@NonNull
|
||||
private final InterfaceParams mIface;
|
||||
private final String mIfName;
|
||||
@NonNull
|
||||
private final DhcpLeaseRepository mLeaseRepo;
|
||||
@NonNull
|
||||
@@ -161,20 +160,20 @@ public class DhcpServer {
|
||||
}
|
||||
}
|
||||
|
||||
public DhcpServer(@NonNull Looper looper, @NonNull InterfaceParams iface,
|
||||
public DhcpServer(@NonNull Looper looper, @NonNull String ifName,
|
||||
@NonNull DhcpServingParams params, @NonNull SharedLog log) {
|
||||
this(looper, iface, params, log, null);
|
||||
this(looper, ifName, params, log, null);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DhcpServer(@NonNull Looper looper, @NonNull InterfaceParams iface,
|
||||
DhcpServer(@NonNull Looper looper, @NonNull String ifName,
|
||||
@NonNull DhcpServingParams params, @NonNull SharedLog log,
|
||||
@Nullable Dependencies deps) {
|
||||
if (deps == null) {
|
||||
deps = new DependenciesImpl();
|
||||
}
|
||||
mHandler = new ServerHandler(looper);
|
||||
mIface = iface;
|
||||
mIfName = ifName;
|
||||
mServingParams = params;
|
||||
mLog = log;
|
||||
mDeps = deps;
|
||||
@@ -444,7 +443,7 @@ public class DhcpServer {
|
||||
|
||||
private boolean addArpEntry(@NonNull MacAddress macAddr, @NonNull Inet4Address inetAddr) {
|
||||
try {
|
||||
mDeps.addArpEntry(inetAddr, macAddr, mIface.name, mSocket);
|
||||
mDeps.addArpEntry(inetAddr, macAddr, mIfName, mSocket);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
mLog.e("Error adding client to ARP table", e);
|
||||
@@ -526,7 +525,7 @@ public class DhcpServer {
|
||||
// SO_BINDTODEVICE actually takes a string. This works because the first member
|
||||
// of struct ifreq is a NULL-terminated interface name.
|
||||
// TODO: add a setsockoptString()
|
||||
Os.setsockoptIfreq(mSocket, SOL_SOCKET, SO_BINDTODEVICE, mIface.name);
|
||||
Os.setsockoptIfreq(mSocket, SOL_SOCKET, SO_BINDTODEVICE, mIfName);
|
||||
Os.setsockoptInt(mSocket, SOL_SOCKET, SO_BROADCAST, 1);
|
||||
Os.bind(mSocket, Inet4Address.ANY, DHCP_SERVER);
|
||||
NetworkUtils.protectFromVpn(mSocket);
|
||||
|
||||
@@ -138,9 +138,9 @@ public class IpServer extends StateMachine {
|
||||
return NetdService.getInstance();
|
||||
}
|
||||
|
||||
public DhcpServer makeDhcpServer(Looper looper, InterfaceParams iface,
|
||||
public DhcpServer makeDhcpServer(Looper looper, String ifName,
|
||||
DhcpServingParams params, SharedLog log) {
|
||||
return new DhcpServer(looper, iface, params, log);
|
||||
return new DhcpServer(looper, ifName, params, log);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,12 +256,6 @@ public class IpServer extends StateMachine {
|
||||
if (mUsingLegacyDhcp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final InterfaceParams ifaceParams = mDeps.getInterfaceParams(mIfaceName);
|
||||
if (ifaceParams == null) {
|
||||
Log.e(TAG, "Failed to find interface params for DHCPv4");
|
||||
return false;
|
||||
}
|
||||
final DhcpServingParams params;
|
||||
try {
|
||||
params = new DhcpServingParams.Builder()
|
||||
@@ -277,7 +271,7 @@ public class IpServer extends StateMachine {
|
||||
return false;
|
||||
}
|
||||
|
||||
mDhcpServer = mDeps.makeDhcpServer(getHandler().getLooper(), ifaceParams, params,
|
||||
mDhcpServer = mDeps.makeDhcpServer(getHandler().getLooper(), mIfaceName, params,
|
||||
mLog.forSubComponent("DHCP"));
|
||||
mDhcpServer.start();
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,6 @@ import static android.net.dhcp.DhcpPacket.INADDR_BROADCAST;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -48,7 +47,6 @@ import android.net.dhcp.DhcpLeaseRepository.InvalidAddressException;
|
||||
import android.net.dhcp.DhcpLeaseRepository.OutOfAddressesException;
|
||||
import android.net.dhcp.DhcpServer.Clock;
|
||||
import android.net.dhcp.DhcpServer.Dependencies;
|
||||
import android.net.util.InterfaceParams;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.test.TestLooper;
|
||||
import android.support.test.filters.SmallTest;
|
||||
@@ -74,9 +72,6 @@ import java.util.Set;
|
||||
public class DhcpServerTest {
|
||||
private static final String PROP_DEXMAKER_SHARE_CLASSLOADER = "dexmaker.share_classloader";
|
||||
private static final String TEST_IFACE = "testiface";
|
||||
private static final MacAddress TEST_IFACE_MAC = MacAddress.fromString("11:22:33:44:55:66");
|
||||
private static final InterfaceParams TEST_IFACEPARAMS =
|
||||
new InterfaceParams(TEST_IFACE, 1, TEST_IFACE_MAC);
|
||||
|
||||
private static final Inet4Address TEST_SERVER_ADDR = parseAddr("192.168.0.2");
|
||||
private static final LinkAddress TEST_SERVER_LINKADDR = new LinkAddress(TEST_SERVER_ADDR, 20);
|
||||
@@ -149,7 +144,7 @@ public class DhcpServerTest {
|
||||
.build();
|
||||
|
||||
mLooper = new TestLooper();
|
||||
mServer = new DhcpServer(mLooper.getLooper(), TEST_IFACEPARAMS, servingParams,
|
||||
mServer = new DhcpServer(mLooper.getLooper(), TEST_IFACE, servingParams,
|
||||
new SharedLog(DhcpServerTest.class.getSimpleName()), mDeps);
|
||||
|
||||
mServer.start();
|
||||
|
||||
@@ -404,7 +404,7 @@ public class IpServerTest {
|
||||
|
||||
private void assertDhcpStarted(IpPrefix expectedPrefix) {
|
||||
verify(mDependencies, times(1)).makeDhcpServer(
|
||||
eq(mLooper.getLooper()), eq(TEST_IFACE_PARAMS), any(), eq(mSharedLog));
|
||||
eq(mLooper.getLooper()), eq(IFACE_NAME), any(), eq(mSharedLog));
|
||||
verify(mDhcpServer, times(1)).start();
|
||||
final DhcpServingParams params = mDhcpParamsCaptor.getValue();
|
||||
// Last address byte is random
|
||||
|
||||
@@ -240,7 +240,7 @@ public class TetheringTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DhcpServer makeDhcpServer(Looper looper, InterfaceParams iface,
|
||||
public DhcpServer makeDhcpServer(Looper looper, String ifName,
|
||||
DhcpServingParams params, SharedLog log) {
|
||||
return mDhcpServer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user