aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-01 16:53:50 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-02 16:13:26 +0200
commit68d1b0a1528d6efd0d94afa43e9fc4b4857ca694 (patch)
tree39cf2db4798d377b90d73b3ddd016532cf4a2150 /tcp.c
parent5566386f5f1134c86db82464a4c10656ef1e11fe (diff)
downloadpasst-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.tar
passt-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.tar.gz
passt-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.tar.bz2
passt-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.tar.lz
passt-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.tar.xz
passt-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.tar.zst
passt-68d1b0a1528d6efd0d94afa43e9fc4b4857ca694.zip
tcp: Simplify packet length calculation when preparing headers
tcp_fill_headers[46]() compute the L3 packet length from the L4 packet length, then their caller tcp_l2_buf_fill_headers() converts it back to the L4 packet length. We can just use the L4 length throughout. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>eewwee Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/tcp.c b/tcp.c
index f8b31c1..43206d0 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1341,7 +1341,7 @@ static void tcp_fill_header(struct tcphdr *th,
* @check: Checksum, if already known
* @seq: Sequence number for this segment
*
- * Return: The total length of the IPv4 packet, host order
+ * Return: The IPv4 payload length, host order
*/
static size_t tcp_fill_headers4(const struct ctx *c,
const struct tcp_tap_conn *conn,
@@ -1367,7 +1367,7 @@ static size_t tcp_fill_headers4(const struct ctx *c,
tcp_update_check_tcp4(iph, th);
- return l3len;
+ return l4len;
}
/**
@@ -1380,7 +1380,7 @@ static size_t tcp_fill_headers4(const struct ctx *c,
* @check: Checksum, if already known
* @seq: Sequence number for this segment
*
- * Return: The total length of the IPv6 packet, host order
+ * Return: The IPv6 payload length, host order
*/
static size_t tcp_fill_headers6(const struct ctx *c,
const struct tcp_tap_conn *conn,
@@ -1388,7 +1388,6 @@ static size_t tcp_fill_headers6(const struct ctx *c,
size_t dlen, uint32_t seq)
{
size_t l4len = dlen + sizeof(*th);
- size_t l3len = l4len + sizeof(*ip6h);
ip6h->payload_len = htons(l4len);
ip6h->saddr = conn->faddr.a6;
@@ -1409,7 +1408,7 @@ static size_t tcp_fill_headers6(const struct ctx *c,
tcp_update_check_tcp6(ip6h, th);
- return l3len;
+ return l4len;
}
/**
@@ -1429,21 +1428,16 @@ static size_t tcp_l2_buf_fill_headers(const struct ctx *c,
const uint16_t *check, uint32_t seq)
{
const struct in_addr *a4 = inany_v4(&conn->faddr);
- size_t l3len, l4len;
if (a4) {
- l3len = tcp_fill_headers4(c, conn, iov[TCP_IOV_IP].iov_base,
- iov[TCP_IOV_PAYLOAD].iov_base, dlen,
- check, seq);
- l4len = l3len - sizeof(struct iphdr);
- } else {
- l3len = tcp_fill_headers6(c, conn, iov[TCP_IOV_IP].iov_base,
- iov[TCP_IOV_PAYLOAD].iov_base, dlen,
- seq);
- l4len = l3len - sizeof(struct ipv6hdr);
+ return tcp_fill_headers4(c, conn, iov[TCP_IOV_IP].iov_base,
+ iov[TCP_IOV_PAYLOAD].iov_base, dlen,
+ check, seq);
}
- return l4len;
+ return tcp_fill_headers6(c, conn, iov[TCP_IOV_IP].iov_base,
+ iov[TCP_IOV_PAYLOAD].iov_base, dlen,
+ seq);
}
/**