diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-11-27 14:54:08 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-11-28 14:03:16 +0100 |
commit | 2abf5ab7f3734eae9377cfab4759ae83fabf3a7e (patch) | |
tree | 52228cc67321b7565287eb60211f54308173abe9 /tcp_vu.c | |
parent | 08ea3cc581beed16afff3fa934f31cbdb82cbb95 (diff) | |
download | passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.tar passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.tar.gz passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.tar.bz2 passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.tar.lz passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.tar.xz passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.tar.zst passt-2abf5ab7f3734eae9377cfab4759ae83fabf3a7e.zip |
tcp: Merge tcp_update_check_tcp[46]()
The only reason we need separate functions for the IPv4 and IPv6 case is
to calculate the checksum of the IP pseudo-header, which is different for
the two cases. However, the caller already knows which path it's on and
can access the values needed for the pseudo-header partial sum more easily
than tcp_update_check_tcp[46]() can.
So, merge these functions into a single tcp_update_csum() function that
just takes the pseudo-header partial sum, calculated in the caller.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp_vu.c')
-rw-r--r-- | tcp_vu.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -71,22 +71,28 @@ static void tcp_vu_update_check(const struct flowside *tapside, struct iovec *iov, int iov_cnt) { char *base = iov[0].iov_base; + struct iov_tail payload; + struct tcphdr *th; + uint32_t psum; if (inany_v4(&tapside->oaddr)) { - struct tcphdr *th = vu_payloadv4(base); + const struct in_addr *src4 = inany_v4(&tapside->oaddr); + const struct in_addr *dst4 = inany_v4(&tapside->eaddr); const struct iphdr *iph = vu_ip(base); - struct iov_tail payload = IOV_TAIL(iov, iov_cnt, - (char *)(th + 1) - base); + size_t l4len = ntohs(iph->tot_len) - sizeof(*iph); - tcp_update_check_tcp4(iph, th, &payload); + th = vu_payloadv4(base); + psum = proto_ipv4_header_psum(l4len, IPPROTO_TCP, *src4, *dst4); } else { - struct tcphdr *th = vu_payloadv6(base); const struct ipv6hdr *ip6h = vu_ip(base); - struct iov_tail payload = IOV_TAIL(iov, iov_cnt, - (char *)(th + 1) - base); + size_t l4len = ntohs(ip6h->payload_len); - tcp_update_check_tcp6(ip6h, th, &payload); + th = vu_payloadv6(base); + psum = proto_ipv6_header_psum(l4len, IPPROTO_TCP, + &ip6h->saddr, &ip6h->daddr); } + payload = IOV_TAIL(iov, iov_cnt, (char *)(th + 1) - base); + tcp_update_csum(psum, th, &payload); } /** |