summaryrefslogtreecommitdiffstats
path: root/lib/checksum.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2022-02-26 13:20:16 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2022-02-26 16:49:12 +0100
commit89087f23b589b051910c26ae7772256adacc35a7 (patch)
treec9def558726faf899559f96edd04f727fb54cf29 /lib/checksum.h
parentlib: guard checksum.h against multiple inclusion (diff)
downloadfrr-89087f23b589b051910c26ae7772256adacc35a7.tar.xz
frr-89087f23b589b051910c26ae7772256adacc35a7.zip
lib: use iovec for checksum code
... to allow checksumming noncontiguous blurbs of data. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/checksum.h')
-rw-r--r--lib/checksum.h38
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/checksum.h b/lib/checksum.h
index 16e694542..508c3f38a 100644
--- a/lib/checksum.h
+++ b/lib/checksum.h
@@ -27,9 +27,41 @@ struct ipv6_ph {
uint8_t next_hdr;
} __attribute__((packed));
-extern int in_cksum(void *data, int nbytes);
-extern int in_cksum_with_ph4(struct ipv4_ph *ph, void *data, int nbytes);
-extern int in_cksum_with_ph6(struct ipv6_ph *ph, void *data, int nbytes);
+
+extern uint16_t in_cksumv(const struct iovec *iov, size_t iov_len);
+
+static inline uint16_t in_cksum(const void *data, size_t nbytes)
+{
+ struct iovec iov[1];
+
+ iov[0].iov_base = (void *)data;
+ iov[0].iov_len = nbytes;
+ return in_cksumv(iov, array_size(iov));
+}
+
+static inline uint16_t in_cksum_with_ph4(const struct ipv4_ph *ph,
+ const void *data, size_t nbytes)
+{
+ struct iovec iov[2];
+
+ iov[0].iov_base = (void *)ph;
+ iov[0].iov_len = sizeof(*ph);
+ iov[1].iov_base = (void *)data;
+ iov[1].iov_len = nbytes;
+ return in_cksumv(iov, array_size(iov));
+}
+
+static inline uint16_t in_cksum_with_ph6(const struct ipv6_ph *ph,
+ const void *data, size_t nbytes)
+{
+ struct iovec iov[2];
+
+ iov[0].iov_base = (void *)ph;
+ iov[0].iov_len = sizeof(*ph);
+ iov[1].iov_base = (void *)data;
+ iov[1].iov_len = nbytes;
+ return in_cksumv(iov, array_size(iov));
+}
#define FLETCHER_CHECKSUM_VALIDATE 0xffff
extern uint16_t fletcher_checksum(uint8_t *, const size_t len,