FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
lisp_gpe_sub_interface.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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  * @file
17  * @brief LISP sub-interfaces.
18  *
19  */
22 #include <vnet/fib/fib_table.h>
23 #include <vnet/interface.h>
24 
25 /**
26  * @brief Pool of all l3-sub-interfaces
27  */
29 
30 /**
31  * A DB of all LISP L3 sub-interfaces. The key is:{VNI,l-RLOC}
32  */
34 
35 /**
36  * A DB of all VNET L3 sub-interfaces. The key is:{VNI,l-RLOC}
37  * Used in the data-plane for interface lookup on decap.
38  */
40 
41 /**
42  * The next available sub-interface ID. FIXME
43  */
45 
46 
47 static index_t
49 {
50  uword *p;
51 
53 
54  clib_memset (&key, 0, sizeof (key));
55  ip_address_copy (&key.local_rloc, lrloc);
56  key.vni = vni;
58 
59  if (NULL == p)
60  return (INDEX_INVALID);
61  else
62  return (p[0]);
63 }
64 
65 static void
67 {
69  l3s->key, l3s - lisp_gpe_sub_interface_pool);
71  l3s->key, l3s->sw_if_index);
72 }
73 
74 static void
76 {
79 }
80 
83 {
85 }
86 
87 static void
89 {
90  fib_node_index_t fib_index;
91 
94  ASSERT (FIB_NODE_INDEX_INVALID != fib_index);
95 
97 
100  ASSERT (FIB_NODE_INDEX_INVALID != fib_index);
101 
103 }
104 
105 static void
107 {
112 
117 }
118 
119 index_t
121  u32 overlay_table_id, u32 vni)
122 {
124  index_t l3si;
125 
126  l3si = lisp_gpe_sub_interface_db_find (lrloc, vni);
127 
128  if (INDEX_INVALID == l3si)
129  {
130  u32 main_sw_if_index, sub_sw_if_index;
131 
132  /*
133  * find the main interface from the VNI
134  */
135  main_sw_if_index =
136  lisp_gpe_tenant_l3_iface_add_or_lock (vni, overlay_table_id,
137  1 /* with_default_route */ );
138 
139  vnet_sw_interface_t sub_itf_template = {
141  .flood_class = VNET_FLOOD_CLASS_NORMAL,
142  .sup_sw_if_index = main_sw_if_index,
143  .sub.id = lisp_gpe_sub_interface_id++,
144  };
145 
146  if (NULL != vnet_create_sw_interface (vnet_get_main (),
147  &sub_itf_template,
148  &sub_sw_if_index))
149  return (INDEX_INVALID);
150 
152  clib_memset (l3s, 0, sizeof (*l3s));
153  l3s->key = clib_mem_alloc (sizeof (*l3s->key));
154  clib_memset (l3s->key, 0, sizeof (*l3s->key));
155 
156  ip_address_copy (&l3s->key->local_rloc, lrloc);
157  l3s->key->vni = vni;
158  l3s->main_sw_if_index = main_sw_if_index;
159  l3s->sw_if_index = sub_sw_if_index;
160  l3s->eid_table_id = overlay_table_id;
161 
162  l3si = (l3s - lisp_gpe_sub_interface_pool);
163 
164  // FIXME. enable When we get an adj
167 
169  l3s->sw_if_index,
171 
173  }
174  else
175  {
176  l3s = lisp_gpe_sub_interface_get_i (l3si);
177  l3s->eid_table_id = overlay_table_id;
178  }
179 
181  l3s->locks++;
182 
183  return (l3si);
184 }
185 
186 void
188 {
190 
191  l3s = lisp_gpe_sub_interface_get_i (l3si);
192 
193  ASSERT (0 != l3s->locks);
194  l3s->locks--;
195 
196  if (0 == l3s->locks)
197  {
199  l3s->eid_table_id);
200 
204 
206 
207  clib_mem_free (l3s->key);
209  }
210 }
211 
214 {
215  return (lisp_gpe_sub_interface_get_i (l3si));
216 }
217 
218 u8 *
220 {
221  lisp_gpe_sub_interface_t *l3s = va_arg (*ap, lisp_gpe_sub_interface_t *);
222  vnet_main_t *vnm = vnet_get_main ();
223 
224  s = format (s, "%-16U",
226  vnm, vnet_get_sw_interface (vnm, l3s->sw_if_index));
227  s = format (s, "%=8d", l3s->key->vni);
228  s = format (s, "%=15d", l3s->sw_if_index);
229  s = format (s, "%U", format_ip_address, &l3s->key->local_rloc);
230 
231  return (s);
232 }
233 
234 /** CLI command to show LISP-GPE interfaces. */
235 static clib_error_t *
237  unformat_input_t * input,
238  vlib_cli_command_t * cmd)
239 {
241 
242  vlib_cli_output (vm, "%-16s%=8s%=15s%s", "Name", "VNI", "sw_if_index",
243  "local RLOC");
244 
245  /* *INDENT-OFF* */
247  {
249  }
250  /* *INDENT-ON* */
251 
252  return 0;
253 }
254 
255 /* *INDENT-OFF* */
257  .path = "show gpe sub-interface",
258  .short_help = "show gpe sub-interface",
259  .function = lisp_gpe_sub_interface_show,
260 };
261 /* *INDENT-ON* */
262 
263 static clib_error_t *
265 {
267  hash_create_mem (0,
268  sizeof (lisp_gpe_sub_interface_key_t), sizeof (uword));
270  hash_create_mem (0,
271  sizeof (lisp_gpe_sub_interface_key_t), sizeof (uword));
272 
273  return (NULL);
274 }
275 
277 
278 /*
279  * fd.io coding-style-patch-verification: ON
280  *
281  * Local Variables:
282  * eval: (c-set-style "gnu")
283  * End:
284  */
lisp_gpe_sub_interface_key_t_::local_rloc
ip_address_t local_rloc
The local-RLOC.
Definition: lisp_gpe_sub_interface.h:34
ip_address
Definition: ip_types.h:79
lisp_gpe_sub_interface_t_::locks
u32 locks
A reference counting lock on the number of users of this interface.
Definition: lisp_gpe_sub_interface.h:70
vnet_sw_interface_set_flags
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, vnet_sw_interface_flags_t flags)
Definition: interface.c:523
vnet_sw_interface_t::type
vnet_sw_interface_type_t type
Definition: interface.h:871
vnet_sw_interface_t
Definition: interface.h:869
lisp_gpe_sub_interface_key_t_
A Key for lookup in the L£ sub-interface DB.
Definition: lisp_gpe_sub_interface.h:29
lisp_gpe_sub_interface_module_init
static clib_error_t * lisp_gpe_sub_interface_module_init(vlib_main_t *vm)
Definition: lisp_gpe_sub_interface.c:264
ip4_main
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1104
ip4_sw_interface_enable_disable
void ip4_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip4_forward.c:602
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
vni
u32 vni
Definition: flow_types.api:160
VNET_SW_INTERFACE_TYPE_SUB
@ VNET_SW_INTERFACE_TYPE_SUB
Definition: interface.h:767
lisp_gpe_sub_interface_get_i
lisp_gpe_sub_interface_t * lisp_gpe_sub_interface_get_i(index_t l3si)
Definition: lisp_gpe_sub_interface.c:82
vlib_cli_command_t::path
char * path
Definition: cli.h:96
lisp_gpe_sub_interface_unset_table
static void lisp_gpe_sub_interface_unset_table(u32 sw_if_index, u32 table_id)
Definition: lisp_gpe_sub_interface.c:106
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
VNET_FLOOD_CLASS_NORMAL
@ VNET_FLOOD_CLASS_NORMAL
Definition: interface.h:819
fib_table.h
hash_set_mem
#define hash_set_mem(h, key, value)
Definition: hash.h:275
VNET_SW_INTERFACE_FLAG_ADMIN_UP
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:844
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
lisp_gpe_sub_interface.h
LISP sub-interfaces.
lisp_gpe_sub_interface_t_::sw_if_index
u32 sw_if_index
The SW if index assigned to this sub-interface.
Definition: lisp_gpe_sub_interface.h:75
unformat_input_t
struct _unformat_input_t unformat_input_t
lisp_gpe_sub_interface_pool
static lisp_gpe_sub_interface_t * lisp_gpe_sub_interface_pool
Pool of all l3-sub-interfaces.
Definition: lisp_gpe_sub_interface.c:28
format_lisp_gpe_sub_interface
u8 * format_lisp_gpe_sub_interface(u8 *s, va_list *ap)
Definition: lisp_gpe_sub_interface.c:219
key
typedef key
Definition: ipsec_types.api:91
lisp_gpe_sub_interface_t_::main_sw_if_index
u32 main_sw_if_index
The SW IF index assigned to the main interface of which this is a sub.
Definition: lisp_gpe_sub_interface.h:80
lisp_gpe_sub_interface_db_insert
static void lisp_gpe_sub_interface_db_insert(const lisp_gpe_sub_interface_t *l3s)
Definition: lisp_gpe_sub_interface.c:66
ip4_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:120
lisp_gpe_sub_interface_db_remove
static void lisp_gpe_sub_interface_db_remove(const lisp_gpe_sub_interface_t *l3s)
Definition: lisp_gpe_sub_interface.c:75
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
hash_create_mem
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:660
hash_unset_mem
#define hash_unset_mem(h, key)
Definition: hash.h:291
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
fib_table_find_or_create_and_lock
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1170
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
vnet_create_sw_interface
clib_error_t * vnet_create_sw_interface(vnet_main_t *vnm, vnet_sw_interface_t *template, u32 *sw_if_index)
Definition: interface.c:619
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
format_ip_address
u8 * format_ip_address(u8 *s, va_list *args)
Definition: ip_types.c:21
uword
u64 uword
Definition: types.h:112
lisp_gpe_tenant.h
lisp_gpe_sub_interface_set_table
static void lisp_gpe_sub_interface_set_table(u32 sw_if_index, u32 table_id)
Definition: lisp_gpe_sub_interface.c:88
lisp_gpe_tenant_l3_iface_unlock
void lisp_gpe_tenant_l3_iface_unlock(u32 vni)
Release the lock held on the tenant's L3 interface.
Definition: lisp_gpe_tenant.c:139
interface.h
lisp_gpe_sub_interface_get
const lisp_gpe_sub_interface_t * lisp_gpe_sub_interface_get(index_t l3si)
Definition: lisp_gpe_sub_interface.c:213
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
ip6_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Definition: ip6.h:127
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
lisp_gpe_sub_interface_show
static clib_error_t * lisp_gpe_sub_interface_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI command to show LISP-GPE interfaces.
Definition: lisp_gpe_sub_interface.c:236
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2785
lisp_gpe_sub_interfaces_sw_if_index
uword * lisp_gpe_sub_interfaces_sw_if_index
A DB of all VNET L3 sub-interfaces.
Definition: lisp_gpe_sub_interface.c:39
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
vnet_main_t
Definition: vnet.h:76
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
table_id
u32 table_id
Definition: wireguard.api:102
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
lisp_gpe_sub_interface_db_find
static index_t lisp_gpe_sub_interface_db_find(const ip_address_t *lrloc, u32 vni)
Definition: lisp_gpe_sub_interface.c:48
ip6_sw_interface_enable_disable
void ip6_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip6_forward.c:240
lisp_gpe_sub_interface_command
vlib_cli_command_t lisp_gpe_sub_interface_command
(constructor) VLIB_CLI_COMMAND (lisp_gpe_sub_interface_command)
Definition: lisp_gpe_sub_interface.c:256
lisp_gpe_sub_interface_find_or_create_and_lock
index_t lisp_gpe_sub_interface_find_or_create_and_lock(const ip_address_t *lrloc, u32 overlay_table_id, u32 vni)
Definition: lisp_gpe_sub_interface.c:120
lisp_gpe_sub_interface_t_::key
lisp_gpe_sub_interface_key_t * key
The interface's key inthe DB; rloc & vni; The key is allocated from the heap so it can be used in the...
Definition: lisp_gpe_sub_interface.h:59
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
lisp_gpe_sub_interface_t_
A LISP L3 sub-interface.
Definition: lisp_gpe_sub_interface.h:52
u8
unsigned char u8
Definition: types.h:56
lisp_gpe_sub_interface_unlock
void lisp_gpe_sub_interface_unlock(index_t l3si)
Definition: lisp_gpe_sub_interface.c:187
clib_error_t
Definition: clib_error.h:21
lisp_gpe_tenant_l3_iface_add_or_lock
u32 lisp_gpe_tenant_l3_iface_add_or_lock(u32 vni, u32 table_id, u8 with_default_route)
Add/create and lock a new or find and lock the existing L3 interface for the tenant.
Definition: lisp_gpe_tenant.c:110
lisp_gpe_sub_interface_key_t_::vni
u32 vni
The VNI.
Definition: lisp_gpe_sub_interface.h:39
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
fib_table_unlock
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1342
lisp_gpe_sub_interfaces
static uword * lisp_gpe_sub_interfaces
A DB of all LISP L3 sub-interfaces.
Definition: lisp_gpe_sub_interface.c:33
FIB_SOURCE_LISP
@ FIB_SOURCE_LISP
LISP.
Definition: fib_source.h:83
vlib_cli_command_t
Definition: cli.h:92
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
ip_address_copy
void ip_address_copy(ip_address_t *dst, const ip_address_t *src)
Definition: ip_types.c:133
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
lisp_gpe_sub_interface_id
static u32 lisp_gpe_sub_interface_id
The next available sub-interface ID.
Definition: lisp_gpe_sub_interface.c:44
clib_mem_alloc
static void * clib_mem_alloc(uword size)
Definition: mem.h:256
vnet_delete_sub_interface
int vnet_delete_sub_interface(u32 sw_if_index)
Definition: interface.c:1095
lisp_gpe_sub_interface_t_::eid_table_id
u32 eid_table_id
The Table-ID in the overlay that this interface is bound to.
Definition: lisp_gpe_sub_interface.h:64
format_vnet_sw_interface_name
format_function_t format_vnet_sw_interface_name
Definition: interface_funcs.h:456