Merge "Support for dns domain."
This commit is contained in:
committed by
Android (Google) Code Review
commit
402d9c853f
@@ -54,6 +54,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
private String mIfaceName;
|
private String mIfaceName;
|
||||||
private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
|
private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
|
||||||
private Collection<InetAddress> mDnses = new ArrayList<InetAddress>();
|
private Collection<InetAddress> mDnses = new ArrayList<InetAddress>();
|
||||||
|
private String mDomains;
|
||||||
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
||||||
private ProxyProperties mHttpProxy;
|
private ProxyProperties mHttpProxy;
|
||||||
|
|
||||||
@@ -82,6 +83,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
mIfaceName = source.getInterfaceName();
|
mIfaceName = source.getInterfaceName();
|
||||||
for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
|
for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
|
||||||
for (InetAddress i : source.getDnses()) mDnses.add(i);
|
for (InetAddress i : source.getDnses()) mDnses.add(i);
|
||||||
|
mDomains = source.getDomains();
|
||||||
for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
|
for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
|
||||||
mHttpProxy = (source.getHttpProxy() == null) ?
|
mHttpProxy = (source.getHttpProxy() == null) ?
|
||||||
null : new ProxyProperties(source.getHttpProxy());
|
null : new ProxyProperties(source.getHttpProxy());
|
||||||
@@ -120,6 +122,14 @@ public class LinkProperties implements Parcelable {
|
|||||||
return Collections.unmodifiableCollection(mDnses);
|
return Collections.unmodifiableCollection(mDnses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDomains() {
|
||||||
|
return mDomains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomains(String domains) {
|
||||||
|
mDomains = domains;
|
||||||
|
}
|
||||||
|
|
||||||
public void addRoute(RouteInfo route) {
|
public void addRoute(RouteInfo route) {
|
||||||
if (route != null) mRoutes.add(route);
|
if (route != null) mRoutes.add(route);
|
||||||
}
|
}
|
||||||
@@ -138,6 +148,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
mIfaceName = null;
|
mIfaceName = null;
|
||||||
mLinkAddresses.clear();
|
mLinkAddresses.clear();
|
||||||
mDnses.clear();
|
mDnses.clear();
|
||||||
|
mDomains = null;
|
||||||
mRoutes.clear();
|
mRoutes.clear();
|
||||||
mHttpProxy = null;
|
mHttpProxy = null;
|
||||||
}
|
}
|
||||||
@@ -162,12 +173,14 @@ public class LinkProperties implements Parcelable {
|
|||||||
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
|
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
|
||||||
dns += "] ";
|
dns += "] ";
|
||||||
|
|
||||||
|
String domainName = "Domains: " + mDomains;
|
||||||
|
|
||||||
String routes = " Routes: [";
|
String routes = " Routes: [";
|
||||||
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
||||||
routes += "] ";
|
routes += "] ";
|
||||||
String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " ");
|
String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " ");
|
||||||
|
|
||||||
return ifaceName + linkAddresses + routes + dns + proxy;
|
return ifaceName + linkAddresses + routes + dns + domainName + proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,6 +214,12 @@ public class LinkProperties implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public boolean isIdenticalDnses(LinkProperties target) {
|
public boolean isIdenticalDnses(LinkProperties target) {
|
||||||
Collection<InetAddress> targetDnses = target.getDnses();
|
Collection<InetAddress> targetDnses = target.getDnses();
|
||||||
|
String targetDomains = target.getDomains();
|
||||||
|
if (mDomains == null) {
|
||||||
|
if (targetDomains != null) return false;
|
||||||
|
} else {
|
||||||
|
if (mDomains.equals(targetDomains) == false) return false;
|
||||||
|
}
|
||||||
return (mDnses.size() == targetDnses.size()) ?
|
return (mDnses.size() == targetDnses.size()) ?
|
||||||
mDnses.containsAll(targetDnses) : false;
|
mDnses.containsAll(targetDnses) : false;
|
||||||
}
|
}
|
||||||
@@ -359,6 +378,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
|
return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
|
||||||
+ mLinkAddresses.size() * 31
|
+ mLinkAddresses.size() * 31
|
||||||
+ mDnses.size() * 37
|
+ mDnses.size() * 37
|
||||||
|
+ ((null == mDomains) ? 0 : mDomains.hashCode())
|
||||||
+ mRoutes.size() * 41
|
+ mRoutes.size() * 41
|
||||||
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()));
|
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()));
|
||||||
}
|
}
|
||||||
@@ -377,6 +397,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
for(InetAddress d : mDnses) {
|
for(InetAddress d : mDnses) {
|
||||||
dest.writeByteArray(d.getAddress());
|
dest.writeByteArray(d.getAddress());
|
||||||
}
|
}
|
||||||
|
dest.writeString(mDomains);
|
||||||
|
|
||||||
dest.writeInt(mRoutes.size());
|
dest.writeInt(mRoutes.size());
|
||||||
for(RouteInfo route : mRoutes) {
|
for(RouteInfo route : mRoutes) {
|
||||||
@@ -413,6 +434,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
netProp.addDns(InetAddress.getByAddress(in.createByteArray()));
|
netProp.addDns(InetAddress.getByAddress(in.createByteArray()));
|
||||||
} catch (UnknownHostException e) { }
|
} catch (UnknownHostException e) { }
|
||||||
}
|
}
|
||||||
|
netProp.setDomains(in.readString());
|
||||||
addressCount = in.readInt();
|
addressCount = in.readInt();
|
||||||
for (int i=0; i<addressCount; i++) {
|
for (int i=0; i<addressCount; i++) {
|
||||||
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ int dhcp_do_request(const char *ifname,
|
|||||||
const char *dns2,
|
const char *dns2,
|
||||||
const char *server,
|
const char *server,
|
||||||
uint32_t *lease,
|
uint32_t *lease,
|
||||||
const char *vendorInfo);
|
const char *vendorInfo,
|
||||||
|
const char *domains);
|
||||||
|
|
||||||
int dhcp_do_request_renew(const char *ifname,
|
int dhcp_do_request_renew(const char *ifname,
|
||||||
const char *ipaddr,
|
const char *ipaddr,
|
||||||
@@ -46,7 +47,8 @@ int dhcp_do_request_renew(const char *ifname,
|
|||||||
const char *dns2,
|
const char *dns2,
|
||||||
const char *server,
|
const char *server,
|
||||||
uint32_t *lease,
|
uint32_t *lease,
|
||||||
const char *vendorInfo);
|
const char *vendorInfo,
|
||||||
|
const char *domains);
|
||||||
|
|
||||||
int dhcp_stop(const char *ifname);
|
int dhcp_stop(const char *ifname);
|
||||||
int dhcp_release_lease(const char *ifname);
|
int dhcp_release_lease(const char *ifname);
|
||||||
@@ -68,6 +70,7 @@ static struct fieldIds {
|
|||||||
jmethodID addLinkAddress;
|
jmethodID addLinkAddress;
|
||||||
jmethodID addGateway;
|
jmethodID addGateway;
|
||||||
jmethodID addDns;
|
jmethodID addDns;
|
||||||
|
jmethodID setDomains;
|
||||||
jmethodID setServerAddress;
|
jmethodID setServerAddress;
|
||||||
jmethodID setLeaseDuration;
|
jmethodID setLeaseDuration;
|
||||||
jmethodID setVendorInfo;
|
jmethodID setVendorInfo;
|
||||||
@@ -120,18 +123,18 @@ static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstr
|
|||||||
char server[PROPERTY_VALUE_MAX];
|
char server[PROPERTY_VALUE_MAX];
|
||||||
uint32_t lease;
|
uint32_t lease;
|
||||||
char vendorInfo[PROPERTY_VALUE_MAX];
|
char vendorInfo[PROPERTY_VALUE_MAX];
|
||||||
|
char domains[PROPERTY_VALUE_MAX];
|
||||||
|
|
||||||
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
|
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
|
||||||
if (nameStr == NULL) return (jboolean)false;
|
if (nameStr == NULL) return (jboolean)false;
|
||||||
|
|
||||||
if (renew) {
|
if (renew) {
|
||||||
result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
|
result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
|
||||||
dns1, dns2, server, &lease, vendorInfo);
|
dns1, dns2, server, &lease, vendorInfo, domains);
|
||||||
} else {
|
} else {
|
||||||
result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
|
result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
|
||||||
dns1, dns2, server, &lease, vendorInfo);
|
dns1, dns2, server, &lease, vendorInfo, domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
env->ReleaseStringUTFChars(ifname, nameStr);
|
env->ReleaseStringUTFChars(ifname, nameStr);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.clear);
|
env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.clear);
|
||||||
@@ -160,6 +163,9 @@ static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.setDomains,
|
||||||
|
env->NewStringUTF(domains));
|
||||||
|
|
||||||
result = env->CallBooleanMethod(dhcpResults,
|
result = env->CallBooleanMethod(dhcpResults,
|
||||||
dhcpResultsFieldIds.addDns, env->NewStringUTF(dns2));
|
dhcpResultsFieldIds.addDns, env->NewStringUTF(dns2));
|
||||||
}
|
}
|
||||||
@@ -251,6 +257,8 @@ int register_android_net_NetworkUtils(JNIEnv* env)
|
|||||||
env->GetMethodID(dhcpResultsClass, "addGateway", "(Ljava/lang/String;)Z");
|
env->GetMethodID(dhcpResultsClass, "addGateway", "(Ljava/lang/String;)Z");
|
||||||
dhcpResultsFieldIds.addDns =
|
dhcpResultsFieldIds.addDns =
|
||||||
env->GetMethodID(dhcpResultsClass, "addDns", "(Ljava/lang/String;)Z");
|
env->GetMethodID(dhcpResultsClass, "addDns", "(Ljava/lang/String;)Z");
|
||||||
|
dhcpResultsFieldIds.setDomains =
|
||||||
|
env->GetMethodID(dhcpResultsClass, "setDomains", "(Ljava/lang/String;)V");
|
||||||
dhcpResultsFieldIds.setServerAddress =
|
dhcpResultsFieldIds.setServerAddress =
|
||||||
env->GetMethodID(dhcpResultsClass, "setServerAddress", "(Ljava/lang/String;)Z");
|
env->GetMethodID(dhcpResultsClass, "setServerAddress", "(Ljava/lang/String;)Z");
|
||||||
dhcpResultsFieldIds.setLeaseDuration =
|
dhcpResultsFieldIds.setLeaseDuration =
|
||||||
|
|||||||
@@ -2524,19 +2524,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
SystemProperties.set(key, "");
|
SystemProperties.set(key, "");
|
||||||
}
|
}
|
||||||
mNumDnsEntries = last;
|
mNumDnsEntries = last;
|
||||||
|
if (SystemProperties.get("net.dns.search").equals(domains) == false) {
|
||||||
|
SystemProperties.set("net.dns.search", domains);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
try {
|
try {
|
||||||
mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses));
|
mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses), domains);
|
||||||
mNetd.setDefaultInterfaceForDns(iface);
|
mNetd.setDefaultInterfaceForDns(iface);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (DBG) loge("exception setting default dns interface: " + e);
|
if (DBG) loge("exception setting default dns interface: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!domains.equals(SystemProperties.get("net.dns.search"))) {
|
|
||||||
SystemProperties.set("net.dns.search", domains);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2552,13 +2552,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
String network = nt.getNetworkInfo().getTypeName();
|
String network = nt.getNetworkInfo().getTypeName();
|
||||||
synchronized (mDnsLock) {
|
synchronized (mDnsLock) {
|
||||||
if (!mDnsOverridden) {
|
if (!mDnsOverridden) {
|
||||||
changed = updateDns(network, p.getInterfaceName(), dnses, "");
|
changed = updateDns(network, p.getInterfaceName(), dnses, p.getDomains());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
mNetd.setDnsServersForInterface(p.getInterfaceName(),
|
mNetd.setDnsServersForInterface(p.getInterfaceName(),
|
||||||
NetworkUtils.makeStrings(dnses));
|
NetworkUtils.makeStrings(dnses), p.getDomains());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (DBG) loge("exception setting dns servers: " + e);
|
if (DBG) loge("exception setting dns servers: " + e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user