Move send_tun into tun.c as well.

Also remove a redundant include in checksum.c.

Change-Id: I0b8858343b1496f22904d3b316b6c435be0f648a
diff --git a/Android.mk b/Android.mk
index 819c86f..bdb9317 100644
--- a/Android.mk
+++ b/Android.mk
@@ -30,7 +30,7 @@
 
 LOCAL_MODULE := clatd_test
 LOCAL_CFLAGS := -Wall -Werror -Wunused-parameter
-LOCAL_SRC_FILES := clatd_test.cpp dump.c checksum.c translate.c icmp.c ipv4.c ipv6.c logging.c
+LOCAL_SRC_FILES := clatd_test.cpp dump.c checksum.c translate.c icmp.c ipv4.c ipv6.c logging.c tun.c
 LOCAL_MODULE_TAGS := eng tests
 LOCAL_SHARED_LIBRARIES := liblog
 
diff --git a/checksum.c b/checksum.c
index 3dd1e00..23a7c02 100644
--- a/checksum.c
+++ b/checksum.c
@@ -22,7 +22,6 @@
 #include <netinet/tcp.h>
 #include <netinet/ip6.h>
 #include <netinet/icmp6.h>
-#include <linux/icmp.h>
 
 #include "checksum.h"
 
diff --git a/clatd.h b/clatd.h
index 6368a09..ca7ad74 100644
--- a/clatd.h
+++ b/clatd.h
@@ -18,6 +18,8 @@
 #ifndef __CLATD_H__
 #define __CLATD_H__
 
+#include <sys/uio.h>
+
 #define MAXMTU 1500
 #define PACKETLEN (MAXMTU+sizeof(struct tun_pi))
 #define CLATD_VERSION "1.3"
@@ -30,4 +32,15 @@
 // how frequently (in seconds) to poll for an address change while there is no traffic
 #define NO_TRAFFIC_INTERFACE_POLL_FREQUENCY 90
 
+// A clat_packet is an array of iovec structures representing a packet that we are translating.
+// The CLAT_POS_XXX constants represent the array indices within the clat_packet that contain
+// specific parts of the packet. The packet_* functions operate on all the packet segments past a
+// given position.
+typedef enum {
+    CLAT_POS_TUNHDR, CLAT_POS_IPHDR, CLAT_POS_FRAGHDR, CLAT_POS_TRANSPORTHDR,
+    CLAT_POS_ICMPERR_IPHDR, CLAT_POS_ICMPERR_FRAGHDR, CLAT_POS_ICMPERR_TRANSPORTHDR,
+    CLAT_POS_PAYLOAD, CLAT_POS_MAX
+} clat_packet_index;
+typedef struct iovec clat_packet[CLAT_POS_MAX];
+
 #endif /* __CLATD_H__ */
diff --git a/translate.c b/translate.c
index 487468b..ddc9bac 100644
--- a/translate.c
+++ b/translate.c
@@ -16,7 +16,6 @@
  * translate.c - CLAT functions / partial implementation of rfc6145
  */
 #include <string.h>
-#include <sys/uio.h>
 
 #include "icmp.h"
 #include "translate.h"
@@ -25,6 +24,7 @@
 #include "config.h"
 #include "logging.h"
 #include "debug.h"
+#include "tun.h"
 
 /* function: packet_checksum
  * calculates the checksum over all the packet components starting from pos
@@ -465,10 +465,6 @@
   return CLAT_POS_PAYLOAD + 1;
 }
 
-void send_tun(int fd, clat_packet out, int iov_len) {
-  writev(fd, out, iov_len);
-}
-
 // Weak symbol so we can override it in the unit test.
 void send_rawv6(int fd, clat_packet out, int iov_len) __attribute__((weak));
 
diff --git a/translate.h b/translate.h
index 46e178b..aa8b736 100644
--- a/translate.h
+++ b/translate.h
@@ -32,17 +32,6 @@
 
 #define MAX_TCP_HDR (15 * 4)   // Data offset field is 4 bits and counts in 32-bit words.
 
-// A clat_packet is an array of iovec structures representing a packet that we are translating.
-// The CLAT_POS_XXX constants represent the array indices within the clat_packet that contain
-// specific parts of the packet. The packet_* functions operate on all the packet segments past a
-// given position.
-typedef enum {
-    CLAT_POS_TUNHDR, CLAT_POS_IPHDR, CLAT_POS_FRAGHDR, CLAT_POS_TRANSPORTHDR,
-    CLAT_POS_ICMPERR_IPHDR, CLAT_POS_ICMPERR_FRAGHDR, CLAT_POS_ICMPERR_TRANSPORTHDR,
-    CLAT_POS_PAYLOAD, CLAT_POS_MAX
-} clat_packet_index;
-typedef struct iovec clat_packet[CLAT_POS_MAX];
-
 // Calculates the checksum over all the packet components starting from pos.
 uint16_t packet_checksum(uint32_t checksum, clat_packet packet, clat_packet_index pos);
 
diff --git a/tun.c b/tun.c
index ef6b111..a1b7254 100644
--- a/tun.c
+++ b/tun.c
@@ -22,6 +22,9 @@
 #include <linux/if.h>
 #include <linux/if_tun.h>
 #include <sys/ioctl.h>
+#include <sys/uio.h>
+
+#include "clatd.h"
 
 /* function: tun_open
  * tries to open the tunnel device
@@ -60,3 +63,7 @@
   strcpy(dev, ifr.ifr_name);
   return 0;
 }
+
+void send_tun(int fd, clat_packet out, int iov_len) {
+  writev(fd, out, iov_len);
+}
diff --git a/tun.h b/tun.h
index 9ccb037..771814d 100644
--- a/tun.h
+++ b/tun.h
@@ -18,6 +18,10 @@
 #ifndef __TUN_H__
 #define __TUN_H__
 
+#include <linux/if.h>
+
+#include "clatd.h"
+
 struct tun_data {
   char device4[IFNAMSIZ];
   int read_fd6, write_fd6, fd4;
@@ -26,5 +30,6 @@
 int set_nonblocking(int fd);
 int tun_open();
 int tun_alloc(char *dev, int fd);
+void send_tun(int fd, clat_packet out, int iov_len);
 
 #endif