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

Commit 8058f621 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Support for dns domain.

bug:6799630
Change-Id: I10070eddb65b7b60f0bc2b3e1e320e1aa4ec6e98
parent f89a5ef9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -238,4 +238,7 @@ public class DhcpResults implements Parcelable {
        vendorInfo = info;
    }

    public void setDomains(String domains) {
        linkProperties.setDomains(domains);
    }
}
+25 −3
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public class LinkProperties implements Parcelable {
    private String mIfaceName;
    private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
    private Collection<InetAddress> mDnses = new ArrayList<InetAddress>();
    private String mDomains;
    private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
    private ProxyProperties mHttpProxy;

@@ -82,6 +83,7 @@ public class LinkProperties implements Parcelable {
            mIfaceName = source.getInterfaceName();
            for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
            for (InetAddress i : source.getDnses()) mDnses.add(i);
            mDomains = source.getDomains();
            for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
            mHttpProxy = (source.getHttpProxy() == null)  ?
                    null : new ProxyProperties(source.getHttpProxy());
@@ -120,6 +122,14 @@ public class LinkProperties implements Parcelable {
        return Collections.unmodifiableCollection(mDnses);
    }

    public String getDomains() {
        return mDomains;
    }

    public void setDomains(String domains) {
        mDomains = domains;
    }

    public void addRoute(RouteInfo route) {
        if (route != null) mRoutes.add(route);
    }
@@ -138,6 +148,7 @@ public class LinkProperties implements Parcelable {
        mIfaceName = null;
        mLinkAddresses.clear();
        mDnses.clear();
        mDomains = null;
        mRoutes.clear();
        mHttpProxy = null;
    }
@@ -162,12 +173,14 @@ public class LinkProperties implements Parcelable {
        for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
        dns += "] ";

        String domainName = "Domains: " + mDomains;

        String routes = " Routes: [";
        for (RouteInfo route : mRoutes) routes += route.toString() + ",";
        routes += "] ";
        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) {
        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()) ?
                    mDnses.containsAll(targetDnses) : false;
    }
@@ -359,6 +378,7 @@ public class LinkProperties implements Parcelable {
        return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
                + mLinkAddresses.size() * 31
                + mDnses.size() * 37
                + ((null == mDomains) ? 0 : mDomains.hashCode())
                + mRoutes.size() * 41
                + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()));
    }
@@ -377,6 +397,7 @@ public class LinkProperties implements Parcelable {
        for(InetAddress d : mDnses) {
            dest.writeByteArray(d.getAddress());
        }
        dest.writeString(mDomains);

        dest.writeInt(mRoutes.size());
        for(RouteInfo route : mRoutes) {
@@ -413,6 +434,7 @@ public class LinkProperties implements Parcelable {
                        netProp.addDns(InetAddress.getByAddress(in.createByteArray()));
                    } catch (UnknownHostException e) { }
                }
                netProp.setDomains(in.readString());
                addressCount = in.readInt();
                for (int i=0; i<addressCount; i++) {
                    netProp.addRoute((RouteInfo)in.readParcelable(null));
+1 −1
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ interface INetworkManagementService
    /**
     * Bind name servers to an interface in the DNS resolver.
     */
    void setDnsServersForInterface(String iface, in String[] servers);
    void setDnsServersForInterface(String iface, in String[] servers, String domains);

    /**
     * Flush the DNS cache associated with the default interface.
+13 −5
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ int dhcp_do_request(const char *ifname,
                    const char *dns2,
                    const char *server,
                    uint32_t *lease,
                    const char *vendorInfo);
                    const char *vendorInfo,
                    const char *domains);

int dhcp_do_request_renew(const char *ifname,
                    const char *ipaddr,
@@ -46,7 +47,8 @@ int dhcp_do_request_renew(const char *ifname,
                    const char *dns2,
                    const char *server,
                    uint32_t *lease,
                    const char *vendorInfo);
                    const char *vendorInfo,
                    const char *domains);

int dhcp_stop(const char *ifname);
int dhcp_release_lease(const char *ifname);
@@ -68,6 +70,7 @@ static struct fieldIds {
    jmethodID addLinkAddress;
    jmethodID addGateway;
    jmethodID addDns;
    jmethodID setDomains;
    jmethodID setServerAddress;
    jmethodID setLeaseDuration;
    jmethodID setVendorInfo;
@@ -120,18 +123,18 @@ static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstr
    char  server[PROPERTY_VALUE_MAX];
    uint32_t lease;
    char vendorInfo[PROPERTY_VALUE_MAX];
    char domains[PROPERTY_VALUE_MAX];

    const char *nameStr = env->GetStringUTFChars(ifname, NULL);
    if (nameStr == NULL) return (jboolean)false;

    if (renew) {
        result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
                dns1, dns2, server, &lease, vendorInfo);
                dns1, dns2, server, &lease, vendorInfo, domains);
    } else {
        result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
                dns1, dns2, server, &lease, vendorInfo);
                dns1, dns2, server, &lease, vendorInfo, domains);
    }

    env->ReleaseStringUTFChars(ifname, nameStr);
    if (result == 0) {
        env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.clear);
@@ -160,6 +163,9 @@ static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstr
    }

    if (result == 0) {
        env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.setDomains,
                env->NewStringUTF(domains));

        result = env->CallBooleanMethod(dhcpResults,
                dhcpResultsFieldIds.addDns, env->NewStringUTF(dns2));
    }
@@ -251,6 +257,8 @@ int register_android_net_NetworkUtils(JNIEnv* env)
            env->GetMethodID(dhcpResultsClass, "addGateway", "(Ljava/lang/String;)Z");
    dhcpResultsFieldIds.addDns =
            env->GetMethodID(dhcpResultsClass, "addDns", "(Ljava/lang/String;)Z");
    dhcpResultsFieldIds.setDomains =
            env->GetMethodID(dhcpResultsClass, "setDomains", "(Ljava/lang/String;)V");
    dhcpResultsFieldIds.setServerAddress =
            env->GetMethodID(dhcpResultsClass, "setServerAddress", "(Ljava/lang/String;)Z");
    dhcpResultsFieldIds.setLeaseDuration =
+7 −7
Original line number Diff line number Diff line
@@ -2524,19 +2524,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            SystemProperties.set(key, "");
        }
        mNumDnsEntries = last;
        if (SystemProperties.get("net.dns.search").equals(domains) == false) {
            SystemProperties.set("net.dns.search", domains);
            changed = true;
        }

        if (changed) {
            try {
                mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses));
                mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses), domains);
                mNetd.setDefaultInterfaceForDns(iface);
            } catch (Exception 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;
    }

@@ -2552,13 +2552,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                String network = nt.getNetworkInfo().getTypeName();
                synchronized (mDnsLock) {
                    if (!mDnsOverridden) {
                        changed = updateDns(network, p.getInterfaceName(), dnses, "");
                        changed = updateDns(network, p.getInterfaceName(), dnses, p.getDomains());
                    }
                }
            } else {
                try {
                    mNetd.setDnsServersForInterface(p.getInterfaceName(),
                            NetworkUtils.makeStrings(dnses));
                            NetworkUtils.makeStrings(dnses), p.getDomains());
                } catch (Exception e) {
                    if (DBG) loge("exception setting dns servers: " + e);
                }
Loading