2 * Copyright (c) 2015 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 * cli.c: command line interface
18 * Copyright (c) 2008 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 #include <vlib/vlib.h>
42 /* Root of all show commands. */
44 VLIB_CLI_COMMAND (vlib_cli_show_command, static) = {
46 .short_help = "Show commands",
50 /* Root of all clear commands. */
52 VLIB_CLI_COMMAND (vlib_cli_clear_command, static) = {
54 .short_help = "Clear commands",
58 /* Root of all set commands. */
60 VLIB_CLI_COMMAND (vlib_cli_set_command, static) = {
62 .short_help = "Set commands",
66 /* Root of all test commands. */
68 VLIB_CLI_COMMAND (vlib_cli_test_command, static) = {
70 .short_help = "Test commands",
74 /* Returns bitmap of commands which match key. */
76 vlib_cli_sub_command_match (vlib_cli_command_t * c, unformat_input_t * input)
80 vlib_cli_parse_position_t *p;
82 unformat_skip_white_space (input);
88 k = unformat_get_input (input);
102 case UNFORMAT_END_OF_INPUT:
103 /* White space or end of input removes any non-white
104 matches that were before possible. */
105 if (i < vec_len (c->sub_command_positions)
106 && clib_bitmap_count_set_bits (match) > 1)
108 p = vec_elt_at_index (c->sub_command_positions, i);
109 for (n = 0; n < vec_len (p->bitmaps); n++)
110 match = clib_bitmap_andnot (match, p->bitmaps[n]);
115 unformat_put_input (input);
119 if (i >= vec_len (c->sub_command_positions))
122 clib_bitmap_free (match);
126 p = vec_elt_at_index (c->sub_command_positions, i);
127 if (vec_len (p->bitmaps) == 0)
131 if (n < 0 || n >= vec_len (p->bitmaps))
135 match = clib_bitmap_dup (p->bitmaps[n]);
137 match = clib_bitmap_and (match, p->bitmaps[n]);
139 if (clib_bitmap_is_zero (match))
147 /* Looks for string based sub-input formatted { SUB-INPUT }. */
149 unformat_vlib_cli_sub_input (unformat_input_t * i, va_list * args)
151 unformat_input_t *sub_input = va_arg (*args, unformat_input_t *);
157 c = unformat_get_input (i);
169 /* Put back paren. */
170 if (c != UNFORMAT_END_OF_INPUT)
171 unformat_put_input (i);
173 if (c == '{' && unformat (i, "%v", &s))
175 unformat_init_vector (sub_input, s);
184 static vlib_cli_command_t *
185 get_sub_command (vlib_cli_main_t * cm, vlib_cli_command_t * parent, u32 si)
187 vlib_cli_sub_command_t *s = vec_elt_at_index (parent->sub_commands, si);
188 return vec_elt_at_index (cm->commands, s->index);
192 unformat_vlib_cli_sub_command (unformat_input_t * i, va_list * args)
194 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
195 vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
196 vlib_cli_command_t **result = va_arg (*args, vlib_cli_command_t **);
197 vlib_cli_main_t *cm = &vm->cli_main;
198 uword *match_bitmap, is_unique, index;
201 vlib_cli_sub_rule_t *sr;
202 vlib_cli_parse_rule_t *r;
203 vec_foreach (sr, c->sub_rules)
206 r = vec_elt_at_index (cm->parse_rules, sr->rule_index);
207 vec_add2 (cm->parse_rule_data, d, 1);
208 vec_reset_length (d[0]);
210 d[0] = _vec_resize (d[0],
211 /* length increment */ 1,
213 /* header_bytes */ 0,
214 /* data align */ sizeof (uword));
215 if (unformat_user (i, r->unformat_function, vm, d[0]))
217 *result = vec_elt_at_index (cm->commands, sr->command_index);
223 match_bitmap = vlib_cli_sub_command_match (c, i);
224 is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1;
228 index = clib_bitmap_first_set (match_bitmap);
229 *result = get_sub_command (cm, c, index);
231 clib_bitmap_free (match_bitmap);
237 format_vlib_cli_command_help (u8 * s, va_list * args)
239 vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
240 int is_long = va_arg (*args, int);
241 if (is_long && c->long_help)
242 s = format (s, "%s", c->long_help);
243 else if (c->short_help)
244 s = format (s, "%s", c->short_help);
246 s = format (s, "%v commands", c->path);
251 format_vlib_cli_parse_rule_name (u8 * s, va_list * args)
253 vlib_cli_parse_rule_t *r = va_arg (*args, vlib_cli_parse_rule_t *);
254 return format (s, "<%U>", format_c_identifier, r->name);
258 format_vlib_cli_path (u8 * s, va_list * args)
260 u8 *path = va_arg (*args, u8 *);
263 for (i = 0; i < vec_len (path); i++)
269 vec_add1 (s, '<'); /* start of <RULE> */
273 /* _ -> space in rules. */
274 vec_add1 (s, in_rule ? ' ' : '_');
280 vec_add1 (s, '>'); /* end of <RULE> */
287 vec_add1 (s, path[i]);
293 vec_add1 (s, '>'); /* terminate <RULE> */
298 static vlib_cli_command_t *
299 all_subs (vlib_cli_main_t * cm, vlib_cli_command_t * subs, u32 command_index)
301 vlib_cli_command_t *c = vec_elt_at_index (cm->commands, command_index);
302 vlib_cli_sub_command_t *sc;
303 vlib_cli_sub_rule_t *sr;
306 vec_add1 (subs, c[0]);
308 vec_foreach (sr, c->sub_rules)
309 subs = all_subs (cm, subs, sr->command_index);
310 vec_foreach (sc, c->sub_commands) subs = all_subs (cm, subs, sc->index);
316 vlib_cli_cmp_rule (void *a1, void *a2)
318 vlib_cli_sub_rule_t *r1 = a1;
319 vlib_cli_sub_rule_t *r2 = a2;
321 return vec_cmp (r1->name, r2->name);
325 vlib_cli_cmp_command (void *a1, void *a2)
327 vlib_cli_command_t *c1 = a1;
328 vlib_cli_command_t *c2 = a2;
330 return vec_cmp (c1->path, c2->path);
333 static clib_error_t *
334 vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
335 vlib_cli_main_t * cm,
336 unformat_input_t * input,
337 uword parent_command_index)
339 vlib_cli_command_t *parent, *c;
340 clib_error_t *error = 0;
341 unformat_input_t sub_input;
343 uword is_main_dispatch = cm == &vm->cli_main;
345 parent = vec_elt_at_index (cm->commands, parent_command_index);
346 if (is_main_dispatch && unformat (input, "help"))
348 uword help_at_end_of_line, i;
350 help_at_end_of_line =
351 unformat_check_input (input) == UNFORMAT_END_OF_INPUT;
356 (input, unformat_vlib_cli_sub_command, vm, c, &parent))
359 else if (!(unformat_check_input (input) == UNFORMAT_END_OF_INPUT))
366 /* help SUB-COMMAND => long format help.
367 "help" at end of line: show all commands. */
368 if (!help_at_end_of_line)
369 vlib_cli_output (vm, "%U", format_vlib_cli_command_help, c,
372 else if (vec_len (c->sub_commands) + vec_len (c->sub_rules) == 0)
373 vlib_cli_output (vm, "%v: no sub-commands", c->path);
377 vlib_cli_sub_command_t *sc;
378 vlib_cli_sub_rule_t *sr, *subs;
380 subs = vec_dup (c->sub_rules);
382 /* Add in rules if any. */
383 vec_foreach (sc, c->sub_commands)
385 vec_add2 (subs, sr, 1);
387 sr->command_index = sc->index;
391 vec_sort_with_function (subs, vlib_cli_cmp_rule);
393 for (i = 0; i < vec_len (subs); i++)
395 vlib_cli_command_t *d;
396 vlib_cli_parse_rule_t *r;
398 d = vec_elt_at_index (cm->commands, subs[i].command_index);
400 subs[i].rule_index != ~0 ? vec_elt_at_index (cm->parse_rules,
408 format_vlib_cli_parse_rule_name, r,
409 format_vlib_cli_command_help, d, /* is_long */ 0);
414 format_vlib_cli_command_help, d, /* is_long */ 0);
421 else if (is_main_dispatch
422 && (unformat (input, "choices") || unformat (input, "?")))
424 vlib_cli_command_t *sub, *subs;
426 subs = all_subs (cm, 0, parent_command_index);
427 vec_sort_with_function (subs, vlib_cli_cmp_command);
428 vec_foreach (sub, subs)
429 vlib_cli_output (vm, " %-40U %U",
430 format_vlib_cli_path, sub->path,
431 format_vlib_cli_command_help, sub, /* is_long */ 0);
435 else if (unformat (input, "comment %v", &string))
440 else if (unformat (input, "uncomment %U",
441 unformat_vlib_cli_sub_input, &sub_input))
444 vlib_cli_dispatch_sub_commands (vm, cm, &sub_input,
445 parent_command_index);
446 unformat_free (&sub_input);
450 if (unformat_user (input, unformat_vlib_cli_sub_command, vm, parent, &c))
452 unformat_input_t *si;
453 uword has_sub_commands =
454 vec_len (c->sub_commands) + vec_len (c->sub_rules) > 0;
457 if (unformat_user (input, unformat_vlib_cli_sub_input, &sub_input))
460 if (has_sub_commands)
461 error = vlib_cli_dispatch_sub_commands (vm, cm, si, c - cm->commands);
463 if (has_sub_commands && !error)
464 /* Found valid sub-command. */ ;
466 else if (c->function)
468 clib_error_t *c_error;
470 /* Skip white space for benefit of called function. */
471 unformat_skip_white_space (si);
473 if (unformat (si, "?"))
475 vlib_cli_output (vm, " %-40U %U", format_vlib_cli_path, c->path, format_vlib_cli_command_help, c, /* is_long */
481 vlib_worker_thread_barrier_sync (vm);
483 c_error = c->function (vm, si, c);
486 vlib_worker_thread_barrier_release (vm);
491 clib_error_return (0, "%v: %v", c->path, c_error->what);
492 clib_error_free (c_error);
493 /* Free sub input. */
501 /* Free any previous error. */
502 clib_error_free (error);
506 error = clib_error_return (0, "%v: no sub-commands", c->path);
508 /* Free sub input. */
520 return clib_error_return (0, "%v: unknown input `%U'", parent->path,
521 format_unformat_error, input);
523 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
528 void vlib_unix_error_report (vlib_main_t *, clib_error_t *)
529 __attribute__ ((weak));
532 vlib_unix_error_report (vlib_main_t * vm, clib_error_t * error)
536 /* Process CLI input. */
538 vlib_cli_input (vlib_main_t * vm,
539 unformat_input_t * input,
540 vlib_cli_output_function_t * function, uword function_arg)
542 vlib_process_t *cp = vlib_get_current_process (vm);
543 vlib_cli_main_t *cm = &vm->cli_main;
545 vlib_cli_output_function_t *save_function;
546 uword save_function_arg;
548 save_function = cp->output_function;
549 save_function_arg = cp->output_function_arg;
551 cp->output_function = function;
552 cp->output_function_arg = function_arg;
556 vec_reset_length (cm->parse_rule_data);
557 error = vlib_cli_dispatch_sub_commands (vm, &vm->cli_main, input, /* parent */
560 while (!error && !unformat (input, "%U", unformat_eof));
564 vlib_cli_output (vm, "%v", error->what);
565 vlib_unix_error_report (vm, error);
566 clib_error_free (error);
569 cp->output_function = save_function;
570 cp->output_function_arg = save_function_arg;
573 /* Output to current CLI connection. */
575 vlib_cli_output (vlib_main_t * vm, char *fmt, ...)
577 vlib_process_t *cp = vlib_get_current_process (vm);
582 s = va_format (0, fmt, &va);
585 /* Terminate with \n if not present. */
586 if (vec_len (s) > 0 && s[vec_len (s) - 1] != '\n')
589 if ((!cp) || (!cp->output_function))
590 fformat (stdout, "%v", s);
592 cp->output_function (cp->output_function_arg, s, vec_len (s));
597 static clib_error_t *
598 show_memory_usage (vlib_main_t * vm,
599 unformat_input_t * input, vlib_cli_command_t * cmd)
605 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
607 if (unformat (input, "verbose"))
611 error = clib_error_return (0, "unknown input `%U'",
612 format_unformat_error, input);
620 vlib_cli_output (vm, "Thread %d %v\n", index, vlib_worker_threads[index].name);
621 vlib_cli_output (vm, "%U\n", format_mheap, clib_per_cpu_mheaps[index], verbose);
629 VLIB_CLI_COMMAND (show_memory_usage_command, static) = {
630 .path = "show memory",
631 .short_help = "Show current memory usage",
632 .function = show_memory_usage,
636 static clib_error_t *
637 enable_disable_memory_trace (vlib_main_t * vm,
638 unformat_input_t * input,
639 vlib_cli_command_t * cmd)
641 clib_error_t *error = 0;
644 if (!unformat_user (input, unformat_vlib_enable_disable, &enable))
646 error = clib_error_return (0, "expecting enable/on or disable/off");
650 clib_mem_trace (enable);
657 VLIB_CLI_COMMAND (enable_disable_memory_trace_command, static) = {
658 .path = "memory-trace",
659 .short_help = "Enable/disable memory allocation trace",
660 .function = enable_disable_memory_trace,
665 static clib_error_t *
666 test_heap_validate (vlib_main_t * vm, unformat_input_t * input,
667 vlib_cli_command_t * cmd)
669 clib_error_t *error = 0;
673 if (unformat (input, "on"))
677 heap = clib_per_cpu_mheaps[this_vlib_main->cpu_index];
678 mheap = mheap_header(heap);
679 mheap->flags |= MHEAP_FLAG_VALIDATE;
680 // Turn off small object cache because it delays detection of errors
681 mheap->flags &= ~MHEAP_FLAG_SMALL_OBJECT_CACHE;
686 else if (unformat (input, "off"))
690 heap = clib_per_cpu_mheaps[this_vlib_main->cpu_index];
691 mheap = mheap_header(heap);
692 mheap->flags &= ~MHEAP_FLAG_VALIDATE;
693 mheap->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE;
697 else if (unformat (input, "now"))
701 heap = clib_per_cpu_mheaps[this_vlib_main->cpu_index];
702 mheap = mheap_header(heap);
703 mheap_validate(heap);
706 vlib_cli_output (vm, "heap validation complete");
711 return clib_error_return (0, "unknown input `%U'",
712 format_unformat_error, input);
719 VLIB_CLI_COMMAND (cmd_test_heap_validate,static) = {
720 .path = "test heap-validate",
721 .short_help = "<on/off/now> validate heap on future allocs/frees or right now",
722 .function = test_heap_validate,
728 * A trivial test harness to verify the per-process output_function
729 * is working correcty.
732 static clib_error_t *
733 sleep_ten_seconds (vlib_main_t * vm,
734 unformat_input_t * input, vlib_cli_command_t * cmd)
739 vlib_cli_output (vm, "Starting 10 seconds sleep with id %u\n", my_id);
741 for (i = 0; i < 10; i++)
743 vlib_process_wait_for_event_or_clock (vm, 1.0);
744 vlib_cli_output (vm, "Iteration number %u, my id: %u\n", i, my_id);
746 vlib_cli_output (vm, "Done with sleep with id %u\n", my_id);
751 VLIB_CLI_COMMAND (ping_command, static) = {
752 .path = "test sleep",
753 .function = sleep_ten_seconds,
754 .short_help = "Sleep for 10 seconds",
757 #endif /* ifdef TEST_CODE */
760 vlib_cli_normalize_path (char *input, char **result)
765 uword index_of_last_space = ~0;
770 /* Multiple white space -> single space. */
777 if (l > 0 && s[l - 1] != ' ')
785 if (l > 0 && s[l - 1] == ' ')
786 index_of_last_space = vec_len (s);
793 /* Remove any extra space at end. */
794 if (l > 0 && s[l - 1] == ' ')
798 return index_of_last_space;
802 parent_path_len (char *path)
805 for (i = vec_len (path) - 1; i >= 0; i--)
814 add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index)
816 vlib_cli_command_t *p, *c;
817 vlib_cli_sub_command_t *sub_c;
821 p = vec_elt_at_index (cm->commands, parent_index);
822 c = vec_elt_at_index (cm->commands, child_index);
824 l = parent_path_len (c->path);
826 sub_name = vec_dup ((u8 *) c->path);
829 ASSERT (l + 1 < vec_len (c->path));
831 vec_add (sub_name, c->path + l + 1, vec_len (c->path) - (l + 1));
834 if (sub_name[0] == '%')
837 vlib_cli_sub_rule_t *sr;
840 vec_delete (sub_name, 1, 0);
842 if (!p->sub_rule_index_by_name)
843 p->sub_rule_index_by_name = hash_create_vec ( /* initial length */ 32,
844 sizeof (sub_name[0]),
846 q = hash_get_mem (p->sub_rule_index_by_name, sub_name);
849 sr = vec_elt_at_index (p->sub_rules, q[0]);
850 ASSERT (sr->command_index == child_index);
854 q = hash_get_mem (cm->parse_rule_index_by_name, sub_name);
856 clib_error ("reference to unknown rule `%%%v' in path `%v'",
859 hash_set_mem (p->sub_rule_index_by_name, sub_name,
860 vec_len (p->sub_rules));
861 vec_add2 (p->sub_rules, sr, 1);
863 sr->rule_index = q[0];
864 sr->command_index = child_index;
868 if (!p->sub_command_index_by_name)
869 p->sub_command_index_by_name = hash_create_vec ( /* initial length */ 32,
873 /* Check if sub-command has already been created. */
874 if (hash_get_mem (p->sub_command_index_by_name, sub_name))
880 vec_add2 (p->sub_commands, sub_c, 1);
881 sub_c->index = child_index;
882 sub_c->name = sub_name;
883 hash_set_mem (p->sub_command_index_by_name, sub_c->name,
884 sub_c - p->sub_commands);
886 vec_validate (p->sub_command_positions, vec_len (sub_c->name) - 1);
887 for (i = 0; i < vec_len (sub_c->name); i++)
890 vlib_cli_parse_position_t *pos;
892 pos = vec_elt_at_index (p->sub_command_positions, i);
895 pos->min_char = sub_c->name[i];
897 n = sub_c->name[i] - pos->min_char;
900 pos->min_char = sub_c->name[i];
901 vec_insert (pos->bitmaps, -n, 0);
905 vec_validate (pos->bitmaps, n);
907 clib_bitmap_ori (pos->bitmaps[n], sub_c - p->sub_commands);
912 vlib_cli_make_parent (vlib_cli_main_t * cm, uword ci)
916 vlib_cli_command_t *c, *parent;
918 /* Root command (index 0) should have already been added. */
919 ASSERT (vec_len (cm->commands) > 0);
921 c = vec_elt_at_index (cm->commands, ci);
922 p_len = parent_path_len (c->path);
924 /* No space? Parent is root command. */
927 add_sub_command (cm, 0, ci);
932 vec_add (p_path, c->path, p_len);
934 p = hash_get_mem (cm->command_index_by_path, p_path);
939 /* Parent does not exist; create it. */
940 vec_add2 (cm->commands, parent, 1);
941 parent->path = p_path;
942 hash_set_mem (cm->command_index_by_path, parent->path,
943 parent - cm->commands);
944 pi = parent - cm->commands;
952 add_sub_command (cm, pi, ci);
954 /* Create parent's parent. */
956 vlib_cli_make_parent (cm, pi);
960 vlib_cli_command_is_empty (vlib_cli_command_t * c)
962 return (c->long_help == 0 && c->short_help == 0 && c->function == 0);
966 vlib_cli_register (vlib_main_t * vm, vlib_cli_command_t * c)
968 vlib_cli_main_t *cm = &vm->cli_main;
969 clib_error_t *error = 0;
971 char *normalized_path;
973 if ((error = vlib_call_init_function (vm, vlib_cli_init)))
976 (void) vlib_cli_normalize_path (c->path, &normalized_path);
978 if (!cm->command_index_by_path)
979 cm->command_index_by_path = hash_create_vec ( /* initial length */ 32,
983 /* See if command already exists with given path. */
984 p = hash_get_mem (cm->command_index_by_path, normalized_path);
987 vlib_cli_command_t *d;
990 d = vec_elt_at_index (cm->commands, ci);
992 /* If existing command was created via vlib_cli_make_parent
993 replaced it with callers data. */
994 if (vlib_cli_command_is_empty (d))
996 vlib_cli_command_t save = d[0];
998 ASSERT (!vlib_cli_command_is_empty (c));
1000 /* Copy callers fields. */
1003 /* Save internal fields. */
1004 d->path = save.path;
1005 d->sub_commands = save.sub_commands;
1006 d->sub_command_index_by_name = save.sub_command_index_by_name;
1007 d->sub_command_positions = save.sub_command_positions;
1008 d->sub_rules = save.sub_rules;
1012 clib_error_return (0, "duplicate command name with path %v",
1015 vec_free (normalized_path);
1021 /* Command does not exist: create it. */
1023 /* Add root command (index 0). */
1024 if (vec_len (cm->commands) == 0)
1026 /* Create command with index 0; path is empty string. */
1027 vec_resize (cm->commands, 1);
1030 ci = vec_len (cm->commands);
1031 hash_set_mem (cm->command_index_by_path, normalized_path, ci);
1032 vec_add1 (cm->commands, c[0]);
1034 c = vec_elt_at_index (cm->commands, ci);
1035 c->path = normalized_path;
1037 /* Don't inherit from registration. */
1038 c->sub_commands = 0;
1039 c->sub_command_index_by_name = 0;
1040 c->sub_command_positions = 0;
1043 vlib_cli_make_parent (cm, ci);
1048 vlib_cli_register_parse_rule (vlib_main_t * vm, vlib_cli_parse_rule_t * r_reg)
1050 vlib_cli_main_t *cm = &vm->cli_main;
1051 vlib_cli_parse_rule_t *r;
1052 clib_error_t *error = 0;
1056 if (!cm->parse_rule_index_by_name)
1057 cm->parse_rule_index_by_name = hash_create_vec ( /* initial length */ 32,
1058 sizeof (r->name[0]),
1061 /* Make vector copy of name. */
1062 r_name = format (0, "%s", r_reg->name);
1064 if ((p = hash_get_mem (cm->parse_rule_index_by_name, r_name)))
1067 return clib_error_return (0, "duplicate parse rule name `%s'",
1071 vec_add2 (cm->parse_rules, r, 1);
1073 r->name = (char *) r_name;
1074 hash_set_mem (cm->parse_rule_index_by_name, r->name, r - cm->parse_rules);
1080 /* $$$ turn back on again someday, maybe */
1081 static clib_error_t *vlib_cli_register_parse_rules (vlib_main_t * vm,
1082 vlib_cli_parse_rule_t *
1084 vlib_cli_parse_rule_t *
1086 __attribute__ ((unused))
1088 clib_error_t *error = 0;
1089 vlib_cli_parse_rule_t *r;
1091 for (r = lo; r < hi; r = clib_elf_section_data_next (r, 0))
1093 if (!r->name || strlen (r->name) == 0)
1095 error = clib_error_return (0, "parse rule with no name");
1099 error = vlib_cli_register_parse_rule (vm, r);
1109 static clib_error_t *
1110 vlib_cli_init (vlib_main_t * vm)
1112 vlib_cli_main_t *cm = &vm->cli_main;
1113 clib_error_t *error = 0;
1114 vlib_cli_command_t *cmd;
1116 cmd = cm->cli_command_registrations;
1120 error = vlib_cli_register (vm, cmd);
1123 cmd = cmd->next_cli_command;
1128 VLIB_INIT_FUNCTION (vlib_cli_init);
1131 * fd.io coding-style-patch-verification: ON
1134 * eval: (c-set-style "gnu")