2 * SPDX-License-Identifier: Apache-2.0
3 * Copyright(c) 2021 Cisco Systems, Inc.
8 #include <vnet/interface.h>
9 #include <vnet/hash/hash.h>
11 vnet_hash_main_t vnet_hash_main;
14 format_vnet_hash (u8 *s, va_list *args)
16 vnet_hash_function_registration_t *hash =
17 va_arg (*args, vnet_hash_function_registration_t *);
19 s = format (s, "[name: %s ", hash->name);
20 s = format (s, "priority: %u ", hash->priority);
21 s = format (s, "description: %s]", hash->description);
26 * select hash func with highest priority
29 vnet_hash_default_function (vnet_hash_fn_type_t ftype)
31 vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations;
32 vnet_hash_function_registration_t *tmp_hash = hash;
35 if (hash->priority > tmp_hash->priority)
39 return tmp_hash->function[ftype];
43 vnet_hash_function_from_name (const char *name, vnet_hash_fn_type_t ftype)
45 vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations;
48 if (strcmp (hash->name, name) == 0)
54 return hash->function[ftype];
57 vnet_hash_function_registration_t *
58 vnet_hash_function_from_func (vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype)
60 vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations;
63 if (hash->function[ftype] == fn)
71 vnet_hash_init (vlib_main_t *vm)
76 VLIB_INIT_FUNCTION (vnet_hash_init);