Declare pos as clat_packet_index instead of int

Bug: 11542311
Change-Id: Id5771c9685286b70a8ad283c259c7f83662e8b76
diff --git a/ipv4.c b/ipv4.c
index 2695a86..4b0db39 100644
--- a/ipv4.c
+++ b/ipv4.c
@@ -31,8 +31,8 @@
  * len      - size of ip payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int icmp_packet(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t checksum,
-                size_t len) {
+int icmp_packet(clat_packet out, clat_packet_index pos, const struct icmphdr *icmp,
+                uint32_t checksum, size_t len) {
   const uint8_t *payload;
   size_t payload_size;
 
@@ -54,7 +54,7 @@
  * len    - size of packet
  * returns: the highest position in the output clat_packet that's filled in
  */
-int ipv4_packet(clat_packet out, int pos, const uint8_t *packet, size_t len) {
+int ipv4_packet(clat_packet out, clat_packet_index pos, const uint8_t *packet, size_t len) {
   const struct iphdr *header = (struct iphdr *) packet;
   struct ip6_hdr *ip6_targ = (struct ip6_hdr *) out[pos].iov_base;
   struct ip6_frag *frag_hdr;
diff --git a/ipv6.c b/ipv6.c
index d519e1b..b485313 100644
--- a/ipv6.c
+++ b/ipv6.c
@@ -34,7 +34,8 @@
  * len      - size of ip payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int icmp6_packet(clat_packet out, int pos, const struct icmp6_hdr *icmp6, size_t len) {
+int icmp6_packet(clat_packet out, clat_packet_index pos, const struct icmp6_hdr *icmp6,
+                 size_t len) {
   const uint8_t *payload;
   size_t payload_size;
 
@@ -74,7 +75,7 @@
  * len    - size of packet
  * returns: the highest position in the output clat_packet that's filled in
  */
-int ipv6_packet(clat_packet out, int pos, const uint8_t *packet, size_t len) {
+int ipv6_packet(clat_packet out, clat_packet_index pos, const uint8_t *packet, size_t len) {
   const struct ip6_hdr *ip6 = (struct ip6_hdr *) packet;
   struct iphdr *ip_targ = (struct iphdr *) out[pos].iov_base;
   struct ip6_frag *frag_hdr = NULL;
diff --git a/translate.c b/translate.c
index b357057..e93a93a 100644
--- a/translate.c
+++ b/translate.c
@@ -33,7 +33,7 @@
  * pos      - position to start counting from
  * returns  - the completed 16-bit checksum, ready to write into a checksum header field
  */
-uint16_t packet_checksum(uint32_t checksum, clat_packet packet, int pos) {
+uint16_t packet_checksum(uint32_t checksum, clat_packet packet, clat_packet_index pos) {
   int i;
   for (i = pos; i < CLAT_POS_MAX; i++) {
     if (packet[i].iov_len > 0) {
@@ -49,7 +49,7 @@
  * pos    - position to start counting after
  * returns: the total length of the packet components after pos
  */
-uint16_t packet_length(clat_packet packet, int pos) {
+uint16_t packet_length(clat_packet packet, clat_packet_index pos) {
   size_t len = 0;
   int i;
   for (i = pos + 1; i < CLAT_POS_MAX; i++) {
@@ -224,8 +224,8 @@
  * payload_size - size of payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t checksum,
-                  const uint8_t *payload, size_t payload_size) {
+int icmp_to_icmp6(clat_packet out, clat_packet_index pos, const struct icmphdr *icmp,
+                  uint32_t checksum, const uint8_t *payload, size_t payload_size) {
   struct icmp6_hdr *icmp6_targ = out[pos].iov_base;
   uint8_t icmp6_type;
   int clat_packet_len;
@@ -278,7 +278,7 @@
  * payload_size - size of payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6,
+int icmp6_to_icmp(clat_packet out, clat_packet_index pos, const struct icmp6_hdr *icmp6,
                   const uint8_t *payload, size_t payload_size) {
   struct icmphdr *icmp_targ = out[pos].iov_base;
   uint8_t icmp_type;
@@ -324,8 +324,7 @@
  * len      - size of ip payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int generic_packet(clat_packet out, int pos,
-                   const uint8_t *payload, size_t len) {
+int generic_packet(clat_packet out, clat_packet_index pos, const uint8_t *payload, size_t len) {
   out[pos].iov_len = 0;
   out[CLAT_POS_PAYLOAD].iov_base = (uint8_t *) payload;
   out[CLAT_POS_PAYLOAD].iov_len = len;
@@ -341,7 +340,7 @@
  * new_sum  - pseudo-header checksum of new header
  * len      - size of ip payload
  */
-int udp_packet(clat_packet out, int pos, const struct udphdr *udp,
+int udp_packet(clat_packet out, clat_packet_index pos, const struct udphdr *udp,
                uint32_t old_sum, uint32_t new_sum, size_t len) {
   const uint8_t *payload;
   size_t payload_size;
@@ -365,7 +364,7 @@
  * len      - size of ip payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp,
+int tcp_packet(clat_packet out, clat_packet_index pos, const struct tcphdr *tcp,
                uint32_t old_sum, uint32_t new_sum, size_t len) {
   const uint8_t *payload;
   size_t payload_size, header_size;
@@ -402,9 +401,8 @@
  * payload_size - size of payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int udp_translate(clat_packet out, int pos, const struct udphdr *udp,
-                  uint32_t old_sum, uint32_t new_sum,
-                  const uint8_t *payload, size_t payload_size) {
+int udp_translate(clat_packet out, clat_packet_index pos, const struct udphdr *udp,
+                  uint32_t old_sum, uint32_t new_sum, const uint8_t *payload, size_t payload_size) {
   struct udphdr *udp_targ = out[pos].iov_base;
 
   memcpy(udp_targ, udp, sizeof(struct udphdr));
@@ -443,8 +441,8 @@
  * payload_size - size of payload
  * returns: the highest position in the output clat_packet that's filled in
  */
-int tcp_translate(clat_packet out, int pos, const struct tcphdr *tcp, size_t header_size,
-                  uint32_t old_sum, uint32_t new_sum,
+int tcp_translate(clat_packet out, clat_packet_index pos, const struct tcphdr *tcp,
+                  size_t header_size, uint32_t old_sum, uint32_t new_sum,
                   const uint8_t *payload, size_t payload_size) {
   struct tcphdr *tcp_targ = out[pos].iov_base;
   out[pos].iov_len = header_size;
diff --git a/translate.h b/translate.h
index ab20a55..421d2a5 100644
--- a/translate.h
+++ b/translate.h
@@ -36,18 +36,18 @@
 // 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.
-enum clat_packet_index {
+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, int pos);
+uint16_t packet_checksum(uint32_t checksum, clat_packet packet, clat_packet_index pos);
 
 // Returns the total length of the packet components after pos.
-uint16_t packet_length(clat_packet packet, int pos);
+uint16_t packet_length(clat_packet packet, clat_packet_index pos);
 
 // Returns true iff the given IPv6 address is in the plat subnet.
 int is_in_plat_subnet(const struct in6_addr *addr6);
@@ -64,8 +64,8 @@
                       const uint8_t *packet, size_t packetsize);
 
 // Translate IPv4 and IPv6 packets.
-int ipv4_packet(clat_packet out, int pos, const uint8_t *packet, size_t len);
-int ipv6_packet(clat_packet out, int pos, const uint8_t *packet, size_t len);
+int ipv4_packet(clat_packet out, clat_packet_index pos, const uint8_t *packet, size_t len);
+int ipv6_packet(clat_packet out, clat_packet_index pos, const uint8_t *packet, size_t len);
 
 // Deal with fragmented packets.
 size_t maybe_fill_frag_header(struct ip6_frag *frag_hdr, struct ip6_hdr *ip6_targ,
@@ -73,25 +73,24 @@
 uint8_t parse_frag_header(const struct ip6_frag *frag_hdr, struct iphdr *ip_targ);
 
 // Translate ICMP packets.
-int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t checksum,
-                  const uint8_t *payload, size_t payload_size);
-int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6,
+int icmp_to_icmp6(clat_packet out, clat_packet_index pos, const struct icmphdr *icmp,
+                  uint32_t checksum, const uint8_t *payload, size_t payload_size);
+int icmp6_to_icmp(clat_packet out, clat_packet_index pos, const struct icmp6_hdr *icmp6,
                   const uint8_t *payload, size_t payload_size);
 
 // Translate generic IP packets.
-int generic_packet(clat_packet out, int pos,
-                   const uint8_t *payload, size_t len);
+int generic_packet(clat_packet out, clat_packet_index pos, const uint8_t *payload, size_t len);
 
 // Translate TCP and UDP packets.
-int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp,
+int tcp_packet(clat_packet out, clat_packet_index pos, const struct tcphdr *tcp,
                uint32_t old_sum, uint32_t new_sum, size_t len);
-int udp_packet(clat_packet out, int pos, const struct udphdr *udp,
+int udp_packet(clat_packet out, clat_packet_index pos, const struct udphdr *udp,
                uint32_t old_sum, uint32_t new_sum, size_t len);
 
-int tcp_translate(clat_packet out, int pos, const struct tcphdr *tcp, size_t header_size,
-                  uint32_t old_sum, uint32_t new_sum,
+int tcp_translate(clat_packet out, clat_packet_index pos, const struct tcphdr *tcp,
+                  size_t header_size, uint32_t old_sum, uint32_t new_sum,
                   const uint8_t *payload, size_t payload_size);
-int udp_translate(clat_packet out, int pos, const struct udphdr *udp,
+int udp_translate(clat_packet out, clat_packet_index pos, const struct udphdr *udp,
                   uint32_t old_sum, uint32_t new_sum,
                   const uint8_t *payload, size_t payload_size);