shill: Add ArpGateway and network-based leases

Add two arguments to the DHCP client:
  - Turn on ArpGateway (ARP for default gateway in order to test validity
    of lease) by default, and use the same manager flag as flimflam did.

  - Use per-network lease files for Ethernet and WiFi.  This means that
    multiple leases can be held in parallel for different Ethernet devices
    and WiFi SSIDs.

Bonus changes: Fix DHCP lease filename template which was broken in flimflam
and ported with full fidelity to shill.  Make removal of old lease files
conditional on whether the lease file was non-default.

BUG=chromium-os:25717,chromium-os:16885
TEST=New unit tests + manual: Ensure dhcpcd runs with correct arguments ("-R"
added when ArpGateway is enabled on the manager, no "-R" otherwise), and that
the "set_arpgw" command in crosh works correctly.  Monitor dhcpcd command line
for new lease suffix parameter, and ensure that leases are being written out
to those files, and that the files are not being removed on program exit.
CQ-DEPEND=Iac282c1686695239a790bbcc0d110c6a69bf45e0

Change-Id: I68bb3cbd18c95f01003eaf049fa60aad446f8116
Reviewed-on: https://gerrit.chromium.org/gerrit/22065
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/dhcp_config.h b/dhcp_config.h
index 2afa200..429e15e 100644
--- a/dhcp_config.h
+++ b/dhcp_config.h
@@ -22,6 +22,16 @@
 class GLib;
 class ProxyFactory;
 
+// This class provides a DHCP client instance for the device |device_name|.
+// If |request_hostname| is non-empty, it asks the DHCP server to register
+// this hostname on our behalf, for purposes of administration or creating
+// a dynamic DNS entry.
+//
+// The DHPCConfig instance asks the DHCP client to create a lease file
+// containing the name |lease_file_suffix|.  If this suffix is the same as
+// |device_name|, the lease is considered to be ephemeral, and the lease
+// file is removed whenever this DHCPConfig instance is no longer needed.
+// Otherwise, the lease file persists and will be re-used in future attempts.
 class DHCPConfig : public IPConfig {
  public:
   typedef std::map<std::string, DBus::Variant> Configuration;
@@ -33,6 +43,8 @@
              DHCPProvider *provider,
              const std::string &device_name,
              const std::string &request_hostname,
+             const std::string &lease_file_suffix,
+             bool arp_gateway,
              GLib *glib);
   virtual ~DHCPConfig();
 
@@ -64,8 +76,9 @@
   FRIEND_TEST(DHCPConfigTest, RestartNoClient);
   FRIEND_TEST(DHCPConfigTest, StartFail);
   FRIEND_TEST(DHCPConfigTest, StartWithHostname);
+  FRIEND_TEST(DHCPConfigTest, StartWithoutArpGateway);
   FRIEND_TEST(DHCPConfigTest, StartWithoutHostname);
-  FRIEND_TEST(DHCPConfigTest, StartSuccess);
+  FRIEND_TEST(DHCPConfigTest, StartWithoutLeaseSuffix);
   FRIEND_TEST(DHCPConfigTest, Stop);
   FRIEND_TEST(DHCPProviderTest, CreateConfig);
 
@@ -127,6 +140,14 @@
   // server in the request.
   std::string request_hostname_;
 
+  // DHCP lease file suffix, used to differentiate the lease of one interface
+  // or network from another.
+  std::string lease_file_suffix_;
+
+  // Specifies whether to supply an argument to the DHCP client to validate
+  // the acquired IP address using an ARP request to the gateway IP address.
+  bool arp_gateway_;
+
   // The PID of the spawned DHCP client. May be 0 if no client has been spawned
   // yet or the client has died.
   int pid_;