FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
hash.c
Go to the documentation of this file.
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 
12 
13 u8 *
14 format_vnet_hash (u8 *s, va_list *args)
15 {
17  va_arg (*args, vnet_hash_function_registration_t *);
18 
19  s = format (s, "[name: %s ", hash->name);
20  s = format (s, "priority: %u ", hash->priority);
21  s = format (s, "description: %s]", hash->description);
22  return s;
23 }
24 
25 /**
26  * select hash func with highest priority
27  */
30 {
32  vnet_hash_function_registration_t *tmp_hash = hash;
33  while (hash)
34  {
35  if (hash->priority > tmp_hash->priority)
36  tmp_hash = hash;
37  hash = hash->next;
38  }
39  return tmp_hash->function[ftype];
40 }
41 
44 {
46  while (hash)
47  {
48  if (strcmp (hash->name, name) == 0)
49  break;
50  hash = hash->next;
51  }
52  if (!hash)
53  return (0);
54  return hash->function[ftype];
55 }
56 
59 {
61  while (hash)
62  {
63  if (hash->function[ftype] == fn)
64  break;
65  hash = hash->next;
66  }
67  return hash;
68 }
69 
70 static clib_error_t *
72 {
73  return (0);
74 }
75 
vlib.h
vnet_hash_function_registration::priority
int priority
Definition: hash.h:29
name
string name[64]
Definition: fib.api:25
vnet_hash_function_registration::function
vnet_hash_fn_t function[VNET_HASH_FN_TYPE_N]
Definition: hash.h:30
vnet_hash_fn_t
void(* vnet_hash_fn_t)(void **p, u32 *h, u32 n_packets)
Definition: hash.h:23
hash.h
vnet_hash_fn_type_t
vnet_hash_fn_type_t
Definition: hash.h:15
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
format_vnet_hash
u8 * format_vnet_hash(u8 *s, va_list *args)
Definition: hash.c:14
vnet_hash_function_registration::next
struct vnet_hash_function_registration * next
Definition: hash.h:32
vnet_hash_function_from_name
vnet_hash_fn_t vnet_hash_function_from_name(const char *name, vnet_hash_fn_type_t ftype)
Definition: hash.c:43
interface.h
vnet_hash_function_from_func
vnet_hash_function_registration_t * vnet_hash_function_from_func(vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype)
Definition: hash.c:58
vnet_hash_init
static clib_error_t * vnet_hash_init(vlib_main_t *vm)
Definition: hash.c:71
vnet_hash_default_function
vnet_hash_fn_t vnet_hash_default_function(vnet_hash_fn_type_t ftype)
select hash func with highest priority
Definition: hash.c:29
vnet_hash_function_registration
Definition: hash.h:25
format
description fragment has unexpected format
Definition: map.api:433
vnet_hash_main
vnet_hash_main_t vnet_hash_main
Definition: hash.c:11
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vnet_hash_main_t
Definition: hash.h:35
vnet_hash_function_registration::description
const char * description
Definition: hash.h:28
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vnet_hash_main_t::hash_registrations
vnet_hash_function_registration_t * hash_registrations
Definition: hash.h:37
vnet_hash_function_registration::name
const char * name
Definition: hash.h:27
vnet.h