diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2013-04-10 16:52:22 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2013-04-12 12:35:41 +0900 |
commit | ee80ca65907d214e2483e315a1ba7f610184de03 (patch) | |
tree | 9fb525e543515052c55a8c52ca9db6c4a790d89a /translate.h | |
parent | d90841824dc00f65a48a789396c7f428807432ca (diff) | |
download | android_external_android-clat-ee80ca65907d214e2483e315a1ba7f610184de03.tar.gz android_external_android-clat-ee80ca65907d214e2483e315a1ba7f610184de03.tar.bz2 android_external_android-clat-ee80ca65907d214e2483e315a1ba7f610184de03.zip |
Improve checksum calculation and address checking
1. Add a function that calculates the checksum of all the packet
components starting from the specified position. This
simplifies the code a bit and makes it easier to translate
nested packets like ICMP error messages.
2. Don't hardcode IP source and destination addresses. This is
required to translate ICMP error messages.
Bug: 8276725
Change-Id: I2cae45683ae3943e508608fd0a140180dbc60823
Diffstat (limited to 'translate.h')
-rw-r--r-- | translate.h | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/translate.h b/translate.h index 07db023..120fecf 100644 --- a/translate.h +++ b/translate.h @@ -23,14 +23,21 @@ #define MAX_TCP_HDR (15 * 4) // Data offset field is 4 bits and counts in 32-bit words. // A clat_packet is an array of iovec structures representing a packet that we are translating. -// The POS_XXX constants represent the array indices within the clat_packet that contain specific -// parts of the packet. -enum clat_packet_index { POS_TUNHDR, POS_IPHDR, POS_TRANSPORTHDR, POS_ICMPIPHDR, - POS_PAYLOAD, POS_MAX }; -typedef struct iovec clat_packet[POS_MAX]; - -// Returns the total length of the packet components after index. -uint16_t payload_length(clat_packet packet, int index); +// The CLAT_POS_XXX constants represent the array indices within the clat_packet that contain +// specific parts of the packet. The packet_* functions operate on all the packet segments past a +// given position. +enum clat_packet_index { CLAT_POS_TUNHDR, CLAT_POS_IPHDR, CLAT_POS_TRANSPORTHDR, + CLAT_POS_PAYLOAD, CLAT_POS_MAX }; +typedef struct iovec clat_packet[CLAT_POS_MAX]; + +// Calculates the checksum over all the packet components starting from pos. +uint16_t packet_checksum(uint32_t checksum, clat_packet packet, int pos); + +// Returns the total length of the packet components after pos. +uint16_t packet_length(clat_packet packet, int pos); + +// Returns true iff the given IPv6 address is in the plat subnet. +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); |