public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] checksum: Fix calculation for ICMP checksum on IPv4
@ 2022-10-25 16:07 Stefano Brivio
  2022-10-25 17:25 ` Stefano Brivio
  2022-10-26  0:06 ` David Gibson
  0 siblings, 2 replies; 6+ messages in thread
From: Stefano Brivio @ 2022-10-25 16:07 UTC (permalink / raw)
  To: passt-dev; +Cc: Paul Holzinger, David Gibson

We need to zero out the checksum field before calculating the
checksum, of course. I have no idea how this passed the "icmp" test
set, looking into it.

Reported-by: Paul Holzinger <pholzing@redhat.com>
Fixes: 67ab6171729c ("Add csum_icmp4() helper for calculating ICMP checksums")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 checksum.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/checksum.c b/checksum.c
index 09d2c7c..c59869c 100644
--- a/checksum.c
+++ b/checksum.c
@@ -160,10 +160,13 @@ void csum_udp4(struct udphdr *udp4hr, in_addr_t saddr, in_addr_t daddr,
  */
 void csum_icmp4(struct icmphdr *icmp4hr, const void *payload, size_t len)
 {
-	/* Partial checksum for ICMP header alone */
-	uint32_t psum = sum_16b(icmp4hr, sizeof(*icmp4hr));
+	uint32_t psum;
 
 	icmp4hr->checksum = 0;
+
+	/* Partial checksum for ICMP header alone */
+	psum = sum_16b(icmp4hr, sizeof(*icmp4hr));
+
 	icmp4hr->checksum = csum_unaligned(payload, len, psum);
 }
 
-- 
@@ -160,10 +160,13 @@ void csum_udp4(struct udphdr *udp4hr, in_addr_t saddr, in_addr_t daddr,
  */
 void csum_icmp4(struct icmphdr *icmp4hr, const void *payload, size_t len)
 {
-	/* Partial checksum for ICMP header alone */
-	uint32_t psum = sum_16b(icmp4hr, sizeof(*icmp4hr));
+	uint32_t psum;
 
 	icmp4hr->checksum = 0;
+
+	/* Partial checksum for ICMP header alone */
+	psum = sum_16b(icmp4hr, sizeof(*icmp4hr));
+
 	icmp4hr->checksum = csum_unaligned(payload, len, psum);
 }
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-26 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25 16:07 [PATCH] checksum: Fix calculation for ICMP checksum on IPv4 Stefano Brivio
2022-10-25 17:25 ` Stefano Brivio
2022-10-26  0:06 ` David Gibson
     [not found]   ` <CAFsF8v+x-c=Rk6z+-hwwFWt0PvEu10u-rpkQ4F=Z2jbfAJPoww@mail.gmail.com>
2022-10-26 12:57     ` Stefano Brivio
     [not found]       ` <CAFsF8vLk_Qyva32Z5pH5Jic+NeFKrnaPLm_pw_QDARfjdiXQvQ@mail.gmail.com>
2022-10-26 13:40         ` Stefano Brivio
2022-10-26 14:28           ` Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).