From 32d106e154d0388ac13774fad3c58ff60ba9ae8f Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Mon, 25 Jul 2011 15:26:56 -0700 Subject: [PATCH 1/3] Filter out addresses that are 0. If the address is "any" address, i.e. an address which is all zeros for both IPv4 and IPv6 ignore it. Bug: 5073048 Change-Id: I8b9f64103aaffd001114a672375ff5f99616c327 --- .../internal/telephony/DataCallState.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/telephony/java/com/android/internal/telephony/DataCallState.java b/telephony/java/com/android/internal/telephony/DataCallState.java index a69ce8b7fe603..6d8956f452b75 100644 --- a/telephony/java/com/android/internal/telephony/DataCallState.java +++ b/telephony/java/com/android/internal/telephony/DataCallState.java @@ -142,13 +142,15 @@ public class DataCallState { } catch (IllegalArgumentException e) { throw new UnknownHostException("Non-numeric ip addr=" + addr); } - if (addrPrefixLen == 0) { - // Assume point to point - addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128; + if (! ia.isAnyLocalAddress()) { + if (addrPrefixLen == 0) { + // Assume point to point + addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128; + } + if (DBG) Log.d(LOG_TAG, "addr/pl=" + addr + "/" + addrPrefixLen); + la = new LinkAddress(ia, addrPrefixLen); + linkProperties.addLinkAddress(la); } - if (DBG) Log.d(LOG_TAG, "addr/pl=" + addr + "/" + addrPrefixLen); - la = new LinkAddress(ia, addrPrefixLen); - linkProperties.addLinkAddress(la); } } else { throw new UnknownHostException("no address for ifname=" + ifname); @@ -163,21 +165,24 @@ public class DataCallState { } catch (IllegalArgumentException e) { throw new UnknownHostException("Non-numeric dns addr=" + addr); } - linkProperties.addDns(ia); + if (! ia.isAnyLocalAddress()) { + linkProperties.addDns(ia); + } } } else if (okToUseSystemPropertyDns){ String dnsServers[] = new String[2]; dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1"); dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2"); for (String dnsAddr : dnsServers) { - InetAddress ia; - try { - ia = NetworkUtils.numericToInetAddress(dnsAddr); - } catch (IllegalArgumentException e) { - throw new UnknownHostException("Non-numeric dns addr=" - + dnsAddr); - } + InetAddress ia; + try { + ia = NetworkUtils.numericToInetAddress(dnsAddr); + } catch (IllegalArgumentException e) { + throw new UnknownHostException("Non-numeric dns addr=" + dnsAddr); + } + if (! ia.isAnyLocalAddress()) { linkProperties.addDns(ia); + } } } else { throw new UnknownHostException("Empty dns response and no system default dns"); @@ -199,7 +204,9 @@ public class DataCallState { } catch (IllegalArgumentException e) { throw new UnknownHostException("Non-numeric gateway addr=" + addr); } - linkProperties.addRoute(new RouteInfo(ia)); + if (! ia.isAnyLocalAddress()) { + linkProperties.addRoute(new RouteInfo(ia)); + } } result = SetupResult.SUCCESS; From 572b7048a6ed6cf6c5f6bc6c9d542dc377d601ff Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Mon, 25 Jul 2011 17:00:13 -0700 Subject: [PATCH 2/3] Use dns proxy a bit. Sets the current default interface and sets the dns per interface. port of changes 23041 and 22098 from opensource. bug:5060618 Change-Id: I80e7ef88727eeb8ff2b48059f69b270e5a6b5c16 --- core/java/android/net/NetworkUtils.java | 15 +++++ .../android/os/INetworkManagementService.aidl | 19 ++++++ .../android/server/ConnectivityService.java | 11 ++++ .../server/NetworkManagementService.java | 60 +++++++++++++++++++ 4 files changed, 105 insertions(+) diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java index 76534ef3d8a7d..e07cbcefbb899 100644 --- a/core/java/android/net/NetworkUtils.java +++ b/core/java/android/net/NetworkUtils.java @@ -20,6 +20,7 @@ import java.net.InetAddress; import java.net.Inet4Address; import java.net.Inet6Address; import java.net.UnknownHostException; +import java.util.Collection; import android.util.Log; @@ -235,4 +236,18 @@ public class NetworkUtils { throw new IllegalArgumentException(e); } } + + /** + * Create a string array of host addresses from a collection of InetAddresses + * @param addrs a Collection of InetAddresses + * @return an array of Strings containing their host addresses + */ + public static String[] makeStrings(Collection addrs) { + String[] result = new String[addrs.size()]; + int i=0; + for (InetAddress addr : addrs) { + result[i++] = addr.getHostAddress(); + } + return result; + } } diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl index 5a245f8785455..87c2d5932f8b5 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -224,4 +224,23 @@ interface INetworkManagementService */ int getInterfaceTxThrottle(String iface); + /** + * Sets the name fo the default interface in the DNS resolver. + */ + void setDefaultInterfaceForDns(String iface); + + /** + * Bind name servers to an interface in the DNS resolver. + */ + void setDnsServersForInterface(String iface, in String[] servers); + + /** + * Flush the DNS cache associated with the default interface. + */ + void flushDefaultDnsCache(); + + /** + * Flush the DNS cache associated with the specified interface. + */ + void flushInterfaceDnsCache(String iface); } diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 2bbf92e2bb7e4..3c2f6195d3815 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -1757,8 +1757,19 @@ public class ConnectivityService extends IConnectivityManager.Stub { LinkProperties p = nt.getLinkProperties(); if (p == null) return; Collection dnses = p.getDnses(); + try { + mNetd.setDnsServersForInterface(p.getInterfaceName(), + NetworkUtils.makeStrings(dnses)); + } catch (Exception e) { + Slog.e(TAG, "exception setting dns servers: " + e); + } boolean changed = false; if (mNetConfigs[netType].isDefault()) { + try { + mNetd.setDefaultInterfaceForDns(p.getInterfaceName()); + } catch (Exception e) { + Slog.e(TAG, "exception setting default dns interface: " + e); + } int j = 1; if (dnses.size() == 0 && mDefaultDns != null) { String dnsString = mDefaultDns.getHostAddress(); diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index 0b4b95893254f..9a5d0becfe2a6 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -949,4 +949,64 @@ class NetworkManagementService extends INetworkManagementService.Stub { public int getInterfaceTxThrottle(String iface) { return getInterfaceThrottle(iface, false); } + + public void setDefaultInterfaceForDns(String iface) throws IllegalStateException { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); + try { + String cmd = "resolver setdefaultif " + iface; + + mConnector.doCommand(cmd); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native daemon to set default interface", e); + } + } + + public void setDnsServersForInterface(String iface, String[] servers) + throws IllegalStateException { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_NETWORK_STATE, + "NetworkManagementService"); + try { + String cmd = "resolver setifdns " + iface; + for (String s : servers) { + InetAddress a = NetworkUtils.numericToInetAddress(s); + if (a.isAnyLocalAddress() == false) { + cmd += " " + a.getHostAddress(); + } + } + mConnector.doCommand(cmd); + } catch (IllegalArgumentException e) { + throw new IllegalStateException("Error setting dnsn for interface", e); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native daemon to set dns for interface", e); + } + } + + public void flushDefaultDnsCache() throws IllegalStateException { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); + try { + String cmd = "resolver flushdefaultif"; + + mConnector.doCommand(cmd); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native daemon to flush default interface", e); + } + } + + public void flushInterfaceDnsCache(String iface) throws IllegalStateException { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); + try { + String cmd = "resolver flushif " + iface; + + mConnector.doCommand(cmd); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native daemon to flush interface " + iface, e); + } + } } From ac74551bb42eb2d6775d994357481113375574e7 Mon Sep 17 00:00:00 2001 From: John Michelau Date: Mon, 25 Jul 2011 20:42:50 -0500 Subject: [PATCH 3/3] Disable name lookups for dumpstate calls to "iptables -L" The name lookups are not helpful enough to warrant the large delays they can cause. Change-Id: I8710e76b15b7cf060b7f4f89128ea3249fcdbd0d --- cmds/dumpstate/dumpstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c index 209417bd2b0b6..05e40448bad32 100644 --- a/cmds/dumpstate/dumpstate.c +++ b/cmds/dumpstate/dumpstate.c @@ -113,8 +113,8 @@ static void dumpstate() { dump_file("NETWORK ROUTES", "/proc/net/route"); dump_file("NETWORK ROUTES IPV6", "/proc/net/ipv6_route"); dump_file("ARP CACHE", "/proc/net/arp"); - run_command("IPTABLES", 10, "su", "root", "iptables", "-L", NULL); - run_command("IPTABLE NAT", 10, "su", "root", "iptables", "-t", "nat", "-L", NULL); + run_command("IPTABLES", 10, "su", "root", "iptables", "-L", "-n", NULL); + run_command("IPTABLE NAT", 10, "su", "root", "iptables", "-t", "nat", "-L", "-n", NULL); run_command("WIFI NETWORKS", 20, "su", "root", "wpa_cli", "list_networks", NULL);