Commit c26c6bc2 authored by Ondrej Zajicek (work)'s avatar Ondrej Zajicek (work)
Browse files

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.
parent a948cf9a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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 *);
+44 −0
Original line number Diff line number Diff line
@@ -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;
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -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
+0 −12
Original line number Diff line number Diff line
@@ -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, "");
}


+4 −4
Original line number Diff line number Diff line
@@ -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

Loading