From c5746708478dd0c1b430de3ea6b92c8657bb4bcd Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 13 Apr 2021 23:56:24 +0200 Subject: [PATCH 1/7] build: don't use $(top_srcdir) in vtysh_scan It's not necessary and can confuse scripts. Signed-off-by: David Lamparter --- pathd/subdir.am | 4 ++-- zebra/subdir.am | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pathd/subdir.am b/pathd/subdir.am index 38df326489..4eabdd2ac5 100644 --- a/pathd/subdir.am +++ b/pathd/subdir.am @@ -5,13 +5,13 @@ if PATHD noinst_LIBRARIES += pathd/libpath.a sbin_PROGRAMS += pathd/pathd -vtysh_scan += $(top_srcdir)/pathd/path_cli.c +vtysh_scan += pathd/path_cli.c vtysh_daemons += pathd # TODO add man page #man8 += $(MANBUILD)/pathd.8 if PATHD_PCEP -vtysh_scan += $(top_srcdir)/pathd/path_pcep_cli.c +vtysh_scan += pathd/path_pcep_cli.c module_LTLIBRARIES += pathd/pathd_pcep.la endif diff --git a/zebra/subdir.am b/zebra/subdir.am index 80ea9ac7b8..f0d1c5844f 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -232,7 +232,7 @@ zebra_dplane_fpm_nl_la_SOURCES = zebra/dplane_fpm_nl.c zebra_dplane_fpm_nl_la_LDFLAGS = -avoid-version -module -shared -export-dynamic zebra_dplane_fpm_nl_la_LIBADD = -vtysh_scan += $(top_srcdir)/zebra/dplane_fpm_nl.c +vtysh_scan += zebra/dplane_fpm_nl.c endif if NETLINK_DEBUG From 5a4ee981d0f7e503c8dc8fee16d9e9d01e3e2f54 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 13 Apr 2021 23:34:34 +0200 Subject: [PATCH 2/7] vtysh: fix extract.pl for commands with "_cmd" If the command includes `_cmd`, hilarity ensues ;) Signed-off-by: David Lamparter --- vtysh/extract.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 4855c23f4b..5e2189aadf 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -269,7 +269,7 @@ EOF foreach (sort keys %odefun) { my ($node, $str) = (split (/,/)); $cmd = $ocmd{$_}; - $cmd =~ s/_cmd/_cmd_vtysh/; + $cmd =~ s/_cmd$/_cmd_vtysh/; printf " install_element ($node, &$cmd);\n"; } From 48843422d3433682d8b14e9224dd71aeb82afb63 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 13 Apr 2021 23:24:44 +0200 Subject: [PATCH 3/7] vtysh: add lib/log_vty.c to vtysh_scan Rather than copying everything over, include the file in vtysh_scan for automatic pickup. Signed-off-by: David Lamparter --- lib/log_vty.c | 10 +-- lib/subdir.am | 1 + vtysh/extract.pl.in | 2 +- vtysh/vtysh.c | 156 -------------------------------------------- 4 files changed, 7 insertions(+), 162 deletions(-) diff --git a/lib/log_vty.c b/lib/log_vty.c index c26621ae99..c6788dd35a 100644 --- a/lib/log_vty.c +++ b/lib/log_vty.c @@ -146,11 +146,11 @@ void log_show_syslog(struct vty *vty) zlog_progname); } -DEFUN (show_logging, - show_logging_cmd, - "show logging", - SHOW_STR - "Show current logging configuration\n") +DEFUN_NOSH (show_logging, + show_logging_cmd, + "show logging", + SHOW_STR + "Show current logging configuration\n") { log_show_syslog(vty); diff --git a/lib/subdir.am b/lib/subdir.am index 0853d4bb2b..978899c6ee 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -141,6 +141,7 @@ vtysh_scan += \ lib/if_rmap.c \ lib/keychain.c \ lib/lib_vty.c \ + lib/log_vty.c \ lib/nexthop_group.c \ lib/plist.c \ lib/routemap.c \ diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 5e2189aadf..5719fac846 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -103,7 +103,7 @@ sub scan_file { elsif ($file =~ /lib\/(filter|filter_cli)\.c$/) { $protocol = "VTYSH_ACL"; } - elsif ($file =~ /lib\/lib_vty\.c$/) { + elsif ($file =~ /lib\/(lib|log)_vty\.c$/) { $protocol = "VTYSH_ALL"; } elsif ($file =~ /lib\/agentx\.c$/) { diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 75fee1d297..a1417430ec 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2964,136 +2964,6 @@ DEFUN (vtysh_show_logging, "Logging configuration for %s:\n"); } -DEFUNSH(VTYSH_ALL, vtysh_log_stdout, vtysh_log_stdout_cmd, "log stdout", - "Logging control\n" - "Set stdout logging level\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_stdout_level, vtysh_log_stdout_level_cmd, - "log stdout ", - "Logging control\n" - "Set stdout logging level\n" LOG_LEVEL_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, no_vtysh_log_stdout, no_vtysh_log_stdout_cmd, - "no log stdout [LEVEL]", NO_STR - "Logging control\n" - "Cancel logging to stdout\n" - "Logging level\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_file, vtysh_log_file_cmd, "log file FILENAME", - "Logging control\n" - "Logging to file\n" - "Logging filename\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_file_level, vtysh_log_file_level_cmd, - "log file FILENAME ", - "Logging control\n" - "Logging to file\n" - "Logging filename\n" LOG_LEVEL_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, no_vtysh_log_file, no_vtysh_log_file_cmd, - "no log file [FILENAME [LEVEL]]", NO_STR - "Logging control\n" - "Cancel logging to file\n" - "Logging file name\n" - "Logging level\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_monitor, vtysh_log_monitor_cmd, - "log monitor []", - "Logging control\n" - "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, no_vtysh_log_monitor, no_vtysh_log_monitor_cmd, - "no log monitor [LEVEL]", NO_STR - "Logging control\n" - "Disable terminal line (monitor) logging\n" - "Logging level\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_syslog, vtysh_log_syslog_cmd, - "log syslog []", - "Logging control\n" - "Set syslog logging level\n" LOG_LEVEL_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, no_vtysh_log_syslog, no_vtysh_log_syslog_cmd, - "no log syslog []", - NO_STR - "Logging control\n" - "Cancel logging to syslog\n" - LOG_LEVEL_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_facility, vtysh_log_facility_cmd, - "log facility ", - "Logging control\n" - "Facility parameter for syslog messages\n" LOG_FACILITY_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, no_vtysh_log_facility, no_vtysh_log_facility_cmd, - "no log facility []", - NO_STR - "Logging control\n" - "Reset syslog facility to default (daemon)\n" - LOG_FACILITY_DESC) -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_record_priority, vtysh_log_record_priority_cmd, - "log record-priority", - "Logging control\n" - "Log the priority of the message within the message\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, no_vtysh_log_record_priority, - no_vtysh_log_record_priority_cmd, "no log record-priority", NO_STR - "Logging control\n" - "Do not log the priority of the message within the message\n") -{ - return CMD_SUCCESS; -} - -DEFUNSH(VTYSH_ALL, vtysh_log_timestamp_precision, - vtysh_log_timestamp_precision_cmd, "log timestamp precision (0-6)", - "Logging control\n" - "Timestamp configuration\n" - "Set the timestamp precision\n" - "Number of subsecond digits\n") -{ - return CMD_SUCCESS; -} - DEFUNSH(VTYSH_ALL, vtysh_debug_memstats, vtysh_debug_memstats_cmd, "[no] debug memstats-at-exit", NO_STR @@ -3103,16 +2973,6 @@ DEFUNSH(VTYSH_ALL, vtysh_debug_memstats, return CMD_SUCCESS; } -DEFUNSH(VTYSH_ALL, no_vtysh_log_timestamp_precision, - no_vtysh_log_timestamp_precision_cmd, "no log timestamp precision", - NO_STR - "Logging control\n" - "Timestamp configuration\n" - "Reset the timestamp precision to the default value of 0\n") -{ - return CMD_SUCCESS; -} - DEFUNSH(VTYSH_ALL, vtysh_service_password_encrypt, vtysh_service_password_encrypt_cmd, "service password-encryption", "Set up miscellaneous service\n" @@ -4605,22 +4465,6 @@ void vtysh_init_vty(void) /* Logging */ install_element(VIEW_NODE, &vtysh_show_logging_cmd); - install_element(CONFIG_NODE, &vtysh_log_stdout_cmd); - install_element(CONFIG_NODE, &vtysh_log_stdout_level_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_stdout_cmd); - install_element(CONFIG_NODE, &vtysh_log_file_cmd); - install_element(CONFIG_NODE, &vtysh_log_file_level_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_file_cmd); - install_element(CONFIG_NODE, &vtysh_log_monitor_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_monitor_cmd); - install_element(CONFIG_NODE, &vtysh_log_syslog_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_syslog_cmd); - install_element(CONFIG_NODE, &vtysh_log_facility_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_facility_cmd); - install_element(CONFIG_NODE, &vtysh_log_record_priority_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_record_priority_cmd); - install_element(CONFIG_NODE, &vtysh_log_timestamp_precision_cmd); - install_element(CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd); install_element(CONFIG_NODE, &vtysh_service_password_encrypt_cmd); install_element(CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd); From c4e57cd52e4faace1645291a6ab3b9a84993a9fc Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 13 Apr 2021 23:55:58 +0200 Subject: [PATCH 4/7] vtysh: add lib/spf_backoff.c to vtysh_scan Signed-off-by: David Lamparter --- lib/subdir.am | 1 + vtysh/extract.pl.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/subdir.am b/lib/subdir.am index 978899c6ee..61390419f2 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -146,6 +146,7 @@ vtysh_scan += \ lib/plist.c \ lib/routemap.c \ lib/routemap_cli.c \ + lib/spf_backoff.c \ lib/vrf.c \ lib/vty.c \ # end diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 5719fac846..345e564e01 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -133,6 +133,9 @@ sub scan_file { $protocol = "VTYSH_RIPD"; } } + elsif ($file =~ /lib\/spf_backoff\.c$/) { + $protocol = "VTYSH_ISISD"; + } elsif ($file =~ /lib\/vty\.c$/) { $protocol = "VTYSH_ALL"; } From 9cb089fc43bccbe4159c7a9a24e9dc06ed5c943f Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 14 Apr 2021 00:00:43 +0200 Subject: [PATCH 5/7] vtysh: add lib/resolver.c to vtysh_scan Signed-off-by: David Lamparter --- lib/subdir.am | 1 + vtysh/extract.pl.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/subdir.am b/lib/subdir.am index 61390419f2..bd24ccbfb8 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -144,6 +144,7 @@ vtysh_scan += \ lib/log_vty.c \ lib/nexthop_group.c \ lib/plist.c \ + lib/resolver.c \ lib/routemap.c \ lib/routemap_cli.c \ lib/spf_backoff.c \ diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 345e564e01..2b26d366f8 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -133,6 +133,9 @@ sub scan_file { $protocol = "VTYSH_RIPD"; } } + elsif ($file =~ /lib\/resolver\.c$/) { + $protocol = "VTYSH_NHRPD|VTYSH_BGPD"; + } elsif ($file =~ /lib\/spf_backoff\.c$/) { $protocol = "VTYSH_ISISD"; } From ee4dcee834a2e16ce0085902a6c3bbd55cac99a9 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 14 Apr 2021 00:04:12 +0200 Subject: [PATCH 6/7] vtysh: add lib/thread.c to vtysh_scan Signed-off-by: David Lamparter --- lib/subdir.am | 1 + lib/thread.c | 26 +++++++++++++------------- vtysh/extract.pl.in | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/subdir.am b/lib/subdir.am index bd24ccbfb8..b7efec4882 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -148,6 +148,7 @@ vtysh_scan += \ lib/routemap.c \ lib/routemap_cli.c \ lib/spf_backoff.c \ + lib/thread.c \ lib/vrf.c \ lib/vty.c \ # end diff --git a/lib/thread.c b/lib/thread.c index 866090341e..e0b6b24595 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -300,13 +300,13 @@ static uint8_t parse_filter(const char *filterstr) } #ifndef EXCLUDE_CPU_TIME -DEFUN (show_thread_cpu, - show_thread_cpu_cmd, - "show thread cpu [FILTER]", - SHOW_STR - "Thread information\n" - "Thread CPU usage\n" - "Display filter (rwtex)\n") +DEFUN_NOSH (show_thread_cpu, + show_thread_cpu_cmd, + "show thread cpu [FILTER]", + SHOW_STR + "Thread information\n" + "Thread CPU usage\n" + "Display filter (rwtex)\n") { uint8_t filter = (uint8_t)-1U; int idx = 0; @@ -367,12 +367,12 @@ static void show_thread_poll_helper(struct vty *vty, struct thread_master *m) } } -DEFUN (show_thread_poll, - show_thread_poll_cmd, - "show thread poll", - SHOW_STR - "Thread information\n" - "Show poll FD's and information\n") +DEFUN_NOSH (show_thread_poll, + show_thread_poll_cmd, + "show thread poll", + SHOW_STR + "Thread information\n" + "Show poll FD's and information\n") { struct listnode *node; struct thread_master *m; diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 2b26d366f8..af974771cc 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -139,7 +139,7 @@ sub scan_file { elsif ($file =~ /lib\/spf_backoff\.c$/) { $protocol = "VTYSH_ISISD"; } - elsif ($file =~ /lib\/vty\.c$/) { + elsif ($file =~ /lib\/(vty|thread)\.c$/) { $protocol = "VTYSH_ALL"; } elsif ($file =~ /librfp\/.*\.c$/ || $file =~ /rfapi\/.*\.c$/) { From 010bf6f1caf0eed23bf3ba580a2fcb2a64aec837 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 14 Apr 2021 00:11:02 +0200 Subject: [PATCH 7/7] python: add demo checker tool using frr.xref More of a demo on what to do with the frr.xref file, but also slightly useful in finding vtysh SNAFUs :) Signed-off-by: David Lamparter --- python/vtysh-cmd-check.py | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 python/vtysh-cmd-check.py diff --git a/python/vtysh-cmd-check.py b/python/vtysh-cmd-check.py new file mode 100644 index 0000000000..ef9eea41ad --- /dev/null +++ b/python/vtysh-cmd-check.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# +# Quick demo program that checks whether files define commands that aren't +# in vtysh. Execute after building. +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# For more information, please refer to + +import os +import json +import subprocess + +os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +with open("frr.xref", "r") as fd: + data = json.load(fd) + +vtysh_scan, _ = subprocess.Popen( + ["make", "var-vtysh_scan"], stdout=subprocess.PIPE +).communicate() +vtysh_scan = set(vtysh_scan.decode("US-ASCII").split()) + +check = set() +vtysh = {} + +for cmd, defs in data["cli"].items(): + for binary, clidef in defs.items(): + if clidef["defun"]["file"].startswith("vtysh/"): + vtysh[clidef["string"]] = clidef + +for cmd, defs in data["cli"].items(): + for binary, clidef in defs.items(): + if clidef["defun"]["file"].startswith("vtysh/"): + continue + + if clidef["defun"]["file"] not in vtysh_scan: + vtysh_def = vtysh.get(clidef["string"]) + if vtysh_def is not None: + print( + "\033[33m%s defines %s, has a custom define in vtysh %s\033[m" + % (clidef["defun"]["file"], cmd, vtysh_def["defun"]["file"]) + ) + else: + print( + "\033[31m%s defines %s, not in vtysh_scan\033[m" + % (clidef["defun"]["file"], cmd) + ) + check.add(clidef["defun"]["file"]) + +print("\nfiles to check:\n\t" + " ".join(sorted(check)))