Signed-off-by: Dmitry Fleytman <dmi...@daynix.com>
Signed-off-by: Yan Vugenfirer <y...@daynix.com>
---
 iov.c |   29 +++++++++++++++++++++++++++++
 iov.h |    3 +++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/iov.c b/iov.c
index 0f96493..5d4f94c 100644
--- a/iov.c
+++ b/iov.c
@@ -16,6 +16,7 @@
  */
 
 #include "iov.h"
+#include "net/checksum.h"
 
 size_t iov_from_buf(struct iovec *iov, unsigned int iov_cnt,
                     const void *buf, size_t iov_off, size_t size)
@@ -130,3 +131,31 @@ void iov_hexdump(const struct iovec *iov, const unsigned 
int iov_cnt,
         fprintf(fp, "\n");
     }
 }
+
+uint32_t
+iov_net_csum_add(const struct iovec *iov, const unsigned int iov_cnt,
+                 size_t iov_off, size_t size)
+{
+    size_t iovec_off, buf_off;
+    unsigned int i;
+    uint32_t res = 0;
+    uint32_t seq = 0;
+
+    iovec_off = 0;
+    buf_off = 0;
+    for (i = 0; i < iov_cnt && size; i++) {
+        if (iov_off < (iovec_off + iov[i].iov_len)) {
+            size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size);
+            void *chunk_buf = iov[i].iov_base + (iov_off - iovec_off);
+
+            res += net_checksum_add_cont(len, chunk_buf, seq);
+            seq += len;
+
+            buf_off += len;
+            iov_off += len;
+            size -= len;
+        }
+        iovec_off += iov[i].iov_len;
+    }
+    return res;
+}
diff --git a/iov.h b/iov.h
index 94d2f78..ba385f5 100644
--- a/iov.h
+++ b/iov.h
@@ -21,3 +21,6 @@ size_t iov_clear(const struct iovec *iov, const unsigned int 
iov_cnt,
                  size_t iov_off, size_t size);
 void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
                  FILE *fp, const char *prefix, size_t limit);
+uint32_t
+iov_net_csum_add(const struct iovec *iov, const unsigned int iov_cnt,
+                 size_t iov_off, size_t size);
-- 
1.7.7.6


Reply via email to