FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
lcp_adj.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __LCP_ADJ_DELEGATE_H__
17 #define __LCP_ADJ_DELEGATE_H__
18 
19 #include <vppinfra/bihash_32_8.h>
20 
21 typedef struct lcp_adj_key_t_
22 {
24  u8 rewrite[28];
26 
27 STATIC_ASSERT (sizeof (lcp_adj_key_t) == 32, "LCP ADJ Key size changed");
28 
29 typedef struct lcp_adj_kv_t_
30 {
31  union
32  {
33  BVT (clib_bihash_kv) kv;
34  struct
35  {
37  u64 v;
38  };
39  };
40 } lcp_adj_kv_t;
41 
42 STATIC_ASSERT (sizeof (lcp_adj_kv_t) == sizeof (BVT (clib_bihash_kv)),
43  "LCP ADJ Key size changed");
44 
45 /**
46  * The table of adjacencies indexed by the rewrite string
47  */
48 extern BVT (clib_bihash) lcp_adj_tbl;
49 
52 {
53  /*
54  * Construct the key from the provided rewrite, then pad with zeros
55  * to ensure the key does not have garbage bytes
56  */
57  ASSERT (len <= sizeof (key->rewrite));
58  clib_memcpy_fast (key->rewrite, rewrite, len);
59  clib_memset (key->rewrite + len, 0, sizeof (key->rewrite) - len);
60  key->sw_if_index = sw_if_index;
61 }
62 
65 {
66  lcp_adj_kv_t kv;
67 
69 
70  if (!BV (clib_bihash_search_inline) (&lcp_adj_tbl, &kv.kv))
71  return (kv.v);
72 
73  return (ADJ_INDEX_INVALID);
74 }
75 
76 /*
77  * fd.io coding-style-patch-verification: ON
78  *
79  * Local Variables:
80  * eval: (c-set-style "gnu")
81  * End:
82  */
83 
84 #endif
lcp_adj_key_t_
Definition: lcp_adj.h:21
lcp_adj_mk_key
static_always_inline void lcp_adj_mk_key(const u8 *rewrite, u8 len, u32 sw_if_index, lcp_adj_key_t *key)
Definition: lcp_adj.h:51
ADJ_INDEX_INVALID
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
lcp_adj_kv_t_::v
u64 v
Definition: lcp_adj.h:37
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
clib_bihash_search_inline
int clib_bihash_search_inline(clib_bihash *h, clib_bihash_kv *in_out_kv)
Search a bi-hash table.
key
typedef key
Definition: ipsec_types.api:88
BVT
BVT(clib_bihash) lcp_adj_tbl
The table of adjacencies indexed by the rewrite string.
Definition: l2_fib.c:1069
len
u8 len
Definition: ip_types.api:103
static_always_inline
#define static_always_inline
Definition: clib.h:112
bihash_32_8.h
lcp_adj_key_t_::sw_if_index
u32 sw_if_index
Definition: lcp_adj.h:23
lcp_adj_key_t_::rewrite
u8 rewrite[28]
Definition: lcp_adj.h:24
lcp_adj_kv_t
struct lcp_adj_kv_t_ lcp_adj_kv_t
u64
unsigned long u64
Definition: types.h:89
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
adj_index_t
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u8
unsigned char u8
Definition: types.h:56
lcp_adj_key_t
struct lcp_adj_key_t_ lcp_adj_key_t
lcp_adj_kv_t_
Definition: lcp_adj.h:29
lcp_adj_lkup
static_always_inline adj_index_t lcp_adj_lkup(const u8 *rewrite, u8 len, u32 sw_if_index)
Definition: lcp_adj.h:64
STATIC_ASSERT
STATIC_ASSERT(sizeof(lcp_adj_key_t)==32, "LCP ADJ Key size changed")
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
rewrite
rewrite
Definition: pnat.api:158
lcp_adj_kv_t_::k
lcp_adj_key_t k
Definition: lcp_adj.h:36