diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-05-01 16:53:49 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-05-02 16:13:23 +0200 |
commit | 5566386f5f1134c86db82464a4c10656ef1e11fe (patch) | |
tree | a30c8aeb05689d3eb730c92858661c212b55b5c6 /udp.c | |
parent | 9e22c53aa92552bd5c015c2597512056f8def4d8 (diff) | |
download | passt-5566386f5f1134c86db82464a4c10656ef1e11fe.tar passt-5566386f5f1134c86db82464a4c10656ef1e11fe.tar.gz passt-5566386f5f1134c86db82464a4c10656ef1e11fe.tar.bz2 passt-5566386f5f1134c86db82464a4c10656ef1e11fe.tar.lz passt-5566386f5f1134c86db82464a4c10656ef1e11fe.tar.xz passt-5566386f5f1134c86db82464a4c10656ef1e11fe.tar.zst passt-5566386f5f1134c86db82464a4c10656ef1e11fe.zip |
treewide: Standardise variable names for various packet lengths
At various points we need to track the lengths of a packet including or
excluding various different sets of headers. We don't always use the same
variable names for doing so. Worse in some places we use the same name
for different things: e.g. tcp_fill_headers[46]() use ip_len for the
length including the IP headers, but then tcp_send_flag() which calls it
uses it to mean the IP payload length only.
To improve clarity, standardise on these names:
dlen: L4 protocol payload length ("data length")
l4len: plen + length of L4 protocol header
l3len: l4len + length of IPv4/IPv6 header
l2len: l3len + length of L2 (ethernet) header
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'udp.c')
-rw-r--r-- | udp.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -570,16 +570,16 @@ static void udp_splice_sendfrom(const struct ctx *c, unsigned start, unsigned n, * @c: Execution context * @b: Pointer to udp4_l2_buf to update * @dstport: Destination port number - * @datalen: Length of UDP payload + * @dlen: Length of UDP payload * @now: Current timestamp * * Return: size of tap frame with headers */ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b, - in_port_t dstport, size_t datalen, + in_port_t dstport, size_t dlen, const struct timespec *now) { - size_t ip_len = datalen + sizeof(b->iph) + sizeof(b->uh); + size_t l3len = dlen + sizeof(b->iph) + sizeof(b->uh); in_port_t srcport = ntohs(b->s_in.sin_port); struct in_addr src = b->s_in.sin_addr; @@ -602,17 +602,17 @@ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b, src = c->ip4.gw; } - b->iph.tot_len = htons(ip_len); + b->iph.tot_len = htons(l3len); b->iph.daddr = c->ip4.addr_seen.s_addr; b->iph.saddr = src.s_addr; - b->iph.check = csum_ip4_header(ip_len, IPPROTO_UDP, + b->iph.check = csum_ip4_header(l3len, IPPROTO_UDP, src, c->ip4.addr_seen); b->uh.source = b->s_in.sin_port; b->uh.dest = htons(dstport); - b->uh.len = htons(datalen + sizeof(b->uh)); + b->uh.len = htons(dlen + sizeof(b->uh)); - return tap_frame_len(c, &b->taph, ip_len + sizeof(b->eh)); + return tap_frame_len(c, &b->taph, l3len + sizeof(b->eh)); } /** @@ -620,19 +620,19 @@ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b, * @c: Execution context * @b: Pointer to udp6_l2_buf to update * @dstport: Destination port number - * @datalen: Length of UDP payload + * @dlen: Length of UDP payload * @now: Current timestamp * * Return: size of tap frame with headers */ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b, - in_port_t dstport, size_t datalen, + in_port_t dstport, size_t dlen, const struct timespec *now) { const struct in6_addr *src = &b->s_in6.sin6_addr; const struct in6_addr *dst = &c->ip6.addr_seen; - uint16_t payload_len = datalen + sizeof(b->uh); in_port_t srcport = ntohs(b->s_in6.sin6_port); + uint16_t l4len = dlen + sizeof(b->uh); if (IN6_IS_ADDR_LINKLOCAL(src)) { dst = &c->ip6.addr_ll_seen; @@ -668,7 +668,7 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b, } - b->ip6h.payload_len = htons(payload_len); + b->ip6h.payload_len = htons(l4len); b->ip6h.daddr = *dst; b->ip6h.saddr = *src; b->ip6h.version = 6; @@ -678,9 +678,9 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b, b->uh.source = b->s_in6.sin6_port; b->uh.dest = htons(dstport); b->uh.len = b->ip6h.payload_len; - csum_udp6(&b->uh, src, dst, b->data, datalen); + csum_udp6(&b->uh, src, dst, b->data, dlen); - return tap_frame_len(c, &b->taph, payload_len + + return tap_frame_len(c, &b->taph, l4len + sizeof(b->ip6h) + sizeof(b->eh)); } |