Enable RFC 7217 stable privacy addresses

... on kernels that support this feature. Android property server is
used in combination with SELinux policy to limit access to the
necessary stable secret.

This change also makes some small improvements and fixes to
libnetdutils.

ip -6 addr indicates stable_privacy addresses with "flags 800"

wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 3000
inet6 fdd5:6241:900d:0:d547:442:33d7:1982/64 scope global temporary dynamic
inet6 fdd5:6241:900d:0:9dbe:3875:1cab:eaf2/64 scope global mngtmpaddr dynamic flags 800
inet6 2401:fa00:4:ca0:d547:442:33d7:1982/64 scope global temporary dynamic
inet6 2401:fa00:4:ca0:6281:68a2:7124:6848/64 scope global mngtmpaddr dynamic flags 800
inet6 fe80::d5a7:18ed:4ea7:50d8/64 scope link flags 800

Test: as follows
    - built
    - flashed
    - booted
    - "runtest -x .../netd_unit_test.cpp" passes
Bug: 17613910

Change-Id: I0e0b6bbd15cb9d46368bed8aef5dac2f6183d32a
diff --git a/server/InterfaceController.h b/server/InterfaceController.h
index 80ebe5c..30898f2 100644
--- a/server/InterfaceController.h
+++ b/server/InterfaceController.h
@@ -17,13 +17,24 @@
 #ifndef _INTERFACE_CONTROLLER_H
 #define _INTERFACE_CONTROLLER_H
 
+#include <functional>
 #include <string>
 
+#include <netdutils/Status.h>
+
+// TODO: move InterfaceController into android::net namespace.
+namespace android {
+namespace net {
+class StablePrivacyTest;
+}  // namespace net
+}  // namespace android
+
 class InterfaceController {
 public:
     static void initializeAll();
 
     static int setEnableIPv6(const char *interface, const int on);
+    static android::netdutils::Status setIPv6AddrGenMode(const std::string& interface, int mode);
     static int setAcceptIPv6Ra(const char *interface, const int on);
     static int setAcceptIPv6Dad(const char *interface, const int on);
     static int setIPv6DadTransmits(const char *interface, const char *value);
@@ -43,13 +54,25 @@
             const char *value);
 
 private:
-    static void setAcceptRA(const char* value);
-    static void setAcceptRARouteTable(int tableOrOffset);
-    static void setBaseReachableTimeMs(unsigned int millis);
-    static void setIPv6OptimisticMode(const char *value);
+  friend class android::net::StablePrivacyTest;
 
-    InterfaceController() = delete;
-    ~InterfaceController() = delete;
+  using GetPropertyFn =
+      std::function<std::string(const std::string& key, const std::string& dflt)>;
+  using SetPropertyFn =
+      std::function<android::netdutils::Status(const std::string& key, const std::string& val)>;
+
+  // Helper function exported from this compilation unit for testing.
+  static android::netdutils::Status enableStablePrivacyAddresses(const std::string& iface,
+                                                                 GetPropertyFn getProperty,
+                                                                 SetPropertyFn setProperty);
+
+  static void setAcceptRA(const char* value);
+  static void setAcceptRARouteTable(int tableOrOffset);
+  static void setBaseReachableTimeMs(unsigned int millis);
+  static void setIPv6OptimisticMode(const char* value);
+
+  InterfaceController() = delete;
+  ~InterfaceController() = delete;
 };
 
 #endif