From 27518c2ffd0ef75e973a64870da0e3339f39ccce Mon Sep 17 00:00:00 2001 From: Nick Zavaritsky Date: Thu, 27 Feb 2020 15:54:58 +0000 Subject: geneve gtpu vxlan vxlan-gpe: VRF-aware bypass node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bypass node MUST NOT intercept a packet if destination IP doesn’t match a local address. However IP address interpretation depends on the VRF, hence bypass node must take that into account. This patch also factors-out common VTEP management and checking code. Type: improvement Signed-off-by: Nick Zavaritsky Change-Id: I5665d94882bbf45d15f8da140c7ada528ec7fa94 --- src/vnet/ip/vtep.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/vnet/ip/vtep.c (limited to 'src/vnet/ip/vtep.c') diff --git a/src/vnet/ip/vtep.c b/src/vnet/ip/vtep.c new file mode 100644 index 00000000000..d0493f8cd2f --- /dev/null +++ b/src/vnet/ip/vtep.c @@ -0,0 +1,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 + +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: + */ -- cgit 1.2.3-korg