summaryrefslogtreecommitdiff
path: root/nest/proto.c
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2020-05-14 03:48:17 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2020-06-28 15:38:47 +0200
commitc26c6bc2d78a2fe76f27dcc9fbb5afc95c3a7626 (patch)
treeb9058f04982a155d2a214e488e143bf1fac36597 /nest/proto.c
parenta948cf9a5c338518773e6c98e895c829c469f56b (diff)
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.
Diffstat (limited to 'nest/proto.c')
-rw-r--r--nest/proto.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/nest/proto.c b/nest/proto.c
index 85090424..41b3a6b9 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -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;
+ }
+}