From ee80ca65907d214e2483e315a1ba7f610184de03 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 10 Apr 2013 16:52:22 +0900 Subject: 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 --- ipv6.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'ipv6.c') diff --git a/ipv6.c b/ipv6.c index 8011ce9..bb1dc24 100644 --- a/ipv6.c +++ b/ipv6.c @@ -100,12 +100,11 @@ int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len) { return 0; // silently ignore } - for(i = 0; i < 3; i++) { - if(ip6->ip6_src.s6_addr32[i] != Global_Clatd_Config.plat_subnet.s6_addr32[i]) { - log_bad_address("ipv6_packet/wrong source address: %s", &ip6->ip6_src); - return 0; - } + if (!is_in_plat_subnet(&ip6->ip6_src) && ip6->ip6_nxt) { + log_bad_address("ipv6_packet/wrong source address: %s", &ip6->ip6_src); + return 0; } + if(!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &Global_Clatd_Config.ipv6_local_subnet)) { log_bad_address("ipv6_packet/wrong destination address: %s", &ip6->ip6_dst); return 0; @@ -149,7 +148,7 @@ int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len) { } // Set the length and calculate the checksum. - ip_targ->tot_len = htons(ntohs(ip_targ->tot_len) + payload_length(out, pos)); + ip_targ->tot_len = htons(ntohs(ip_targ->tot_len) + packet_length(out, pos)); ip_targ->check = ip_checksum(ip_targ, sizeof(struct iphdr)); return iov_len; } -- cgit v1.2.3