0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Show info from multiple protocols when protocol is not specified

Most commands like 'show ospf neighbors' fail when protocol is not
specified and there are multiple instances of given protocol type.
This is annoying in BIRD 2, as many protocols have IPv4 and IPv6
instances. The patch changes that by showing output from all protocol
instances of appropriate type.

Note that the patch also removes terminating cli_msg() call from these
commands and moves it to the common iterating code.
This commit is contained in:
Ondrej Zajicek (work) 2020-05-14 03:48:17 +02:00
parent a948cf9a5c
commit c26c6bc2d7
13 changed files with 62 additions and 39 deletions

View File

@ -58,6 +58,9 @@ void cli_printf(cli *, int, char *, ...);
#define cli_msg(x...) cli_printf(this_cli, x)
void cli_set_log_echo(cli *, uint mask, uint size);
static inline void cli_separator(cli *c)
{ if (c->last_reply) cli_printf(c, -c->last_reply, ""); };
/* Functions provided to sysdep layer */
cli *cli_new(void *);

View File

@ -2084,3 +2084,47 @@ proto_get_named(struct symbol *sym, struct protocol *pr)
return p;
}
struct proto *
proto_iterate_named(struct symbol *sym, struct protocol *proto, struct proto *old)
{
if (sym)
{
/* Just the first pass */
if (old)
{
cli_msg(0, "");
return NULL;
}
if (sym->class != SYM_PROTO)
cf_error("%s: Not a protocol", sym->name);
struct proto *p = sym->proto->proto;
if (!p || (p->proto != proto))
cf_error("%s: Not a %s protocol", sym->name, proto->name);
return p;
}
else
{
for (struct proto *p = !old ? HEAD(proto_list) : NODE_NEXT(old);
NODE_VALID(p);
p = NODE_NEXT(p))
{
if ((p->proto == proto) && (p->proto_state != PS_DOWN))
{
cli_separator(this_cli);
return p;
}
}
/* Not found anything during first pass */
if (!old)
cf_error("There is no %s protocol running", proto->name);
/* No more items */
cli_msg(0, "");
return NULL;
}
}

View File

@ -292,6 +292,10 @@ void proto_cmd_mrtdump(struct proto *, uintptr_t, int);
void proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, uintptr_t, int), int restricted, uintptr_t arg);
struct proto *proto_get_named(struct symbol *, struct protocol *);
struct proto *proto_iterate_named(struct symbol *sym, struct protocol *proto, struct proto *old);
#define PROTO_WALK_CMD(sym,pr,p) for(struct proto *p = NULL; p = proto_iterate_named(sym, pr, p); )
#define CMD_RELOAD 0
#define CMD_RELOAD_IN 1

View File

@ -1891,7 +1891,6 @@ babel_show_interfaces(struct proto *P, const char *iff)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1023, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -1915,8 +1914,6 @@ babel_show_interfaces(struct proto *P, const char *iff)
ifa->cf->rxcost, nbrs, MAX(timer, 0),
ifa->next_hop_ip4, ifa->next_hop_ip6);
}
cli_msg(0, "");
}
void
@ -1930,7 +1927,6 @@ babel_show_neighbors(struct proto *P, const char *iff)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1024, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -1955,8 +1951,6 @@ babel_show_neighbors(struct proto *P, const char *iff)
n->addr, ifa->iface->name, n->cost, rts, hellos, MAX(timer, 0));
}
}
cli_msg(0, "");
}
static void
@ -1998,7 +1992,6 @@ babel_show_entries(struct proto *P)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1025, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -2008,8 +2001,6 @@ babel_show_entries(struct proto *P)
babel_show_entries_(p, &p->ip4_rtable);
babel_show_entries_(p, &p->ip6_rtable);
cli_msg(0, "");
}
static void
@ -2041,7 +2032,6 @@ babel_show_routes(struct proto *P)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1025, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -2051,8 +2041,6 @@ babel_show_routes(struct proto *P)
babel_show_routes_(p, &p->ip4_rtable);
babel_show_routes_(p, &p->ip6_rtable);
cli_msg(0, "");
}

View File

@ -130,16 +130,16 @@ dynamic_attr: BABEL_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_BAB
CF_CLI_HELP(SHOW BABEL, ..., [[Show information about Babel protocol]]);
CF_CLI(SHOW BABEL INTERFACES, optproto opttext, [<name>] [\"<interface>\"], [[Show information about Babel interfaces]])
{ babel_show_interfaces(proto_get_named($4, &proto_babel), $5); };
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_interfaces(p, $5); };
CF_CLI(SHOW BABEL NEIGHBORS, optproto opttext, [<name>] [\"<interface>\"], [[Show information about Babel neighbors]])
{ babel_show_neighbors(proto_get_named($4, &proto_babel), $5); };
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_neighbors(p, $5); };
CF_CLI(SHOW BABEL ENTRIES, optproto opttext, [<name>], [[Show information about Babel prefix entries]])
{ babel_show_entries(proto_get_named($4, &proto_babel)); };
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_entries(p); };
CF_CLI(SHOW BABEL ROUTES, optproto opttext, [<name>], [[Show information about Babel route entries]])
{ babel_show_routes(proto_get_named($4, &proto_babel)); };
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_routes(p); };
CF_CODE

View File

@ -1104,7 +1104,6 @@ bfd_show_sessions(struct proto *P)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1020, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -1129,8 +1128,6 @@ bfd_show_sessions(struct proto *P)
s->addr, ifname, bfd_state_names[state], tbuf, tx_int, timeout);
}
HASH_WALK_END;
cli_msg(0, "");
}

