From: Dmitry Fleytman <dmitry.fleytman@ravellosystems.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Alex Fishman <alex.fishman@ravellosystems.com>,
Dmitry Fleytman <dmitry.fleytman@ravellosystems.com>,
yvugenfi@redhat.com, Izik Eidus <izik.eidus@ravellosystems.com>,
Yan Vugenfirer <yan@daynix.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Dmitry Fleytman <dmitry@daynix.com>
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
Date: Thu, 15 Mar 2012 23:09:01 +0200 [thread overview]
Message-ID: <1331845748-6026-3-git-send-email-dmitry.fleytman@ravellosystems.com> (raw)
In-Reply-To: <1331845748-6026-1-git-send-email-dmitry.fleytman@ravellosystems.com>
Adding utility function net_raw_checksum() that calculates checksum
of buffer given
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Yan Vugenfirer <yan@daynix.com>
---
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 <stdint.h>
-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 */
--
1.7.7.6
next prev parent reply other threads:[~2012-03-15 21:13 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-15 21:08 [Qemu-devel] [PATCH v4 0/9] VMXNET3 paravirtual NIC device implementation Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 1/9] Adding missing flag VIRTIO_NET_HDR_F_DATA_VALID from Linux kernel source tre Reformatting comments according to checkpatch.pl requirements Dmitry Fleytman
2012-03-15 21:09 ` Dmitry Fleytman [this message]
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 3/9] Adding utility function iov_net_csum_add() for iovec checksum calculation Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 4/9] MSI-X state save/load invocations moved to PCI Device save/load callbacks to avoid code duplication in MSI-X-enabled devices that support live migration Dmitry Fleytman
2012-03-15 23:00 ` Michael S. Tsirkin
2012-03-16 9:18 ` Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 5/9] Header with various utility functions shared by VMWARE SCSI and network devi Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 6/9] Various utility functions used by VMWARE network devices Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 7/9] Packet abstraction " Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 8/9] VMXNET3 paravirtual device implementation Dmitry Fleytman
2012-03-15 21:09 ` [Qemu-devel] [PATCH v4 9/9] VMXNET3 paravirtualized device integration. Interface type "vmxnet3" added Dmitry Fleytman
2012-03-16 11:35 ` Paolo Bonzini
2012-03-18 9:26 ` Dmitry Fleytman
2012-03-18 8:29 ` [Qemu-devel] [PATCH v4 0/9] VMXNET3 paravirtual NIC device implementation Gerhard Wiesinger
2012-03-18 15:30 ` Dmitry Fleytman
2012-03-19 19:24 ` Gerhard Wiesinger
2012-03-20 8:00 ` Dmitry Fleytman
2012-03-21 6:59 ` Gerhard Wiesinger
2012-03-25 6:39 ` Gerhard Wiesinger
2012-03-18 8:32 ` Gerhard Wiesinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1331845748-6026-3-git-send-email-dmitry.fleytman@ravellosystems.com \
--to=dmitry.fleytman@ravellosystems.com \
--cc=alex.fishman@ravellosystems.com \
--cc=aliguori@us.ibm.com \
--cc=dmitry@daynix.com \
--cc=izik.eidus@ravellosystems.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yan@daynix.com \
--cc=yvugenfi@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).