diff options
-rw-r--r-- | ipv4.c | 8 | ||||
-rw-r--r-- | ipv6.c | 8 | ||||
-rw-r--r-- | translate.c | 16 | ||||
-rw-r--r-- | translate.h | 3 |
4 files changed, 29 insertions, 6 deletions
@@ -123,12 +123,14 @@ int ipv4_packet(clat_packet out, int pos, const char *packet, size_t len) { // Calculate the pseudo-header checksum. checksum = ipv6_pseudo_header_checksum(0, ip6_targ, len_left); - if(nxthdr == IPPROTO_ICMPV6) { + if (nxthdr == IPPROTO_ICMPV6) { iov_len = icmp_packet(out, pos + 1, (const struct icmphdr *) next_header, checksum, len_left); - } else if(nxthdr == IPPROTO_TCP) { + } else if (nxthdr == IPPROTO_TCP) { iov_len = tcp_packet(out, pos + 1, (const struct tcphdr *) next_header, checksum, len_left); - } else if(nxthdr == IPPROTO_UDP) { + } else if (nxthdr == IPPROTO_UDP) { iov_len = udp_packet(out, pos + 1, (const struct udphdr *) next_header, checksum, len_left); + } else if (nxthdr == IPPROTO_GRE) { + iov_len = generic_packet(out, pos + 1, next_header, len_left); } else { #if CLAT_DEBUG logmsg_dbg(ANDROID_LOG_ERROR, "ip_packet/unknown protocol: %x",header->protocol); @@ -136,14 +136,16 @@ int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len) { checksum = ipv4_pseudo_header_checksum(0, ip_targ, len_left); // does not support IPv6 extension headers, this will drop any packet with them - if(protocol == IPPROTO_ICMP) { + if (protocol == IPPROTO_ICMP) { iov_len = icmp6_packet(out, pos + 1, (const struct icmp6_hdr *) next_header, len_left); - } else if(ip6->ip6_nxt == IPPROTO_TCP) { + } else if (ip6->ip6_nxt == IPPROTO_TCP) { iov_len = tcp_packet(out, pos + 1, (const struct tcphdr *) next_header, checksum, len_left); - } else if(ip6->ip6_nxt == IPPROTO_UDP) { + } else if (ip6->ip6_nxt == IPPROTO_UDP) { iov_len = udp_packet(out, pos + 1, (const struct udphdr *) next_header, checksum, len_left); + } else if (ip6->ip6_nxt == IPPROTO_GRE) { + iov_len = generic_packet(out, pos + 1, next_header, len_left); } else { #if CLAT_DEBUG logmsg(ANDROID_LOG_ERROR, "ipv6_packet/unknown next header type: %x", ip6->ip6_nxt); diff --git a/translate.c b/translate.c index 599182d..00ea0b9 100644 --- a/translate.c +++ b/translate.c @@ -278,6 +278,22 @@ int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, return clat_packet_len; } +/* function: generic_packet + * takes a generic IP packet and sets it up for translation + * out - output packet + * pos - position in the output packet of the transport header + * payload - pointer to IP payload + * 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) { + out[pos].iov_len = 0; + out[CLAT_POS_PAYLOAD].iov_base = (char *) payload; + out[CLAT_POS_PAYLOAD].iov_len = len; + + return CLAT_POS_PAYLOAD + 1; +} + /* function: udp_packet * takes a udp packet and sets it up for translation * out - output packet diff --git a/translate.h b/translate.h index c4d8ede..9f1ac15 100644 --- a/translate.h +++ b/translate.h @@ -57,6 +57,9 @@ int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, const char *payload, size_t payload_size); +// Translate generic IP packets. +int generic_packet(clat_packet out, int pos, const char *payload, size_t len); + // Translate TCP and UDP packets. int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, uint32_t checksum, size_t len); int udp_packet(clat_packet out, int pos, const struct udphdr *udp, uint32_t checksum, size_t len); |