]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Added proto_get_named() to be used in CLI commands to get protocol instance
authorMartin Mares <mj@ucw.cz>
Fri, 3 Dec 1999 11:40:45 +0000 (11:40 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 3 Dec 1999 11:40:45 +0000 (11:40 +0000)
of a given protocol with optionally given name. See `show static' for an
example.

nest/proto.c
nest/protocol.h

index 94bbbfd8349f7a71465b02c0cc4912477d0ee588..a0beb5fb8a73b1eebf848d63503810e9fc458421 100644 (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;
+}
index 0962ccfd89f4b8edf9bfe41a0ece91ccecff859c..3e53c86cea42f11ce5df509f82e3f020d8afc37d 100644 (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;