aboutgitcodebugslistschat
path: root/checksum.c
diff options
context:
space:
mode:
Diffstat (limited to 'checksum.c')
-rw-r--r--checksum.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/checksum.c b/checksum.c
index 78c6960..f35c948 100644
--- a/checksum.c
+++ b/checksum.c
@@ -52,6 +52,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <linux/icmp.h>
#include <linux/icmpv6.h>
/**
@@ -108,6 +109,21 @@ uint16_t csum_unaligned(const void *buf, size_t len, uint32_t init)
}
/**
+ * csum_icmp4() - Calculate and set checksum for an ICMP packet
+ * @icmp4hr: ICMP header, initialised apart from checksum
+ * @payload: ICMP packet payload
+ * @len: Length of @payload (not including ICMP header)
+ */
+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));
+
+ icmp4hr->checksum = 0;
+ icmp4hr->checksum = csum_unaligned(payload, len, psum);
+}
+
+/**
* csum_icmp6() - Calculate and set checksum for an ICMPv6 packet
* @icmp6hr: ICMPv6 header, initialised apart from checksum
* @saddr: IPv6 source address