FD.io VPP  v21.01.1
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);
27  ip46_address_is_ip4 (ip) ?
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;
43  ip46_address_is_ip4 (ip) ?
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  */
#define hash_set(h, key, value)
Definition: hash.h:255
uword vtep_addr_ref(vtep_table_t *t, u32 fib_index, ip46_address_t *ip)
Definition: vtep.c:19
#define hash_unset(h, key)
Definition: hash.h:261
uword * vtep6
Definition: vtep.h:65
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
#define ALWAYS_ASSERT(truth)
unsigned int u32
Definition: types.h:88
#define hash_get(h, key)
Definition: hash.h:249
uword vtep_addr_unref(vtep_table_t *t, u32 fib_index, ip46_address_t *ip)
Definition: vtep.c:34
static void hash_unset_mem_free(uword **h, const void *key)
Definition: hash.h:295
vl_api_address_t ip
Definition: l2.api:501
u64 uword
Definition: types.h:112
uword * vtep4
Definition: vtep.h:64
#define hash_get_mem(h, key)
Definition: hash.h:269
static void hash_set_mem_alloc(uword **h, const void *key, uword v)
Definition: hash.h:279