diff options
author | Brian Carlstrom <bdc@google.com> | 2014-02-24 20:03:01 -0800 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2014-02-24 21:14:51 -0800 |
commit | fcac410fa15613873a07143ccd46470b869346a3 (patch) | |
tree | a76ca896fc7cb5801acf16edfcfd7f3bb6962014 | |
parent | f3beefc96a5a4f295562f60d648bd6e795980a10 (diff) | |
download | platform_external_android-clat-fcac410fa15613873a07143ccd46470b869346a3.tar.gz platform_external_android-clat-fcac410fa15613873a07143ccd46470b869346a3.tar.bz2 platform_external_android-clat-fcac410fa15613873a07143ccd46470b869346a3.zip |
Use uint8_t not char for binary data to avoid -Wall -Werror issues on x86 builds
Change-Id: Ib61e67f15360c27c3ebf61f870a9482217c52357
-rw-r--r-- | clatd.c | 2 | ||||
-rw-r--r-- | clatd_test.cpp | 102 | ||||
-rw-r--r-- | dump.c | 21 | ||||
-rw-r--r-- | dump.h | 16 | ||||
-rw-r--r-- | ipv4.c | 8 | ||||
-rw-r--r-- | ipv6.c | 8 | ||||
-rw-r--r-- | translate.c | 37 | ||||
-rw-r--r-- | translate.h | 21 |
8 files changed, 117 insertions, 98 deletions
@@ -302,7 +302,7 @@ void configure_interface(const char *uplink_interface, const char *plat_prefix, */ void read_packet(int active_fd, const struct tun_data *tunnel) { ssize_t readlen; - char packet[PACKETLEN]; + uint8_t packet[PACKETLEN]; // in case something ignores the packet length memset(packet, 0, PACKETLEN); diff --git a/clatd_test.cpp b/clatd_test.cpp index b70f9af..ba78898 100644 --- a/clatd_test.cpp +++ b/clatd_test.cpp @@ -101,28 +101,28 @@ static const char kIPv6PlatSubnet[] = "64:ff9b::"; 0, 0, 0, (protocol), // A fragmented DNS request. -static const char kIPv4Frag1[] = { +static const uint8_t kIPv4Frag1[] = { 0x45, 0x00, 0x00, 0x24, 0xfe, 0x47, 0x20, 0x00, 0x40, 0x11, 0x8c, 0x6d, 0xc0, 0x00, 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x14, 0x5d, 0x00, 0x35, 0x00, 0x29, 0x68, 0xbb, 0x50, 0x47, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00 }; -static const char kIPv4Frag2[] = { +static const uint8_t kIPv4Frag2[] = { 0x45, 0x00, 0x00, 0x24, 0xfe, 0x47, 0x20, 0x02, 0x40, 0x11, 0x8c, 0x6b, 0xc0, 0x00, 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x04, 0x69, 0x70, 0x76, 0x34, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65 }; -static const char kIPv4Frag3[] = { +static const uint8_t kIPv4Frag3[] = { 0x45, 0x00, 0x00, 0x1d, 0xfe, 0x47, 0x00, 0x04, 0x40, 0x11, 0xac, 0x70, 0xc0, 0x00, 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 }; -static const char *kIPv4Fragments[] = { kIPv4Frag1, kIPv4Frag2, kIPv4Frag3 }; -static const int kIPv4FragLengths[] = { sizeof(kIPv4Frag1), sizeof(kIPv4Frag2), - sizeof(kIPv4Frag3) }; +static const uint8_t *kIPv4Fragments[] = { kIPv4Frag1, kIPv4Frag2, kIPv4Frag3 }; +static const size_t kIPv4FragLengths[] = { sizeof(kIPv4Frag1), sizeof(kIPv4Frag2), + sizeof(kIPv4Frag3) }; -static const char kIPv6Frag1[] = { +static const uint8_t kIPv6Frag1[] = { 0x60, 0x00, 0x00, 0x00, 0x00, 0x18, 0x2c, 0x40, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x0b, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x64, 0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, @@ -132,7 +132,7 @@ static const char kIPv6Frag1[] = { 0x00, 0x01, 0x00, 0x00 }; -static const char kIPv6Frag2[] = { +static const uint8_t kIPv6Frag2[] = { 0x60, 0x00, 0x00, 0x00, 0x00, 0x18, 0x2c, 0x40, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x0b, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x64, 0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, @@ -142,7 +142,7 @@ static const char kIPv6Frag2[] = { 0x6f, 0x67, 0x6c, 0x65 }; -static const char kIPv6Frag3[] = { +static const uint8_t kIPv6Frag3[] = { 0x60, 0x00, 0x00, 0x00, 0x00, 0x11, 0x2c, 0x40, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x0b, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x64, 0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, @@ -150,11 +150,11 @@ static const char kIPv6Frag3[] = { 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0xfe, 0x47, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 }; -static const char *kIPv6Fragments[] = { kIPv6Frag1, kIPv6Frag2, kIPv6Frag3 }; -static const int kIPv6FragLengths[] = { sizeof(kIPv6Frag1), sizeof(kIPv6Frag2), - sizeof(kIPv6Frag3) }; +static const uint8_t *kIPv6Fragments[] = { kIPv6Frag1, kIPv6Frag2, kIPv6Frag3 }; +static const size_t kIPv6FragLengths[] = { sizeof(kIPv6Frag1), sizeof(kIPv6Frag2), + sizeof(kIPv6Frag3) }; -static const char kReassembledIPv4[] = { +static const uint8_t kReassembledIPv4[] = { 0x45, 0x00, 0x00, 0x3d, 0xfe, 0x47, 0x00, 0x00, 0x40, 0x11, 0xac, 0x54, 0xc0, 0x00, 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x14, 0x5d, 0x00, 0x35, 0x00, 0x29, 0x68, 0xbb, 0x50, 0x47, @@ -170,8 +170,8 @@ static const uint32_t kPayloadPartialChecksum = 0x31e9c; static const uint16_t kUdpV4Checksum = 0xd0c7; static const uint16_t kUdpV6Checksum = 0xa74a; -int ip_version(const char *packet) { - int version = packet[0] >> 4; +uint8_t ip_version(const uint8_t *packet) { + uint8_t version = packet[0] >> 4; return version; } @@ -197,7 +197,7 @@ int ipv6_fragment_offset(struct ip6_frag *frag) { return ntohs((frag->ip6f_offlg & IP6F_OFF_MASK) >> 3); } -void check_packet(const char *packet, size_t len, const char *msg) { +void check_packet(const uint8_t *packet, size_t len, const char *msg) { void *payload; size_t payload_length = 0; uint32_t pseudo_checksum = 0; @@ -282,16 +282,16 @@ void check_packet(const char *packet, size_t len, const char *msg) { } } -void reassemble_packet(const char **fragments, const int lengths[], int numpackets, - char *reassembled, size_t *reassembled_len, const char *msg) { +void reassemble_packet(const uint8_t **fragments, const size_t lengths[], int numpackets, + uint8_t *reassembled, size_t *reassembled_len, const char *msg) { struct iphdr *ip = NULL; struct ip6_hdr *ip6 = NULL; int total_length, pos = 0; uint8_t protocol; - int version = ip_version(fragments[0]); + uint8_t version = ip_version(fragments[0]); for (int i = 0; i < numpackets; i++) { - const char *packet = fragments[i]; + const uint8_t *packet = fragments[i]; int len = lengths[i]; int headersize, payload_offset; @@ -370,7 +370,7 @@ void reassemble_packet(const char **fragments, const int lengths[], int numpacke *reassembled_len = total_length; } -void check_data_matches(const char *expected, const char *actual, size_t len, const char *msg) { +void check_data_matches(const uint8_t *expected, const uint8_t *actual, size_t len, const char *msg) { if (memcmp(expected, actual, len)) { // Hex dump, 20 bytes per line, one space between bytes (1 byte = 3 chars), indented by 4. int hexdump_len = len * 3 + (len / 20 + 1) * 5; @@ -392,9 +392,9 @@ void check_data_matches(const char *expected, const char *actual, size_t len, co } } -void fix_udp_checksum(char* packet) { +void fix_udp_checksum(uint8_t* packet) { uint32_t pseudo_checksum; - int version = ip_version(packet); + uint8_t version = ip_version(packet); struct udphdr *udp; switch (version) { case 4: { @@ -418,7 +418,7 @@ void fix_udp_checksum(char* packet) { udp->check = ip_checksum_finish(ip_checksum_add(pseudo_checksum, udp, ntohs(udp->len))); } -void do_translate_packet(const char *original, size_t original_len, char *out, size_t *outlen, +void do_translate_packet(const uint8_t *original, size_t original_len, uint8_t *out, size_t *outlen, const char *msg) { int fds[2]; if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, fds)) { @@ -471,17 +471,17 @@ void do_translate_packet(const char *original, size_t original_len, char *out, s } } -void check_translated_packet(const char *original, size_t original_len, - const char *expected, size_t expected_len, const char *msg) { - char translated[MAXMTU]; +void check_translated_packet(const uint8_t *original, size_t original_len, + const uint8_t *expected, size_t expected_len, const char *msg) { + uint8_t translated[MAXMTU]; size_t translated_len = sizeof(translated); do_translate_packet(original, original_len, translated, &translated_len, msg); EXPECT_EQ(expected_len, translated_len) << msg << ": Translated packet length incorrect\n"; check_data_matches(expected, translated, translated_len, msg); } -void check_fragment_translation(const char *original[], const int original_lengths[], - const char *expected[], const int expected_lengths[], +void check_fragment_translation(const uint8_t *original[], const size_t original_lengths[], + const uint8_t *expected[], const size_t expected_lengths[], int numfragments, const char *msg) { for (int i = 0; i < numfragments; i++) { // Check that each of the fragments translates as expected. @@ -492,12 +492,12 @@ void check_fragment_translation(const char *original[], const int original_lengt } // Sanity check that reassembling the original and translated fragments produces valid packets. - char reassembled[MAXMTU]; + uint8_t reassembled[MAXMTU]; size_t reassembled_len = sizeof(reassembled); reassemble_packet(original, original_lengths, numfragments, reassembled, &reassembled_len, msg); check_packet(reassembled, reassembled_len, msg); - char translated[MAXMTU]; + uint8_t translated[MAXMTU]; size_t translated_len = sizeof(translated); do_translate_packet(reassembled, reassembled_len, translated, &translated_len, msg); check_packet(translated, translated_len, msg); @@ -516,37 +516,37 @@ class ClatdTest : public ::testing::Test { TEST_F(ClatdTest, Sanitycheck) { // Sanity checks the data. - char v4_header[] = { IPV4_UDP_HEADER }; + uint8_t v4_header[] = { IPV4_UDP_HEADER }; ASSERT_EQ(sizeof(struct iphdr), sizeof(v4_header)) << "Test IPv4 header: incorrect length\n"; - char v6_header[] = { IPV6_UDP_HEADER }; + uint8_t v6_header[] = { IPV6_UDP_HEADER }; ASSERT_EQ(sizeof(struct ip6_hdr), sizeof(v6_header)) << "Test IPv6 header: incorrect length\n"; - char udp_header[] = { UDP_HEADER }; + uint8_t udp_header[] = { UDP_HEADER }; ASSERT_EQ(sizeof(struct udphdr), sizeof(udp_header)) << "Test UDP header: incorrect length\n"; // Sanity checks check_packet. struct udphdr *udp; - char v4_udp_packet[] = { IPV4_UDP_HEADER UDP_HEADER PAYLOAD }; + uint8_t v4_udp_packet[] = { IPV4_UDP_HEADER UDP_HEADER PAYLOAD }; udp = (struct udphdr *) (v4_udp_packet + sizeof(struct iphdr)); fix_udp_checksum(v4_udp_packet); ASSERT_EQ(kUdpV4Checksum, udp->check) << "UDP/IPv4 packet checksum sanity check\n"; check_packet(v4_udp_packet, sizeof(v4_udp_packet), "UDP/IPv4 packet sanity check"); - char v6_udp_packet[] = { IPV6_UDP_HEADER UDP_HEADER PAYLOAD }; + uint8_t v6_udp_packet[] = { IPV6_UDP_HEADER UDP_HEADER PAYLOAD }; udp = (struct udphdr *) (v6_udp_packet + sizeof(struct ip6_hdr)); fix_udp_checksum(v6_udp_packet); ASSERT_EQ(kUdpV6Checksum, udp->check) << "UDP/IPv6 packet checksum sanity check\n"; check_packet(v6_udp_packet, sizeof(v6_udp_packet), "UDP/IPv6 packet sanity check"); - char ipv4_ping[] = { IPV4_ICMP_HEADER IPV4_PING PAYLOAD }; + uint8_t ipv4_ping[] = { IPV4_ICMP_HEADER IPV4_PING PAYLOAD }; check_packet(ipv4_ping, sizeof(ipv4_ping), "IPv4 ping sanity check"); - char ipv6_ping[] = { IPV6_ICMPV6_HEADER IPV6_PING PAYLOAD }; + uint8_t ipv6_ping[] = { IPV6_ICMPV6_HEADER IPV6_PING PAYLOAD }; check_packet(ipv6_ping, sizeof(ipv6_ping), "IPv6 ping sanity check"); // Sanity checks reassemble_packet. - char reassembled[MAXMTU]; + uint8_t reassembled[MAXMTU]; size_t total_length = sizeof(reassembled); reassemble_packet(kIPv4Fragments, kIPv4FragLengths, ARRAYSIZE(kIPv4Fragments), reassembled, &total_length, "Reassembly sanity check"); @@ -567,15 +567,15 @@ TEST_F(ClatdTest, Sanitycheck) { TEST_F(ClatdTest, PseudoChecksum) { uint32_t pseudo_checksum; - char v4_header[] = { IPV4_UDP_HEADER }; - char v4_pseudo_header[] = { IPV4_PSEUDOHEADER(v4_header, UDP_LEN) }; + uint8_t v4_header[] = { IPV4_UDP_HEADER }; + uint8_t v4_pseudo_header[] = { IPV4_PSEUDOHEADER(v4_header, UDP_LEN) }; pseudo_checksum = ipv4_pseudo_header_checksum((struct iphdr *) v4_header, UDP_LEN); EXPECT_EQ(ip_checksum_finish(pseudo_checksum), ip_checksum(v4_pseudo_header, sizeof(v4_pseudo_header))) << "ipv4_pseudo_header_checksum incorrect\n"; - char v6_header[] = { IPV6_UDP_HEADER }; - char v6_pseudo_header[] = { IPV6_PSEUDOHEADER(v6_header, IPPROTO_UDP, UDP_LEN) }; + uint8_t v6_header[] = { IPV6_UDP_HEADER }; + uint8_t v6_pseudo_header[] = { IPV6_PSEUDOHEADER(v6_header, IPPROTO_UDP, UDP_LEN) }; pseudo_checksum = ipv6_pseudo_header_checksum((struct ip6_hdr *) v6_header, UDP_LEN, IPPROTO_UDP); EXPECT_EQ(ip_checksum_finish(pseudo_checksum), ip_checksum(v6_pseudo_header, sizeof(v6_pseudo_header))) @@ -583,15 +583,15 @@ TEST_F(ClatdTest, PseudoChecksum) { } TEST_F(ClatdTest, TransportChecksum) { - char udphdr[] = { UDP_HEADER }; - char payload[] = { PAYLOAD }; + uint8_t udphdr[] = { UDP_HEADER }; + uint8_t payload[] = { PAYLOAD }; EXPECT_EQ(kUdpPartialChecksum, ip_checksum_add(0, udphdr, sizeof(udphdr))) << "UDP partial checksum\n"; EXPECT_EQ(kPayloadPartialChecksum, ip_checksum_add(0, payload, sizeof(payload))) << "Payload partial checksum\n"; - char ip[] = { IPV4_UDP_HEADER }; - char ip6[] = { IPV6_UDP_HEADER }; + uint8_t ip[] = { IPV4_UDP_HEADER }; + uint8_t ip6[] = { IPV6_UDP_HEADER }; uint32_t ipv4_pseudo_sum = ipv4_pseudo_header_checksum((struct iphdr *) ip, UDP_LEN); uint32_t ipv6_pseudo_sum = ipv6_pseudo_header_checksum((struct ip6_hdr *) ip6, UDP_LEN, IPPROTO_UDP); @@ -643,8 +643,8 @@ TEST_F(ClatdTest, AdjustChecksum) { } TEST_F(ClatdTest, Translate) { - char udp_ipv4[] = { IPV4_UDP_HEADER UDP_HEADER PAYLOAD }; - char udp_ipv6[] = { IPV6_UDP_HEADER UDP_HEADER PAYLOAD }; + uint8_t udp_ipv4[] = { IPV4_UDP_HEADER UDP_HEADER PAYLOAD }; + uint8_t udp_ipv6[] = { IPV6_UDP_HEADER UDP_HEADER PAYLOAD }; fix_udp_checksum(udp_ipv4); fix_udp_checksum(udp_ipv6); check_translated_packet(udp_ipv4, sizeof(udp_ipv4), udp_ipv6, sizeof(udp_ipv6), @@ -652,8 +652,8 @@ TEST_F(ClatdTest, Translate) { check_translated_packet(udp_ipv6, sizeof(udp_ipv6), udp_ipv4, sizeof(udp_ipv4), "UDP/IPv6 -> UDP/IPv4 translation"); - char ipv4_ping[] = { IPV4_ICMP_HEADER IPV4_PING PAYLOAD }; - char ipv6_ping[] = { IPV6_ICMPV6_HEADER IPV6_PING PAYLOAD }; + uint8_t ipv4_ping[] = { IPV4_ICMP_HEADER IPV4_PING PAYLOAD }; + uint8_t ipv6_ping[] = { IPV6_ICMPV6_HEADER IPV6_PING PAYLOAD }; check_translated_packet(ipv4_ping, sizeof(ipv4_ping), ipv6_ping, sizeof(ipv6_ping), "ICMP->ICMPv6 translation"); check_translated_packet(ipv6_ping, sizeof(ipv6_ping), ipv4_ping, sizeof(ipv4_ping), @@ -130,7 +130,8 @@ void dump_icmp6(struct icmp6_hdr *icmp6) { } /* print udp header */ -void dump_udp_generic(const struct udphdr *udp, uint32_t temp_checksum, const char *payload, size_t payload_size) { +void dump_udp_generic(const struct udphdr *udp, uint32_t temp_checksum, + const uint8_t *payload, size_t payload_size) { uint16_t my_checksum; temp_checksum = ip_checksum_add(temp_checksum, udp, sizeof(struct udphdr)); @@ -145,14 +146,16 @@ void dump_udp_generic(const struct udphdr *udp, uint32_t temp_checksum, const ch } /* print ipv4/udp header */ -void dump_udp(const struct udphdr *udp, const struct iphdr *ip, const char *payload, size_t payload_size) { +void dump_udp(const struct udphdr *udp, const struct iphdr *ip, + const uint8_t *payload, size_t payload_size) { uint32_t temp_checksum; temp_checksum = ipv4_pseudo_header_checksum(ip, sizeof(*udp) + payload_size); dump_udp_generic(udp, temp_checksum, payload, payload_size); } /* print ipv6/udp header */ -void dump_udp6(const struct udphdr *udp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size) { +void dump_udp6(const struct udphdr *udp, const struct ip6_hdr *ip6, + const uint8_t *payload, size_t payload_size) { uint32_t temp_checksum; temp_checksum = ipv6_pseudo_header_checksum(ip6, sizeof(*udp) + payload_size, IPPROTO_UDP); dump_udp_generic(udp, temp_checksum, payload, payload_size); @@ -200,7 +203,9 @@ void dump_tcp_generic(const struct tcphdr *tcp, const char *options, size_t opti } /* print ipv4/tcp header */ -void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, const char *payload, size_t payload_size, const char *options, size_t options_size) { +void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, + const uint8_t *payload, size_t payload_size, + const char *options, size_t options_size) { uint32_t temp_checksum; temp_checksum = ipv4_pseudo_header_checksum(ip, sizeof(*tcp) + options_size + payload_size); @@ -208,7 +213,9 @@ void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, const char *payl } /* print ipv6/tcp header */ -void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size, const char *options, size_t options_size) { +void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, + const uint8_t *payload, size_t payload_size, + const char *options, size_t options_size) { uint32_t temp_checksum; temp_checksum = ipv6_pseudo_header_checksum(ip6, sizeof(*tcp) + options_size + payload_size, IPPROTO_TCP); @@ -216,13 +223,13 @@ void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, const char * } /* generic hex dump */ -void logcat_hexdump(const char *info, const char *data, size_t len) { +void logcat_hexdump(const char *info, const uint8_t *data, size_t len) { char output[PACKETLEN*3+2]; size_t i; output[0] = '\0'; for(i = 0; i < len && i < PACKETLEN; i++) { - snprintf(output + i*3, 4, " %02x", (uint8_t)data[i]); + snprintf(output + i*3, 4, " %02x", data[i]); } output[len*3+3] = '\0'; @@ -20,15 +20,21 @@ void dump_ip(struct iphdr *header); void dump_icmp(struct icmphdr *icmp); -void dump_udp(const struct udphdr *udp, const struct iphdr *ip, const char *payload, size_t payload_size); -void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, const char *payload, size_t payload_size, const char *options, size_t options_size); +void dump_udp(const struct udphdr *udp, const struct iphdr *ip, + const uint8_t *payload, size_t payload_size); +void dump_tcp(const struct tcphdr *tcp, const struct iphdr *ip, + const uint8_t *payload, size_t payload_size, + const char *options, size_t options_size); void dump_ip6(struct ip6_hdr *header); void dump_icmp6(struct icmp6_hdr *icmp6); -void dump_udp6(const struct udphdr *udp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size); -void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size, const char *options, size_t options_size); +void dump_udp6(const struct udphdr *udp, const struct ip6_hdr *ip6, + const uint8_t *payload, size_t payload_size); +void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, + const uint8_t *payload, size_t payload_size, + const char *options, size_t options_size); -void logcat_hexdump(const char *info, const char *data, size_t len); +void logcat_hexdump(const char *info, const uint8_t *data, size_t len); void dump_iovec(const struct iovec *iov, int iov_len); #endif /* __DUMP_H__ */ @@ -33,7 +33,7 @@ */ int icmp_packet(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t checksum, size_t len) { - const char *payload; + const uint8_t *payload; size_t payload_size; if(len < sizeof(struct icmphdr)) { @@ -41,7 +41,7 @@ int icmp_packet(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t c return 0; } - payload = (const char *) (icmp + 1); + payload = (const uint8_t *) (icmp + 1); payload_size = len - sizeof(struct icmphdr); return icmp_to_icmp6(out, pos, icmp, checksum, payload, payload_size); @@ -54,13 +54,13 @@ int icmp_packet(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t c * 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 char *packet, size_t len) { +int ipv4_packet(clat_packet out, int 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; size_t frag_hdr_len; uint8_t nxthdr; - const char *next_header; + const uint8_t *next_header; size_t len_left; uint32_t old_sum, new_sum; int iov_len; @@ -35,7 +35,7 @@ * 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) { - const char *payload; + const uint8_t *payload; size_t payload_size; if(len < sizeof(struct icmp6_hdr)) { @@ -43,7 +43,7 @@ int icmp6_packet(clat_packet out, int pos, const struct icmp6_hdr *icmp6, size_t return 0; } - payload = (const char *) (icmp6 + 1); + payload = (const uint8_t *) (icmp6 + 1); payload_size = len - sizeof(struct icmp6_hdr); return icmp6_to_icmp(out, pos, icmp6, payload, payload_size); @@ -74,12 +74,12 @@ void log_bad_address(const char *fmt, const struct in6_addr *src, const struct i * 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 char *packet, size_t len) { +int ipv6_packet(clat_packet out, int 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; uint8_t protocol; - const char *next_header; + const uint8_t *next_header; size_t len_left; uint32_t old_sum, new_sum; int iov_len; diff --git a/translate.c b/translate.c index 7585092..b357057 100644 --- a/translate.c +++ b/translate.c @@ -225,7 +225,7 @@ uint8_t parse_frag_header(const struct ip6_frag *frag_hdr, struct iphdr *ip_targ * 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 char *payload, size_t payload_size) { + 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; @@ -256,7 +256,7 @@ int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t // Ping packet. icmp6_targ->icmp6_id = icmp->un.echo.id; icmp6_targ->icmp6_seq = icmp->un.echo.sequence; - out[CLAT_POS_PAYLOAD].iov_base = (char *) payload; + out[CLAT_POS_PAYLOAD].iov_base = (uint8_t *) payload; out[CLAT_POS_PAYLOAD].iov_len = payload_size; clat_packet_len = CLAT_POS_PAYLOAD + 1; } else { @@ -279,7 +279,7 @@ int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t * 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, - const char *payload, size_t payload_size) { + const uint8_t *payload, size_t payload_size) { struct icmphdr *icmp_targ = out[pos].iov_base; uint8_t icmp_type; int clat_packet_len; @@ -302,7 +302,7 @@ int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, // Ping packet. icmp_targ->un.echo.id = icmp6->icmp6_id; icmp_targ->un.echo.sequence = icmp6->icmp6_seq; - out[CLAT_POS_PAYLOAD].iov_base = (char *) payload; + out[CLAT_POS_PAYLOAD].iov_base = (uint8_t *) payload; out[CLAT_POS_PAYLOAD].iov_len = payload_size; clat_packet_len = CLAT_POS_PAYLOAD + 1; } else { @@ -324,9 +324,10 @@ int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, * 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 char *payload, size_t len) { +int generic_packet(clat_packet out, int pos, + const uint8_t *payload, size_t len) { out[pos].iov_len = 0; - out[CLAT_POS_PAYLOAD].iov_base = (char *) payload; + out[CLAT_POS_PAYLOAD].iov_base = (uint8_t *) payload; out[CLAT_POS_PAYLOAD].iov_len = len; return CLAT_POS_PAYLOAD + 1; @@ -342,7 +343,7 @@ int generic_packet(clat_packet out, int pos, const char *payload, size_t len) { */ int udp_packet(clat_packet out, int pos, const struct udphdr *udp, uint32_t old_sum, uint32_t new_sum, size_t len) { - const char *payload; + const uint8_t *payload; size_t payload_size; if(len < sizeof(struct udphdr)) { @@ -350,7 +351,7 @@ int udp_packet(clat_packet out, int pos, const struct udphdr *udp, return 0; } - payload = (const char *) (udp + 1); + payload = (const uint8_t *) (udp + 1); payload_size = len - sizeof(struct udphdr); return udp_translate(out, pos, udp, old_sum, new_sum, payload, payload_size); @@ -366,7 +367,7 @@ int udp_packet(clat_packet out, int pos, const struct udphdr *udp, */ int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, uint32_t old_sum, uint32_t new_sum, size_t len) { - const char *payload; + const uint8_t *payload; size_t payload_size, header_size; if(len < sizeof(struct tcphdr)) { @@ -385,7 +386,7 @@ int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, } header_size = tcp->doff * 4; - payload = ((const char *) tcp) + header_size; + payload = ((const uint8_t *) tcp) + header_size; payload_size = len - header_size; return tcp_translate(out, pos, tcp, header_size, old_sum, new_sum, payload, payload_size); @@ -401,14 +402,15 @@ int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, * 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 char *payload, size_t payload_size) { +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) { struct udphdr *udp_targ = out[pos].iov_base; memcpy(udp_targ, udp, sizeof(struct udphdr)); out[pos].iov_len = sizeof(struct udphdr); - out[CLAT_POS_PAYLOAD].iov_base = (char *) payload; + out[CLAT_POS_PAYLOAD].iov_base = (uint8_t *) payload; out[CLAT_POS_PAYLOAD].iov_len = payload_size; if (udp_targ->check) { @@ -442,7 +444,8 @@ int udp_translate(clat_packet out, int pos, const struct udphdr *udp, uint32_t o * 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, const char *payload, size_t payload_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; @@ -456,7 +459,7 @@ int tcp_translate(clat_packet out, int pos, const struct tcphdr *tcp, size_t hea memcpy(tcp_targ, tcp, header_size); - out[CLAT_POS_PAYLOAD].iov_base = (char *)payload; + out[CLAT_POS_PAYLOAD].iov_base = (uint8_t *) payload; out[CLAT_POS_PAYLOAD].iov_len = payload_size; tcp_targ->check = ip_checksum_adjust(tcp->check, old_sum, new_sum); @@ -471,8 +474,8 @@ int tcp_translate(clat_packet out, int pos, const struct tcphdr *tcp, size_t hea * packet - packet * packetsize - size of packet */ -void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, const char *packet, - size_t packetsize) { +void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, + const uint8_t *packet, size_t packetsize) { int fd; int iov_len = 0; diff --git a/translate.h b/translate.h index 5efa817..ab20a55 100644 --- a/translate.h +++ b/translate.h @@ -60,12 +60,12 @@ void fill_ip6_header(struct ip6_hdr *ip6, uint16_t payload_len, uint8_t protocol const struct iphdr *old_header); // Translate and send packets. -void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, const char *packet, - size_t packetsize); +void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, + const uint8_t *packet, size_t packetsize); // Translate IPv4 and IPv6 packets. -int ipv4_packet(clat_packet out, int pos, const char *packet, size_t len); -int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len); +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); // Deal with fragmented packets. size_t maybe_fill_frag_header(struct ip6_frag *frag_hdr, struct ip6_hdr *ip6_targ, @@ -74,12 +74,13 @@ 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 char *payload, size_t payload_size); + const uint8_t *payload, size_t payload_size); int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, - const char *payload, size_t payload_size); + const uint8_t *payload, size_t payload_size); // Translate generic IP packets. -int generic_packet(clat_packet out, int pos, const char *payload, size_t len); +int generic_packet(clat_packet out, int 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, @@ -88,8 +89,10 @@ int udp_packet(clat_packet out, int 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, const char *payload, size_t payload_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, - uint32_t old_sum, uint32_t new_sum, const char *payload, size_t payload_size); + uint32_t old_sum, uint32_t new_sum, + const uint8_t *payload, size_t payload_size); #endif /* __TRANSLATE_H__ */ |