View File

@ -182,7 +182,7 @@ bfd_neighbor: ipa bfd_neigh_iface bfd_neigh_local bfd_neigh_multihop
CF_CLI_HELP(SHOW BFD, ..., [[Show information about BFD protocol]]);
CF_CLI(SHOW BFD SESSIONS, optproto, [<name>], [[Show information about BFD sessions]])
{ bfd_show_sessions(proto_get_named($4, &proto_bfd)); };
{ PROTO_WALK_CMD($4, &proto_bfd, p) bfd_show_sessions(p); };
CF_CODE

View File

@ -513,13 +513,13 @@ dynamic_attr: OSPF_ROUTER_ID { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID, T_QUA
CF_CLI_HELP(SHOW OSPF, ..., [[Show information about OSPF protocol]]);
CF_CLI(SHOW OSPF, optproto, [<name>], [[Show information about OSPF protocol]])
{ ospf_sh(proto_get_named($3, &proto_ospf)); };
{ PROTO_WALK_CMD($3, &proto_ospf, p) ospf_sh(p); };
CF_CLI(SHOW OSPF NEIGHBORS, optproto opttext, [<name>] [\"<interface>\"], [[Show information about OSPF neighbors]])
{ ospf_sh_neigh(proto_get_named($4, &proto_ospf), $5); };
{ PROTO_WALK_CMD($4, &proto_ospf, p) ospf_sh_neigh(p, $5); };
CF_CLI(SHOW OSPF INTERFACE, optproto opttext, [<name>] [\"<interface>\"], [[Show information about interface]])
{ ospf_sh_iface(proto_get_named($4, &proto_ospf), $5); };
{ PROTO_WALK_CMD($4, &proto_ospf, p) ospf_sh_iface(p, $5); };
CF_CLI_HELP(SHOW OSPF TOPOLOGY, [all] [<name>], [[Show information about OSPF network topology]])

View File

@ -800,7 +800,6 @@ ospf_sh_neigh(struct proto *P, const char *iff)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1013, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -811,7 +810,6 @@ ospf_sh_neigh(struct proto *P, const char *iff)
if ((iff == NULL) || patmatch(iff, ifa->ifname))
WALK_LIST(n, ifa->neigh_list)
ospf_sh_neigh_info(n);
cli_msg(0, "");
}
void
@ -826,7 +824,6 @@ ospf_sh(struct proto *P)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1014, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -896,7 +893,6 @@ ospf_sh(struct proto *P)
FIB_WALK_END;
}
cli_msg(0, "");
}
void
@ -908,7 +904,6 @@ ospf_sh_iface(struct proto *P, const char *iff)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1015, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -916,7 +911,6 @@ ospf_sh_iface(struct proto *P, const char *iff)
WALK_LIST(ifa, p->iface_list)
if ((iff == NULL) || patmatch(iff, ifa->ifname))
ospf_iface_info(ifa);
cli_msg(0, "");
}
/* lsa_compare_for_state() - Compare function for 'show ospf state'

View File

@ -196,10 +196,10 @@ dynamic_attr: RIP_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_RIP_TAG)
CF_CLI_HELP(SHOW RIP, ..., [[Show information about RIP protocol]]);
CF_CLI(SHOW RIP INTERFACES, optproto opttext, [<name>] [\"<interface>\"], [[Show information about RIP interfaces]])
{ rip_show_interfaces(proto_get_named($4, &proto_rip), $5); };
{ PROTO_WALK_CMD($4, &proto_rip, p) rip_show_interfaces(p, $5); };
CF_CLI(SHOW RIP NEIGHBORS, optproto opttext, [<name>] [\"<interface>\"], [[Show information about RIP neighbors]])
{ rip_show_neighbors(proto_get_named($4, &proto_rip), $5); };
{ PROTO_WALK_CMD($4, &proto_rip, p) rip_show_neighbors(p, $5); };
CF_CODE

View File

@ -1232,7 +1232,6 @@ rip_show_interfaces(struct proto *P, const char *iff)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1021, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -1256,8 +1255,6 @@ rip_show_interfaces(struct proto *P, const char *iff)
cli_msg(-1021, "%-10s %-6s %6u %6u %7t",
ifa->iface->name, (ifa->up ? "Up" : "Down"), ifa->cf->metric, nbrs, timer);
}
cli_msg(0, "");
}
void
@ -1270,7 +1267,6 @@ rip_show_neighbors(struct proto *P, const char *iff)
if (p->p.proto_state != PS_UP)
{
cli_msg(-1022, "%s: is not up", p->p.name);
cli_msg(0, "");
return;
}
@ -1293,8 +1289,6 @@ rip_show_neighbors(struct proto *P, const char *iff)
n->nbr->addr, ifa->iface->name, ifa->cf->metric, n->uc, timer);
}
}
cli_msg(0, "");
}
static void

View File

@ -158,7 +158,7 @@ stat_route_opt_list:
CF_CLI(SHOW STATIC, optproto, [<name>], [[Show details of static protocol]])
{ static_show(proto_get_named($3, &proto_static)); } ;
{ PROTO_WALK_CMD($3, &proto_static, p) static_show(p); } ;
CF_CODE

View File

@ -647,7 +647,6 @@ static_show(struct proto *P)
WALK_LIST(r, c->routes)
static_show_rt(r);
cli_msg(0, "");
}