LCOV - code coverage report
Current view: top level - vnet/ip - ip_psh_cksum.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 14 14 100.0 %
Date: 2023-10-26 01:39:38 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: Apache-2.0
       3             :  * Copyright(c) 2021 Cisco Systems, Inc.
       4             :  */
       5             : 
       6             : #ifndef included_ip_psh_cksum_h
       7             : #define included_ip_psh_cksum_h
       8             : 
       9             : #include <vnet/ip/ip.h>
      10             : #include <vppinfra/vector/ip_csum.h>
      11             : 
      12             : typedef struct _ip4_psh
      13             : {
      14             :   ip4_address_t src;
      15             :   ip4_address_t dst;
      16             :   u8 zero;
      17             :   u8 proto;
      18             :   u16 l4len;
      19             : } ip4_psh_t;
      20             : 
      21             : typedef struct _ip6_psh
      22             : {
      23             :   ip6_address_t src;
      24             :   ip6_address_t dst;
      25             :   u32 l4len;
      26             :   u32 proto;
      27             : } ip6_psh_t;
      28             : 
      29             : STATIC_ASSERT (sizeof (ip4_psh_t) == 12, "ipv4 pseudo header is 12B");
      30             : STATIC_ASSERT (sizeof (ip6_psh_t) == 40, "ipv6 pseudo header is 40B");
      31             : 
      32             : static_always_inline u16
      33      677144 : ip4_pseudo_header_cksum (ip4_header_t *ip4)
      34             : {
      35      677144 :   ip4_psh_t psh = { 0 };
      36      677144 :   psh.src = ip4->src_address;
      37      677144 :   psh.dst = ip4->dst_address;
      38      677144 :   psh.proto = ip4->protocol;
      39      677144 :   psh.l4len = clib_host_to_net_u16 (clib_net_to_host_u16 (ip4->length) -
      40             :                                     sizeof (ip4_header_t));
      41      677144 :   return ~(clib_ip_csum ((u8 *) &psh, sizeof (ip4_psh_t)));
      42             : }
      43             : 
      44             : static_always_inline u16
      45      551359 : ip6_pseudo_header_cksum (ip6_header_t *ip6)
      46             : {
      47      551359 :   ip6_psh_t psh = { 0 };
      48      551359 :   psh.src = ip6->src_address;
      49      551359 :   psh.dst = ip6->dst_address;
      50      551359 :   psh.l4len = ip6->payload_length;
      51      551359 :   psh.proto = clib_host_to_net_u32 ((u32) ip6->protocol);
      52      551359 :   return ~(clib_ip_csum ((u8 *) &psh, sizeof (ip6_psh_t)));
      53             : }
      54             : 
      55             : #endif /* included_ip_psh_cksum_h */

Generated by: LCOV version 1.14