LCOV - code coverage report
Current view: top level - plugins/wireguard - wireguard_index_table.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 18 19 94.7 %
Date: 2023-07-05 22:20:52 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       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:
       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             : #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>
      21             : 
      22             : u32
      23         214 : wg_index_table_add (vlib_main_t *vm, wg_index_table_t *table,
      24             :                     u32 peer_pool_idx, u32 rnd_seed)
      25             : {
      26             :   u32 key;
      27             : 
      28             :   while (1)
      29             :     {
      30         214 :       key = random_u32 (&rnd_seed);
      31         214 :       if (hash_get (table->hash, key))
      32           0 :         continue;
      33             : 
      34         214 :       vlib_worker_thread_barrier_sync (vm);
      35         214 :       hash_set (table->hash, key, peer_pool_idx);
      36         214 :       vlib_worker_thread_barrier_release (vm);
      37         214 :       break;
      38             :     }
      39         214 :   return key;
      40             : }
      41             : 
      42             : void
      43         214 : wg_index_table_del (vlib_main_t *vm, wg_index_table_t *table, u32 key)
      44             : {
      45             :   uword *p;
      46         214 :   p = hash_get (table->hash, key);
      47         214 :   if (p)
      48             :     {
      49         214 :       vlib_worker_thread_barrier_sync (vm);
      50         214 :       hash_unset (table->hash, key);
      51         214 :       vlib_worker_thread_barrier_release (vm);
      52             :     }
      53         214 : }
      54             : 
      55             : u32 *
      56        4454 : wg_index_table_lookup (const wg_index_table_t * table, u32 key)
      57             : {
      58             :   uword *p;
      59             : 
      60        4454 :   p = hash_get (table->hash, key);
      61        4454 :   return (u32 *) p;
      62             : }
      63             : 
      64             : /*
      65             :  * fd.io coding-style-patch-verification: ON
      66             :  *
      67             :  * Local Variables:
      68             :  * eval: (c-set-style "gnu")
      69             :  * End:
      70             :  */

Generated by: LCOV version 1.14