aboutgitcodebugslistschat
path: root/checksum.c
diff options
context:
space:
mode:
authorLaurent Vivier <lvivier@redhat.com>2024-10-03 16:51:08 +0200
committerStefano Brivio <sbrivio@redhat.com>2024-10-04 14:51:13 +0200
commit151dbe0d3d3690978a0a5cf3b8fa9808bd708668 (patch)
tree0f0b3daf785a837b8648b55b3ad2fa6ea5aad7f0 /checksum.c
parent3d484aa370902873bd42a434fa856b9ee3eac228 (diff)
downloadpasst-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.tar
passt-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.tar.gz
passt-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.tar.bz2
passt-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.tar.lz
passt-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.tar.xz
passt-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.tar.zst
passt-151dbe0d3d3690978a0a5cf3b8fa9808bd708668.zip
udp: Update UDP checksum using an iovec array
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 <lvivier@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'checksum.c')
-rw-r--r--checksum.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/checksum.c b/checksum.c
index cf85019..c673993 100644
--- a/checksum.c
+++ b/checksum.c
@@ -166,22 +166,24 @@ uint32_t proto_ipv4_header_psum(uint16_t l4len, uint8_t protocol,
* @udp4hr: UDP header, initialised apart from checksum
* @saddr: IPv4 source address
* @daddr: IPv4 destination address
- * @payload: UDP packet payload
- * @dlen: Length of @payload (not including UDP header)
+ * @iov: Pointer to the array of IO vectors
+ * @iov_cnt: Length of the array
+ * @offset: UDP payload offset in the iovec array
*/
void csum_udp4(struct udphdr *udp4hr,
struct in_addr saddr, struct in_addr daddr,
- const void *payload, size_t dlen)
+ const struct iovec *iov, int iov_cnt, size_t offset)
{
/* UDP checksums are optional, so don't bother */
udp4hr->check = 0;
if (UDP4_REAL_CHECKSUMS) {
- uint16_t l4len = dlen + sizeof(struct udphdr);
+ uint16_t l4len = iov_size(iov, iov_cnt) - offset +
+ sizeof(struct udphdr);
uint32_t psum = proto_ipv4_header_psum(l4len, IPPROTO_UDP,
saddr, daddr);
psum = csum_unfolded(udp4hr, sizeof(struct udphdr), psum);
- udp4hr->check = csum(payload, dlen, psum);
+ udp4hr->check = csum_iov(iov, iov_cnt, offset, psum);
}
}
@@ -227,19 +229,24 @@ uint32_t proto_ipv6_header_psum(uint16_t payload_len, uint8_t protocol,
/**
* csum_udp6() - Calculate and set checksum for a UDP over IPv6 packet
* @udp6hr: UDP header, initialised apart from checksum
- * @payload: UDP packet payload
- * @dlen: Length of @payload (not including UDP header)
+ * @saddr: Source address
+ * @daddr: Destination address
+ * @iov: Pointer to the array of IO vectors
+ * @iov_cnt: Length of the array
+ * @offset: UDP payload offset in the iovec array
*/
void csum_udp6(struct udphdr *udp6hr,
const struct in6_addr *saddr, const struct in6_addr *daddr,
- const void *payload, size_t dlen)
+ const struct iovec *iov, int iov_cnt, size_t offset)
{
- uint32_t psum = proto_ipv6_header_psum(dlen + sizeof(struct udphdr),
- IPPROTO_UDP, saddr, daddr);
+ uint16_t l4len = iov_size(iov, iov_cnt) - offset +
+ sizeof(struct udphdr);
+ uint32_t psum = proto_ipv6_header_psum(l4len, IPPROTO_UDP,
+ saddr, daddr);
udp6hr->check = 0;
psum = csum_unfolded(udp6hr, sizeof(struct udphdr), psum);
- udp6hr->check = csum(payload, dlen, psum);
+ udp6hr->check = csum_iov(iov, iov_cnt, offset, psum);
}
/**