2 * SPDX-License-Identifier: Apache-2.0
3 * Copyright(c) 2021 Cisco Systems, Inc.
6 #ifndef __VNET_HASH_H__
7 #define __VNET_HASH_H__
11 #define foreach_vnet_hash_fn_types \
12 _ (ETHERNET, 0, "hash-fn-ethernet") \
13 _ (IP, 1, "hash-fn-ip")
17 #define _(f, n, s) VNET_HASH_FN_TYPE_##f,
18 foreach_vnet_hash_fn_types
21 } vnet_hash_fn_type_t;
23 typedef void (*vnet_hash_fn_t) (void **p, u32 *h, u32 n_packets);
25 typedef struct vnet_hash_function_registration
28 const char *description;
30 vnet_hash_fn_t function[VNET_HASH_FN_TYPE_N];
32 struct vnet_hash_function_registration *next;
33 } vnet_hash_function_registration_t;
37 vnet_hash_function_registration_t *hash_registrations;
40 extern vnet_hash_main_t vnet_hash_main;
42 #define VNET_REGISTER_HASH_FUNCTION(x, ...) \
43 __VA_ARGS__ vnet_hash_function_registration_t __vnet_hash_function_##x; \
44 static void __clib_constructor __vnet_hash_function_registration_##x (void) \
46 vnet_hash_main_t *hm = &vnet_hash_main; \
47 __vnet_hash_function_##x.next = hm->hash_registrations; \
48 hm->hash_registrations = &__vnet_hash_function_##x; \
50 __VA_ARGS__ vnet_hash_function_registration_t __vnet_hash_function_##x
52 vnet_hash_fn_t vnet_hash_default_function (vnet_hash_fn_type_t ftype);
53 vnet_hash_fn_t vnet_hash_function_from_name (const char *name,
54 vnet_hash_fn_type_t ftype);
55 vnet_hash_function_registration_t *
56 vnet_hash_function_from_func (vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype);
57 format_function_t format_vnet_hash;