From f51d2a6b979a8c4efe9836f69767956c9e03322f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 5 Sep 2024 09:11:04 -0400 Subject: [PATCH] zebra: Don't display the vrf if not using namespace based vrfs Currently when doing a `show ip route table XXXX`, zebra is displaying the current default vrf as the vrf we are in. We are displaying a table not a vrf. This is only true if you are not using namespace based vrf's, so modify the output to display accordingly. Signed-off-by: Donald Sharp --- zebra/table_manager.h | 1 + zebra/zebra_vrf.c | 2 ++ zebra/zebra_vty.c | 26 +++++++++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/zebra/table_manager.h b/zebra/table_manager.h index 21691994cb..f16efdd626 100644 --- a/zebra/table_manager.h +++ b/zebra/table_manager.h @@ -24,6 +24,7 @@ extern "C" { #if !defined(GNU_LINUX) /* BSD systems */ +#define RT_TABLE_ID_MAIN 0 #else /* Linux Systems */ diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index e464e47b1f..2b3cfc8766 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -398,6 +398,7 @@ vrf_id_t zebra_vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id) RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { zvrf = vrf->info; + if (zvrf == NULL) continue; /* case vrf with netns : match the netnsid */ @@ -408,6 +409,7 @@ vrf_id_t zebra_vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id) /* VRF is VRF_BACKEND_VRF_LITE */ if (zvrf->table_id != table_id) continue; + return zvrf_id(zvrf); } } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 8c0d6df68a..89a60636cd 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -942,11 +942,27 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, if (!tableid) vty_out(vty, "VRF %s:\n", zvrf_name(zvrf)); - else - vty_out(vty, - "VRF %s table %u:\n", - zvrf_name(zvrf), - tableid); + else { + if (vrf_is_backend_netns()) + vty_out(vty, "VRF %s table %u:\n", + zvrf_name(zvrf), tableid); + else { + vrf_id_t vrf = + zebra_vrf_lookup_by_table(tableid, + zvrf->zns->ns_id); + + if (vrf == VRF_DEFAULT && + tableid != RT_TABLE_ID_MAIN) + vty_out(vty, "table %u:\n", tableid); + else { + struct zebra_vrf *zvrf2 = + zebra_vrf_lookup_by_id(vrf); + + vty_out(vty, "VRF %s table %u:\n", + zvrf_name(zvrf2), tableid); + } + } + } } ctx->header_done = true; first = 0; -- 2.39.5