summaryrefslogtreecommitdiffstats
path: root/ipv4.c
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2013-04-08 19:12:43 +0900
committerLorenzo Colitti <lorenzo@google.com>2013-04-12 09:59:11 +0900
commit5cc877d4fc20d66ca5a057a3dc445adb998409bd (patch)
tree04c07f58d75f425022269f6a441e59fa890f5729 /ipv4.c
parentf913fe49272286a7f1e58d94a208b6dc06a51fd2 (diff)
downloadandroid_external_android-clat-5cc877d4fc20d66ca5a057a3dc445adb998409bd.tar.gz
android_external_android-clat-5cc877d4fc20d66ca5a057a3dc445adb998409bd.tar.bz2
android_external_android-clat-5cc877d4fc20d66ca5a057a3dc445adb998409bd.zip
Treat the options as part of the TCP header.
This simplifies the code and makes UDP and TCP look the same. It will also make it easier to implement nested translation in the future because there will only be one iovec array entry for the transport layer header, regardless of whether we are translating UDP or TCP and regardless of the presence of options. Also get rid of a couple of memcpy statements by pointing to the original data instead. Bug: 8276725 Change-Id: I6a702aefdf3a070eedfc6f7d3ebec21880ecc22b
Diffstat (limited to 'ipv4.c')
-rw-r--r--ipv4.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/ipv4.c b/ipv4.c
index 784f10c..243f9d0 100644
--- a/ipv4.c
+++ b/ipv4.c
@@ -64,40 +64,30 @@ void icmp_packet(int fd, const char *packet, size_t len, struct iphdr *ip) {
* ip - ip header
*/
void tcp_packet(int fd, const char *packet, size_t len, struct iphdr *ip) {
- struct tcphdr tcp;
+ const struct tcphdr *tcp = (const struct tcphdr *) packet;
const char *payload;
- const char *options;
- size_t payload_size, options_size;
+ size_t payload_size, header_size;
if(len < sizeof(tcp)) {
logmsg_dbg(ANDROID_LOG_ERROR,"tcp_packet/(too small)");
return;
}
- memcpy(&tcp, packet, sizeof(tcp));
-
- if(tcp.doff < 5) {
- logmsg_dbg(ANDROID_LOG_ERROR,"tcp_packet/tcp header length set to less than 5: %x",tcp.doff);
+ if(tcp->doff < 5) {
+ logmsg_dbg(ANDROID_LOG_ERROR,"tcp_packet/tcp header length set to less than 5: %x", tcp->doff);
return;
}
- if((size_t)tcp.doff*4 > len) {
- logmsg_dbg(ANDROID_LOG_ERROR,"tcp_packet/tcp header length set too large: %x",tcp.doff);
+ if((size_t) tcp->doff*4 > len) {
+ logmsg_dbg(ANDROID_LOG_ERROR,"tcp_packet/tcp header length set too large: %x", tcp->doff);
return;
}
- if(tcp.doff > 5) {
- options = packet + sizeof(tcp);
- options_size = tcp.doff*4 - sizeof(tcp);
- } else {
- options = NULL;
- options_size = 0;
- }
-
- payload = packet + tcp.doff*4;
- payload_size = len - tcp.doff*4;
+ header_size = tcp->doff * 4;
+ payload = packet + header_size;
+ payload_size = len - header_size;
- tcp_to_tcp6(fd,ip,&tcp,payload,payload_size,options,options_size);
+ tcp_to_tcp6(fd, ip, tcp, header_size, payload, payload_size);
}
/* function: udp_packet