summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSubash Abhinov Kasiviswanathan <subashab@codeaurora.org>2015-10-26 18:45:04 -0600
committerSubash Abhinov Kasiviswanathan <subashab@codeaurora.org>2015-11-15 13:21:45 -0700
commit32961d08e3abe5b4e81178bb8c37dd4df231306d (patch)
treec1e80bcbc7c1c0bb7792e1ac5fb4b0aa690bb633
parentb38ac868d20bb9c1cae087ab18691d242aad0c5c (diff)
downloadandroid_external_android-clat-32961d08e3abe5b4e81178bb8c37dd4df231306d.tar.gz
android_external_android-clat-32961d08e3abe5b4e81178bb8c37dd4df231306d.tar.bz2
android_external_android-clat-32961d08e3abe5b4e81178bb8c37dd4df231306d.zip
clatd: Relay checksum information from packet socket to TUN interface
With this change, we can notify network stack to disable checksum validation for GRO packets as well as other packets which have checksum validation completed earlier in a driver. GRO packets have the ip_summed field set to CHECKSUM_PARTIAL while checksum offloaded packets have the ip_summed field as CHECKSUM_UNNECESSARY. Kernel copies this ip_summed field to the status field in the tpacket filter. The information from the status field is then passed as part of the TUN header to the TUN interface. Any other packet will have the complete checksum validation done in the network stack. Note that this only applies to packets which are captured in packet sockets and passed onto the TUN interface. Change-Id: I536c0356cbbf30fed7ecda5fdd0d38fa0dfd7bf3
-rw-r--r--clatd.c2
-rw-r--r--clatd_test.cpp3
-rw-r--r--ring.c12
-rw-r--r--ring.h3
-rw-r--r--translate.c9
-rw-r--r--translate.h4
6 files changed, 24 insertions, 9 deletions
diff --git a/clatd.c b/clatd.c
index faeb679..a454770 100644
--- a/clatd.c
+++ b/clatd.c
@@ -364,7 +364,7 @@ void read_packet(int read_fd, int write_fd, int to_ipv6) {
packet = (uint8_t *) (tun_header + 1);
readlen -= sizeof(*tun_header);
- translate_packet(write_fd, to_ipv6, packet, readlen);
+ translate_packet(write_fd, to_ipv6, packet, readlen, TP_CSUM_NONE);
}
/* function: event_loop
diff --git a/clatd_test.cpp b/clatd_test.cpp
index 7e218f0..6e374d2 100644
--- a/clatd_test.cpp
+++ b/clatd_test.cpp
@@ -30,6 +30,7 @@ extern "C" {
#include "translate.h"
#include "config.h"
#include "clatd.h"
+#include "ring.h"
}
// For convenience.
@@ -456,7 +457,7 @@ void do_translate_packet(const uint8_t *original, size_t original_len, uint8_t *
break;
}
- translate_packet(write_fd, (version == 4), original, original_len);
+ translate_packet(write_fd, (version == 4), original, original_len, TP_CSUM_NONE);
snprintf(foo, sizeof(foo), "%s: Invalid translated packet", msg);
if (version == 6) {
diff --git a/ring.c b/ring.c
index 5e99fd5..17f8026 100644
--- a/ring.c
+++ b/ring.c
@@ -117,9 +117,19 @@ static struct tpacket2_hdr* ring_advance(struct packet_ring *ring) {
*/
void ring_read(struct packet_ring *ring, int write_fd, int to_ipv6) {
struct tpacket2_hdr *tp = ring->next;
+ uint16_t val = TP_CSUM_NONE;
if (tp->tp_status & TP_STATUS_USER) {
+ //We expect only GRO coalesced packets to have TP_STATUS_CSUMNOTREADY
+ //(ip_summed = CHECKSUM_PARTIAL) in this path. Note that these packets have already gone
+ //through checksum validation in GRO engine. CHECKSUM_PARTIAL is defined to be 3 while
+ //CHECKSUM_UNNECESSARY is defined to be 1.
+ //Kernel only checks for CHECKSUM_UNNECESSARY (TP_CSUM_UNNECESSARY) bit while processing a
+ //packet, so its ok to pass only this bit rather than the full ip_summed field.
+ if ((tp->tp_status & TP_STATUS_CSUMNOTREADY) || (tp->tp_status & TP_STATUS_CSUM_UNNECESSARY)) {
+ val = TP_CSUM_UNNECESSARY;
+ }
uint8_t *packet = ((uint8_t *) tp) + tp->tp_net;
- translate_packet(write_fd, to_ipv6, packet, tp->tp_len);
+ translate_packet(write_fd, to_ipv6, packet, tp->tp_len, val);
tp->tp_status = TP_STATUS_KERNEL;
tp = ring_advance(ring);
}
diff --git a/ring.h b/ring.h
index b9b8c11..9e517be 100644
--- a/ring.h
+++ b/ring.h
@@ -42,6 +42,9 @@ struct tun_data;
// results in 656 frames (1048576 bytes).
#define TP_NUM_BLOCKS 16
+#define TP_CSUM_NONE (0)
+#define TP_CSUM_UNNECESSARY (1)
+
struct packet_ring {
uint8_t *base;
struct tpacket2_hdr *next;
diff --git a/translate.c b/translate.c
index ddc9bac..bce9270 100644
--- a/translate.c
+++ b/translate.c
@@ -108,8 +108,8 @@ struct in6_addr ipv4_addr_to_ipv6_addr(uint32_t addr4) {
* tun_header - tunnel header, already allocated
* proto - ethernet protocol id: ETH_P_IP(ipv4) or ETH_P_IPV6(ipv6)
*/
-void fill_tun_header(struct tun_pi *tun_header, uint16_t proto) {
- tun_header->flags = 0;
+void fill_tun_header(struct tun_pi *tun_header, uint16_t proto, uint16_t skip_csum) {
+ tun_header->flags = htons(skip_csum);
tun_header->proto = htons(proto);
}
@@ -491,8 +491,9 @@ void send_rawv6(int fd, clat_packet out, int iov_len) {
* to_ipv6 - true if translating to ipv6, false if translating to ipv4
* packet - packet
* packetsize - size of packet
+ * skip_csum - true if kernel has to skip checksum validation, false if it has to validate checksum.
*/
-void translate_packet(int fd, int to_ipv6, const uint8_t *packet, size_t packetsize) {
+void translate_packet(int fd, int to_ipv6, const uint8_t *packet, size_t packetsize, uint16_t skip_csum) {
int iov_len = 0;
// Allocate buffers for all packet headers.
@@ -524,7 +525,7 @@ void translate_packet(int fd, int to_ipv6, const uint8_t *packet, size_t packets
} else {
iov_len = ipv6_packet(out, CLAT_POS_IPHDR, packet, packetsize);
if (iov_len > 0) {
- fill_tun_header(&tun_targ, ETH_P_IP);
+ fill_tun_header(&tun_targ, ETH_P_IP, skip_csum);
out[CLAT_POS_TUNHDR].iov_len = sizeof(tun_targ);
send_tun(fd, out, iov_len);
}
diff --git a/translate.h b/translate.h
index aa8b736..3c249eb 100644
--- a/translate.h
+++ b/translate.h
@@ -42,14 +42,14 @@ uint16_t packet_length(clat_packet packet, clat_packet_index pos);
int is_in_plat_subnet(const struct in6_addr *addr6);
// Functions to create tun, IPv4, and IPv6 headers.
-void fill_tun_header(struct tun_pi *tun_header, uint16_t proto);
+void fill_tun_header(struct tun_pi *tun_header, uint16_t proto, uint16_t skip_csum);
void fill_ip_header(struct iphdr *ip_targ, uint16_t payload_len, uint8_t protocol,
const struct ip6_hdr *old_header);
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(int fd, int to_ipv6, const uint8_t *packet, size_t packetsize);
+void translate_packet(int fd, int to_ipv6, const uint8_t *packet, size_t packetsize, uint16_t skip_csum);
// Translate IPv4 and IPv6 packets.
int ipv4_packet(clat_packet out, clat_packet_index pos, const uint8_t *packet, size_t len);