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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/adj/adj_nbr.h>
17 #include <vnet/adj/adj_internal.h>
18 #include <vnet/ethernet/arp_packet.h>
19 #include <vnet/fib/fib_walk.h>
22 * Vector Hash tables of neighbour (traditional) adjacencies
23 * Key: interface(for the vector index), address (and its proto),
24 * link-type/ether-type.
26 static uword **adj_nbr_tables[FIB_PROTOCOL_IP_MAX];
28 typedef struct adj_nbr_key_t_
30 ip46_address_t ank_ip;
34 #define ADJ_NBR_SET_KEY(_key, _lt, _nh) \
36 ip46_address_copy(&(_key).ank_ip, (_nh)); \
37 _key.ank_linkt = (_lt); \
40 #define ADJ_NBR_ITF_OK(_proto, _itf) \
41 (((_itf) < vec_len(adj_nbr_tables[_proto])) && \
42 (NULL != adj_nbr_tables[_proto][sw_if_index]))
45 adj_nbr_insert (fib_protocol_t nh_proto,
46 vnet_link_t link_type,
47 const ip46_address_t *nh_addr,
49 adj_index_t adj_index)
53 if (sw_if_index >= vec_len(adj_nbr_tables[nh_proto]))
55 vec_validate(adj_nbr_tables[nh_proto], sw_if_index);
57 if (NULL == adj_nbr_tables[nh_proto][sw_if_index])
59 adj_nbr_tables[nh_proto][sw_if_index] =
60 hash_create_mem(0, sizeof(adj_nbr_key_t), sizeof(adj_index_t));
63 ADJ_NBR_SET_KEY(kv, link_type, nh_addr);
65 hash_set_mem_alloc (&adj_nbr_tables[nh_proto][sw_if_index],
70 adj_nbr_remove (adj_index_t ai,
71 fib_protocol_t nh_proto,
72 vnet_link_t link_type,
73 const ip46_address_t *nh_addr,
78 if (!ADJ_NBR_ITF_OK(nh_proto, sw_if_index))
81 ADJ_NBR_SET_KEY(kv, link_type, nh_addr);
83 hash_unset_mem_free(&adj_nbr_tables[nh_proto][sw_if_index], &kv);
85 if (0 == hash_elts(adj_nbr_tables[nh_proto][sw_if_index]))
87 hash_free(adj_nbr_tables[nh_proto][sw_if_index]);
92 adj_nbr_find (fib_protocol_t nh_proto,
93 vnet_link_t link_type,
94 const ip46_address_t *nh_addr,
100 ADJ_NBR_SET_KEY(kv, link_type, nh_addr);
102 if (!ADJ_NBR_ITF_OK(nh_proto, sw_if_index))
103 return (ADJ_INDEX_INVALID);
105 p = hash_get_mem(adj_nbr_tables[nh_proto][sw_if_index], &kv);
111 return (ADJ_INDEX_INVALID);
115 adj_get_nd_node (fib_protocol_t proto)
118 case FIB_PROTOCOL_IP4:
119 return (ip4_arp_node.index);
120 case FIB_PROTOCOL_IP6:
121 return (ip6_discover_neighbor_node.index);
122 case FIB_PROTOCOL_MPLS:
126 return (ip4_arp_node.index);
130 * @brief Check and set feature flags if o/p interface has any o/p features.
133 adj_nbr_evaluate_feature (adj_index_t ai)
136 vnet_feature_main_t *fm = &feature_main;
143 switch (adj->ia_link)
146 arc_index = ip4_main.lookup_main.output_feature_arc_index;
149 arc_index = ip6_main.lookup_main.output_feature_arc_index;
152 arc_index = mpls_main.output_feature_arc_index;
158 sw_if_index = adj->rewrite_header.sw_if_index;
159 if (vec_len(fm->feature_count_by_sw_if_index[arc_index]) > sw_if_index)
161 feature_count = fm->feature_count_by_sw_if_index[arc_index][sw_if_index];
162 if (feature_count > 0)
164 vnet_feature_config_main_t *cm;
166 adj->rewrite_header.flags |= VNET_REWRITE_HAS_FEATURES;
167 cm = &fm->feature_config_mains[arc_index];
169 adj->ia_cfg_index = vec_elt (cm->config_index_by_sw_if_index,
176 static ip_adjacency_t*
177 adj_nbr_alloc (fib_protocol_t nh_proto,
178 vnet_link_t link_type,
179 const ip46_address_t *nh_addr,
184 adj = adj_alloc(nh_proto);
186 adj_nbr_insert(nh_proto, link_type, nh_addr,
191 * since we just added the ADJ we have no rewrite string for it,
194 adj->lookup_next_index = IP_LOOKUP_NEXT_ARP;
195 adj->sub_type.nbr.next_hop = *nh_addr;
196 adj->ia_link = link_type;
197 adj->ia_nh_proto = nh_proto;
198 adj->rewrite_header.sw_if_index = sw_if_index;
199 vnet_rewrite_update_mtu(vnet_get_main(), adj->ia_link,
200 &adj->rewrite_header);
202 adj_nbr_evaluate_feature (adj_get_index(adj));
207 * adj_nbr_add_or_lock
209 * Add an adjacency for the neighbour requested.
211 * The key for an adj is:
212 * - the Next-hops protocol (i.e. v4 or v6)
213 * - the address of the next-hop
214 * - the interface the next-hop is reachable through
217 adj_nbr_add_or_lock (fib_protocol_t nh_proto,
218 vnet_link_t link_type,
219 const ip46_address_t *nh_addr,
222 adj_index_t adj_index;
224 adj_index = adj_nbr_find(nh_proto, link_type, nh_addr, sw_if_index);
226 if (ADJ_INDEX_INVALID == adj_index)
231 vnm = vnet_get_main();
232 adj = adj_nbr_alloc(nh_proto, link_type, nh_addr, sw_if_index);
233 adj_index = adj_get_index(adj);
236 if (ip46_address_is_equal(&ADJ_BCAST_ADDR, nh_addr))
238 adj->lookup_next_index = IP_LOOKUP_NEXT_BCAST;
241 vnet_rewrite_init(vnm, sw_if_index, link_type,
242 adj_get_nd_node(nh_proto),
243 vnet_tx_node_index_for_sw_interface(vnm, sw_if_index),
244 &adj->rewrite_header);
247 * we need a rewrite where the destination IP address is converted
248 * to the appropriate link-layer address. This is interface specific.
249 * So ask the interface to do it.
251 vnet_update_adjacency_for_sw_interface(vnm, sw_if_index, adj_index);
258 adj_delegate_adj_created(adj_get(adj_index));
263 adj_nbr_add_or_lock_w_rewrite (fib_protocol_t nh_proto,
264 vnet_link_t link_type,
265 const ip46_address_t *nh_addr,
269 adj_index_t adj_index;
271 adj_index = adj_nbr_find(nh_proto, link_type, nh_addr, sw_if_index);
273 if (ADJ_INDEX_INVALID == adj_index)
277 adj = adj_nbr_alloc(nh_proto, link_type, nh_addr, sw_if_index);
278 adj->rewrite_header.sw_if_index = sw_if_index;
279 adj_index = adj_get_index(adj);
283 adj_nbr_update_rewrite(adj_index,
284 ADJ_NBR_REWRITE_FLAG_COMPLETE,
287 adj_delegate_adj_created(adj_get(adj_index));
293 * adj_nbr_update_rewrite
295 * Update the adjacency's rewrite string. A NULL string implies the
296 * rewrite is reset (i.e. when ARP/ND entry is gone).
297 * NB: the adj being updated may be handling traffic in the DP.
300 adj_nbr_update_rewrite (adj_index_t adj_index,
301 adj_nbr_rewrite_flag_t flags,
306 ASSERT(ADJ_INDEX_INVALID != adj_index);
308 adj = adj_get(adj_index);
310 if (flags & ADJ_NBR_REWRITE_FLAG_COMPLETE)
313 * update the adj's rewrite string and build the arc
314 * from the rewrite node to the interface's TX node
316 adj_nbr_update_rewrite_internal(adj, IP_LOOKUP_NEXT_REWRITE,
317 adj_get_rewrite_node(adj->ia_link),
318 vnet_tx_node_index_for_sw_interface(
320 adj->rewrite_header.sw_if_index),
325 adj_nbr_update_rewrite_internal(adj, IP_LOOKUP_NEXT_ARP,
326 adj_get_nd_node(adj->ia_nh_proto),
327 vnet_tx_node_index_for_sw_interface(
329 adj->rewrite_header.sw_if_index),
335 * adj_nbr_update_rewrite_internal
337 * Update the adjacency's rewrite string. A NULL string implies the
338 * rewrite is reset (i.e. when ARP/ND entry is gone).
339 * NB: the adj being updated may be handling traffic in the DP.
342 adj_nbr_update_rewrite_internal (ip_adjacency_t *adj,
343 ip_lookup_next_t adj_next_index,
348 ip_adjacency_t *walk_adj;
349 adj_index_t walk_ai, ai;
354 vm = vlib_get_main();
355 old_next = adj->lookup_next_index;
357 ai = walk_ai = adj_get_index(adj);
358 if (VNET_LINK_MPLS == adj->ia_link)
361 * The link type MPLS has no children in the control plane graph, it only
362 * has children in the data-plane graph. The backwalk is up the former.
363 * So we need to walk from its IP cousin.
365 walk_ai = adj_nbr_find(adj->ia_nh_proto,
366 fib_proto_to_link(adj->ia_nh_proto),
367 &adj->sub_type.nbr.next_hop,
368 adj->rewrite_header.sw_if_index);
372 * Don't call the walk re-entrantly
374 if (ADJ_INDEX_INVALID != walk_ai)
376 walk_adj = adj_get(walk_ai);
377 if (ADJ_FLAG_SYNC_WALK_ACTIVE & walk_adj->ia_flags)
384 * Prevent re-entrant walk of the same adj
386 walk_adj->ia_flags |= ADJ_FLAG_SYNC_WALK_ACTIVE;
396 * lock the adjacencies that are affected by updates this walk will provoke.
397 * Since the aim of the walk is to update children to link to a different
398 * DPO, this adj will no longer be in use and its lock count will drop to 0.
399 * We don't want it to be deleted as part of this endeavour.
405 * Updating a rewrite string is not atomic;
406 * - the rewrite string is too long to write in one instruction
407 * - when swapping from incomplete to complete, we also need to update
408 * the VLIB graph next-index of the adj.
409 * ideally we would only want to suspend forwarding via this adj whilst we
410 * do this, but we do not have that level of granularity - it's suspend all
411 * worker threads or nothing.
412 * The other choices are:
413 * - to mark the adj down and back walk so child load-balances drop this adj
415 * - update the next_node index of this adj to point to error-drop
416 * both of which will mean for MAC change we will drop for this adj
417 * which is not acceptable. However, when the adj changes type (from
418 * complete to incomplete and vice-versa) the child DPOs, which have the
419 * VLIB graph next node index, will be sending packets to the wrong graph
420 * node. So from the options above, updating the next_node of the adj to
421 * be drop will work, but it relies on each graph node v4/v6/mpls, rewrite/
422 * arp/midchain always be valid w.r.t. a mis-match of adj type and node type
423 * (i.e. a rewrite adj in the arp node). This is not enforceable. Getting it
424 * wrong will lead to hard to find bugs since its a race condition. So we
425 * choose the more reliable method of updating the children to use the drop,
426 * then switching adj's type, then updating the children again. Did I mention
427 * that this doesn't happen often...
428 * So we need to distinguish between the two cases:
430 * 2 - adj type change
433 old_next != adj_next_index &&
434 ADJ_INDEX_INVALID != walk_ai)
437 * the adj is changing type. we need to fix all children so that they
438 * stack momentarily on a drop, while the adj changes. If we don't do
439 * this the children will send packets to a VLIB graph node that does
440 * not correspond to the adj's type - and it goes downhill from there.
442 fib_node_back_walk_ctx_t bw_ctx = {
443 .fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_DOWN,
445 * force this walk to be synchronous. if we don't and a node in the graph
446 * (a heavily shared path-list) chooses to back-ground the walk (make it
447 * async) then it will pause and we will do the adj update below, before
448 * all the children are updated. not good.
450 .fnbw_flags = FIB_NODE_BW_FLAG_FORCE_SYNC,
453 fib_walk_sync(FIB_NODE_TYPE_ADJ, walk_ai, &bw_ctx);
455 * fib_walk_sync may allocate a new adjacency and potentially cuase a
456 * realloc for adj_pool. When that happens, adj pointer is no longer
457 * valid here. We refresh the adj pointer accordingly.
463 * If we are just updating the MAC string of the adj (which we also can't
464 * do atomically), then we need to stop packets switching through the adj.
465 * We can't do that on a per-adj basis, so it's all the packets.
466 * If we are updating the type, and we walked back to the children above,
467 * then this barrier serves to flush the queues/frames.
469 vlib_worker_thread_barrier_sync(vm);
471 adj->lookup_next_index = adj_next_index;
472 adj->ia_node_index = this_node;
477 * new rewrite provided.
478 * fill in the adj's rewrite string, and build the VLIB graph arc.
480 vnet_rewrite_set_data_internal(&adj->rewrite_header,
481 sizeof(adj->rewrite_data),
488 vnet_rewrite_clear_data_internal(&adj->rewrite_header,
489 sizeof(adj->rewrite_data));
491 adj->rewrite_header.next_index = vlib_node_add_next(vlib_get_main(),
496 * done with the rewrite update - let the workers loose.
498 vlib_worker_thread_barrier_release(vm);
501 (old_next != adj->lookup_next_index) &&
502 (ADJ_INDEX_INVALID != walk_ai))
505 * backwalk to the children so they can stack on the now updated
508 fib_node_back_walk_ctx_t bw_ctx = {
509 .fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE,
512 fib_walk_sync(FIB_NODE_TYPE_ADJ, walk_ai, &bw_ctx);
515 * Prevent re-entrant walk of the same adj
519 walk_adj = adj_get(walk_ai);
520 walk_adj->ia_flags &= ~ADJ_FLAG_SYNC_WALK_ACTIVE;
523 adj_delegate_adj_modified(adj);
529 adj_nbr_db_size (void)
531 fib_protocol_t proto;
535 for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
537 vec_foreach_index(sw_if_index, adj_nbr_tables[proto])
539 if (NULL != adj_nbr_tables[proto][sw_if_index])
541 count += hash_elts(adj_nbr_tables[proto][sw_if_index]);
549 * @brief Walk all adjacencies on a link for a given next-hop protocol
552 adj_nbr_walk (u32 sw_if_index,
553 fib_protocol_t adj_nh_proto,
557 adj_index_t ai, *ais, *aip;
560 if (!ADJ_NBR_ITF_OK(adj_nh_proto, sw_if_index))
565 /* elements may be removed from the table during the walk, so
566 * collect the set first then process them */
567 hash_foreach_mem (key, ai, adj_nbr_tables[adj_nh_proto][sw_if_index],
572 vec_foreach(aip, ais)
574 /* An adj may be deleted during the walk so check first */
575 if (!pool_is_free_index(adj_pool, *aip))
582 * @brief Walk adjacencies on a link with a given v4 next-hop.
583 * that is visit the adjacencies with different link types.
586 adj_nbr_walk_nh4 (u32 sw_if_index,
587 const ip4_address_t *addr,
591 if (!ADJ_NBR_ITF_OK(FIB_PROTOCOL_IP4, sw_if_index))
594 ip46_address_t nh = {
600 FOR_EACH_VNET_LINK(linkt)
602 ai = adj_nbr_find (FIB_PROTOCOL_IP4, linkt, &nh, sw_if_index);
604 if (INDEX_INVALID != ai)
610 * @brief Walk adjacencies on a link with a given v6 next-hop.
611 * that is visit the adjacencies with different link types.
614 adj_nbr_walk_nh6 (u32 sw_if_index,
615 const ip6_address_t *addr,
619 if (!ADJ_NBR_ITF_OK(FIB_PROTOCOL_IP6, sw_if_index))
622 ip46_address_t nh = {
628 FOR_EACH_VNET_LINK(linkt)
630 ai = adj_nbr_find (FIB_PROTOCOL_IP6, linkt, &nh, sw_if_index);
632 if (INDEX_INVALID != ai)
638 * @brief Walk adjacencies on a link with a given next-hop.
639 * that is visit the adjacencies with different link types.
642 adj_nbr_walk_nh (u32 sw_if_index,
643 fib_protocol_t adj_nh_proto,
644 const ip46_address_t *nh,
648 if (!ADJ_NBR_ITF_OK(adj_nh_proto, sw_if_index))
651 switch (adj_nh_proto)
653 case FIB_PROTOCOL_IP4:
654 adj_nbr_walk_nh4(sw_if_index, &nh->ip4, cb, ctx);
656 case FIB_PROTOCOL_IP6:
657 adj_nbr_walk_nh6(sw_if_index, &nh->ip6, cb, ctx);
659 case FIB_PROTOCOL_MPLS:
666 * Flags associated with the interface state walks
668 typedef enum adj_nbr_interface_flags_t_
670 ADJ_NBR_INTERFACE_UP = (1 << 0),
671 } adj_nbr_interface_flags_t;
674 * Context for the state change walk of the DB
676 typedef struct adj_nbr_interface_state_change_ctx_t_
679 * Flags on the interface
681 adj_nbr_interface_flags_t flags;
682 } adj_nbr_interface_state_change_ctx_t;
685 adj_nbr_interface_state_change_one (adj_index_t ai,
689 * Back walk the graph to inform the forwarding entries
690 * that this interface state has changed. Do this synchronously
691 * since this is the walk that provides convergence
693 adj_nbr_interface_state_change_ctx_t *ctx = arg;
694 fib_node_back_walk_ctx_t bw_ctx = {
695 .fnbw_reason = ((ctx->flags & ADJ_NBR_INTERFACE_UP) ?
696 FIB_NODE_BW_REASON_FLAG_INTERFACE_UP :
697 FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN),
699 * the force sync applies only as far as the first fib_entry.
700 * And it's the fib_entry's we need to converge away from
701 * the adjacencies on the now down link
703 .fnbw_flags = (!(ctx->flags & ADJ_NBR_INTERFACE_UP) ?
704 FIB_NODE_BW_FLAG_FORCE_SYNC :
705 FIB_NODE_BW_FLAG_NONE),
711 adj->ia_flags |= ADJ_FLAG_SYNC_WALK_ACTIVE;
712 fib_walk_sync(FIB_NODE_TYPE_ADJ, ai, &bw_ctx);
713 adj->ia_flags &= ~ADJ_FLAG_SYNC_WALK_ACTIVE;
715 return (ADJ_WALK_RC_CONTINUE);
719 * @brief Registered function for SW interface state changes
721 static clib_error_t *
722 adj_nbr_sw_interface_state_change (vnet_main_t * vnm,
726 fib_protocol_t proto;
729 * walk each adj on the interface and trigger a walk from that adj
731 for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
733 adj_nbr_interface_state_change_ctx_t ctx = {
734 .flags = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
735 ADJ_NBR_INTERFACE_UP :
739 adj_nbr_walk(sw_if_index, proto,
740 adj_nbr_interface_state_change_one,
747 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION_PRIO(
748 adj_nbr_sw_interface_state_change,
749 VNET_ITF_FUNC_PRIORITY_HIGH);
752 * @brief Invoked on each SW interface of a HW interface when the
753 * HW interface state changes
756 adj_nbr_hw_sw_interface_state_change (vnet_main_t * vnm,
760 adj_nbr_interface_state_change_ctx_t *ctx = arg;
761 fib_protocol_t proto;
764 * walk each adj on the interface and trigger a walk from that adj
766 for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
768 adj_nbr_walk(sw_if_index, proto,
769 adj_nbr_interface_state_change_one,
772 return (WALK_CONTINUE);
776 * @brief Registered callback for HW interface state changes
778 static clib_error_t *
779 adj_nbr_hw_interface_state_change (vnet_main_t * vnm,
784 * walk SW interface on the HW
786 adj_nbr_interface_state_change_ctx_t ctx = {
787 .flags = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
788 ADJ_NBR_INTERFACE_UP :
792 vnet_hw_interface_walk_sw(vnm, hw_if_index,
793 adj_nbr_hw_sw_interface_state_change,
799 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION_PRIO(
800 adj_nbr_hw_interface_state_change,
801 VNET_ITF_FUNC_PRIORITY_HIGH);
804 adj_nbr_interface_delete_one (adj_index_t ai,
808 * Back walk the graph to inform the forwarding entries
809 * that this interface has been deleted.
811 fib_node_back_walk_ctx_t bw_ctx = {
812 .fnbw_reason = FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE,
820 adj->ia_flags |= ADJ_FLAG_SYNC_WALK_ACTIVE;
821 fib_walk_sync(FIB_NODE_TYPE_ADJ, ai, &bw_ctx);
822 adj->ia_flags &= ~ADJ_FLAG_SYNC_WALK_ACTIVE;
825 return (ADJ_WALK_RC_CONTINUE);
829 * adj_nbr_interface_add_del
831 * Registered to receive interface Add and delete notifications
833 static clib_error_t *
834 adj_nbr_interface_add_del (vnet_main_t * vnm,
838 fib_protocol_t proto;
843 * not interested in interface additions. we will not back walk
844 * to resolve paths through newly added interfaces. Why? The control
845 * plane should have the brains to add interfaces first, then routes.
846 * So the case where there are paths with a interface that matches
847 * one just created is the case where the path resolved through an
848 * interface that was deleted, and still has not been removed. The
849 * new interface added, is NO GUARANTEE that the interface being
850 * added now, even though it may have the same sw_if_index, is the
851 * same interface that the path needs. So tough!
852 * If the control plane wants these routes to resolve it needs to
853 * remove and add them again.
858 for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
860 adj_nbr_walk(sw_if_index, proto,
861 adj_nbr_interface_delete_one,
869 VNET_SW_INTERFACE_ADD_DEL_FUNCTION(adj_nbr_interface_add_del);
873 adj_nbr_show_one (adj_index_t ai,
876 vlib_cli_output (arg, "[@%d] %U",
878 format_ip_adjacency, ai,
879 FORMAT_IP_ADJACENCY_NONE);
881 return (ADJ_WALK_RC_CONTINUE);
884 static clib_error_t *
885 adj_nbr_show (vlib_main_t * vm,
886 unformat_input_t * input,
887 vlib_cli_command_t * cmd)
889 adj_index_t ai = ADJ_INDEX_INVALID;
890 ip46_address_t nh = ip46_address_initializer;
891 u32 sw_if_index = ~0;
893 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
895 if (unformat (input, "%U",
896 unformat_vnet_sw_interface, vnet_get_main(),
899 else if (unformat (input, "%U",
900 unformat_ip46_address, &nh, IP46_TYPE_ANY))
902 else if (unformat (input, "%d", &ai))
908 if (ADJ_INDEX_INVALID != ai)
910 vlib_cli_output (vm, "[@%d] %U",
912 format_ip_adjacency, ai,
913 FORMAT_IP_ADJACENCY_DETAIL);
915 else if (~0 != sw_if_index)
917 fib_protocol_t proto;
919 if (ip46_address_is_zero(&nh))
921 for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
923 adj_nbr_walk(sw_if_index, proto,
930 proto = (ip46_address_is_ip4(&nh) ?
933 adj_nbr_walk_nh(sw_if_index, proto, &nh,
940 fib_protocol_t proto;
942 for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
944 vec_foreach_index(sw_if_index, adj_nbr_tables[proto])
946 adj_nbr_walk(sw_if_index, proto,
957 * Show all neighbour adjacencies.
959 * @cliexstart{sh adj nbr}
960 * [@2] ipv4 via 1.0.0.2 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
961 * [@3] mpls via 1.0.0.2 loop0: MPLS_UNICAST: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
962 * [@4] ipv4 via 1.0.0.3 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
963 * [@5] mpls via 1.0.0.3 loop0: MPLS_UNICAST: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
966 VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
967 .path = "show adj nbr",
968 .short_help = "show adj nbr [<adj_index>] [interface]",
969 .function = adj_nbr_show,
973 format_adj_nbr_incomplete (u8* s, va_list *ap)
975 index_t index = va_arg(*ap, index_t);
976 CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
977 vnet_main_t * vnm = vnet_get_main();
978 ip_adjacency_t * adj = adj_get(index);
980 s = format (s, "arp-%U", format_vnet_link, adj->ia_link);
981 s = format (s, ": via %U",
982 format_ip46_address, &adj->sub_type.nbr.next_hop,
983 adj_proto_to_46(adj->ia_nh_proto));
984 s = format (s, " %U",
985 format_vnet_sw_if_index_name,
986 vnm, adj->rewrite_header.sw_if_index);
992 format_adj_nbr (u8* s, va_list *ap)
994 index_t index = va_arg(*ap, index_t);
995 CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
996 ip_adjacency_t * adj = adj_get(index);
998 s = format (s, "%U", format_vnet_link, adj->ia_link);
999 s = format (s, " via %U ",
1000 format_ip46_address, &adj->sub_type.nbr.next_hop,
1001 adj_proto_to_46(adj->ia_nh_proto));
1002 s = format (s, "%U",
1003 format_vnet_rewrite,
1004 &adj->rewrite_header, sizeof (adj->rewrite_data), 0);
1010 adj_dpo_lock (dpo_id_t *dpo)
1012 adj_lock(dpo->dpoi_index);
1015 adj_dpo_unlock (dpo_id_t *dpo)
1017 adj_unlock(dpo->dpoi_index);
1023 fib_show_memory_usage("Adjacency",
1024 pool_elts(adj_pool),
1026 sizeof(ip_adjacency_t));
1029 const static dpo_vft_t adj_nbr_dpo_vft = {
1030 .dv_lock = adj_dpo_lock,
1031 .dv_unlock = adj_dpo_unlock,
1032 .dv_format = format_adj_nbr,
1033 .dv_mem_show = adj_mem_show,
1034 .dv_get_urpf = adj_dpo_get_urpf,
1036 const static dpo_vft_t adj_nbr_incompl_dpo_vft = {
1037 .dv_lock = adj_dpo_lock,
1038 .dv_unlock = adj_dpo_unlock,
1039 .dv_format = format_adj_nbr_incomplete,
1040 .dv_get_urpf = adj_dpo_get_urpf,
1044 * @brief The per-protocol VLIB graph nodes that are assigned to an adjacency
1047 * this means that these graph nodes are ones from which a nbr is the
1048 * parent object in the DPO-graph.
1050 const static char* const nbr_ip4_nodes[] =
1055 const static char* const nbr_ip6_nodes[] =
1060 const static char* const nbr_mpls_nodes[] =
1065 const static char* const nbr_ethernet_nodes[] =
1070 const static char* const * const nbr_nodes[DPO_PROTO_NUM] =
1072 [DPO_PROTO_IP4] = nbr_ip4_nodes,
1073 [DPO_PROTO_IP6] = nbr_ip6_nodes,
1074 [DPO_PROTO_MPLS] = nbr_mpls_nodes,
1075 [DPO_PROTO_ETHERNET] = nbr_ethernet_nodes,
1078 const static char* const nbr_incomplete_ip4_nodes[] =
1083 const static char* const nbr_incomplete_ip6_nodes[] =
1085 "ip6-discover-neighbor",
1088 const static char* const nbr_incomplete_mpls_nodes[] =
1090 "mpls-adj-incomplete",
1094 const static char* const * const nbr_incomplete_nodes[DPO_PROTO_NUM] =
1096 [DPO_PROTO_IP4] = nbr_incomplete_ip4_nodes,
1097 [DPO_PROTO_IP6] = nbr_incomplete_ip6_nodes,
1098 [DPO_PROTO_MPLS] = nbr_incomplete_mpls_nodes,
1102 adj_nbr_module_init (void)
1104 dpo_register(DPO_ADJACENCY,
1107 dpo_register(DPO_ADJACENCY_INCOMPLETE,
1108 &adj_nbr_incompl_dpo_vft,
1109 nbr_incomplete_nodes);