From patchwork Thu Jun 30 08:40:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 932202 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 p5U8iM5r029005 for ; Thu, 30 Jun 2011 08:44:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756044Ab1F3IoO (ORCPT ); Thu, 30 Jun 2011 04:44:14 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:44108 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758252Ab1F3IoF (ORCPT ); Thu, 30 Jun 2011 04:44:05 -0400 Received: by iyb12 with SMTP id 12so1722680iyb.19 for ; Thu, 30 Jun 2011 01:44:04 -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=u82zHLe+fAogK8VI5bokZ/jsseT36KVlFdoPDefJ7qM=; b=xrxr9V3WhdY/Wcgn1M29biD3m/+Zmp+DukW/qTYBxTyX/7syKrFmGxkgF9DuWfPiwW NMX4g57oL1buzro8OL1vVCJPKGACvWTCGKg31pK7mFIHQuyKitubOQak8oc1XB2e640i oD55rwB7vpVStCvaJjEcuvwlgy2QZ1MXaEH88= Received: by 10.42.163.199 with SMTP id d7mr1730888icy.261.1309423444284; Thu, 30 Jun 2011 01:44:04 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id d6sm1967338icx.1.2011.06.30.01.44.00 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Jun 2011 01:44:03 -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 04/31] kvm tools: Implement IP checksum for uip Date: Thu, 30 Jun 2011 16:40:52 +0800 Message-Id: <1309423279-3093-5-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:44:23 +0000 (UTC) Other protocal, e.g. TCP, UDP, ICMP, can use uip_csum() to make checsksum as well. Signed-off-by: Asias He --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 2 ++ tools/kvm/uip/csum.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/uip/csum.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 7dc5bb2..ece542c 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -48,6 +48,7 @@ OBJS += irq.o OBJS += uip/arp.o OBJS += uip/ipv4.o OBJS += uip/buf.o +OBJS += uip/csum.o OBJS += kvm-cmd.o OBJS += kvm-debug.o OBJS += kvm-help.o diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index e48420d..00100e1 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -103,6 +103,8 @@ static inline u16 uip_ip_len(struct uip_ip *ip) int uip_tx_do_ipv4(struct uip_tx_arg *arg); int uip_tx_do_arp(struct uip_tx_arg *arg); +u16 uip_csum_ip(struct uip_ip *ip); + struct uip_buf *uip_buf_set_used(struct uip_info *info, struct uip_buf *buf); struct uip_buf *uip_buf_set_free(struct uip_info *info, struct uip_buf *buf); struct uip_buf *uip_buf_get_used(struct uip_info *info); diff --git a/tools/kvm/uip/csum.c b/tools/kvm/uip/csum.c new file mode 100644 index 0000000..8023ddb --- /dev/null +++ b/tools/kvm/uip/csum.c @@ -0,0 +1,25 @@ +#include "kvm/uip.h" + +static u16 uip_csum(u16 csum, u8 *addr, u16 count) +{ + long sum = csum; + + while (count > 1) { + sum += *(u16 *)addr; + addr += 2; + count -= 2; + } + + if (count > 0) + sum += *(unsigned char *)addr; + + while (sum>>16) + sum = (sum & 0xffff) + (sum >> 16); + + return ~sum; +} + +u16 uip_csum_ip(struct uip_ip *ip) +{ + return uip_csum(0, &ip->vhl, uip_ip_hdrlen(ip)); +}