diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2014-06-02 15:49:36 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2014-06-10 21:32:52 +0900 |
commit | 91d0f1bc6dd24e54ed3caef9b08525b332ab0adf (patch) | |
tree | f03037b2887e6e5787d4d47fe1967c57dbcfd3f2 /translate.c | |
parent | fc0f94a75c7a6d16ea9e327092f132a0d2c9175e (diff) | |
download | android_external_android-clat-91d0f1bc6dd24e54ed3caef9b08525b332ab0adf.tar.gz android_external_android-clat-91d0f1bc6dd24e54ed3caef9b08525b332ab0adf.tar.bz2 android_external_android-clat-91d0f1bc6dd24e54ed3caef9b08525b332ab0adf.zip |
Make translate_packet take a fd instead of a tun header.
This will make it easier to use separate fds for reading and
writing in a future change.
Bug: 15340961
Change-Id: I5b081b05765cae0488ac599be5738ce9737cae41
Diffstat (limited to 'translate.c')
-rw-r--r-- | translate.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/translate.c b/translate.c index e93a93a..958ce2f 100644 --- a/translate.c +++ b/translate.c @@ -466,15 +466,13 @@ int tcp_translate(clat_packet out, clat_packet_index pos, const struct tcphdr *t } /* function: translate_packet - * takes a tun header and a packet and sends it down the stack - * tunnel - tun device data - * tun_header - tun header + * takes a packet, translates it, and writes it to fd + * fd - fd to write translated packet to + * to_ipv6 - true if translating to ipv6, false if translating to ipv4 * packet - packet * packetsize - size of packet */ -void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, - const uint8_t *packet, size_t packetsize) { - int fd; +void translate_packet(int fd, int to_ipv6, const uint8_t *packet, size_t packetsize) { int iov_len = 0; // Allocate buffers for all packet headers. @@ -498,23 +496,14 @@ void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, { NULL, 0 }, // Payload. No buffer, it's a pointer to the original payload. }; - if(tun_header->flags != 0) { - logmsg(ANDROID_LOG_WARN, "translate_packet: unexpected flags = %d", tun_header->flags); - } - - if(ntohs(tun_header->proto) == ETH_P_IP) { - fd = tunnel->fd6; - fill_tun_header(&tun_targ, ETH_P_IPV6); + if (to_ipv6) { iov_len = ipv4_packet(out, CLAT_POS_IPHDR, packet, packetsize); - } else if(ntohs(tun_header->proto) == ETH_P_IPV6) { - fd = tunnel->fd4; - fill_tun_header(&tun_targ, ETH_P_IP); - iov_len = ipv6_packet(out, CLAT_POS_IPHDR, packet, packetsize); } else { - logmsg(ANDROID_LOG_WARN, "translate_packet: unknown packet type = %x",tun_header->proto); + iov_len = ipv6_packet(out, CLAT_POS_IPHDR, packet, packetsize); } if (iov_len > 0) { + fill_tun_header(&tun_targ, to_ipv6 ? ETH_P_IPV6 : ETH_P_IP); writev(fd, out, iov_len); } } |