Line data Source code
1 : /* 2 : * SPDX-License-Identifier: Apache-2.0 3 : * Copyright(c) 2021 Cisco Systems, Inc. 4 : */ 5 : 6 : #include <vlib/vlib.h> 7 : #include <vnet/vnet.h> 8 : #include <vnet/interface.h> 9 : #include <vnet/hash/hash.h> 10 : 11 : vnet_hash_main_t vnet_hash_main; 12 : 13 : u8 * 14 6 : format_vnet_hash (u8 *s, va_list *args) 15 : { 16 6 : vnet_hash_function_registration_t *hash = 17 : va_arg (*args, vnet_hash_function_registration_t *); 18 : 19 6 : s = format (s, "[name: %s ", hash->name); 20 6 : s = format (s, "priority: %u ", hash->priority); 21 6 : s = format (s, "description: %s]", hash->description); 22 6 : return s; 23 : } 24 : 25 : /** 26 : * select hash func with highest priority 27 : */ 28 : vnet_hash_fn_t 29 6300 : vnet_hash_default_function (vnet_hash_fn_type_t ftype) 30 : { 31 6300 : vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations; 32 6300 : vnet_hash_function_registration_t *tmp_hash = hash; 33 44100 : while (hash) 34 : { 35 37800 : if (hash->priority > tmp_hash->priority) 36 0 : tmp_hash = hash; 37 37800 : hash = hash->next; 38 : } 39 6300 : return tmp_hash->function[ftype]; 40 : } 41 : 42 : vnet_hash_fn_t 43 9 : vnet_hash_function_from_name (const char *name, vnet_hash_fn_type_t ftype) 44 : { 45 9 : vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations; 46 25 : while (hash) 47 : { 48 25 : if (strcmp (hash->name, name) == 0) 49 9 : break; 50 16 : hash = hash->next; 51 : } 52 9 : if (!hash) 53 0 : return (0); 54 9 : return hash->function[ftype]; 55 : } 56 : 57 : vnet_hash_function_registration_t * 58 6 : vnet_hash_function_from_func (vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype) 59 : { 60 6 : vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations; 61 6 : while (hash) 62 : { 63 6 : if (hash->function[ftype] == fn) 64 6 : break; 65 0 : hash = hash->next; 66 : } 67 6 : return hash; 68 : } 69 : 70 : static clib_error_t * 71 559 : vnet_hash_init (vlib_main_t *vm) 72 : { 73 559 : return (0); 74 : } 75 : 76 69999 : VLIB_INIT_FUNCTION (vnet_hash_init);