summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
Diffstat (limited to 'nest')
-rw-r--r--nest/cli.h3
-rw-r--r--nest/proto.c44
-rw-r--r--nest/protocol.h4
3 files changed, 51 insertions, 0 deletions
diff --git a/nest/cli.h b/nest/cli.h
index 6040be91..8a3294c5 100644
--- a/nest/cli.h
+++ b/nest/cli.h
@@ -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 *);
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;
+ }
+}
diff --git a/nest/protocol.h b/nest/protocol.h
index a934c047..14b6123a 100644
--- a/nest/protocol.h
+++ b/nest/protocol.h
@@ -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