shill: Enable and disable IPv6 with interface events

Move device IP flag setting to a generic private method device.cc.
Use this to export the IPv6 address privacy flag setter.  Also use
this to enable and disable IPv6 at the same time that IPv4 address
configs are created and destroyed.  This will ensure that IPv6
kernel addrconfig starts and stops at the correct time.

BUG=chromium-os:23570
TEST=WiFiManager.050IPv6Basic: Passed during initial
connection, but failed due to some sort of DBus introspection
error in the second pass.  Manual: Monitor flags file for correct
operation on ethernet plug/unplug.  Manually verify the various
IPv6 addresses and routes being created and removed.

Change-Id: Id358b33dbf9faa602a181938ad524290b59a08b0
Reviewed-on: https://gerrit.chromium.org/gerrit/12577
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/device.h b/device.h
index 299b0c6..c019a8f 100644
--- a/device.h
+++ b/device.h
@@ -14,6 +14,7 @@
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
 #include "shill/event_dispatcher.h"
+#include "shill/ip_address.h"
 #include "shill/ipconfig.h"
 #include "shill/property_store.h"
 #include "shill/refptr_types.h"
@@ -73,6 +74,9 @@
   virtual void ChangePIN(const std::string &old_pin,
                          const std::string &new_pin,
                          Error *error);
+  virtual void DisableIPv6();
+  virtual void EnableIPv6();
+  virtual void EnableIPv6Privacy();
 
   // Returns true if the selected service on the device (if any) is connected.
   // Returns false if there is no selected service, or if the selected service
@@ -114,7 +118,7 @@
   DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); }
 
  protected:
-  FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
+  FRIEND_TEST(DeviceTest, AcquireIPConfig);
   FRIEND_TEST(DeviceTest, DestroyIPConfig);
   FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
   FRIEND_TEST(DeviceTest, GetProperties);
@@ -134,7 +138,7 @@
   // requests a new IP configuration. Registers a callback to
   // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
   // request was successfully sent.
-  bool AcquireDHCPConfig();
+  bool AcquireIPConfig();
 
   // Maintain connection state (Routes, IP Addresses and DNS) in the OS.
   void CreateConnection();
@@ -168,6 +172,12 @@
   friend class CellularTest;
   friend class WiFiMainTest;
 
+  static const char kIPFlagTemplate[];
+  static const char kIPFlagVersion4[];
+  static const char kIPFlagVersion6[];
+  static const char kIPFlagDisableIPv6[];
+  static const char kIPFlagUseTempAddr[];
+  static const char kIPFlagUseTempAddrUsedAndDefault[];
   static const char kStoragePowered[];
   static const char kStorageIPConfigs[];
 
@@ -180,6 +190,12 @@
   // |suffix| is injected into the storage identifier used for the configs.
   std::string SerializeIPConfigs(const std::string &suffix);
 
+  // Set an IP configuration flag on the device.  |ip_version| should be
+  // "ipv6" or "ipv4".  |flag| should be the name of the flag to be set
+  // and |value| is what this flag should be set to.
+  bool SetIPFlag(IPAddress::Family family, const std::string &flag,
+                 const std::string &value);
+
   std::vector<std::string> AvailableIPConfigs(Error *error);
   std::string GetRpcConnectionIdentifier();