summaryrefslogtreecommitdiff
path: root/zebra/interface.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-10-14 21:06:38 +0300
committerIgor Ryzhov <iryzhov@nfware.com>2021-10-15 03:44:42 +0300
commit31eab818f69a3b4d47b9819e6c10f24c14e134b2 (patch)
tree477110582b8de35a3a44ec0cd9a029fd20ae3cc0 /zebra/interface.c
parent4ff97453d0c5064da279c76e0602fdaf75f2a675 (diff)
zebra: fix "show interface IFNAME" for netns
With netns VRF backend, we may have multiple interfaces with the same name. Currently, the function output is not deterministic in this case, it returns the first interface that it finds in the list. Be more explicit and tell the user that we need the VRF name. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'zebra/interface.c')
-rw-r--r--zebra/interface.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/zebra/interface.c b/zebra/interface.c
index a68d00d55c..b9605e138a 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -2485,12 +2485,24 @@ DEFPY (show_interface_name_vrf_all,
VRF_ALL_CMD_HELP_STR
JSON_STR)
{
- struct interface *ifp;
+ struct interface *ifp = NULL;
+ struct interface *ifptmp;
+ struct vrf *vrf;
json_object *json = NULL;
+ int count = 0;
interface_update_stats();
- ifp = if_lookup_by_name_all_vrf(ifname);
+ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+ ifptmp = if_lookup_by_name_vrf(ifname, vrf);
+ if (ifptmp) {
+ ifp = ifptmp;
+ count++;
+ if (!vrf_is_backend_netns())
+ break;
+ }
+ }
+
if (ifp == NULL) {
if (uj)
vty_out(vty, "{}\n");
@@ -2498,6 +2510,17 @@ DEFPY (show_interface_name_vrf_all,
vty_out(vty, "%% Can't find interface %s\n", ifname);
return CMD_WARNING;
}
+ if (count > 1) {
+ if (uj) {
+ vty_out(vty, "{}\n");
+ } else {
+ vty_out(vty,
+ "%% There are multiple interfaces with name %s\n",
+ ifname);
+ vty_out(vty, "%% You must specify the VRF name\n");
+ }
+ return CMD_WARNING;
+ }
if (uj)
json = json_object_new_object();