shill: resolver: Use (even) smaller DNS timeout

Use the new glibc facility for sub-second timeouts, and choose
300 milliseconds for the timeout.  However, only do this by
default for Ethernet and WiFi networks, since VPN networks
in particular have trouble with this configuration (due to many
name servers and search domains, as well as the additional
latency inherent to such networks).  Also, increase the number
of attempts, so we still spend a reasonable amount of time
overall waiting for a DNS response.

Provide a means to change which technologies are setup in this
manner.

BUG=chromium-os:29124
TEST=Manual: Install connection manager, verify via strace that
gethostbyname now waits 300 ms, and retries 15 times per trial (*).
Ensure Chromium continues to work correctly under light loads.
Also, connect via Verizon and VPN and ensure DNS parameters
are back to the long timeout.
List manager properties and ensure it says "ethernet,wifi" for
ShortDNSTimeoutTechnologies and that this is saved out to the
profile.
New unit tests.
CQ-DEPENDS=Ib9ffc59bbfcd5bf3f57d146965c5a43a936348f8

*: Each trial consists of a nameserver / IP address pair, so
for example, if we have IPv6 connectivity and have two "server"
entries in resolv.conf, we first do 30 tries of IPv6 requests,
alternating between the two servers, then another 30 alternating
IPv4 requests between them.  This was tested by intentionally
making the DNS server unreachable and instrumenting the gethostbyname
request via strace.

Change-Id: Idd331b4a9fcf96d457ab9959537aefcb86328e12
Reviewed-on: https://gerrit.chromium.org/gerrit/26493
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/resolver.h b/resolver.h
index 382fdd9..8c56712 100644
--- a/resolver.h
+++ b/resolver.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -20,6 +20,15 @@
 // of an ipconfig into a "resolv.conf" formatted file.
 class Resolver {
  public:
+  enum TimeoutParameters {
+    kDefaultTimeout,
+    kShortTimeout
+  };
+
+  // The default comma-separated list of technologies for which short
+  // DNS timeouts should be enabled.
+  static const char kDefaultShortTimeoutTechnologies[];
+
   virtual ~Resolver();
 
   // Since this is a singleton, use Resolver::GetInstance()->Foo()
@@ -27,14 +36,16 @@
 
   virtual void set_path(const FilePath &path) { path_ = path; }
 
-  // Set the default domain name service parameters, given an ipconfig entry
-  virtual bool SetDNSFromIPConfig(const IPConfigRefPtr &ipconfig);
+  // Set the default domain name service parameters, given an ipconfig entry.
+  virtual bool SetDNSFromIPConfig(const IPConfigRefPtr &ipconfig,
+                                  TimeoutParameters timeout);
 
-  // Set the default domain name service parameters, given an ipconfig entry
+  // Set the default domain name service parameters, given an ipconfig entry.
   virtual bool SetDNSFromLists(const std::vector<std::string> &dns_servers,
-                               const std::vector<std::string> &domain_search);
+                               const std::vector<std::string> &domain_search,
+                               TimeoutParameters timeout);
 
-  // Remove any created domain name service file
+  // Remove any created domain name service file.
   virtual bool ClearDNS();
 
  protected:
@@ -44,6 +55,9 @@
   friend struct base::DefaultLazyInstanceTraits<Resolver>;
   friend class ResolverTest;
 
+  static const char kDefaultTimeoutOptions[];
+  static const char kShortTimeoutOptions[];
+
   FilePath path_;
 
   DISALLOW_COPY_AND_ASSIGN(Resolver);