summaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/vtep.c
blob: d0493f8cd2f9f088be101eb61e8d77713b0e4108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (c) 2020 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vnet/ip/vtep.h>

uword
vtep_addr_ref (vtep_table_t * t, u32 fib_index, ip46_address_t * ip)
{
  vtep4_key_t key4 = {.addr = ip->ip4,.fib_index = fib_index };
  vtep6_key_t key6 = {.addr = ip->ip6,.fib_index = fib_index };
  uword *vtep = ip46_address_is_ip4 (ip) ?
    hash_get (t->vtep4, key4.as_u64) : hash_get_mem (t->vtep6, &key6);
  if (vtep)
    return ++(*vtep);
  ip46_address_is_ip4 (ip) ?
    hash_set (t->vtep4, key4.as_u64, 1) :
    hash_set_mem_alloc (&t->vtep6, &key6, 1);
  return 1;
}

uword
vtep_addr_unref (vtep_table_t * t, u32 fib_index, ip46_address_t * ip)
{
  vtep4_key_t key4 = {.addr = ip->ip4,.fib_index = fib_index };
  vtep6_key_t key6 = {.addr = ip->ip6,.fib_index = fib_index };
  uword *vtep = ip46_address_is_ip4 (ip) ?
    hash_get (t->vtep4, key4.as_u64) : hash_get_mem (t->vtep6, &key6);
  ALWAYS_ASSERT (vtep);
  if (--(*vtep) != 0)
    return *vtep;
  ip46_address_is_ip4 (ip) ?
    hash_unset (t->vtep4, key4.as_u64) :
    hash_unset_mem_free (&t->vtep6, &key6);
  return 0;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */