On 26/09/2024 15:29, 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 <lvivier(a)redhat.com> --- checksum.c | 1 - tcp.c | 127 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 99 insertions(+), 29 deletions(-).../** * tcp_update_check_tcp6() - Calculate TCP checksum for IPv6 - * @ip6h: IPv6 header - * @bp: TCP header followed by TCP payload - */ -static void tcp_update_check_tcp6(const struct ipv6hdr *ip6h, - struct tcp_payload_t *bp) + * @src: IPv6 source address + * @dst: IPv6 destination address + * @iov: Pointer to the array of IO vectors + * @iov_cnt: Length of the array + * @l4offset: IPv6 payload offset in the iovec array + */ +void tcp_update_check_tcp6(const struct in6_addr *src, + const struct in6_addr *dst, + const struct iovec *iov, int iov_cnt, + size_t l4offset) { - uint16_t l4len = ntohs(ip6h->payload_len); - uint32_t sum = proto_ipv6_header_psum(l4len, IPPROTO_TCP, - &ip6h->saddr, &ip6h->daddr); + size_t check_ofs; + __sum16 *check; + int check_idx; + uint32_t sum; + + sum = proto_ipv6_header_psum(iov_size(iov, iov_cnt) - l4offset, + IPPROTO_TCP, src, dst); - bp->th.check = 0; - bp->th.check = csum(bp, l4len, sum); + check_idx = iov_skip_bytes(iov, iov_cnt, + l4offset + offsetof(struct tcphdr, check), + &check_ofs); + + if (check_idx >= iov_cnt) + die("TCP6 buffer is too small"); + if (check_ofs + sizeof(*check) > iov[check_idx].iov_len) + die("TCP6 checksum field memory is not contiguous"); +I'm going to resend, I forgot to update tcp_update_check_tcp6(). Laurent