fib: Use the VLIB logger for adjacency debugging
[vpp.git] / src / vnet / adj / adj.c
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 #include <vnet/adj/adj.h>
17 #include <vnet/adj/adj_internal.h>
18 #include <vnet/adj/adj_glean.h>
19 #include <vnet/adj/adj_midchain.h>
20 #include <vnet/adj/adj_mcast.h>
21 #include <vnet/adj/adj_delegate.h>
22 #include <vnet/fib/fib_node_list.h>
23 #include <vnet/fib/fib_walk.h>
24
25 /* Adjacency packet/byte counters indexed by adjacency index. */
26 vlib_combined_counter_main_t adjacency_counters = {
27     .name = "adjacency",
28     .stat_segment_name = "/net/adjacency",
29 };
30
31 /*
32  * the single adj pool
33  */
34 ip_adjacency_t *adj_pool;
35
36 /**
37  * The adjacency logger
38  */
39 vlib_log_class_t adj_logger;
40
41 /**
42  * @brief Global Config for enabling per-adjacency counters.
43  * By default these are disabled.
44  */
45 int adj_per_adj_counters;
46
47 const ip46_address_t ADJ_BCAST_ADDR = {
48     .ip6 = {
49         .as_u64[0] = 0xffffffffffffffff,
50         .as_u64[1] = 0xffffffffffffffff,
51     },
52 };
53
54 /**
55  * Adj flag names
56  */
57 static const char *adj_attr_names[] = ADJ_ATTR_NAMES;
58
59 always_inline void
60 adj_poison (ip_adjacency_t * adj)
61 {
62     if (CLIB_DEBUG > 0)
63     {
64         clib_memset (adj, 0xfe, sizeof (adj[0]));
65     }
66 }
67
68 ip_adjacency_t *
69 adj_alloc (fib_protocol_t proto)
70 {
71     ip_adjacency_t *adj;
72     u8 need_barrier_sync = 0;
73     vlib_main_t *vm;
74     vm = vlib_get_main();
75
76     ASSERT (vm->thread_index == 0);
77
78     pool_get_aligned_will_expand (adj_pool, need_barrier_sync,
79                                   CLIB_CACHE_LINE_BYTES);
80     /* If the adj_pool will expand, stop the parade. */
81     if (need_barrier_sync)
82         vlib_worker_thread_barrier_sync (vm);
83
84     pool_get_aligned(adj_pool, adj, CLIB_CACHE_LINE_BYTES);
85
86     adj_poison(adj);
87
88     /* Validate adjacency counters. */
89     if (need_barrier_sync == 0)
90     {
91         /* If the adj counter pool will expand, stop the parade */
92         need_barrier_sync = vlib_validate_combined_counter_will_expand
93             (&adjacency_counters, adj_get_index (adj));
94         if (need_barrier_sync)
95             vlib_worker_thread_barrier_sync (vm);
96     }
97     vlib_validate_combined_counter(&adjacency_counters,
98                                    adj_get_index(adj));
99
100     /* Make sure certain fields are always initialized. */
101     vlib_zero_combined_counter(&adjacency_counters,
102                                adj_get_index(adj));
103     fib_node_init(&adj->ia_node,
104                   FIB_NODE_TYPE_ADJ);
105
106     adj->ia_nh_proto = proto;
107     adj->ia_flags = 0;
108     adj->ia_cfg_index = 0;
109     adj->rewrite_header.sw_if_index = ~0;
110     adj->rewrite_header.flags = 0;
111     adj->lookup_next_index = 0;
112     adj->ia_delegates = NULL;
113
114     /* lest it become a midchain in the future */
115     clib_memset(&adj->sub_type.midchain.next_dpo, 0,
116            sizeof(adj->sub_type.midchain.next_dpo));
117
118     if (need_barrier_sync)
119         vlib_worker_thread_barrier_release (vm);
120
121     return (adj);
122 }
123
124 static int
125 adj_index_is_special (adj_index_t adj_index)
126 {
127     if (ADJ_INDEX_INVALID == adj_index)
128         return (!0);
129
130     return (0);
131 }
132
133 u8*
134 format_adj_flags (u8 * s, va_list * args)
135 {
136     adj_flags_t af;
137     adj_attr_t at;
138
139     af = va_arg (*args, int);
140
141     if (ADJ_FLAG_NONE == af)
142     {
143         return (format(s, "None"));
144     }
145     FOR_EACH_ADJ_ATTR(at)
146     {
147         if (af & (1 << at))
148         {
149             s = format(s, "%s ", adj_attr_names[at]);
150         }
151     }
152     return (s);
153 }
154
155 /**
156  * @brief Pretty print helper function for formatting specific adjacencies.
157  * @param s - input string to format
158  * @param args - other args passed to format function such as:
159  *                 - vnet_main_t
160  *                 - ip_lookup_main_t
161  *                 - adj_index
162  */
163 u8 *
164 format_ip_adjacency (u8 * s, va_list * args)
165 {
166     format_ip_adjacency_flags_t fiaf;
167     ip_adjacency_t * adj;
168     u32 adj_index;
169
170     adj_index = va_arg (*args, u32);
171     fiaf = va_arg (*args, format_ip_adjacency_flags_t);
172
173     if (!adj_is_valid(adj_index))
174       return format(s, "<invalid adjacency>");
175
176     adj = adj_get(adj_index);
177
178     switch (adj->lookup_next_index)
179     {
180     case IP_LOOKUP_NEXT_REWRITE:
181     case IP_LOOKUP_NEXT_BCAST:
182         s = format (s, "%U", format_adj_nbr, adj_index, 0);
183         break;
184     case IP_LOOKUP_NEXT_ARP:
185         s = format (s, "%U", format_adj_nbr_incomplete, adj_index, 0);
186         break;
187     case IP_LOOKUP_NEXT_GLEAN:
188         s = format (s, "%U", format_adj_glean, adj_index, 0);
189         break;
190     case IP_LOOKUP_NEXT_MIDCHAIN:
191         s = format (s, "%U", format_adj_midchain, adj_index, 2);
192         break;
193     case IP_LOOKUP_NEXT_MCAST:
194         s = format (s, "%U", format_adj_mcast, adj_index, 0);
195         break;
196     case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
197         s = format (s, "%U", format_adj_mcast_midchain, adj_index, 0);
198         break;
199     case IP_LOOKUP_NEXT_DROP:
200     case IP_LOOKUP_NEXT_PUNT:
201     case IP_LOOKUP_NEXT_LOCAL:
202     case IP_LOOKUP_NEXT_ICMP_ERROR:
203     case IP_LOOKUP_N_NEXT:
204         break;
205     }
206
207     if (fiaf & FORMAT_IP_ADJACENCY_DETAIL)
208     {
209         vlib_counter_t counts;
210
211         vlib_get_combined_counter(&adjacency_counters, adj_index, &counts);
212         s = format (s, "\n   flags:%U", format_adj_flags, adj->ia_flags);
213         s = format (s, "\n   counts:[%Ld:%Ld]", counts.packets, counts.bytes);
214         s = format (s, "\n   locks:%d", adj->ia_node.fn_locks);
215         s = format(s, "\n delegates:");
216         s = adj_delegate_format(s, adj);
217
218         s = format(s, "\n children:");
219         if (fib_node_list_get_size(adj->ia_node.fn_children))
220         {
221             s = format(s, "\n  ");
222             s = fib_node_children_format(adj->ia_node.fn_children, s);
223         }
224     }
225
226     return s;
227 }
228
229 int
230 adj_recursive_loop_detect (adj_index_t ai,
231                            fib_node_index_t **entry_indicies)
232 {
233     ip_adjacency_t * adj;
234
235     adj = adj_get(ai);
236
237     switch (adj->lookup_next_index)
238     {
239     case IP_LOOKUP_NEXT_REWRITE:
240     case IP_LOOKUP_NEXT_ARP:
241     case IP_LOOKUP_NEXT_GLEAN:
242     case IP_LOOKUP_NEXT_MCAST:
243     case IP_LOOKUP_NEXT_BCAST:
244     case IP_LOOKUP_NEXT_DROP:
245     case IP_LOOKUP_NEXT_PUNT:
246     case IP_LOOKUP_NEXT_LOCAL:
247     case IP_LOOKUP_NEXT_ICMP_ERROR:
248     case IP_LOOKUP_N_NEXT:
249         /*
250          * these adjacency types are terminal graph nodes, so there's no
251          * possibility of a loop down here.
252          */
253         break;
254     case IP_LOOKUP_NEXT_MIDCHAIN:
255     case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
256         return (adj_ndr_midchain_recursive_loop_detect(ai, entry_indicies));
257     }
258
259     return (0);
260 }
261
262 /*
263  * adj_last_lock_gone
264  *
265  * last lock/reference to the adj has gone, we no longer need it.
266  */
267 static void
268 adj_last_lock_gone (ip_adjacency_t *adj)
269 {
270     vlib_main_t * vm = vlib_get_main();
271
272     ASSERT(0 == fib_node_list_get_size(adj->ia_node.fn_children));
273     ADJ_DBG(adj, "last-lock-gone");
274
275     adj_delegate_adj_deleted(adj);
276
277     vlib_worker_thread_barrier_sync (vm);
278
279     switch (adj->lookup_next_index)
280     {
281     case IP_LOOKUP_NEXT_MIDCHAIN:
282         adj_midchain_teardown(adj);
283         /* FALL THROUGH */
284     case IP_LOOKUP_NEXT_ARP:
285     case IP_LOOKUP_NEXT_REWRITE:
286     case IP_LOOKUP_NEXT_BCAST:
287         /*
288          * complete and incomplete nbr adjs
289          */
290         adj_nbr_remove(adj_get_index(adj),
291                        adj->ia_nh_proto,
292                        adj->ia_link,
293                        &adj->sub_type.nbr.next_hop,
294                        adj->rewrite_header.sw_if_index);
295         break;
296     case IP_LOOKUP_NEXT_GLEAN:
297         adj_glean_remove(adj);
298         break;
299     case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
300         adj_midchain_teardown(adj);
301         /* FALL THROUGH */
302     case IP_LOOKUP_NEXT_MCAST:
303         adj_mcast_remove(adj->ia_nh_proto,
304                          adj->rewrite_header.sw_if_index);
305         break;
306     case IP_LOOKUP_NEXT_DROP:
307     case IP_LOOKUP_NEXT_PUNT:
308     case IP_LOOKUP_NEXT_LOCAL:
309     case IP_LOOKUP_NEXT_ICMP_ERROR:
310     case IP_LOOKUP_N_NEXT:
311         /*
312          * type not stored in any DB from which we need to remove it
313          */
314         break;
315     }
316
317     vlib_worker_thread_barrier_release(vm);
318
319     fib_node_deinit(&adj->ia_node);
320     ASSERT(0 == vec_len(adj->ia_delegates));
321     vec_free(adj->ia_delegates);
322     pool_put(adj_pool, adj);
323 }
324
325 u32
326 adj_dpo_get_urpf (const dpo_id_t *dpo)
327 {
328     ip_adjacency_t *adj;
329
330     adj = adj_get(dpo->dpoi_index);
331
332     return (adj->rewrite_header.sw_if_index);
333 }
334
335 u16
336 adj_dpo_get_mtu (const dpo_id_t *dpo)
337 {
338     ip_adjacency_t *adj;
339
340     adj = adj_get(dpo->dpoi_index);
341
342     return (adj->rewrite_header.max_l3_packet_bytes);
343 }
344
345 void
346 adj_lock (adj_index_t adj_index)
347 {
348     ip_adjacency_t *adj;
349
350     if (adj_index_is_special(adj_index))
351     {
352         return;
353     }
354
355     adj = adj_get(adj_index);
356     ASSERT(adj);
357
358     fib_node_lock(&adj->ia_node);
359 }
360
361 void
362 adj_unlock (adj_index_t adj_index)
363 {
364     ip_adjacency_t *adj;
365
366     if (adj_index_is_special(adj_index))
367     {
368         return;
369     }
370
371     adj = adj_get(adj_index);
372     ASSERT(adj);
373
374     fib_node_unlock(&adj->ia_node);
375 }
376
377 u32
378 adj_child_add (adj_index_t adj_index,
379                fib_node_type_t child_type,
380                fib_node_index_t child_index)
381 {
382     ASSERT(ADJ_INDEX_INVALID != adj_index);
383     if (adj_index_is_special(adj_index))
384     {
385         return (~0);
386     }
387
388     return (fib_node_child_add(FIB_NODE_TYPE_ADJ,
389                                adj_index,
390                                child_type,
391                                child_index));
392 }
393
394 void
395 adj_child_remove (adj_index_t adj_index,
396                   u32 sibling_index)
397 {
398     if (adj_index_is_special(adj_index))
399     {
400         return;
401     }
402
403     fib_node_child_remove(FIB_NODE_TYPE_ADJ,
404                           adj_index,
405                           sibling_index);
406 }
407
408 /*
409  * Context for the walk to update the cached feature flags.
410  */
411 typedef struct adj_feature_update_t_
412 {
413     u8 arc;
414     u8 enable;
415 } adj_feature_update_ctx_t;
416
417 static adj_walk_rc_t
418 adj_feature_update_walk_cb (adj_index_t ai,
419                             void *arg)
420 {
421     adj_feature_update_ctx_t *ctx = arg;
422     ip_adjacency_t *adj;
423
424     adj = adj_get(ai);
425
426     /*
427      * this ugly mess matches the feature arc that is changing with affected
428      * adjacencies
429      */
430     if (((ctx->arc == ip6_main.lookup_main.output_feature_arc_index) &&
431          (VNET_LINK_IP6 == adj->ia_link)) ||
432         ((ctx->arc == ip4_main.lookup_main.output_feature_arc_index) &&
433          (VNET_LINK_IP4 == adj->ia_link)) ||
434         ((ctx->arc == mpls_main.output_feature_arc_index) &&
435          (VNET_LINK_MPLS == adj->ia_link)))
436     {
437         vnet_feature_main_t *fm = &feature_main;
438         vnet_feature_config_main_t *cm;
439
440         cm = &fm->feature_config_mains[ctx->arc];
441
442         if (ctx->enable)
443             adj->rewrite_header.flags |= VNET_REWRITE_HAS_FEATURES;
444         else
445             adj->rewrite_header.flags &= ~VNET_REWRITE_HAS_FEATURES;
446
447         adj->ia_cfg_index = vec_elt (cm->config_index_by_sw_if_index,
448                                      adj->rewrite_header.sw_if_index);
449     }
450     return (ADJ_WALK_RC_CONTINUE);
451 }
452
453 static void
454 adj_feature_update (u32 sw_if_index,
455                     u8 arc_index,
456                     u8 is_enable,
457                     void *data)
458 {
459     /*
460      * Walk all the adjacencies on the interface to update the cached
461      * 'has-features' flag
462      */
463     adj_feature_update_ctx_t ctx = {
464         .arc = arc_index,
465         .enable = is_enable,
466     };
467     adj_walk (sw_if_index, adj_feature_update_walk_cb, &ctx);
468 }
469
470 static adj_walk_rc_t
471 adj_mtu_update_walk_cb (adj_index_t ai,
472                         void *arg)
473 {
474     ip_adjacency_t *adj;
475
476     adj = adj_get(ai);
477
478     vnet_rewrite_update_mtu (vnet_get_main(), adj->ia_link,
479                              &adj->rewrite_header);
480     adj_delegate_adj_modified(adj);
481
482     /**
483      * Backwalk to all Path MTU trackers, casual like ..
484      */
485     {
486         fib_node_back_walk_ctx_t bw_ctx = {
487             .fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_MTU,
488         };
489
490         fib_walk_async(FIB_NODE_TYPE_ADJ, ai,
491                        FIB_WALK_PRIORITY_LOW, &bw_ctx);
492     }
493
494     return (ADJ_WALK_RC_CONTINUE);
495 }
496
497 static clib_error_t *
498 adj_mtu_update (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
499 {
500   adj_walk (sw_if_index, adj_mtu_update_walk_cb, NULL);
501
502   return (NULL);
503 }
504
505 VNET_SW_INTERFACE_MTU_CHANGE_FUNCTION(adj_mtu_update);
506
507 /**
508  * @brief Walk the Adjacencies on a given interface
509  */
510 void
511 adj_walk (u32 sw_if_index,
512           adj_walk_cb_t cb,
513           void *ctx)
514 {
515     /*
516      * walk all the neighbor adjacencies
517      */
518     fib_protocol_t proto;
519
520     FOR_EACH_FIB_IP_PROTOCOL(proto)
521     {
522         adj_nbr_walk(sw_if_index, proto, cb, ctx);
523         adj_mcast_walk(sw_if_index, proto, cb, ctx);
524     }
525 }
526
527 /**
528  * @brief Return the link type of the adjacency
529  */
530 vnet_link_t
531 adj_get_link_type (adj_index_t ai)
532 {
533     const ip_adjacency_t *adj;
534
535     adj = adj_get(ai);
536
537     return (adj->ia_link);
538 }
539
540 /**
541  * @brief Return the sw interface index of the adjacency.
542  */
543 u32
544 adj_get_sw_if_index (adj_index_t ai)
545 {
546     const ip_adjacency_t *adj;
547
548     adj = adj_get(ai);
549
550     return (adj->rewrite_header.sw_if_index);
551 }
552
553 /**
554  * @brief Return true if the adjacency is 'UP', i.e. can be used for forwarding
555  * 0 is down, !0 is up.
556  */
557 int
558 adj_is_up (adj_index_t ai)
559 {
560     return (adj_bfd_is_up(ai));
561 }
562
563 /**
564  * @brief Return the rewrite string of the adjacency
565  */
566 const u8*
567 adj_get_rewrite (adj_index_t ai)
568 {
569     vnet_rewrite_header_t *rw;
570     ip_adjacency_t *adj;
571
572     adj = adj_get(ai);
573     rw = &adj->rewrite_header;
574
575     ASSERT (rw->data_bytes != 0xfefe);
576
577     return (rw->data - rw->data_bytes);
578 }
579
580 static fib_node_t *
581 adj_get_node (fib_node_index_t index)
582 {
583     ip_adjacency_t *adj;
584
585     adj = adj_get(index);
586
587     return (&adj->ia_node);
588 }
589
590 #define ADJ_FROM_NODE(_node)                                            \
591     ((ip_adjacency_t*)((char*)_node - STRUCT_OFFSET_OF(ip_adjacency_t, ia_node)))
592
593 static void
594 adj_node_last_lock_gone (fib_node_t *node)
595 {
596     adj_last_lock_gone(ADJ_FROM_NODE(node));
597 }
598
599 static fib_node_back_walk_rc_t
600 adj_back_walk_notify (fib_node_t *node,
601                       fib_node_back_walk_ctx_t *ctx)
602 {
603     ip_adjacency_t *adj;
604
605     adj = ADJ_FROM_NODE(node);
606
607     switch (adj->lookup_next_index)
608     {
609     case IP_LOOKUP_NEXT_MIDCHAIN:
610         adj_midchain_delegate_restack(adj_get_index(adj));
611         break;
612     case IP_LOOKUP_NEXT_ARP:
613     case IP_LOOKUP_NEXT_REWRITE:
614     case IP_LOOKUP_NEXT_BCAST:
615     case IP_LOOKUP_NEXT_GLEAN:
616     case IP_LOOKUP_NEXT_MCAST:
617     case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
618     case IP_LOOKUP_NEXT_DROP:
619     case IP_LOOKUP_NEXT_PUNT:
620     case IP_LOOKUP_NEXT_LOCAL:
621     case IP_LOOKUP_NEXT_ICMP_ERROR:
622     case IP_LOOKUP_N_NEXT:
623         /*
624          * Que pasa. yo soj en el final!
625          */
626         ASSERT(0);
627         break;
628     }
629
630     return (FIB_NODE_BACK_WALK_CONTINUE);
631 }
632
633 /*
634  * Adjacency's graph node virtual function table
635  */
636 static const fib_node_vft_t adj_vft = {
637     .fnv_get = adj_get_node,
638     .fnv_last_lock = adj_node_last_lock_gone,
639     .fnv_back_walk = adj_back_walk_notify,
640 };
641
642 static clib_error_t *
643 adj_module_init (vlib_main_t * vm)
644 {
645     fib_node_register_type(FIB_NODE_TYPE_ADJ, &adj_vft);
646
647     adj_nbr_module_init();
648     adj_glean_module_init();
649     adj_midchain_module_init();
650     adj_mcast_module_init();
651
652     vnet_feature_register(adj_feature_update, NULL);
653
654     adj_logger = vlib_log_register_class("adj", "adj");
655
656     return (NULL);
657 }
658
659 VLIB_INIT_FUNCTION (adj_module_init);
660
661 static clib_error_t *
662 adj_show (vlib_main_t * vm,
663           unformat_input_t * input,
664           vlib_cli_command_t * cmd)
665 {
666     adj_index_t ai = ADJ_INDEX_INVALID;
667     u32 sw_if_index = ~0;
668     int summary = 0;
669
670     while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
671     {
672         if (unformat (input, "%d", &ai))
673             ;
674         else if (unformat (input, "summary") || unformat (input, "sum"))
675             summary = 1;
676         else if (unformat (input, "%U",
677                            unformat_vnet_sw_interface, vnet_get_main(),
678                            &sw_if_index))
679             ;
680         else
681             break;
682     }
683
684     if (summary)
685     {
686         vlib_cli_output (vm, "Number of adjacencies: %d", pool_elts(adj_pool));
687         vlib_cli_output (vm, "Per-adjacency counters: %s",
688                          (adj_are_counters_enabled() ?
689                           "enabled":
690                           "disabled"));
691     }
692     else
693     {
694         if (ADJ_INDEX_INVALID != ai)
695         {
696             if (pool_is_free_index(adj_pool, ai))
697             {
698                 vlib_cli_output (vm, "adjacency %d invalid", ai);
699                 return 0;
700             }
701
702             vlib_cli_output (vm, "[@%d] %U",
703                              ai,
704                              format_ip_adjacency,  ai,
705                              FORMAT_IP_ADJACENCY_DETAIL);
706         }
707         else
708         {
709             /* *INDENT-OFF* */
710             pool_foreach_index (ai, adj_pool)
711              {
712                 if (~0 != sw_if_index &&
713                     sw_if_index != adj_get_sw_if_index(ai))
714                 {
715                 }
716                 else
717                 {
718                     vlib_cli_output (vm, "[@%d] %U",
719                                      ai,
720                                      format_ip_adjacency, ai,
721                                      FORMAT_IP_ADJACENCY_NONE);
722                 }
723             }
724             /* *INDENT-ON* */
725         }
726     }
727     return 0;
728 }
729
730 /*?
731  * Show all adjacencies.
732  * @cliexpar
733  * @cliexstart{sh adj}
734  * [@0]
735  * [@1]  glean: loop0
736  * [@2] ipv4 via 1.0.0.2 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
737  * [@3] mpls via 1.0.0.2 loop0: MPLS: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
738  * [@4] ipv4 via 1.0.0.3 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
739  * [@5] mpls via 1.0.0.3 loop0: MPLS: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
740  * @cliexend
741  ?*/
742 VLIB_CLI_COMMAND (adj_show_command, static) = {
743     .path = "show adj",
744     .short_help = "show adj [<adj_index>] [interface] [summary]",
745     .function = adj_show,
746 };
747
748 /**
749  * @brief CLI invoked function to enable/disable per-adj counters
750  */
751 static clib_error_t *
752 adj_cli_counters_set (vlib_main_t * vm,
753                       unformat_input_t * input,
754                       vlib_cli_command_t * cmd)
755 {
756     clib_error_t *error = NULL;
757     int enable = ~0;
758
759     while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
760     {
761         if (unformat (input, "enable"))
762             enable = 1;
763         else if (unformat (input, "disable"))
764             enable = 0;
765         else
766             break;
767     }
768
769     if (enable != ~0)
770     {
771         /* user requested something sensible */
772         adj_per_adj_counters = enable;
773     }
774     else
775     {
776         error = clib_error_return (0, "specify 'enable' or 'disable'");
777     }
778
779     return (error);
780 }
781
782 /*?
783  * Enable/disable per-adjacency counters. This is optional because it comes
784  * with a non-negligible performance cost.
785  ?*/
786 VLIB_CLI_COMMAND (adj_cli_counters_set_command, static) = {
787     .path = "adjacency counters",
788     .short_help = "adjacency counters [enable|disable]",
789     .function = adj_cli_counters_set,
790 };