]>
Commit | Line | Data |
---|---|---|
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 |
8 | extern "C" { | |
9 | #endif | |
10 | ||
17b48d7d QY |
11 | |
12 | /* IPv4 pseudoheader */ | |
13 | struct 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 */ | |
22 | struct 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 | |
31 | extern uint16_t in_cksumv(const struct iovec *iov, size_t iov_len); | |
32 | ||
33 | static 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 | ||
42 | static 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 | ||
54 | static 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 |
67 | extern 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 */ |