Merge "Retain DNS information from DHCP request"
This commit is contained in:
committed by
Android (Google) Code Review
commit
04e3bb6d32
@@ -24,6 +24,7 @@ import java.net.Inet4Address;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple object for retrieving the results of a DHCP request.
|
* A simple object for retrieving the results of a DHCP request.
|
||||||
@@ -41,14 +42,18 @@ public class DhcpInfoInternal {
|
|||||||
public String serverAddress;
|
public String serverAddress;
|
||||||
public int leaseDuration;
|
public int leaseDuration;
|
||||||
|
|
||||||
private Collection<RouteInfo> routes;
|
private Collection<RouteInfo> mRoutes;
|
||||||
|
|
||||||
public DhcpInfoInternal() {
|
public DhcpInfoInternal() {
|
||||||
routes = new ArrayList<RouteInfo>();
|
mRoutes = new ArrayList<RouteInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRoute(RouteInfo routeInfo) {
|
public void addRoute(RouteInfo routeInfo) {
|
||||||
routes.add(routeInfo);
|
mRoutes.add(routeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<RouteInfo> getRoutes() {
|
||||||
|
return Collections.unmodifiableCollection(mRoutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int convertToInt(String addr) {
|
private int convertToInt(String addr) {
|
||||||
@@ -66,7 +71,7 @@ public class DhcpInfoInternal {
|
|||||||
public DhcpInfo makeDhcpInfo() {
|
public DhcpInfo makeDhcpInfo() {
|
||||||
DhcpInfo info = new DhcpInfo();
|
DhcpInfo info = new DhcpInfo();
|
||||||
info.ipAddress = convertToInt(ipAddress);
|
info.ipAddress = convertToInt(ipAddress);
|
||||||
for (RouteInfo route : routes) {
|
for (RouteInfo route : mRoutes) {
|
||||||
if (route.isDefaultRoute()) {
|
if (route.isDefaultRoute()) {
|
||||||
info.gateway = convertToInt(route.getGateway().getHostAddress());
|
info.gateway = convertToInt(route.getGateway().getHostAddress());
|
||||||
break;
|
break;
|
||||||
@@ -94,14 +99,14 @@ public class DhcpInfoInternal {
|
|||||||
public LinkProperties makeLinkProperties() {
|
public LinkProperties makeLinkProperties() {
|
||||||
LinkProperties p = new LinkProperties();
|
LinkProperties p = new LinkProperties();
|
||||||
p.addLinkAddress(makeLinkAddress());
|
p.addLinkAddress(makeLinkAddress());
|
||||||
for (RouteInfo route : routes) {
|
for (RouteInfo route : mRoutes) {
|
||||||
p.addRoute(route);
|
p.addRoute(route);
|
||||||
}
|
}
|
||||||
|
//if empty, connectivity configures default DNS
|
||||||
if (TextUtils.isEmpty(dns1) == false) {
|
if (TextUtils.isEmpty(dns1) == false) {
|
||||||
p.addDns(NetworkUtils.numericToInetAddress(dns1));
|
p.addDns(NetworkUtils.numericToInetAddress(dns1));
|
||||||
} else {
|
} else {
|
||||||
p.addDns(NetworkUtils.numericToInetAddress(serverAddress));
|
Log.d(TAG, "makeLinkProperties with empty dns1!");
|
||||||
Log.d(TAG, "empty dns1, use dhcp server as dns1!");
|
|
||||||
}
|
}
|
||||||
if (TextUtils.isEmpty(dns2) == false) {
|
if (TextUtils.isEmpty(dns2) == false) {
|
||||||
p.addDns(NetworkUtils.numericToInetAddress(dns2));
|
p.addDns(NetworkUtils.numericToInetAddress(dns2));
|
||||||
@@ -111,11 +116,33 @@ public class DhcpInfoInternal {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Updates the DHCP fields that need to be retained from
|
||||||
|
* original DHCP request if the DHCP renewal shows them as
|
||||||
|
* being empty
|
||||||
|
*/
|
||||||
|
public void updateFromDhcpRequest(DhcpInfoInternal orig) {
|
||||||
|
if (orig == null) return;
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(dns1)) {
|
||||||
|
dns1 = orig.dns1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(dns2)) {
|
||||||
|
dns2 = orig.dns2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mRoutes.size() == 0) {
|
||||||
|
for (RouteInfo route : orig.getRoutes()) {
|
||||||
|
addRoute(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String routeString = "";
|
String routeString = "";
|
||||||
for (RouteInfo route : routes) routeString += route.toString() + " | ";
|
for (RouteInfo route : mRoutes) routeString += route.toString() + " | ";
|
||||||
return "addr: " + ipAddress + "/" + prefixLength +
|
return "addr: " + ipAddress + "/" + prefixLength +
|
||||||
" routes: " + routeString +
|
" mRoutes: " + routeString +
|
||||||
" dns: " + dns1 + "," + dns2 +
|
" dns: " + dns1 + "," + dns2 +
|
||||||
" dhcpServer: " + serverAddress +
|
" dhcpServer: " + serverAddress +
|
||||||
" leaseDuration: " + leaseDuration;
|
" leaseDuration: " + leaseDuration;
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ public class DhcpStateMachine extends StateMachine {
|
|||||||
private PowerManager.WakeLock mDhcpRenewWakeLock;
|
private PowerManager.WakeLock mDhcpRenewWakeLock;
|
||||||
private static final String WAKELOCK_TAG = "DHCP";
|
private static final String WAKELOCK_TAG = "DHCP";
|
||||||
|
|
||||||
|
//Remember DHCP configuration from first request
|
||||||
|
private DhcpInfoInternal mDhcpInfo;
|
||||||
|
|
||||||
private static final int DHCP_RENEW = 0;
|
private static final int DHCP_RENEW = 0;
|
||||||
private static final String ACTION_DHCP_RENEW = "android.net.wifi.DHCP_RENEW";
|
private static final String ACTION_DHCP_RENEW = "android.net.wifi.DHCP_RENEW";
|
||||||
|
|
||||||
@@ -335,9 +338,11 @@ public class DhcpStateMachine extends StateMachine {
|
|||||||
if (dhcpAction == DhcpAction.START) {
|
if (dhcpAction == DhcpAction.START) {
|
||||||
Log.d(TAG, "DHCP request on " + mInterfaceName);
|
Log.d(TAG, "DHCP request on " + mInterfaceName);
|
||||||
success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal);
|
success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal);
|
||||||
|
mDhcpInfo = dhcpInfoInternal;
|
||||||
} else if (dhcpAction == DhcpAction.RENEW) {
|
} else if (dhcpAction == DhcpAction.RENEW) {
|
||||||
Log.d(TAG, "DHCP renewal on " + mInterfaceName);
|
Log.d(TAG, "DHCP renewal on " + mInterfaceName);
|
||||||
success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal);
|
success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal);
|
||||||
|
dhcpInfoInternal.updateFromDhcpRequest(mDhcpInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user