Add ip6 dummy address to keep data usage stats consistent.

Because of the way the tunnel pumps packets into the networking
stack, the netfilter xt_qtaguid module can't track stats
accurately: the totals don't add up.
With "clat" having an ip address, qtaguid will track stats
against it, which then can be deducted from the external iface.

Bug: 11687690
Change-Id: I22ebf26dd9249e821da87665d2bfb0e54d3cdf64
diff --git a/clatd.c b/clatd.c
index 063026d..26ecb57 100644
--- a/clatd.c
+++ b/clatd.c
@@ -205,6 +205,13 @@
     exit(1);
   }
 
+  status = add_address(tunnel->device6, AF_INET6, &Global_Clatd_Config.ipv6_local_address,
+      64, NULL);
+  if(status < 0) {
+    logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_address(6) failed: %s",strerror(-status));
+    exit(1);
+  }
+
   if((status = if_up(tunnel->device6, Global_Clatd_Config.mtu)) < 0) {
     logmsg(ANDROID_LOG_FATAL,"configure_tun_ip/if_up(6) failed: %s",strerror(-status));
     exit(1);
@@ -470,7 +477,7 @@
   // open the tunnel device before dropping privs
   tunnel.fd6 = tun_open();
   if(tunnel.fd6 < 0) {
-    logmsg(ANDROID_LOG_FATAL, "tun_open failed: %s", strerror(errno));
+    logmsg(ANDROID_LOG_FATAL, "tun_open6 failed: %s", strerror(errno));
     exit(1);
   }
 
diff --git a/clatd.conf b/clatd.conf
index 086d39a..578da59 100644
--- a/clatd.conf
+++ b/clatd.conf
@@ -5,6 +5,9 @@
 # ipv4 subnet for the local traffic to use.  This is a /32 host address
 ipv4_local_subnet 192.0.0.4
 
+# ipv6 extra link local address for the ip6 iface.
+ipv6_local_address fe80::c000:0004
+
 # get the plat_subnet from dns lookups (requires DNS64)
 plat_from_dns64 yes
 # hostname to use to lookup plat subnet. must contain only A records
diff --git a/config.c b/config.c
index e7ec80e..61a4ebb 100644
--- a/config.c
+++ b/config.c
@@ -255,6 +255,9 @@
   if(!config_item_ip(root, "ipv4_local_subnet", DEFAULT_IPV4_LOCAL_SUBNET, &Global_Clatd_Config.ipv4_local_subnet))
     goto failed;
 
+  if(!config_item_ip6(root, "ipv6_local_address", DEFAULT_IPV6_LOCAL_ADDRESS, &Global_Clatd_Config.ipv6_local_address))
+    goto failed;
+
   if(plat_prefix) { // plat subnet is coming from the command line
     if(inet_pton(AF_INET6, plat_prefix, &Global_Clatd_Config.plat_subnet) <= 0) {
       logmsg(ANDROID_LOG_FATAL,"invalid IPv6 address specified for plat prefix: %s", plat_prefix);
@@ -295,6 +298,7 @@
 
   logmsg(ANDROID_LOG_DEBUG,"mtu = %d",Global_Clatd_Config.mtu);
   logmsg(ANDROID_LOG_DEBUG,"ipv4mtu = %d",Global_Clatd_Config.ipv4mtu);
+  logmsg(ANDROID_LOG_DEBUG,"ipv6_local_address = %s",inet_ntop(AF_INET6, &Global_Clatd_Config.ipv6_local_address, charbuffer, sizeof(charbuffer)));
   logmsg(ANDROID_LOG_DEBUG,"ipv6_local_subnet = %s",inet_ntop(AF_INET6, &Global_Clatd_Config.ipv6_local_subnet, charbuffer, sizeof(charbuffer)));
   logmsg(ANDROID_LOG_DEBUG,"ipv4_local_subnet = %s",inet_ntop(AF_INET, &Global_Clatd_Config.ipv4_local_subnet, charbuffer, sizeof(charbuffer)));
   logmsg(ANDROID_LOG_DEBUG,"plat_subnet = %s",inet_ntop(AF_INET6, &Global_Clatd_Config.plat_subnet, charbuffer, sizeof(charbuffer)));
diff --git a/config.h b/config.h
index a83cbec..18760c3 100644
--- a/config.h
+++ b/config.h
@@ -22,10 +22,13 @@
 #include <sys/system_properties.h>
 
 #define DEFAULT_IPV4_LOCAL_SUBNET "192.168.255.1"
+#define DEFAULT_IPV6_LOCAL_ADDRESS "fe80::c000:0004"
+
 #define DEFAULT_DNS64_DETECTION_HOSTNAME "ipv4.google.com"
 
 struct clat_config {
   int16_t mtu, ipv4mtu;
+  struct in6_addr ipv6_local_address;
   struct in6_addr ipv6_local_subnet;
   struct in6_addr ipv6_host_id;
   struct in_addr ipv4_local_subnet;