summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-11-02 10:32:19 -0700
committerDamjan Marion <dmarion@me.com>2021-11-02 18:23:15 +0000
commit1e6d30bd444fa95df0f08cdef7e899def56c17a7 (patch)
tree2587b6f80ab9d98762f4166bc0bb2e983d66a2ba /src/vnet
parent06e0085a6721d0c3650c9af2cae9b5aa2dc72f88 (diff)
interface: avoid dependency on crc32 for eth handoff
Make sure the infra works on platforms without crc32, like risc-v Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I5f267497bb4e73a91a5320822ca42388f1f8b037
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/CMakeLists.txt2
-rw-r--r--src/vnet/handoff.c4
-rw-r--r--src/vnet/hash/handoff_eth.c (renamed from src/vnet/hash/crc32_handoff_eth.c)47
3 files changed, 32 insertions, 21 deletions
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt
index 395f958185e..5de06da971f 100644
--- a/src/vnet/CMakeLists.txt
+++ b/src/vnet/CMakeLists.txt
@@ -888,7 +888,7 @@ list(APPEND VNET_SOURCES
hash/hash.c
hash/cli.c
hash/crc32_5tuple.c
- hash/crc32_handoff_eth.c
+ hash/handoff_eth.c
)
list(APPEND VNET_HEADERS
diff --git a/src/vnet/handoff.c b/src/vnet/handoff.c
index 15cfd606aba..5d4ef6f5c1b 100644
--- a/src/vnet/handoff.c
+++ b/src/vnet/handoff.c
@@ -229,7 +229,7 @@ interface_handoff_enable_disable (vlib_main_t *vm, u32 sw_if_index,
return VNET_API_ERROR_UNIMPLEMENTED;
d->hash_fn = vnet_hash_function_from_name (
- "handoff_eth_sym_crc32c", VNET_HASH_FN_TYPE_ETHERNET);
+ "handoff-eth-sym", VNET_HASH_FN_TYPE_ETHERNET);
}
else
{
@@ -238,7 +238,7 @@ interface_handoff_enable_disable (vlib_main_t *vm, u32 sw_if_index,
vnet_hash_default_function (VNET_HASH_FN_TYPE_ETHERNET);
else
d->hash_fn = vnet_hash_function_from_name (
- "handoff_eth_crc32c", VNET_HASH_FN_TYPE_ETHERNET);
+ "handoff-eth", VNET_HASH_FN_TYPE_ETHERNET);
}
}
diff --git a/src/vnet/hash/crc32_handoff_eth.c b/src/vnet/hash/handoff_eth.c
index 13fc12ce6ea..dc8db2ac413 100644
--- a/src/vnet/hash/crc32_handoff_eth.c
+++ b/src/vnet/hash/handoff_eth.c
@@ -20,6 +20,17 @@
#include <vnet/ip/ip6_packet.h>
#include <vnet/mpls/packet.h>
#include <vppinfra/crc32.h>
+#include <vppinfra/xxhash.h>
+
+always_inline u32
+ho_hash (u64 key)
+{
+#ifdef clib_crc32c_uses_intrinsics
+ return clib_crc32c ((u8 *) &key, sizeof (key));
+#else
+ return clib_xxhash (key);
+#endif
+}
static inline u64
ipv4_get_key (ip4_header_t * ip)
@@ -235,7 +246,7 @@ eth_get_key (ethernet_header_t * h0)
}
void
-handoff_eth_crc32c_func (void **p, u32 *hash, u32 n_packets)
+handoff_eth_func (void **p, u32 *hash, u32 n_packets)
{
u32 n_left_from = n_packets;
@@ -253,10 +264,10 @@ handoff_eth_crc32c_func (void **p, u32 *hash, u32 n_packets)
key[2] = eth_get_key ((ethernet_header_t *) p[2]);
key[3] = eth_get_key ((ethernet_header_t *) p[3]);
- hash[0] = clib_crc32c ((u8 *) &key[0], sizeof (key[0]));
- hash[1] = clib_crc32c ((u8 *) &key[1], sizeof (key[1]));
- hash[2] = clib_crc32c ((u8 *) &key[2], sizeof (key[2]));
- hash[3] = clib_crc32c ((u8 *) &key[3], sizeof (key[3]));
+ hash[0] = ho_hash (key[0]);
+ hash[1] = ho_hash (key[1]);
+ hash[2] = ho_hash (key[2]);
+ hash[3] = ho_hash (key[3]);
hash += 4;
n_left_from -= 4;
@@ -268,7 +279,7 @@ handoff_eth_crc32c_func (void **p, u32 *hash, u32 n_packets)
u64 key;
key = eth_get_key ((ethernet_header_t *) p[0]);
- hash[0] = clib_crc32c ((u8 *) &key, sizeof (key));
+ hash[0] = ho_hash (key);
hash += 1;
n_left_from -= 1;
@@ -276,15 +287,15 @@ handoff_eth_crc32c_func (void **p, u32 *hash, u32 n_packets)
}
}
-VNET_REGISTER_HASH_FUNCTION (handoff_eth_crc32c, static) = {
- .name = "handoff-eth-crc32c",
+VNET_REGISTER_HASH_FUNCTION (handoff_eth, static) = {
+ .name = "handoff-eth",
.description = "Ethernet/IPv4/IPv6/MPLS headers",
.priority = 2,
- .function[VNET_HASH_FN_TYPE_ETHERNET] = handoff_eth_crc32c_func,
+ .function[VNET_HASH_FN_TYPE_ETHERNET] = handoff_eth_func,
};
void
-handoff_eth_sym_crc32c_func (void **p, u32 *hash, u32 n_packets)
+handoff_eth_sym_func (void **p, u32 *hash, u32 n_packets)
{
u32 n_left_from = n_packets;
@@ -302,10 +313,10 @@ handoff_eth_sym_crc32c_func (void **p, u32 *hash, u32 n_packets)
key[2] = eth_get_sym_key ((ethernet_header_t *) p[2]);
key[3] = eth_get_sym_key ((ethernet_header_t *) p[3]);
- hash[0] = clib_crc32c ((u8 *) &key[0], sizeof (key[0]));
- hash[1] = clib_crc32c ((u8 *) &key[1], sizeof (key[1]));
- hash[2] = clib_crc32c ((u8 *) &key[2], sizeof (key[2]));
- hash[3] = clib_crc32c ((u8 *) &key[3], sizeof (key[3]));
+ hash[0] = ho_hash (key[0]);
+ hash[1] = ho_hash (key[1]);
+ hash[2] = ho_hash (key[2]);
+ hash[3] = ho_hash (key[3]);
hash += 4;
n_left_from -= 4;
@@ -317,7 +328,7 @@ handoff_eth_sym_crc32c_func (void **p, u32 *hash, u32 n_packets)
u64 key;
key = eth_get_sym_key ((ethernet_header_t *) p[0]);
- hash[0] = clib_crc32c ((u8 *) &key, sizeof (key));
+ hash[0] = ho_hash (key);
hash += 1;
n_left_from -= 1;
@@ -325,11 +336,11 @@ handoff_eth_sym_crc32c_func (void **p, u32 *hash, u32 n_packets)
}
}
-VNET_REGISTER_HASH_FUNCTION (handoff_eth_sym_crc32c, static) = {
- .name = "handoff-eth-sym-crc32c",
+VNET_REGISTER_HASH_FUNCTION (handoff_eth_sym, static) = {
+ .name = "handoff-eth-sym",
.description = "Ethernet/IPv4/IPv6/MPLS headers Symmetric",
.priority = 1,
- .function[VNET_HASH_FN_TYPE_ETHERNET] = handoff_eth_sym_crc32c_func,
+ .function[VNET_HASH_FN_TYPE_ETHERNET] = handoff_eth_sym_func,
};
/*