[PATCH v6 0/5] tcp: use csum_iov() in tcp_update_check_tcp[4|6]()
For vhost-user, we will need to spread TCP payload over several buffers. To re-use tcp_update_check_tcp[4|6](), provide an iovec rather than a pointer to a buffer. This series updates also csum_iov() and pcap_iov() to add an offset of bytes to skip in the iovec array. It's based on top of "tcp: Use tcp_payload_t rather than tcphdr" that is added in the series for convenience. v6: update tcp.c with fix for clang-tidy error and add missing static Laurent Vivier (5): tcp: Use tcp_payload_t rather than tcphdr pcap: Add an offset argument in pcap_iov() checksum: Add an offset argument in csum_iov() tcp: Update TCP checksum using an iovec array udp: Update UDP checksum using an iovec array checksum.c | 46 +++++++++++----- checksum.h | 7 +-- iov.c | 1 - pcap.c | 5 +- pcap.h | 2 +- tap.c | 14 +++-- tap.h | 2 +- tcp.c | 140 +++++++++++++++++++++++++++++++++++++++---------- tcp_buf.c | 29 ---------- tcp_internal.h | 29 ++++++++++ udp.c | 17 ++++-- 11 files changed, 206 insertions(+), 86 deletions(-) -- 2.46.0
As tcp_update_check_tcp4() and tcp_update_check_tcp6() compute the
checksum using the TCP header and the TCP payload, it is clearer
to use a pointer to tcp_payload_t that includes tcphdr and payload
rather than a pointer to tcphdr (and guessing TCP header is
followed by the payload).
Move tcp_payload_t and tcp_flags_t to tcp_internal.h.
(They will be used also by vhost-user).
Signed-off-by: Laurent Vivier
The offset is passed directly to pcap_frame() and allows
any headers that are not part of the frame to
capture to be skipped.
Signed-off-by: Laurent Vivier
The offset allows any headers that are not part of the data
to checksum to be skipped.
Signed-off-by: Laurent Vivier
TCP header and payload are supposed to be in the same buffer,
and tcp_update_check_tcp4()/tcp_update_check_tcp6() compute
the checksum from the base address of the header using the
length of the IP payload.
In the future (for vhost-user) we need to dispatch the TCP header and
the TCP payload through several buffers. To be able to manage that, we
provide an iovec array that points to the data of the TCP frame.
We provide also an offset to be able to provide an array that contains
the TCP frame embedded in an lower level frame, and this offset points
to the TCP header inside the iovec array.
Signed-off-by: Laurent Vivier
On 03/10/2024 16:51, Laurent Vivier wrote:
TCP header and payload are supposed to be in the same buffer, and tcp_update_check_tcp4()/tcp_update_check_tcp6() compute the checksum from the base address of the header using the length of the IP payload.
In the future (for vhost-user) we need to dispatch the TCP header and the TCP payload through several buffers. To be able to manage that, we provide an iovec array that points to the data of the TCP frame. We provide also an offset to be able to provide an array that contains the TCP frame embedded in an lower level frame, and this offset points to the TCP header inside the iovec array.
Signed-off-by: Laurent Vivier
--- Notes: v6: - fix clang-tidy error with ptr - add missing static to tcp_update_check_tcp[4|6]
v5: - s/IPv6/IPv4/ - reintroduce ip6h and iph to avoid iov_size() - check pointer alignment before casting to the type
v4: - replace die() by err() in tcp_update_check_tcp6() too
v3: - replace die() by err() and return - add more information in the error message
v2: - s/payload_offset/l4offset/ - check memory address of the checksum (alignment, iovec boundaries)
checksum.c | 1 - iov.c | 1 - tcp.c | 118 +++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 100 insertions(+), 20 deletions(-)
...
diff --git a/iov.c b/iov.c index 3f9e229a305f..9116dda94247 100644 --- a/iov.c +++ b/iov.c @@ -25,7 +25,6 @@ #include "util.h" #include "iov.h"
- /* iov_skip_bytes() - Skip leading bytes of an IO vector * @iov: IO vector * @n: Number of entries in @iov
This is an unwanted change... could you remove it on merge? Thanks, Laurent
On Thu, 3 Oct 2024 16:55:56 +0200
Laurent Vivier
On 03/10/2024 16:51, Laurent Vivier wrote:
TCP header and payload are supposed to be in the same buffer, and tcp_update_check_tcp4()/tcp_update_check_tcp6() compute the checksum from the base address of the header using the length of the IP payload.
In the future (for vhost-user) we need to dispatch the TCP header and the TCP payload through several buffers. To be able to manage that, we provide an iovec array that points to the data of the TCP frame. We provide also an offset to be able to provide an array that contains the TCP frame embedded in an lower level frame, and this offset points to the TCP header inside the iovec array.
Signed-off-by: Laurent Vivier
--- Notes: v6: - fix clang-tidy error with ptr - add missing static to tcp_update_check_tcp[4|6]
v5: - s/IPv6/IPv4/ - reintroduce ip6h and iph to avoid iov_size() - check pointer alignment before casting to the type
v4: - replace die() by err() in tcp_update_check_tcp6() too
v3: - replace die() by err() and return - add more information in the error message
v2: - s/payload_offset/l4offset/ - check memory address of the checksum (alignment, iovec boundaries)
checksum.c | 1 - iov.c | 1 - tcp.c | 118 +++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 100 insertions(+), 20 deletions(-)
...
diff --git a/iov.c b/iov.c index 3f9e229a305f..9116dda94247 100644 --- a/iov.c +++ b/iov.c @@ -25,7 +25,6 @@ #include "util.h" #include "iov.h"
- /* iov_skip_bytes() - Skip leading bytes of an IO vector * @iov: IO vector * @n: Number of entries in @iov
This is an unwanted change... could you remove it on merge?
Sure. I still have to figure out what causes tests to fail before merging. By applying just this series I haven't seen failures anymore, but I just ran tests twice. It might take a bit. -- Stefano
As for tcp_update_check_tcp4()/tcp_update_check_tcp6(),
change csum_udp4() and csum_udp6() to use an iovec array.
Signed-off-by: Laurent Vivier
On Thu, 3 Oct 2024 16:51:03 +0200
Laurent Vivier
For vhost-user, we will need to spread TCP payload over several buffers. To re-use tcp_update_check_tcp[4|6](), provide an iovec rather than a pointer to a buffer.
This series updates also csum_iov() and pcap_iov() to add an offset of bytes to skip in the iovec array.
It's based on top of "tcp: Use tcp_payload_t rather than tcphdr" that is added in the series for convenience.
v6: update tcp.c with fix for clang-tidy error and add missing static
Laurent Vivier (5): tcp: Use tcp_payload_t rather than tcphdr pcap: Add an offset argument in pcap_iov() checksum: Add an offset argument in csum_iov() tcp: Update TCP checksum using an iovec array udp: Update UDP checksum using an iovec array
I ran tests a few times with just this series, no failures observed. Applied, sorry for the delay. -- Stefano
participants (2)
-
Laurent Vivier
-
Stefano Brivio