back to topotato report
topotato coverage report
Current view: top level - lib - checksum.h (source / functions) Hit Total Coverage
Test: test_pim6_prune_propagate.py::PIM6PrunePropagate Lines: 7 7 100.0 %
Date: 2023-02-24 18:39:23 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef _FRR_CHECKSUM_H
       2             : #define _FRR_CHECKSUM_H
       3             : 
       4             : #include <stdint.h>
       5             : #include <netinet/in.h>
       6             : 
       7             : #ifdef __cplusplus
       8             : extern "C" {
       9             : #endif
      10             : 
      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             : 
      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         294 : static inline uint16_t in_cksum_with_ph6(const struct ipv6_ph *ph,
      55             :                                          const void *data, size_t nbytes)
      56             : {
      57         294 :         struct iovec iov[2];
      58             : 
      59         294 :         iov[0].iov_base = (void *)ph;
      60         294 :         iov[0].iov_len = sizeof(*ph);
      61         294 :         iov[1].iov_base = (void *)data;
      62         294 :         iov[1].iov_len = nbytes;
      63         294 :         return in_cksumv(iov, array_size(iov));
      64             : }
      65             : 
      66             : #define FLETCHER_CHECKSUM_VALIDATE 0xffff
      67             : extern uint16_t fletcher_checksum(uint8_t *, const size_t len,
      68             :                                   const uint16_t offset);
      69             : 
      70             : #ifdef __cplusplus
      71             : }
      72             : #endif
      73             : 
      74             : #endif /* _FRR_CHECKSUM_H */

Generated by: LCOV version v1.16-topotato