clatd: move send_dad out of event_loop() into main()

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id74ad4adf861182d928676213c77a24675c358a4
diff --git a/clatd/clatd.c b/clatd/clatd.c
index bac8b1d..9ac1663 100644
--- a/clatd/clatd.c
+++ b/clatd/clatd.c
@@ -273,17 +273,6 @@
  *   tunnel - tun device data
  */
 void event_loop(struct tun_data *tunnel) {
-  // Apparently some network gear will refuse to perform NS for IPs that aren't DAD'ed,
-  // this would then result in an ipv6-only network with working native ipv6, working
-  // IPv4 via DNS64, but non-functioning IPv4 via CLAT (ie. IPv4 literals + IPv4 only apps).
-  // The kernel itself doesn't do DAD for anycast ips (but does handle IPV6 MLD and handle ND).
-  // So we'll spoof dad here, and yeah, we really should check for a response and in
-  // case of failure pick a different IP.  Seeing as 48-bits of the IP are utterly random
-  // (with the other 16 chosen to guarantee checksum neutrality) this seems like a remote
-  // concern...
-  // TODO: actually perform true DAD
-  send_dad(tunnel->write_fd6, &Global_Clatd_Config.ipv6_local_subnet);
-
   struct pollfd wait_fd[] = {
     { tunnel->read_fd6, POLLIN, 0 },
     { tunnel->fd4, POLLIN, 0 },
diff --git a/clatd/clatd.h b/clatd/clatd.h
index e170c58..5b2b2e6 100644
--- a/clatd/clatd.h
+++ b/clatd/clatd.h
@@ -54,6 +54,8 @@
 
 extern volatile sig_atomic_t running;
 
+void send_dad(int fd, const struct in6_addr* tgt);
+
 void event_loop(struct tun_data *tunnel);
 
 /* function: parse_int
diff --git a/clatd/main.c b/clatd/main.c
index e9bfe43..11067de 100644
--- a/clatd/main.c
+++ b/clatd/main.c
@@ -188,6 +188,17 @@
     exit(1);
   }
 
+  // Apparently some network gear will refuse to perform NS for IPs that aren't DAD'ed,
+  // this would then result in an ipv6-only network with working native ipv6, working
+  // IPv4 via DNS64, but non-functioning IPv4 via CLAT (ie. IPv4 literals + IPv4 only apps).
+  // The kernel itself doesn't do DAD for anycast ips (but does handle IPV6 MLD and handle ND).
+  // So we'll spoof dad here, and yeah, we really should check for a response and in
+  // case of failure pick a different IP.  Seeing as 48-bits of the IP are utterly random
+  // (with the other 16 chosen to guarantee checksum neutrality) this seems like a remote
+  // concern...
+  // TODO: actually perform true DAD
+  send_dad(tunnel.write_fd6, &Global_Clatd_Config.ipv6_local_subnet);
+
   event_loop(&tunnel);
 
   logmsg(ANDROID_LOG_INFO, "Shutting down clat on %s", uplink_interface);