2 * SPDX-License-Identifier: Apache-2.0
3 * Copyright(c) 2021 Cisco Systems, Inc.
6 #ifndef included_ip_psh_cksum_h
7 #define included_ip_psh_cksum_h
9 #include <vnet/ip/ip.h>
10 #include <vppinfra/vector/ip_csum.h>
12 typedef struct _ip4_psh
21 typedef struct _ip6_psh
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");
32 static_always_inline u16
33 ip4_pseudo_header_cksum (ip4_header_t *ip4)
35 ip4_psh_t psh = { 0 };
36 psh.src = ip4->src_address;
37 psh.dst = ip4->dst_address;
38 psh.proto = ip4->protocol;
39 psh.l4len = clib_host_to_net_u16 (clib_net_to_host_u16 (ip4->length) -
40 sizeof (ip4_header_t));
41 return ~clib_net_to_host_u16 (
42 clib_ip_csum ((u8 *) &psh, sizeof (ip4_psh_t)));
45 static_always_inline u16
46 ip6_pseudo_header_cksum (ip6_header_t *ip6)
48 ip6_psh_t psh = { 0 };
49 psh.src = ip6->src_address;
50 psh.dst = ip6->dst_address;
51 psh.l4len = ip6->payload_length;
52 psh.proto = clib_host_to_net_u32 ((u32) ip6->protocol);
53 return ~clib_net_to_host_u16 (
54 clib_ip_csum ((u8 *) &psh, sizeof (ip6_psh_t)));
57 #endif /* included_ip_psh_cksum_h */