blob: 1b53e4dd9fe4170bb99b6444aaac281d028cf3a8 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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 Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys.
18 *
19 */
20
Neale Rannsb80c5362016-10-08 13:03:40 +010021#include <vnet/dpo/load_balance.h>
Filip Tehlar4868ff62017-03-09 16:48:39 +010022#include <vnet/lisp-cp/control.h>
Neale Rannsb80c5362016-10-08 13:03:40 +010023#include <vnet/lisp-cp/lisp_types.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010024#include <vnet/lisp-gpe/lisp_gpe_sub_interface.h>
25#include <vnet/lisp-gpe/lisp_gpe_adjacency.h>
26#include <vnet/lisp-gpe/lisp_gpe_tunnel.h>
27#include <vnet/fib/fib_entry.h>
28#include <vnet/adj/adj_midchain.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050029#include <vppinfra/bihash_24_8.h>
30#include <vppinfra/bihash_template.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010031
32/**
33 * Memory pool of all adjacencies
34 */
35static lisp_gpe_adjacency_t *lisp_adj_pool;
36
37/**
38 * Hash table of all adjacencies. key:{nh, itf}
39 * We never have an all zeros address since the interfaces are multi-access,
40 * therefore there is no ambiguity between a v4 and v6 next-hop, so we don't
41 * need to add the protocol to the key.
42 */
43static
44BVT (clib_bihash)
45 lisp_adj_db;
46
47#define LISP_ADJ_SET_KEY(_key, _itf, _nh) \
48{ \
49 _key.key[0] = (_nh)->ip.v6.as_u64[0]; \
50 _key.key[1] = (_nh)->ip.v6.as_u64[1]; \
51 _key.key[2] = (_itf); \
52}
53
54 static index_t lisp_adj_find (const ip_address_t * addr, u32 sw_if_index)
55{
56 BVT (clib_bihash_kv) kv;
57
58 LISP_ADJ_SET_KEY (kv, sw_if_index, addr);
59
60 if (BV (clib_bihash_search) (&lisp_adj_db, &kv, &kv) < 0)
61 {
62 return (INDEX_INVALID);
63 }
64 else
65 {
66 return (kv.value);
67 }
68}
69
70static void
71lisp_adj_insert (const ip_address_t * addr, u32 sw_if_index, index_t ai)
72{
73 BVT (clib_bihash_kv) kv;
74
75 LISP_ADJ_SET_KEY (kv, sw_if_index, addr);
76 kv.value = ai;
77
78 BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 1);
79}
80
81static void
82lisp_adj_remove (const ip_address_t * addr, u32 sw_if_index)
83{
84 BVT (clib_bihash_kv) kv;
85
86 LISP_ADJ_SET_KEY (kv, sw_if_index, addr);
87
88 BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 0);
89}
90
91static lisp_gpe_adjacency_t *
92lisp_gpe_adjacency_get_i (index_t lai)
93{
94 return (pool_elt_at_index (lisp_adj_pool, lai));
95}
96
97fib_forward_chain_type_t
98lisp_gpe_adj_get_fib_chain_type (const lisp_gpe_adjacency_t * ladj)
99{
100 switch (ip_addr_version (&ladj->remote_rloc))
101 {
102 case IP4:
103 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
104 case IP6:
105 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
106 default:
107 ASSERT (0);
108 break;
109 }
110 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
111}
112
Neale Rannsb80c5362016-10-08 13:03:40 +0100113static void
114ip46_address_to_ip_address (const ip46_address_t * a, ip_address_t * b)
115{
116 if (ip46_address_is_ip4 (a))
117 {
Dave Barachb7b92992018-10-17 10:38:51 -0400118 clib_memset (b, 0, sizeof (*b));
Neale Rannsb80c5362016-10-08 13:03:40 +0100119 ip_address_set (b, &a->ip4, IP4);
120 }
121 else
122 {
123 ip_address_set (b, &a->ip6, IP6);
124 }
125}
126
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100127/**
128 * @brief Stack the tunnel's midchain on the IP forwarding chain of the via
129 */
130static void
Neale Rannsb80c5362016-10-08 13:03:40 +0100131lisp_gpe_adj_stack_one (lisp_gpe_adjacency_t * ladj, adj_index_t ai)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100132{
Neale Ranns5e575b12016-10-03 09:40:25 +0100133 const lisp_gpe_tunnel_t *lgt;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100134
135 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100136
Neale Ranns521a8d72018-12-06 13:46:49 +0000137 adj_nbr_midchain_stack_on_fib_entry (ai,
138 lgt->fib_entry_index,
139 lisp_gpe_adj_get_fib_chain_type
140 (ladj));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100141}
142
Neale Rannsb80c5362016-10-08 13:03:40 +0100143/**
144 * @brief Call back when restacking all adjacencies on a GRE interface
145 */
146static adj_walk_rc_t
147lisp_gpe_adj_walk_cb (adj_index_t ai, void *ctx)
148{
149 lisp_gpe_adjacency_t *ladj = ctx;
150
151 lisp_gpe_adj_stack_one (ladj, ai);
152
153 return (ADJ_WALK_RC_CONTINUE);
154}
155
156static void
157lisp_gpe_adj_stack (lisp_gpe_adjacency_t * ladj)
158{
159 fib_protocol_t nh_proto;
160 ip46_address_t nh;
161
162 ip_address_to_46 (&ladj->remote_rloc, &nh, &nh_proto);
163
164 /*
165 * walk all the adjacencies on th lisp interface and restack them
166 */
167 adj_nbr_walk_nh (ladj->sw_if_index,
168 nh_proto, &nh, lisp_gpe_adj_walk_cb, ladj);
169}
170
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100171static lisp_gpe_next_protocol_e
Neale Ranns924d03a2016-10-19 08:25:46 +0100172lisp_gpe_adj_proto_from_vnet_link_type (vnet_link_t linkt)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100173{
174 switch (linkt)
175 {
Neale Ranns924d03a2016-10-19 08:25:46 +0100176 case VNET_LINK_IP4:
Neale Ranns5e575b12016-10-03 09:40:25 +0100177 return (LISP_GPE_NEXT_PROTO_IP4);
Neale Ranns924d03a2016-10-19 08:25:46 +0100178 case VNET_LINK_IP6:
Neale Ranns5e575b12016-10-03 09:40:25 +0100179 return (LISP_GPE_NEXT_PROTO_IP6);
Neale Ranns924d03a2016-10-19 08:25:46 +0100180 case VNET_LINK_ETHERNET:
Neale Ranns5e575b12016-10-03 09:40:25 +0100181 return (LISP_GPE_NEXT_PROTO_ETHERNET);
Florin Corasce1b4c72017-01-26 14:25:34 -0800182 case VNET_LINK_NSH:
183 return (LISP_GPE_NEXT_PROTO_NSH);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100184 default:
185 ASSERT (0);
186 }
Neale Ranns5e575b12016-10-03 09:40:25 +0100187 return (LISP_GPE_NEXT_PROTO_IP4);
188}
189
190#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40
191
Filip Tehlar4868ff62017-03-09 16:48:39 +0100192static lisp_afi_e
193lisp_afi_from_vnet_link_type (vnet_link_t link)
194{
195 switch (link)
196 {
197 case VNET_LINK_IP4:
198 return LISP_AFI_IP;
199 case VNET_LINK_IP6:
200 return LISP_AFI_IP6;
201 case VNET_LINK_ETHERNET:
202 return LISP_AFI_MAC;
203 default:
204 return LISP_AFI_NO_ADDR;
205 }
206}
207
208static void
209lisp_gpe_increment_stats_counters (lisp_cp_main_t * lcm, ip_adjacency_t * adj,
210 vlib_buffer_t * b)
211{
212 lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main ();
213 lisp_gpe_adjacency_t *ladj;
214 ip_address_t rloc;
215 index_t lai;
216 u32 si, di;
217 gid_address_t src, dst;
Filip Tehlar4868ff62017-03-09 16:48:39 +0100218 uword *feip;
219
220 ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc);
221 si = vnet_buffer (b)->sw_if_index[VLIB_TX];
222 lai = lisp_adj_find (&rloc, si);
223 ASSERT (INDEX_INVALID != lai);
224
225 ladj = pool_elt_at_index (lisp_adj_pool, lai);
226
227 u8 *lisp_data = (u8 *) vlib_buffer_get_current (b);
228
229 /* skip IP header */
230 if (is_v4_packet (lisp_data))
231 lisp_data += sizeof (ip4_header_t);
232 else
233 lisp_data += sizeof (ip6_header_t);
234
235 /* skip UDP header */
236 lisp_data += sizeof (udp_header_t);
237 // TODO: skip TCP?
238
239 /* skip LISP GPE header */
240 lisp_data += sizeof (lisp_gpe_header_t);
241
242 i16 saved_current_data = b->current_data;
243 b->current_data = lisp_data - b->data;
244
245 lisp_afi_e afi = lisp_afi_from_vnet_link_type (adj->ia_link);
246 get_src_and_dst_eids_from_buffer (lcm, b, &src, &dst, afi);
247 b->current_data = saved_current_data;
248 di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, &src);
249 if (PREDICT_FALSE (~0 == di))
250 {
251 clib_warning ("dst mapping not found (%U, %U)", format_gid_address,
252 &src, format_gid_address, &dst);
253 return;
254 }
255
256 feip = hash_get (lcm->fwd_entry_by_mapping_index, di);
257 if (PREDICT_FALSE (!feip))
258 return;
259
260 lisp_stats_key_t key;
Dave Barachb7b92992018-10-17 10:38:51 -0400261 clib_memset (&key, 0, sizeof (key));
Filip Tehlar4868ff62017-03-09 16:48:39 +0100262 key.fwd_entry_index = feip[0];
263 key.tunnel_index = ladj->tunnel_index;
264
265 uword *p = hash_get_mem (lgm->lisp_stats_index_by_key, &key);
Filip Tehlar21511912017-04-07 10:41:42 +0200266 ASSERT (p);
Filip Tehlar4868ff62017-03-09 16:48:39 +0100267
Filip Tehlar4868ff62017-03-09 16:48:39 +0100268 /* compute payload length starting after GPE */
Filip Tehlar21511912017-04-07 10:41:42 +0200269 u32 bytes = b->current_length - (lisp_data - b->data - b->current_data);
Damjan Marionf55f9b82017-05-10 21:06:28 +0200270 vlib_increment_combined_counter (&lgm->counters, vlib_get_thread_index (),
Filip Tehlar21511912017-04-07 10:41:42 +0200271 p[0], 1, bytes);
Filip Tehlar4868ff62017-03-09 16:48:39 +0100272}
273
Neale Ranns5e575b12016-10-03 09:40:25 +0100274static void
Neale Rannsdb14f5a2018-01-29 10:43:33 -0800275lisp_gpe_fixup (vlib_main_t * vm,
276 ip_adjacency_t * adj, vlib_buffer_t * b, const void *data)
Neale Ranns5e575b12016-10-03 09:40:25 +0100277{
Filip Tehlar4868ff62017-03-09 16:48:39 +0100278 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
279
280 if (lcm->flags & LISP_FLAG_STATS_ENABLED)
281 lisp_gpe_increment_stats_counters (lcm, adj, b);
282
Neale Ranns5e575b12016-10-03 09:40:25 +0100283 /* Fixup the checksum and len fields in the LISP tunnel encap
284 * that was applied at the midchain node */
285 ip_udp_fixup_one (vm, b, is_v4_packet (vlib_buffer_get_current (b)));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100286}
287
Neale Rannsb80c5362016-10-08 13:03:40 +0100288/**
289 * @brief The LISP-GPE interface registered function to update, i.e.
290 * provide an rewrite string for, an adjacency.
291 */
292void
293lisp_gpe_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
294{
295 const lisp_gpe_tunnel_t *lgt;
296 lisp_gpe_adjacency_t *ladj;
297 ip_adjacency_t *adj;
298 ip_address_t rloc;
299 vnet_link_t linkt;
Neale Ranns521a8d72018-12-06 13:46:49 +0000300 adj_flags_t af;
Neale Rannsb80c5362016-10-08 13:03:40 +0100301 index_t lai;
302
303 adj = adj_get (ai);
304 ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc);
305
306 /*
307 * find an existing or create a new adj
308 */
309 lai = lisp_adj_find (&rloc, sw_if_index);
310
311 ASSERT (INDEX_INVALID != lai);
312
313 ladj = pool_elt_at_index (lisp_adj_pool, lai);
314 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
315 linkt = adj_get_link_type (ai);
Neale Ranns521a8d72018-12-06 13:46:49 +0000316 af = ADJ_FLAG_MIDCHAIN_IP_STACK;
317 if (VNET_LINK_ETHERNET == linkt)
318 af |= ADJ_FLAG_MIDCHAIN_NO_COUNT;
319
Neale Rannsb80c5362016-10-08 13:03:40 +0100320 adj_nbr_midchain_update_rewrite
Neale Ranns521a8d72018-12-06 13:46:49 +0000321 (ai, lisp_gpe_fixup, NULL, af,
Florin Corasce1b4c72017-01-26 14:25:34 -0800322 lisp_gpe_tunnel_build_rewrite (lgt, ladj,
323 lisp_gpe_adj_proto_from_vnet_link_type
324 (linkt)));
Neale Rannsb80c5362016-10-08 13:03:40 +0100325
326 lisp_gpe_adj_stack_one (ladj, ai);
327}
328
329u8 *
330lisp_gpe_build_rewrite (vnet_main_t * vnm,
331 u32 sw_if_index,
332 vnet_link_t link_type, const void *dst_address)
333{
334 ASSERT (0);
335 return (NULL);
336}
337
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100338index_t
339lisp_gpe_adjacency_find_or_create_and_lock (const locator_pair_t * pair,
340 u32 overlay_table_id, u32 vni)
341{
Neale Rannsb80c5362016-10-08 13:03:40 +0100342 const lisp_gpe_sub_interface_t *l3s;
Neale Ranns5e575b12016-10-03 09:40:25 +0100343 const lisp_gpe_tunnel_t *lgt;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100344 lisp_gpe_adjacency_t *ladj;
345 index_t lai, l3si;
346
347 /*
348 * first find the L3 sub-interface that corresponds to the loacl-rloc and vni
349 */
350 l3si = lisp_gpe_sub_interface_find_or_create_and_lock (&pair->lcl_loc,
351 overlay_table_id,
352 vni);
Neale Rannsb80c5362016-10-08 13:03:40 +0100353 l3s = lisp_gpe_sub_interface_get (l3si);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100354
355 /*
356 * find an existing or create a new adj
357 */
Neale Rannsb80c5362016-10-08 13:03:40 +0100358 lai = lisp_adj_find (&pair->rmt_loc, l3s->sw_if_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100359
360 if (INDEX_INVALID == lai)
361 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100362
363 pool_get (lisp_adj_pool, ladj);
Dave Barachb7b92992018-10-17 10:38:51 -0400364 clib_memset (ladj, 0, sizeof (*ladj));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100365 lai = (ladj - lisp_adj_pool);
366
Neale Rannsb80c5362016-10-08 13:03:40 +0100367 ip_address_copy (&ladj->remote_rloc, &pair->rmt_loc);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100368 ladj->vni = vni;
369 /* transfer the lock to the adj */
370 ladj->lisp_l3_sub_index = l3si;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100371 ladj->sw_if_index = l3s->sw_if_index;
372
373 /* if vni is non-default */
374 if (ladj->vni)
375 ladj->flags = LISP_GPE_FLAGS_I;
376
377 /* work in lisp-gpe not legacy mode */
378 ladj->flags |= LISP_GPE_FLAGS_P;
379
380 /*
381 * find the tunnel that will provide the underlying transport
382 * and hence the rewrite.
383 * The RLOC FIB index is default table - always.
384 */
385 ladj->tunnel_index = lisp_gpe_tunnel_find_or_create_and_lock (pair, 0);
386
387 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
388
389 /*
390 * become of child of the RLOC FIB entry so we are updated when
391 * its reachability changes, allowing us to re-stack the midcahins
392 */
393 ladj->fib_entry_child_index = fib_entry_child_add (lgt->fib_entry_index,
394 FIB_NODE_TYPE_LISP_ADJ,
395 lai);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100396
Neale Rannsb80c5362016-10-08 13:03:40 +0100397 lisp_adj_insert (&ladj->remote_rloc, ladj->sw_if_index, lai);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100398 }
399 else
400 {
401 /* unlock the interface from the find. */
402 lisp_gpe_sub_interface_unlock (l3si);
403 ladj = lisp_gpe_adjacency_get_i (lai);
404 }
405
406 ladj->locks++;
407
408 return (lai);
409}
410
411/**
412 * @brief Get a pointer to a tunnel from a pointer to a FIB node
413 */
414static lisp_gpe_adjacency_t *
415lisp_gpe_adjacency_from_fib_node (const fib_node_t * node)
416{
417 return ((lisp_gpe_adjacency_t *)
418 ((char *) node -
419 STRUCT_OFFSET_OF (lisp_gpe_adjacency_t, fib_node)));
420}
421
422static void
423lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_t * ladj)
424{
Neale Rannsb80c5362016-10-08 13:03:40 +0100425 const lisp_gpe_tunnel_t *lgt;
426
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100427 /*
428 * no children so we are not counting locks. no-op.
429 * at least not counting
430 */
Neale Rannsb80c5362016-10-08 13:03:40 +0100431 lisp_adj_remove (&ladj->remote_rloc, ladj->sw_if_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100432
433 /*
434 * unlock the resources this adj holds
435 */
Neale Rannsb80c5362016-10-08 13:03:40 +0100436 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
437
438 fib_entry_child_remove (lgt->fib_entry_index, ladj->fib_entry_child_index);
439
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100440 lisp_gpe_tunnel_unlock (ladj->tunnel_index);
441 lisp_gpe_sub_interface_unlock (ladj->lisp_l3_sub_index);
442
443 pool_put (lisp_adj_pool, ladj);
444}
445
446void
447lisp_gpe_adjacency_unlock (index_t lai)
448{
449 lisp_gpe_adjacency_t *ladj;
450
451 ladj = lisp_gpe_adjacency_get_i (lai);
452
453 ladj->locks--;
454
455 if (0 == ladj->locks)
456 {
457 lisp_gpe_adjacency_last_lock_gone (ladj);
458 }
459}
460
461const lisp_gpe_adjacency_t *
462lisp_gpe_adjacency_get (index_t lai)
463{
464 return (lisp_gpe_adjacency_get_i (lai));
465}
466
467
468/**
469 * @brief LISP GPE tunnel back walk
470 *
471 * The FIB entry through which this tunnel resolves has been updated.
472 * re-stack the midchain on the new forwarding.
473 */
474static fib_node_back_walk_rc_t
475lisp_gpe_adjacency_back_walk (fib_node_t * node,
476 fib_node_back_walk_ctx_t * ctx)
477{
478 lisp_gpe_adj_stack (lisp_gpe_adjacency_from_fib_node (node));
479
480 return (FIB_NODE_BACK_WALK_CONTINUE);
481}
482
483static fib_node_t *
484lisp_gpe_adjacency_get_fib_node (fib_node_index_t index)
485{
486 lisp_gpe_adjacency_t *ladj;
487
488 ladj = pool_elt_at_index (lisp_adj_pool, index);
489 return (&ladj->fib_node);
490}
491
492static void
493lisp_gpe_adjacency_last_fib_lock_gone (fib_node_t * node)
494{
495 lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_from_fib_node (node));
496}
497
498const static fib_node_vft_t lisp_gpe_tuennel_vft = {
499 .fnv_get = lisp_gpe_adjacency_get_fib_node,
500 .fnv_back_walk = lisp_gpe_adjacency_back_walk,
501 .fnv_last_lock = lisp_gpe_adjacency_last_fib_lock_gone,
502};
503
504u8 *
505format_lisp_gpe_adjacency (u8 * s, va_list * args)
506{
507 lisp_gpe_adjacency_t *ladj = va_arg (*args, lisp_gpe_adjacency_t *);
508 lisp_gpe_adjacency_format_flags_t flags =
Billy McFallcfcf1e22016-10-14 09:51:49 -0400509 va_arg (*args, lisp_gpe_adjacency_format_flags_t);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100510
511 if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL)
512 {
513 s =
514 format (s, "index %d locks:%d\n", ladj - lisp_adj_pool, ladj->locks);
515 }
516
517 s = format (s, " vni: %d,", ladj->vni);
518 s = format (s, " remote-RLOC: %U,", format_ip_address, &ladj->remote_rloc);
519
520 if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL)
521 {
522 s = format (s, " %U\n",
523 format_lisp_gpe_sub_interface,
524 lisp_gpe_sub_interface_get (ladj->lisp_l3_sub_index));
525 s = format (s, " %U\n",
526 format_lisp_gpe_tunnel,
527 lisp_gpe_tunnel_get (ladj->tunnel_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100528 }
529 else
530 {
531 s = format (s, " LISP L3 sub-interface index: %d,",
532 ladj->lisp_l3_sub_index);
533 s = format (s, " LISP tunnel index: %d", ladj->tunnel_index);
534 }
535
536
537 return (s);
538}
539
540static clib_error_t *
541lisp_gpe_adjacency_show (vlib_main_t * vm,
542 unformat_input_t * input, vlib_cli_command_t * cmd)
543{
544 lisp_gpe_adjacency_t *ladj;
545 index_t index;
546
547 if (pool_elts (lisp_adj_pool) == 0)
548 vlib_cli_output (vm, "No lisp-gpe Adjacencies");
549
550 if (unformat (input, "%d", &index))
551 {
552 ladj = lisp_gpe_adjacency_get_i (index);
553 vlib_cli_output (vm, "%U", format_lisp_gpe_adjacency, ladj,
554 LISP_GPE_ADJ_FORMAT_FLAG_DETAIL);
555 }
556 else
557 {
558 /* *INDENT-OFF* */
559 pool_foreach (ladj, lisp_adj_pool,
560 ({
561 vlib_cli_output (vm, "[%d] %U\n",
562 ladj - lisp_adj_pool,
563 format_lisp_gpe_adjacency, ladj,
564 LISP_GPE_ADJ_FORMAT_FLAG_NONE);
565 }));
566 /* *INDENT-ON* */
567 }
568
569 return 0;
570}
571
572/* *INDENT-OFF* */
573VLIB_CLI_COMMAND (show_lisp_gpe_tunnel_command, static) =
574{
Filip Tehlar82786c42017-02-20 15:20:37 +0100575 .path = "show gpe adjacency",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100576 .function = lisp_gpe_adjacency_show,
577};
578/* *INDENT-ON* */
579
580#define LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS (256)
581#define LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE (1<<20)
582
583static clib_error_t *
584lisp_gpe_adj_module_init (vlib_main_t * vm)
585{
586 BV (clib_bihash_init) (&lisp_adj_db,
587 "Adjacency Neighbour table",
588 LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS,
589 LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE);
590
591 fib_node_register_type (FIB_NODE_TYPE_LISP_ADJ, &lisp_gpe_tuennel_vft);
592 return (NULL);
593}
594
Dave Barachf8d50682019-05-14 18:01:44 -0400595VLIB_INIT_FUNCTION (lisp_gpe_adj_module_init);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100596/*
597 * fd.io coding-style-patch-verification: ON
598 *
599 * Local Variables:
600 * eval: (c-set-style "gnu")
601 * End:
602 */