From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes
Date: Thu, 28 Nov 2024 13:08:41 +0100 [thread overview]
Message-ID: <20241128120841.4129705-1-lvivier@redhat.com> (raw)
In tcp_vu_data_from_sock() we compute IPv4 header checksum only
for the first and the last packets, and re-use the first packet checksum
for all the other packets as the content of the header doesn't change.
It's more accurate to check the dlen value to know if the checksum
should change as dlen is the only information that can change in the
loop.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
tcp_vu.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/tcp_vu.c b/tcp_vu.c
index bbae918c3bb3..4e4e916ded78 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -381,12 +381,12 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
struct vu_dev *vdev = c->vdev;
struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE];
const struct flowside *tapside = TAPFLOW(conn);
+ ssize_t len, previous_dlen;
size_t fillsize, hdrlen;
int v6 = CONN_V6(conn);
uint32_t already_sent;
const uint16_t *check;
int i, iov_cnt;
- ssize_t len;
if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) {
debug("Got packet, but RX virtqueue not usable yet");
@@ -460,19 +460,17 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
*/
hdrlen = tcp_vu_hdrlen(v6);
- for (i = 0, check = NULL; i < head_cnt; i++) {
+ for (i = 0, previous_dlen = -1, check = NULL; i < head_cnt; i++) {
struct iovec *iov = &elem[head[i]].in_sg[0];
int buf_cnt = head[i + 1] - head[i];
ssize_t dlen = iov_size(iov, buf_cnt) - hdrlen;
vu_set_vnethdr(vdev, iov->iov_base, buf_cnt);
- /* we compute IPv4 header checksum only for the
- * first and the last, all other checksums are the
- * same as the first one
- */
- if (i + 1 == head_cnt)
+ /* The IPv4 header checksum varies only with dlen */
+ if (previous_dlen != dlen)
check = NULL;
+ previous_dlen = dlen;
tcp_vu_prepare(c, conn, iov->iov_base, dlen, &check);
--
@@ -381,12 +381,12 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
struct vu_dev *vdev = c->vdev;
struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE];
const struct flowside *tapside = TAPFLOW(conn);
+ ssize_t len, previous_dlen;
size_t fillsize, hdrlen;
int v6 = CONN_V6(conn);
uint32_t already_sent;
const uint16_t *check;
int i, iov_cnt;
- ssize_t len;
if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) {
debug("Got packet, but RX virtqueue not usable yet");
@@ -460,19 +460,17 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
*/
hdrlen = tcp_vu_hdrlen(v6);
- for (i = 0, check = NULL; i < head_cnt; i++) {
+ for (i = 0, previous_dlen = -1, check = NULL; i < head_cnt; i++) {
struct iovec *iov = &elem[head[i]].in_sg[0];
int buf_cnt = head[i + 1] - head[i];
ssize_t dlen = iov_size(iov, buf_cnt) - hdrlen;
vu_set_vnethdr(vdev, iov->iov_base, buf_cnt);
- /* we compute IPv4 header checksum only for the
- * first and the last, all other checksums are the
- * same as the first one
- */
- if (i + 1 == head_cnt)
+ /* The IPv4 header checksum varies only with dlen */
+ if (previous_dlen != dlen)
check = NULL;
+ previous_dlen = dlen;
tcp_vu_prepare(c, conn, iov->iov_base, dlen, &check);
--
2.47.0
next reply other threads:[~2024-11-28 12:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 12:08 Laurent Vivier [this message]
2024-11-28 13:04 ` [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes Stefano Brivio
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=20241128120841.4129705-1-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).