diff options
author | Nick Zavaritsky <nick.zavaritsky@emnify.com> | 2020-02-27 15:54:58 +0000 |
---|---|---|
committer | John Lo <loj@cisco.com> | 2020-03-03 16:15:15 +0000 |
commit | 27518c2ffd0ef75e973a64870da0e3339f39ccce (patch) | |
tree | 3fb7afdb06963ae3ef36cc74bfe33e10b8668d5d /src/vnet/ip/vtep.c | |
parent | 297d288ed653abac9d719013c4ead5215230e7da (diff) |
geneve gtpu vxlan vxlan-gpe: VRF-aware bypass node
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 <nick.zavaritsky@emnify.com>
Change-Id: I5665d94882bbf45d15f8da140c7ada528ec7fa94
Diffstat (limited to 'src/vnet/ip/vtep.c')
-rw-r--r-- | src/vnet/ip/vtep.c | 55 |
1 files changed, 55 insertions, 0 deletions
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 <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: + */ |