2 * Copyright (c) 2020 Doc.ai 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 #include <vlib/vlib.h>
17 #include <vppinfra/hash.h>
18 #include <vppinfra/pool.h>
19 #include <vppinfra/random.h>
20 #include <wireguard/wireguard_index_table.h>
23 wg_index_table_add (vlib_main_t *vm, wg_index_table_t *table,
24 u32 peer_pool_idx, u32 rnd_seed)
30 key = random_u32 (&rnd_seed);
31 if (hash_get (table->hash, key))
34 vlib_worker_thread_barrier_sync (vm);
35 hash_set (table->hash, key, peer_pool_idx);
36 vlib_worker_thread_barrier_release (vm);
43 wg_index_table_del (vlib_main_t *vm, wg_index_table_t *table, u32 key)
46 p = hash_get (table->hash, key);
49 vlib_worker_thread_barrier_sync (vm);
50 hash_unset (table->hash, key);
51 vlib_worker_thread_barrier_release (vm);
56 wg_index_table_lookup (const wg_index_table_t * table, u32 key)
60 p = hash_get (table->hash, key);
65 * fd.io coding-style-patch-verification: ON
68 * eval: (c-set-style "gnu")