]> git.proxmox.com Git - mirror_frr.git/blame - lib/checksum.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / checksum.h
CommitLineData
264c806d
DL
1#ifndef _FRR_CHECKSUM_H
2#define _FRR_CHECKSUM_H
3
17b48d7d
QY
4#include <stdint.h>
5#include <netinet/in.h>
6
5e244469
RW
7#ifdef __cplusplus
8extern "C" {
9#endif
10
17b48d7d
QY
11
12/* IPv4 pseudoheader */
13struct ipv4_ph {
14 struct in_addr src;
15 struct in_addr dst;
16 uint8_t rsvd;
17 uint8_t proto;
18 uint16_t len;
19} __attribute__((packed));
20
21/* IPv6 pseudoheader */
22struct ipv6_ph {
23 struct in6_addr src;
24 struct in6_addr dst;
25 uint32_t ulpl;
26 uint8_t zero[3];
27 uint8_t next_hdr;
28} __attribute__((packed));
29
89087f23
DL
30
31extern uint16_t in_cksumv(const struct iovec *iov, size_t iov_len);
32
33static inline uint16_t in_cksum(const void *data, size_t nbytes)
34{
35 struct iovec iov[1];
36
37 iov[0].iov_base = (void *)data;
38 iov[0].iov_len = nbytes;
39 return in_cksumv(iov, array_size(iov));
40}
41
42static inline uint16_t in_cksum_with_ph4(const struct ipv4_ph *ph,
43 const void *data, size_t nbytes)
44{
45 struct iovec iov[2];
46
47 iov[0].iov_base = (void *)ph;
48 iov[0].iov_len = sizeof(*ph);
49 iov[1].iov_base = (void *)data;
50 iov[1].iov_len = nbytes;
51 return in_cksumv(iov, array_size(iov));
52}
53
54static inline uint16_t in_cksum_with_ph6(const struct ipv6_ph *ph,
55 const void *data, size_t nbytes)
56{
57 struct iovec iov[2];
58
59 iov[0].iov_base = (void *)ph;
60 iov[0].iov_len = sizeof(*ph);
61 iov[1].iov_base = (void *)data;
62 iov[1].iov_len = nbytes;
63 return in_cksumv(iov, array_size(iov));
64}
17b48d7d 65
d8a4e42b 66#define FLETCHER_CHECKSUM_VALIDATE 0xffff
d7c0a89a
QY
67extern uint16_t fletcher_checksum(uint8_t *, const size_t len,
68 const uint16_t offset);
5e244469
RW
69
70#ifdef __cplusplus
71}
72#endif
264c806d
DL
73
74#endif /* _FRR_CHECKSUM_H */