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

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.
This commit is contained in:
Martin Mares 1999-12-03 11:40:45 +00:00
parent 28e01f85c6
commit 02c1fbddd4
2 changed files with 30 additions and 0 deletions

View File

@ -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;
}

View File

@ -151,6 +151,7 @@ void proto_build(struct proto_config *);
void *proto_new(struct proto_config *, unsigned size);
void *proto_config_new(struct protocol *, unsigned size);
void proto_show(struct symbol *, int);
struct proto *proto_get_named(struct symbol *, struct protocol *);
extern list proto_list;