summaryrefslogtreecommitdiff
path: root/lib/checksum.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2019-01-22 22:39:47 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2019-05-17 00:27:08 +0000
commit17b48d7d1150ba4b4ee689a925f54b2a236b1d23 (patch)
tree434525bfc4b4599497b63e9aede3705a70ea7ee7 /lib/checksum.c
parentb523b2419e1da54c906ab5a5892ea91f47b94acb (diff)
lib: add internet checksum with pseudoheaders
Add convenience functions to compute the Internet checksum of a data block, including a pseudoheader. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/checksum.c')
-rw-r--r--lib/checksum.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/checksum.c b/lib/checksum.c
index 18e3850474..3473370041 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -46,6 +46,24 @@ int /* return checksum in low-order 16 bits */
return (answer);
}
+int in_cksum_with_ph4(struct ipv4_ph *ph, void *data, int nbytes)
+{
+ uint8_t dat[sizeof(struct ipv4_ph) + nbytes];
+
+ memcpy(dat, ph, sizeof(struct ipv4_ph));
+ memcpy(dat + sizeof(struct ipv4_ph), data, nbytes);
+ return in_cksum(dat, sizeof(dat));
+}
+
+int in_cksum_with_ph6(struct ipv6_ph *ph, void *data, int nbytes)
+{
+ uint8_t dat[sizeof(struct ipv6_ph) + nbytes];
+
+ memcpy(dat, ph, sizeof(struct ipv6_ph));
+ memcpy(dat + sizeof(struct ipv6_ph), data, nbytes);
+ return in_cksum(dat, sizeof(dat));
+}
+
/* Fletcher Checksum -- Refer to RFC1008. */
#define MODX 4102U /* 5802 should be fine */