From patchwork Thu Mar 15 21:09:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 147103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0BE53B6EF4 for ; Fri, 16 Mar 2012 08:58:11 +1100 (EST) Received: from localhost ([::1]:41480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8I0E-0008Qv-GH for incoming@patchwork.ozlabs.org; Thu, 15 Mar 2012 17:14:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8HzF-0005f8-KI for qemu-devel@nongnu.org; Thu, 15 Mar 2012 17:13:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S8HzD-0002lV-Pv for qemu-devel@nongnu.org; Thu, 15 Mar 2012 17:13:29 -0400 Received: from na3sys010aog106.obsmtp.com ([74.125.245.80]:36735) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1S8HzD-0002kg-I8 for qemu-devel@nongnu.org; Thu, 15 Mar 2012 17:13:27 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]) (using TLSv1) by na3sys010aob106.postini.com ([74.125.244.12]) with SMTP ID DSNKT2JbctDLsxUQ5sE5KqbwAsAzvkejEU2d@postini.com; Thu, 15 Mar 2012 14:13:27 PDT Received: by wibhr17 with SMTP id hr17so8273696wib.1 for ; Thu, 15 Mar 2012 14:13:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=bRyMkcupKZAsckYT9Uh70jldL7sA5jxYs/a19nit2S4=; b=Ph29bkjCrykoHOOA2aR15or/MChRDouuxxdkZhwR0H86gRey696tTz53DsLrCfInza FtSB8cEB/kbvZvCd6Ok9G5ptqXDqI84HA7UUDFNdFhmwfxhsM4daVVothKyek6KHwKwl B6HzuJzjiNnhD8DajaHFYBKlFPnp/xxED8viRx+nRsGu3OzNjwLSGL388mqMIOq/ZTPo 6fRE+yBlqBlAzU7u0o7HPd0Kd3pa4ZdNXffL4AZLSuOPC6lMG62qaQNg8901alzwvhAS pOuxa4dCr7j1QZ8eSzvWrijr7nd4jFSlZ4ogUkdesKZGLGHATDZllmZmoYrxmfNtc4I4 xSDg== Received: by 10.216.132.229 with SMTP id o79mr67394wei.64.1331845998849; Thu, 15 Mar 2012 14:13:18 -0700 (PDT) Received: from localhost.localdomain ([95.35.0.236]) by mx.google.com with ESMTPS id ff9sm8091314wib.2.2012.03.15.14.13.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Mar 2012 14:13:17 -0700 (PDT) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Thu, 15 Mar 2012 23:09:01 +0200 Message-Id: <1331845748-6026-3-git-send-email-dmitry.fleytman@ravellosystems.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331845748-6026-1-git-send-email-dmitry.fleytman@ravellosystems.com> References: <1331845748-6026-1-git-send-email-dmitry.fleytman@ravellosystems.com> X-Gm-Message-State: ALoCoQmSxbwhdjvasv7C2uE88YCygnCFYBWDHBhsWxTLqF/7N2aR62riN/nRcx4iT287g+fFrrLH X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 74.125.245.80 Cc: Anthony Liguori , Alex Fishman , Dmitry Fleytman , yvugenfi@redhat.com, Izik Eidus , Yan Vugenfirer , "Michael S. Tsirkin" , Dmitry Fleytman Subject: [Qemu-devel] [PATCH v4 2/9] Adding utility function net_checksum_add_cont() that allows checksum calculation of scattered data with odd chunk sizes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Adding utility function net_raw_checksum() that calculates checksum of buffer given Signed-off-by: Dmitry Fleytman Signed-off-by: Yan Vugenfirer --- net/checksum.c | 13 +++++++------ net/checksum.h | 14 +++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/net/checksum.c b/net/checksum.c index 9919b2e..4fa5563 100644 --- a/net/checksum.c +++ b/net/checksum.c @@ -20,16 +20,17 @@ #define PROTO_TCP 6 #define PROTO_UDP 17 -uint32_t net_checksum_add(int len, uint8_t *buf) +uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq) { uint32_t sum = 0; int i; - for (i = 0; i < len; i++) { - if (i & 1) - sum += (uint32_t)buf[i]; - else - sum += (uint32_t)buf[i] << 8; + for (i = seq; i < seq + len; i++) { + if (i & 1) { + sum += (uint32_t)buf[i - seq]; + } else { + sum += (uint32_t)buf[i - seq] << 8; + } } return sum; } diff --git a/net/checksum.h b/net/checksum.h index 1f05298..171924c 100644 --- a/net/checksum.h +++ b/net/checksum.h @@ -20,10 +20,22 @@ #include -uint32_t net_checksum_add(int len, uint8_t *buf); +uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); uint16_t net_checksum_finish(uint32_t sum); uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, uint8_t *addrs, uint8_t *buf); void net_checksum_calculate(uint8_t *data, int length); +static inline uint32_t +net_checksum_add(int len, uint8_t *buf) +{ + return net_checksum_add_cont(len, buf, 0); +} + +static inline uint16_t +net_raw_checksum(uint8_t *data, int length) +{ + return net_checksum_finish(net_checksum_add(length, data)); +} + #endif /* QEMU_NET_CHECKSUM_H */