Merge pull request #3288 from nitinsoniism/show_intf_brief

zebra: Support "brief" output for "show interface"
This commit is contained in:
David Lamparter 2019-01-29 16:23:36 +01:00 committed by GitHub
commit 185fd9ca77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 120 additions and 10 deletions

View File

@ -1156,6 +1156,106 @@ static const char *zebra_ziftype_2str(zebra_iftype_t zif_type)
} }
} }
/* Interface's brief information print out to vty interface. */
static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf)
{
struct connected *connected;
struct listnode *node;
struct route_node *rn;
struct zebra_if *zebra_if;
struct prefix *p;
struct interface *ifp;
bool print_header = true;
FOR_ALL_INTERFACES (vrf, ifp) {
char global_pfx[PREFIX_STRLEN] = {0};
char buf[PREFIX_STRLEN] = {0};
bool first_pfx_printed = false;
if (print_header) {
vty_out(vty, "%-16s%-8s%-16s%s\n", "Interface",
"Status", "VRF", "Addresses");
vty_out(vty, "%-16s%-8s%-16s%s\n", "---------",
"------", "---", "---------");
print_header = false; /* We have at least 1 iface */
}
zebra_if = ifp->info;
vty_out(vty, "%-16s", ifp->name);
if (if_is_up(ifp))
vty_out(vty, "%-8s", "up");
else
vty_out(vty, "%-8s", "down");
vty_out(vty, "%-16s", vrf->name);
for (rn = route_top(zebra_if->ipv4_subnets); rn;
rn = route_next(rn)) {
if (!rn->info)
continue;
uint32_t list_size = listcount((struct list *)rn->info);
for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node,
connected)) {
if (!CHECK_FLAG(connected->flags,
ZEBRA_IFA_SECONDARY)) {
p = connected->address;
prefix2str(p, buf, sizeof(buf));
if (first_pfx_printed) {
/* padding to prepare row only for ip addr */
vty_out(vty, "%-40s", "");
if (list_size > 1)
vty_out(vty, "+ ");
vty_out(vty, "%s\n", buf);
} else {
if (list_size > 1)
vty_out(vty, "+ ");
vty_out(vty, "%s\n", buf);
}
first_pfx_printed = true;
break;
}
}
}
uint32_t v6_list_size = 0;
for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& (connected->address->family == AF_INET6))
v6_list_size++;
}
for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& !CHECK_FLAG(connected->flags,
ZEBRA_IFA_SECONDARY)
&& (connected->address->family == AF_INET6)) {
p = connected->address;
/* Don't print link local pfx */
if (!IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) {
prefix2str(p, global_pfx, PREFIX_STRLEN);
if (first_pfx_printed) {
/* padding to prepare row only for ip addr */
vty_out(vty, "%-40s", "");
if (v6_list_size > 1)
vty_out(vty, "+ ");
vty_out(vty, "%s\n", global_pfx);
} else {
if (v6_list_size > 1)
vty_out(vty, "+ ");
vty_out(vty, "%s\n", global_pfx);
}
first_pfx_printed = true;
break;
}
}
}
if (!first_pfx_printed)
vty_out(vty, "\n");
}
vty_out(vty, "\n");
}
/* Interface's information print out to vty interface. */ /* Interface's information print out to vty interface. */
static void if_dump_vty(struct vty *vty, struct interface *ifp) static void if_dump_vty(struct vty *vty, struct interface *ifp)
{ {
@ -1456,13 +1556,16 @@ static void interface_update_stats(void)
struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};
#ifndef VTYSH_EXTRACT_PL
#include "zebra/interface_clippy.c"
#endif
/* Show all interfaces to vty. */ /* Show all interfaces to vty. */
DEFUN (show_interface, DEFPY(show_interface, show_interface_cmd,
show_interface_cmd, "show interface [vrf NAME$name] [brief$brief]",
"show interface [vrf NAME]", SHOW_STR
SHOW_STR "Interface status and configuration\n"
"Interface status and configuration\n" VRF_CMD_HELP_STR
VRF_CMD_HELP_STR) "Interface status and configuration summary\n")
{ {
struct vrf *vrf; struct vrf *vrf;
struct interface *ifp; struct interface *ifp;
@ -1470,13 +1573,18 @@ DEFUN (show_interface,
interface_update_stats(); interface_update_stats();
if (argc > 2) if (name)
VRF_GET_ID(vrf_id, argv[3]->arg, false); VRF_GET_ID(vrf_id, name, false);
/* All interface print. */ /* All interface print. */
vrf = vrf_lookup_by_id(vrf_id); vrf = vrf_lookup_by_id(vrf_id);
FOR_ALL_INTERFACES (vrf, ifp) if (brief) {
if_dump_vty(vty, ifp); ifs_dump_brief_vty(vty, vrf);
} else {
FOR_ALL_INTERFACES (vrf, ifp) {
if_dump_vty(vty, ifp);
}
}
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -99,6 +99,8 @@ zebra/zebra_mlag_clippy.c: $(CLIPPY_DEPS)
zebra/zebra_mlag.$(OBJEXT): zebra/zebra_mlag_clippy.c zebra/zebra_mlag.$(OBJEXT): zebra/zebra_mlag_clippy.c
zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS) zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS)
zebra/interface_clippy.c: $(CLIPPY_DEPS)
zebra/interface.$(OBJEXT): zebra/interface_clippy.c
zebra/zebra_vty.$(OBJEXT): zebra/zebra_vty_clippy.c zebra/zebra_vty.$(OBJEXT): zebra/zebra_vty_clippy.c
zebra/zebra_routemap_clippy.c: $(CLIPPY_DEPS) zebra/zebra_routemap_clippy.c: $(CLIPPY_DEPS)