Line data Source code
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 3027 : vtep_addr_ref (vtep_table_t * t, u32 fib_index, ip46_address_t * ip) 20 : { 21 3027 : vtep4_key_t key4 = {.addr = ip->ip4,.fib_index = fib_index }; 22 3027 : vtep6_key_t key6 = {.addr = ip->ip6,.fib_index = fib_index }; 23 3027 : uword *vtep = ip46_address_is_ip4 (ip) ? 24 3273 : hash_get (t->vtep4, key4.as_u64) : hash_get_mem (t->vtep6, &key6); 25 3027 : if (vtep) 26 730 : return ++(*vtep); 27 2297 : ip46_address_is_ip4 (ip) ? 28 2297 : hash_set (t->vtep4, key4.as_u64, 1) : 29 26 : hash_set_mem_alloc (&t->vtep6, &key6, 1); 30 2297 : return 1; 31 : } 32 : 33 : uword 34 2983 : vtep_addr_unref (vtep_table_t * t, u32 fib_index, ip46_address_t * ip) 35 : { 36 2983 : vtep4_key_t key4 = {.addr = ip->ip4,.fib_index = fib_index }; 37 2983 : vtep6_key_t key6 = {.addr = ip->ip6,.fib_index = fib_index }; 38 2983 : uword *vtep = ip46_address_is_ip4 (ip) ? 39 3229 : hash_get (t->vtep4, key4.as_u64) : hash_get_mem (t->vtep6, &key6); 40 2983 : ALWAYS_ASSERT (vtep); 41 2983 : if (--(*vtep) != 0) 42 690 : return *vtep; 43 2293 : ip46_address_is_ip4 (ip) ? 44 2293 : hash_unset (t->vtep4, key4.as_u64) : 45 26 : hash_unset_mem_free (&t->vtep6, &key6); 46 2293 : 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 : */