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>
11 typedef struct _ip4_psh
20 typedef struct _ip6_psh
28 STATIC_ASSERT (sizeof (ip4_psh_t) == 12, "ipv4 pseudo header is 12B");
29 STATIC_ASSERT (sizeof (ip6_psh_t) == 40, "ipv6 pseudo header is 40B");
31 static_always_inline u16
32 ip4_pseudo_header_cksum (ip4_header_t *ip4)
34 ip4_psh_t psh = { 0 };
35 psh.src = ip4->src_address;
36 psh.dst = ip4->dst_address;
37 psh.proto = ip4->protocol;
38 psh.l4len = clib_host_to_net_u16 (clib_net_to_host_u16 (ip4->length) -
39 sizeof (ip4_header_t));
40 return ~clib_net_to_host_u16 (ip_csum (&psh, sizeof (ip4_psh_t)));
43 static_always_inline u16
44 ip6_pseudo_header_cksum (ip6_header_t *ip6)
46 ip6_psh_t psh = { 0 };
47 psh.src = ip6->src_address;
48 psh.dst = ip6->dst_address;
49 psh.l4len = ip6->payload_length;
50 psh.proto = clib_host_to_net_u32 ((u32) ip6->protocol);
51 return ~clib_net_to_host_u16 (ip_csum (&psh, sizeof (ip6_psh_t)));
54 #endif /* included_ip_psh_cksum_h */