aboutgitcodebugslistschat
path: root/icmp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-01 16:53:49 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-02 16:13:23 +0200
commit5566386f5f1134c86db82464a4c10656ef1e11fe (patch)
treea30c8aeb05689d3eb730c92858661c212b55b5c6 /icmp.c
parent9e22c53aa92552bd5c015c2597512056f8def4d8 (diff)
downloadpasst-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 'icmp.c')
-rw-r--r--icmp.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/icmp.c b/icmp.c
index 76bb9e9..1c5cf84 100644
--- a/icmp.c
+++ b/icmp.c
@@ -224,8 +224,8 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
union sockaddr_inany sa = { .sa_family = af };
const socklen_t sl = af == AF_INET ? sizeof(sa.sa4) : sizeof(sa.sa6);
struct icmp_ping_flow *pingf, **id_sock;
+ size_t dlen, l4len;
uint16_t id, seq;
- size_t plen;
void *pkt;
(void)saddr;
@@ -234,11 +234,11 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
if (af == AF_INET) {
const struct icmphdr *ih;
- if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &plen)))
+ if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &dlen)))
return 1;
ih = (struct icmphdr *)pkt;
- plen += sizeof(*ih);
+ l4len = dlen + sizeof(*ih);
if (ih->type != ICMP_ECHO)
return 1;
@@ -250,11 +250,11 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
} else if (af == AF_INET6) {
const struct icmp6hdr *ih;
- if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &plen)))
+ if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &dlen)))
return 1;
ih = (struct icmp6hdr *)pkt;
- plen += sizeof(*ih);
+ l4len = dlen + sizeof(*ih);
if (ih->icmp6_type != ICMPV6_ECHO_REQUEST)
return 1;
@@ -274,7 +274,7 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
pingf->ts = now->tv_sec;
- if (sendto(pingf->sock, pkt, plen, MSG_NOSIGNAL, &sa.sa, sl) < 0) {
+ if (sendto(pingf->sock, pkt, l4len, MSG_NOSIGNAL, &sa.sa, sl) < 0) {
flow_dbg(pingf, "failed to relay request to socket: %s",
strerror(errno));
} else {