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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __LCP_ADJ_DELEGATE_H__
17 #define __LCP_ADJ_DELEGATE_H__
19 #include <vppinfra/bihash_32_8.h>
21 typedef struct lcp_adj_key_t_
27 STATIC_ASSERT (sizeof (lcp_adj_key_t) == 32, "LCP ADJ Key size changed");
29 typedef struct lcp_adj_kv_t_
33 BVT (clib_bihash_kv) kv;
42 STATIC_ASSERT (sizeof (lcp_adj_kv_t) == sizeof (BVT (clib_bihash_kv)),
43 "LCP ADJ Key size changed");
46 * The table of adjacencies indexed by the rewrite string
48 extern BVT (clib_bihash) lcp_adj_tbl;
50 static_always_inline void
51 lcp_adj_mk_key (const u8 *rewrite, u8 len, u32 sw_if_index, lcp_adj_key_t *key)
54 * Construct the key from the provided rewrite, then pad with zeros
55 * to ensure the key does not have garbage bytes
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;
63 static_always_inline adj_index_t
64 lcp_adj_lkup (const u8 *rewrite, u8 len, u32 sw_if_index)
68 lcp_adj_mk_key (rewrite, len, sw_if_index, &kv.k);
70 if (!BV (clib_bihash_search_inline) (&lcp_adj_tbl, &kv.kv))
73 return (ADJ_INDEX_INVALID);
77 * fd.io coding-style-patch-verification: ON
80 * eval: (c-set-style "gnu")