From cd44428d6230880b0f1c1a34886144889ca4ba79 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 24 Jan 2022 07:02:37 -0500 Subject: [PATCH 01/12] bgpd: Prevent use after variable goes out of scope `struct prefix p` was declared inside an if statement where we assign the address of to a pointer that is then passed to a sub function. This will eventually leave us in a bad state. Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index fa83a457bf..f353abead0 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -12249,6 +12249,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, bool first = true; uint16_t show_flags = 0; enum rpki_states rpki_target_state = RPKI_NOT_BEING_USED; + struct prefix p; if (uj) { argc--; @@ -12401,7 +12402,6 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, if (argv_find(argv, argc, "A.B.C.D/M", &idx) || argv_find(argv, argc, "X:X::X:X/M", &idx)) { const char *prefix_str = argv[idx]->arg; - struct prefix p; if (!str2prefix(prefix_str, &p)) { vty_out(vty, "%% Malformed Prefix\n"); From 46b48b330269c82afb19eaa224df701cc5d221f9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 22 Jan 2022 08:15:42 -0500 Subject: [PATCH 02/12] lib: Add more information to `show version` Add to lib/command.c the ability to remember the release/version/system information and to allow `show version` to dump some of it. Signed-off-by: Donald Sharp --- lib/command.c | 27 +++++++++++++++++++++++++-- lib/command.h | 10 ++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/command.c b/lib/command.c index 9cf93ea192..ebdbf162d1 100644 --- a/lib/command.c +++ b/lib/command.c @@ -106,6 +106,21 @@ const char *cmd_domainname_get(void) return host.domainname; } +const char *cmd_system_get(void) +{ + return host.system; +} + +const char *cmd_release_get(void) +{ + return host.release; +} + +const char *cmd_version_get(void) +{ + return host.version; +} + static int root_on_exit(struct vty *vty); /* Standard command node structures. */ @@ -1398,8 +1413,9 @@ DEFUN (show_version, SHOW_STR "Displays zebra version\n") { - vty_out(vty, "%s %s (%s).\n", FRR_FULL_NAME, FRR_VERSION, - cmd_hostname_get() ? cmd_hostname_get() : ""); + vty_out(vty, "%s %s (%s) on %s(%s).\n", FRR_FULL_NAME, FRR_VERSION, + cmd_hostname_get() ? cmd_hostname_get() : "", cmd_system_get(), + cmd_release_get()); vty_out(vty, "%s%s\n", FRR_COPYRIGHT, GIT_INFO); #ifdef ENABLE_VERSION_BUILD_CONFIG vty_out(vty, "configured with:\n %s\n", FRR_CONFIG_ARGS); @@ -2445,6 +2461,10 @@ void cmd_init(int terminal) /* Default host value settings. */ host.name = XSTRDUP(MTYPE_HOST, names.nodename); + host.system = XSTRDUP(MTYPE_HOST, names.sysname); + host.release = XSTRDUP(MTYPE_HOST, names.release); + host.version = XSTRDUP(MTYPE_HOST, names.version); + #ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME if ((strcmp(names.domainname, "(none)") == 0)) host.domainname = NULL; @@ -2563,6 +2583,9 @@ void cmd_terminate(void) } XFREE(MTYPE_HOST, host.name); + XFREE(MTYPE_HOST, host.system); + XFREE(MTYPE_HOST, host.release); + XFREE(MTYPE_HOST, host.version); XFREE(MTYPE_HOST, host.domainname); XFREE(MTYPE_HOST, host.password); XFREE(MTYPE_HOST, host.password_encrypt); diff --git a/lib/command.h b/lib/command.h index c888356d61..a540bdc5c5 100644 --- a/lib/command.h +++ b/lib/command.h @@ -55,6 +55,13 @@ struct host { /* Domainname of this router */ char *domainname; + /* + * Some extra system data that is useful + */ + char *system; + char *release; + char *version; + /* Password for vty interface. */ char *password; char *password_encrypt; @@ -600,6 +607,9 @@ extern int cmd_domainname_set(const char *domainname); extern int cmd_hostname_set(const char *hostname); extern const char *cmd_hostname_get(void); extern const char *cmd_domainname_get(void); +extern const char *cmd_system_get(void); +extern const char *cmd_release_get(void); +extern const char *cmd_version_get(void); /* NOT safe for general use; call this only if DEV_BUILD! */ extern void grammar_sandbox_init(void); From 88fd4cb8ca727917d2f31fcc0be119277c59fb4f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 21 Jan 2022 12:51:11 -0500 Subject: [PATCH 03/12] zebra: Add ability to know when FRR is not asic offloaded Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index fab1e7b897..a7f51e4e09 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3972,6 +3972,8 @@ DEFUN (show_zebra, if (zrouter.asic_offloaded) vty_out(vty, "Asic Offload is being used\n"); + else + vty_out(vty, "Asic offload is not being used\n"); vty_out(vty, " Route Route Neighbor LSP LSP\n"); From dd42779ff92ad55d3715942267382aaa534d69ae Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 21 Jan 2022 13:05:35 -0500 Subject: [PATCH 04/12] zebra: Add to `show zebra` the type of vrf devices being used Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index a7f51e4e09..922d812e37 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3970,6 +3970,15 @@ DEFUN (show_zebra, { struct vrf *vrf; +#ifdef GNU_LINUX + if (!vrf_is_backend_netns()) + vty_out(vty, "VRF devices are available for usage\n"); + else + vty_out(vty, "Namespaces are being used as VRF devices\n"); +#else + vty_out(vty, "No VRF's available on this platform\n"); +#endif + if (zrouter.asic_offloaded) vty_out(vty, "Asic Offload is being used\n"); else From 9783de6fafa9df33f09b9b36ec4821c0b086bf6e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 21 Jan 2022 13:14:39 -0500 Subject: [PATCH 05/12] zebra: Add if v4/v6 forwarding is turned on/off to `show zebra` Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 922d812e37..a7ef2ff17f 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3970,6 +3970,11 @@ DEFUN (show_zebra, { struct vrf *vrf; + vty_out(vty, "ip forwarding is %sturned on\n", + ipforward() ? "" : "not "); + vty_out(vty, "ipv6 fowarding is %sturned on\n", + ipforward_ipv6() ? "" : "not "); + #ifdef GNU_LINUX if (!vrf_is_backend_netns()) vty_out(vty, "VRF devices are available for usage\n"); From 1a97e35eb8027f14fc411d8df6145bd583afa9f5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 21 Jan 2022 13:20:17 -0500 Subject: [PATCH 06/12] zebra: Add MPLS status to `show zebra` Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index a7ef2ff17f..073f1aa379 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3975,6 +3975,8 @@ DEFUN (show_zebra, vty_out(vty, "ipv6 fowarding is %sturned on\n", ipforward_ipv6() ? "" : "not "); + vty_out(vty, "MPLS is %senabled\n", mpls_enabled ? "" : "not "); + #ifdef GNU_LINUX if (!vrf_is_backend_netns()) vty_out(vty, "VRF devices are available for usage\n"); From 090ee85656f78b766a2dbe7bc3ed914305974aa9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 22 Jan 2022 07:53:24 -0500 Subject: [PATCH 07/12] zebra: Add kernel nexthop group support to `show zebra` Signed-off-by: Donald Sharp --- zebra/rt_netlink.c | 3 ++- zebra/zebra_router.h | 7 +++++++ zebra/zebra_vty.c | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 24c01b7f51..2d12ad4c8e 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -3027,11 +3027,12 @@ int netlink_nexthop_read(struct zebra_ns *zns) * this kernel must support them. */ supports_nh = true; - if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_NHG) zlog_debug("Nexthop objects %ssupported on this kernel", supports_nh ? "" : "not "); + zebra_router_set_supports_nhgs(supports_nh); + return ret; } diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index dd788216c7..dafe925c26 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -209,6 +209,8 @@ struct zebra_router { */ bool asic_offloaded; bool notify_on_ack; + + bool supports_nhgs; }; #define GRACEFUL_RESTART_TIME 60 @@ -256,6 +258,11 @@ extern enum multicast_mode multicast_mode_ipv4_get(void); extern bool zebra_router_notify_on_ack(void); +static inline void zebra_router_set_supports_nhgs(bool support) +{ + zrouter.supports_nhgs = support; +} + /* zebra_northbound.c */ extern const struct frr_yang_module_info frr_zebra_info; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 073f1aa379..31064e55aa 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3991,6 +3991,9 @@ DEFUN (show_zebra, else vty_out(vty, "Asic offload is not being used\n"); + vty_out(vty, "Kernel %ssupport Nexthop Groups\n", + zrouter.supports_nhgs ? "does " : "does not "); + vty_out(vty, " Route Route Neighbor LSP LSP\n"); vty_out(vty, From 1777ba2ac470ef7ac5316bc365979e3745f22bbc Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 22 Jan 2022 08:21:34 -0500 Subject: [PATCH 08/12] zebra: Add os and version to `show zebra` Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 1 + 1 file changed, 1 insertion(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 31064e55aa..d866e5ede4 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3970,6 +3970,7 @@ DEFUN (show_zebra, { struct vrf *vrf; + vty_out(vty, "OS: %s(%s)\n", cmd_system_get(), cmd_release_get()); vty_out(vty, "ip forwarding is %sturned on\n", ipforward() ? "" : "not "); vty_out(vty, "ipv6 fowarding is %sturned on\n", From 281686819da2ca61b9c347f3bf75f908cc6b8e52 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 22 Jan 2022 08:31:50 -0500 Subject: [PATCH 09/12] zebra: Add evpn status to `show zebra` Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index d866e5ede4..ba0cb5c964 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3978,6 +3978,8 @@ DEFUN (show_zebra, vty_out(vty, "MPLS is %senabled\n", mpls_enabled ? "" : "not "); + vty_out(vty, "EVPN is %senabled\n", is_evpn_enabled() ? "" : "not "); + #ifdef GNU_LINUX if (!vrf_is_backend_netns()) vty_out(vty, "VRF devices are available for usage\n"); From 954e1a2bc963a98e757b187714a5bad2179dc028 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 4 Feb 2022 08:04:23 -0500 Subject: [PATCH 10/12] zebra: Add knowledge about RA and RFC 5549 to `show zebra` Add to `show zebra` whether or not RA is compiled into FRR and whether or not BGP is using RFC 5549 at the moment. Signed-off-by: Donald Sharp --- zebra/rtadv.c | 25 +++++++++++++++++++++++++ zebra/rtadv.h | 3 +++ zebra/zebra_vty.c | 9 +++++++++ 3 files changed, 37 insertions(+) diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 350b97cc5d..83b141cd7a 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -47,6 +47,8 @@ extern struct zebra_privs_t zserv_privs; +static uint32_t interfaces_configured_for_ra_from_bgp; + #if defined(HAVE_RTADV) #ifndef VTYSH_EXTRACT_PL @@ -1282,6 +1284,9 @@ static void zebra_interface_radv_set(ZAPI_HANDLER_ARGS, int enable) zif = ifp->info; if (enable) { + if (!CHECK_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED)) + interfaces_configured_for_ra_from_bgp++; + SET_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED); ipv6_nd_suppress_ra_set(ifp, RA_ENABLE); if (ra_interval @@ -1290,6 +1295,9 @@ static void zebra_interface_radv_set(ZAPI_HANDLER_ARGS, int enable) VTY_RA_INTERVAL_CONFIGURED)) zif->rtadv.MaxRtrAdvInterval = ra_interval * 1000; } else { + if (CHECK_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED)) + interfaces_configured_for_ra_from_bgp--; + UNSET_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED); if (!CHECK_FLAG(zif->rtadv.ra_configured, VTY_RA_INTERVAL_CONFIGURED)) @@ -2766,6 +2774,8 @@ void rtadv_vrf_terminate(struct zebra_vrf *zvrf) void rtadv_cmd_init(void) { + interfaces_configured_for_ra_from_bgp = 0; + hook_register(zebra_if_extra_info, nd_dump_vty); hook_register(zebra_if_config_wr, rtadv_config_write); @@ -2865,6 +2875,11 @@ static int if_leave_all_router(int sock, struct interface *ifp) return 0; } +bool rtadv_compiled_in(void) +{ + return true; +} + #else void rtadv_vrf_init(struct zebra_vrf *zvrf) { @@ -2920,4 +2935,14 @@ void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS) return; } +bool rtadv_compiled_in(void) +{ + return false; +} + #endif /* HAVE_RTADV */ + +uint32_t rtadv_get_interfaces_configured_from_bgp(void) +{ + return interfaces_configured_for_ra_from_bgp; +} diff --git a/zebra/rtadv.h b/zebra/rtadv.h index 7b71ee45a2..a95174b22b 100644 --- a/zebra/rtadv.h +++ b/zebra/rtadv.h @@ -22,6 +22,7 @@ #ifndef _ZEBRA_RTADV_H #define _ZEBRA_RTADV_H +#include "zebra.h" #include "vty.h" #include "zebra/interface.h" @@ -161,6 +162,8 @@ extern void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS); extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS); extern void rtadv_add_prefix(struct zebra_if *zif, const struct prefix_ipv6 *p); extern void rtadv_delete_prefix(struct zebra_if *zif, const struct prefix *p); +extern uint32_t rtadv_get_interfaces_configured_from_bgp(void); +extern bool rtadv_compiled_in(void); #ifdef __cplusplus } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index ba0cb5c964..6726efe1df 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -61,6 +61,7 @@ #include "zebra/kernel_netlink.h" #include "zebra/table_manager.h" #include "zebra/zebra_script.h" +#include "zebra/rtadv.h" extern int allow_delete; @@ -3994,6 +3995,14 @@ DEFUN (show_zebra, else vty_out(vty, "Asic offload is not being used\n"); + if (rtadv_compiled_in()) { + vty_out(vty, "Router Advertisements are compiled with FRR\n"); + if (rtadv_get_interfaces_configured_from_bgp()) + vty_out(vty, "RFC 5549 is being used by BGP\n"); + } else + vty_out(vty, + "Router Advertisements are not compiled with FRR\n"); + vty_out(vty, "Kernel %ssupport Nexthop Groups\n", zrouter.supports_nhgs ? "does " : "does not "); From 530c9fc4f50b405c7b51156236e1e22ae70f0790 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 4 Feb 2022 08:42:07 -0500 Subject: [PATCH 11/12] zebra: Convert some `show zebra` output to a table Make the output a bit easier to interpret and use by converting to usage of a table. Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 51 +++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 6726efe1df..1d9ed4ddd9 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -33,6 +33,7 @@ #include "routemap.h" #include "srcdest_table.h" #include "vxlan.h" +#include "termtable.h" #include "zebra/zebra_router.h" #include "zebra/zserv.h" @@ -3970,41 +3971,43 @@ DEFUN (show_zebra, ZEBRA_STR) { struct vrf *vrf; + struct ttable *table = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + char *out; - vty_out(vty, "OS: %s(%s)\n", cmd_system_get(), cmd_release_get()); - vty_out(vty, "ip forwarding is %sturned on\n", - ipforward() ? "" : "not "); - vty_out(vty, "ipv6 fowarding is %sturned on\n", - ipforward_ipv6() ? "" : "not "); + ttable_rowseps(table, 0, BOTTOM, true, '-'); + ttable_add_row(table, "OS|%s(%s)", cmd_system_get(), cmd_release_get()); + ttable_add_row(table, "v4 Forwarding|%s", ipforward() ? "On" : "Off"); + ttable_add_row(table, "v6 Forwarding|%s", + ipforward_ipv6() ? "On" : "Off"); + ttable_add_row(table, "MPLS|%s", mpls_enabled ? "On" : "Off"); + ttable_add_row(table, "EVPN|%s", is_evpn_enabled() ? "On" : "Off"); - vty_out(vty, "MPLS is %senabled\n", mpls_enabled ? "" : "not "); - - vty_out(vty, "EVPN is %senabled\n", is_evpn_enabled() ? "" : "not "); #ifdef GNU_LINUX if (!vrf_is_backend_netns()) - vty_out(vty, "VRF devices are available for usage\n"); + ttable_add_row(table, "VRF|l3mdev Available"); else - vty_out(vty, "Namespaces are being used as VRF devices\n"); + ttable_add_row(table, "VRF|Namespaces"); #else - vty_out(vty, "No VRF's available on this platform\n"); + ttable_add_row(table, "VRF|Not Available"); #endif - if (zrouter.asic_offloaded) - vty_out(vty, "Asic Offload is being used\n"); - else - vty_out(vty, "Asic offload is not being used\n"); + ttable_add_row(table, "ASIC offload|%s", + zrouter.asic_offloaded ? "Used" : "Unavailable"); - if (rtadv_compiled_in()) { - vty_out(vty, "Router Advertisements are compiled with FRR\n"); - if (rtadv_get_interfaces_configured_from_bgp()) - vty_out(vty, "RFC 5549 is being used by BGP\n"); - } else - vty_out(vty, - "Router Advertisements are not compiled with FRR\n"); + ttable_add_row(table, "RA|%s", + rtadv_compiled_in() ? "Compiled in" : "Not Compiled in"); + ttable_add_row(table, "RFC 5549|%s", + rtadv_get_interfaces_configured_from_bgp() + ? "BGP is using" + : "BGP is not using"); - vty_out(vty, "Kernel %ssupport Nexthop Groups\n", - zrouter.supports_nhgs ? "does " : "does not "); + ttable_add_row(table, "Kernel NHG|%s", + zrouter.supports_nhgs ? "Available" : "Unavailable"); + + out = ttable_dump(table, "\n"); + vty_out(vty, "%s\n", out); + XFREE(MTYPE_TMP, out); vty_out(vty, " Route Route Neighbor LSP LSP\n"); From 446f6ec5eda5de87d9987a15a28f8f528821765f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 4 Feb 2022 08:44:36 -0500 Subject: [PATCH 12/12] doc: Update `show zebra` command Update the `show zebra` command documentation to show what it is doing now. Signed-off-by: Donald Sharp --- doc/user/zebra.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index 9ed6b6dd7f..7ca473ceb6 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -1155,7 +1155,9 @@ zebra Terminal Mode Commands .. clicmd:: show zebra Display various statistics related to the installation and deletion - of routes, neighbor updates, and LSP's into the kernel. + of routes, neighbor updates, and LSP's into the kernel. In addition + show various zebra state that is useful when debugging an operator's + setup. .. clicmd:: show zebra client [summary]