From patchwork Thu Jun 30 08:41:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 932322 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5U8jEbb009705 for ; Thu, 30 Jun 2011 08:45:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758900Ab1F3IpM (ORCPT ); Thu, 30 Jun 2011 04:45:12 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:59621 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758793Ab1F3IpL (ORCPT ); Thu, 30 Jun 2011 04:45:11 -0400 Received: by mail-iy0-f174.google.com with SMTP id 12so1722525iyb.19 for ; Thu, 30 Jun 2011 01:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=PdBNY44vQ6NZwpjiKpQ6q8Yasnk1I/wx5hxQk3gVLZE=; b=j/CehPXmglAKTQEEab48XmSM4zCvf9IyIzOUvXAmltifyNhZrzvvZfrCnSNDGBx6wY gCNOKZTX/uUPNI7tVpkACzeeshr4G7SJyGZczNYhYJyJxvFM+B1ewQEGUtZ9fb0iTPMr VClXTk8WjLKKC/JqJ4WicXPylJRKWrd8peEtA= Received: by 10.42.154.66 with SMTP id p2mr1558017icw.453.1309423511051; Thu, 30 Jun 2011 01:45:11 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id d6sm1967338icx.1.2011.06.30.01.45.07 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Jun 2011 01:45:10 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , kvm@vger.kernel.org, Asias He Subject: [PATCH v2 19/31] kvm tools: Implement uip_csum_tcp() to calculate TCP checksum Date: Thu, 30 Jun 2011 16:41:07 +0800 Message-Id: <1309423279-3093-20-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1309423279-3093-1-git-send-email-asias.hejun@gmail.com> References: <1309423279-3093-1-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 30 Jun 2011 08:45:15 +0000 (UTC) Signed-off-by: Asias He --- tools/kvm/include/kvm/uip.h | 3 +++ tools/kvm/uip/csum.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index 46cec20..37c87c6 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -28,8 +28,10 @@ /* * IP package maxium len == 64 KBytes * IP header == 20 Bytes + * TCP header == 20 Bytes * UDP header == 8 Bytes */ +#define UIP_MAX_TCP_PAYLOAD (64*1024 - 20 - 20 - 1) #define UIP_MAX_UDP_PAYLOAD (64*1024 - 20 - 8 - 1) struct uip_eth_addr { @@ -269,6 +271,7 @@ int uip_tx_do_arp(struct uip_tx_arg *arg); u16 uip_csum_icmp(struct uip_icmp *icmp); u16 uip_csum_udp(struct uip_udp *udp); +u16 uip_csum_tcp(struct uip_tcp *tcp); u16 uip_csum_ip(struct uip_ip *ip); struct uip_buf *uip_buf_set_used(struct uip_info *info, struct uip_buf *buf); diff --git a/tools/kvm/uip/csum.c b/tools/kvm/uip/csum.c index a152a0f..7ca8bad 100644 --- a/tools/kvm/uip/csum.c +++ b/tools/kvm/uip/csum.c @@ -60,3 +60,33 @@ u16 uip_csum_udp(struct uip_udp *udp) } } + +u16 uip_csum_tcp(struct uip_tcp *tcp) +{ + struct uip_pseudo_hdr hdr; + struct uip_ip *ip; + u16 tcp_len; + u8 *pad; + + ip = &tcp->ip; + tcp_len = ntohs(ip->len) - uip_ip_hdrlen(ip); + + hdr.sip = ip->sip; + hdr.dip = ip->dip; + hdr.zero = 0; + hdr.proto = ip->proto; + hdr.len = htons(tcp_len); + + if (tcp_len > UIP_MAX_TCP_PAYLOAD + 20) + pr_warning("tcp_len(%d) is too large", tcp_len); + + if (tcp_len % 2) { + pad = (u8 *)&tcp->sport + tcp_len; + *pad = 0; + memcpy((u8 *)&tcp->sport + tcp_len + 1, &hdr, sizeof(hdr)); + return uip_csum(0, (u8 *)&tcp->sport, tcp_len + 1 + sizeof(hdr)); + } else { + memcpy((u8 *)&tcp->sport + tcp_len, &hdr, sizeof(hdr)); + return uip_csum(0, (u8 *)&tcp->sport, tcp_len + sizeof(hdr)); + } +}