From: Christophe Saout Subject: Re: skb_checksum_setup and NAT Date: Fri, 29 Sep 2006 00:08:24 +0200 Message-ID: <1159481305.12963.5.camel@leto.intern.saout.de> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-YczU9bYX9AZaQU/mLJ7v" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: Xen Devel List-Id: xen-devel@lists.xenproject.org --=-YczU9bYX9AZaQU/mLJ7v Content-Type: text/plain Content-Transfer-Encoding: 7bit Am Donnerstag, den 28.09.2006, 18:35 +0100 schrieb Keir Fraser: > The Linux network stack doesn't expect to be able to receive packets that > have their protocol-checksum field empty. So we have to add extra packet > flags to signal this situation. It does create something of a mess unless > all parts of the network stack know what's going on. I heard that the > networking maintainers were working on a more generic scheme that we should > be able to make use of. Apart from that, the stack needs to make sure that > the proto_csum_blank field is cleared whenever it fills in the full > checksum. Ok, ip_forward e.g. sets ip_summed to CHECKSUM_NONE, so it indeed assumes the checksum is correctly set. This should probably just be changed accordingly to set CHECKSUM_HW when the incoming packet didn't have a valid checksum set (although the packet was accepted), possibly by adding a new CHECKSUM_xxx define. You are probably talking about the work by Patrick McHardy that is being merged for post-2.6.18: http://www.kernel.org/git/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git&a=search&h=HEAD&s=checksum It looks promising though it doesn't seem to address this problem in particular (?). > For now, if it causes you problems and you just want stuff to work, you can > run ethtool on your interface in domU: 'ethtool -K eth0 tx off'. I just ifdef'ed all places where the NAT code changed the checksum. I'm having a lot of network traffic between DomU's and I'd like to keep CPU usage down. If someone is interested in the patch, it's attached (just the FTP NAT part tested though). --=-YczU9bYX9AZaQU/mLJ7v Content-Disposition: attachment; filename=xen-nat-more-hacking.patch Content-Type: text/x-patch; name=xen-nat-more-hacking.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit diff -urp linux-2.6.18-cs1-xenU.orig/net/ipv4/netfilter/ip_nat_helper.c linux-2.6.18-cs1-xenU/net/ipv4/netfilter/ip_nat_helper.c --- linux-2.6.18-cs1-xenU.orig/net/ipv4/netfilter/ip_nat_helper.c 2006-09-28 23:44:19.000000000 +0200 +++ linux-2.6.18-cs1-xenU/net/ipv4/netfilter/ip_nat_helper.c 2006-09-28 23:43:55.000000000 +0200 @@ -184,9 +184,18 @@ ip_nat_mangle_tcp_packet(struct sk_buff match_offset, match_len, rep_buffer, rep_len); datalen = (*pskb)->len - iph->ihl*4; - tcph->check = 0; - tcph->check = tcp_v4_check(tcph, datalen, iph->saddr, iph->daddr, - csum_partial((char *)tcph, datalen, 0)); +#ifdef CONFIG_XEN + if (!(*pskb)->proto_csum_blank) { +#endif + tcph->check = 0; + tcph->check = tcp_v4_check(tcph, datalen, iph->saddr, iph->daddr, + csum_partial((char *)tcph, datalen, 0)); +#ifdef CONFIG_XEN + } else if (rep_len != match_len) + tcph->check = + ip_nat_cheat_check(htons(datalen - rep_len + match_len), + htons(datalen) ^ 0xFFFF, tcph->check); +#endif if (rep_len != match_len) { set_bit(IPS_SEQ_ADJUST_BIT, &ct->status); @@ -245,6 +254,9 @@ ip_nat_mangle_udp_packet(struct sk_buff udph->len = htons((*pskb)->len - iph->ihl*4); /* fix udp checksum if udp checksum was previously calculated */ +#ifdef CONFIG_XEN + if (!(*pskb)->proto_csum_blank) { +#endif if (udph->check) { int datalen = (*pskb)->len - iph->ihl * 4; udph->check = 0; @@ -253,6 +265,14 @@ ip_nat_mangle_udp_packet(struct sk_buff csum_partial((char *)udph, datalen, 0)); } +#ifdef CONFIG_XEN + } else if (rep_len != match_len && udph->check) { + int datalen = (*pskb)->len - iph->ihl * 4; + udph->check = + ip_nat_cheat_check(htons(datalen - rep_len + match_len), + htons(datalen) ^ 0xFFFF, udph->check); + } +#endif return 1; } @@ -293,6 +313,9 @@ sack_adjust(struct sk_buff *skb, ntohl(sack->start_seq), new_start_seq, ntohl(sack->end_seq), new_end_seq); +#ifdef CONFIG_XEN + if (!skb->proto_csum_blank) +#endif tcph->check = ip_nat_cheat_check(~sack->start_seq, new_start_seq, ip_nat_cheat_check(~sack->end_seq, @@ -381,6 +404,9 @@ ip_nat_seq_adjust(struct sk_buff **pskb, newack = ntohl(tcph->ack_seq) - other_way->offset_before; newack = htonl(newack); +#ifdef CONFIG_XEN + if (!(*pskb)->proto_csum_blank) +#endif tcph->check = ip_nat_cheat_check(~tcph->seq, newseq, ip_nat_cheat_check(~tcph->ack_seq, newack, diff -urp linux-2.6.18-cs1-xenU.orig/net/ipv4/netfilter/ipt_ECN.c linux-2.6.18-cs1-xenU/net/ipv4/netfilter/ipt_ECN.c --- linux-2.6.18-cs1-xenU.orig/net/ipv4/netfilter/ipt_ECN.c 2006-09-28 23:44:19.000000000 +0200 +++ linux-2.6.18-cs1-xenU/net/ipv4/netfilter/ipt_ECN.c 2006-09-28 23:39:46.000000000 +0200 @@ -82,6 +82,9 @@ set_ect_tcp(struct sk_buff **pskb, const diffs[1] = ((u_int16_t *)tcph)[6]; diffs[0] = diffs[0] ^ 0xFFFF; +#ifdef CONFIG_XEN + if (!(*pskb)->proto_csum_blank) +#endif if ((*pskb)->ip_summed != CHECKSUM_UNNECESSARY) tcph->check = csum_fold(csum_partial((char *)diffs, sizeof(diffs), diff -urp linux-2.6.18-cs1-xenU.orig/net/ipv4/netfilter/ipt_REJECT.c linux-2.6.18-cs1-xenU/net/ipv4/netfilter/ipt_REJECT.c --- linux-2.6.18-cs1-xenU.orig/net/ipv4/netfilter/ipt_REJECT.c 2006-09-28 23:44:19.000000000 +0200 +++ linux-2.6.18-cs1-xenU/net/ipv4/netfilter/ipt_REJECT.c 2006-09-28 23:39:46.000000000 +0200 @@ -183,6 +183,10 @@ static void send_reset(struct sk_buff *o tcph->window = 0; tcph->urg_ptr = 0; +#ifdef CONFIG_XEN + nskb->proto_csum_blank = 0; +#endif + /* Adjust TCP checksum */ tcph->check = 0; tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr), --=-YczU9bYX9AZaQU/mLJ7v Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-YczU9bYX9AZaQU/mLJ7v--