aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/ip_psh_cksum.h
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2021-02-23 15:55:04 +0100
committerBeno�t Ganne <bganne@cisco.com>2021-10-01 10:04:24 +0000
commitf5462369f3ad22c9d19f54832faa2b6e61449f66 (patch)
treeaf4c5d3a0218f482b92501b81bdae36cfcfc4d20 /src/vnet/ip/ip_psh_cksum.h
parentde3caf37c64431c199fe649256b268010ce6a4f3 (diff)
devices: add support for pseudo header checksum
Type: improvement Linux uses pseudo header checksum when checksum of l4 is offloaded. This patch adds similar support in virtual interfaces. Change-Id: I6a94d1104e59356f95057e7c122e3be9cd8659a3 Signed-off-by: Aloys Augustin <aloaugus@cisco.com> Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Diffstat (limited to 'src/vnet/ip/ip_psh_cksum.h')
-rw-r--r--src/vnet/ip/ip_psh_cksum.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/vnet/ip/ip_psh_cksum.h b/src/vnet/ip/ip_psh_cksum.h
new file mode 100644
index 00000000000..eaac401f223
--- /dev/null
+++ b/src/vnet/ip/ip_psh_cksum.h
@@ -0,0 +1,54 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2021 Cisco Systems, Inc.
+ */
+
+#ifndef included_ip_psh_cksum_h
+#define included_ip_psh_cksum_h
+
+#include <vnet/ip/ip.h>
+
+typedef struct _ip4_psh
+{
+ ip4_address_t src;
+ ip4_address_t dst;
+ u8 zero;
+ u8 proto;
+ u16 l4len;
+} ip4_psh_t;
+
+typedef struct _ip6_psh
+{
+ ip6_address_t src;
+ ip6_address_t dst;
+ u32 l4len;
+ u32 proto;
+} ip6_psh_t;
+
+STATIC_ASSERT (sizeof (ip4_psh_t) == 12, "ipv4 pseudo header is 12B");
+STATIC_ASSERT (sizeof (ip6_psh_t) == 40, "ipv6 pseudo header is 40B");
+
+static_always_inline u16
+ip4_pseudo_header_cksum (ip4_header_t *ip4)
+{
+ ip4_psh_t psh = { 0 };
+ psh.src = ip4->src_address;
+ psh.dst = ip4->dst_address;
+ psh.proto = ip4->protocol;
+ psh.l4len = clib_host_to_net_u16 (clib_net_to_host_u16 (ip4->length) -
+ sizeof (ip4_header_t));
+ return ~clib_net_to_host_u16 (ip_csum (&psh, sizeof (ip4_psh_t)));
+}
+
+static_always_inline u16
+ip6_pseudo_header_cksum (ip6_header_t *ip6)
+{
+ ip6_psh_t psh = { 0 };
+ psh.src = ip6->src_address;
+ psh.dst = ip6->dst_address;
+ psh.l4len = ip6->payload_length;
+ psh.proto = clib_host_to_net_u32 ((u32) ip6->protocol);
+ return ~clib_net_to_host_u16 (ip_csum (&psh, sizeof (ip6_psh_t)));
+}
+
+#endif /* included_ip_psh_cksum_h */