summaryrefslogtreecommitdiffstats
path: root/nest/proto.c
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-12-03 12:40:45 +0100
committerMartin Mares <mj@ucw.cz>1999-12-03 12:40:45 +0100
commit02c1fbddd462fecc6887a44ef67202870bcae7be (patch)
tree571deb0c83d55826ec90fe317544bd548ac848d3 /nest/proto.c
parent28e01f85c65c536837227829f645818dfa6a2652 (diff)
downloadbird-02c1fbddd462fecc6887a44ef67202870bcae7be.tar
bird-02c1fbddd462fecc6887a44ef67202870bcae7be.zip
Added proto_get_named() to be used in CLI commands to get protocol instance
of a given protocol with optionally given name. See `show static' for an example.
Diffstat (limited to 'nest/proto.c')
-rw-r--r--nest/proto.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/nest/proto.c b/nest/proto.c
index 94bbbfd..a0beb5f 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -499,3 +499,32 @@ proto_show(struct symbol *s, int verbose)
}
cli_msg(0, "");
}
+
+struct proto *
+proto_get_named(struct symbol *sym, struct protocol *pr)
+{
+ struct proto *p, *q;
+
+ if (sym)
+ {
+ if (sym->class != SYM_PROTO)
+ cf_error("%s: Not a protocol", sym->name);
+ p = ((struct proto_config *)sym->def)->proto;
+ if (!p || p->proto != pr)
+ cf_error("%s: Not a %s protocol", sym->name, pr->name);
+ }
+ else
+ {
+ p = NULL;
+ WALK_LIST(q, proto_list)
+ if (q->proto == pr)
+ {
+ if (p)
+ cf_error("There are multiple %s protocols running", pr->name);
+ p = q;
+ }
+ if (!p)
+ cf_error("There is no %s protocol running", pr->name);
+ }
+ return p;
+}