FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
vtep.c
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 #include <vnet/ip/vtep.h>
17 
18 uword
19 vtep_addr_ref (vtep_table_t * t, u32 fib_index, ip46_address_t * ip)
20 {
21  vtep4_key_t key4 = {.addr = ip->ip4,.fib_index = fib_index };
22  vtep6_key_t key6 = {.addr = ip->ip6,.fib_index = fib_index };
23  uword *vtep = ip46_address_is_ip4 (ip) ?
24  hash_get (t->vtep4, key4.as_u64) : hash_get_mem (t->vtep6, &key6);
25  if (vtep)
26  return ++(*vtep);
28  hash_set (t->vtep4, key4.as_u64, 1) :
29  hash_set_mem_alloc (&t->vtep6, &key6, 1);
30  return 1;
31 }
32 
33 uword
34 vtep_addr_unref (vtep_table_t * t, u32 fib_index, ip46_address_t * ip)
35 {
36  vtep4_key_t key4 = {.addr = ip->ip4,.fib_index = fib_index };
37  vtep6_key_t key6 = {.addr = ip->ip6,.fib_index = fib_index };
38  uword *vtep = ip46_address_is_ip4 (ip) ?
39  hash_get (t->vtep4, key4.as_u64) : hash_get_mem (t->vtep6, &key6);
40  ALWAYS_ASSERT (vtep);
41  if (--(*vtep) != 0)
42  return *vtep;
44  hash_unset (t->vtep4, key4.as_u64) :
45  hash_unset_mem_free (&t->vtep6, &key6);
46  return 0;
47 }
48 
49 /*
50  * fd.io coding-style-patch-verification: ON
51  *
52  * Local Variables:
53  * eval: (c-set-style "gnu")
54  * End:
55  */
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
vtep_table_t::vtep4
uword * vtep4
Definition: vtep.h:64
ip46_address_is_ip4
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
vtep_addr_ref
uword vtep_addr_ref(vtep_table_t *t, u32 fib_index, ip46_address_t *ip)
Definition: vtep.c:19
hash_set_mem_alloc
static void hash_set_mem_alloc(uword **h, const void *key, uword v)
Definition: hash.h:279
hash_get
#define hash_get(h, key)
Definition: hash.h:249
uword
u64 uword
Definition: types.h:112
vtep_table_t::vtep6
uword * vtep6
Definition: vtep.h:65
ALWAYS_ASSERT
#define ALWAYS_ASSERT(truth)
Definition: error_bootstrap.h:89
vtep_addr_unref
uword vtep_addr_unref(vtep_table_t *t, u32 fib_index, ip46_address_t *ip)
Definition: vtep.c:34
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
u32
unsigned int u32
Definition: types.h:88
hash_unset_mem_free
static void hash_unset_mem_free(uword **h, const void *key)
Definition: hash.h:295
ip
vl_api_address_t ip
Definition: l2.api:558
vtep_table_t
Definition: vtep.h:62
vtep.h