]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Separated `official protocol names' used in status dumps from name templates
authorMartin Mares <mj@ucw.cz>
Mon, 17 Jan 2000 11:52:50 +0000 (11:52 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 17 Jan 2000 11:52:50 +0000 (11:52 +0000)
used for automatic generation of instance names.

protocol->name is the official name
protocol->template is the name template (usually "name%d"),
should be all lowercase.

Updated all protocols to define the templates, checked that their configuration
grammar includes proto_name which generates the name and interns it in the
symbol table.

13 files changed:
TODO
conf/cf-lex.l
conf/conf.h
nest/config.Y
nest/protocol.h
nest/rt-dev.c
proto/ospf/ospf.c
proto/pipe/pipe.c
proto/rip/rip.c
proto/static/static.c
proto/static/static.h
sysdep/unix/krt.Y
sysdep/unix/krt.c

diff --git a/TODO b/TODO
index 7f36a57145b50301dba0567d929ce075e2a33fb1..7428dfbfd7d416a1c6cffff46740280d575b9285 100644 (file)
--- a/TODO
+++ b/TODO
@@ -26,9 +26,7 @@ Core
 - config: executable config files
 - config: when parsing prefix, check zero bits
 - config: useless rules when protocols disabled
-- config: remove protocol startup priority hacks?
 - config: better datetime format
-- config: avoid upper case in default protocol names
 
 - krt: rescan interfaces when route addition fails?
 - krt: does PERSIST mode have any sense if kernel syncer is shut down as last?
@@ -79,6 +77,7 @@ Cleanup
 - does everybody test return value of sk_open?
 - add references to RFC's we did follow
 - protocols: implement CLI hooks
+- protocols: implement reconfigure hook
 - protocols: use locking
 
 Various ideas
index cd6699fda439d4511ca4fec74c79fcc09100367b..df0f3c1d13a1384369f6c934236a6e23de21fb44 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     BIRD -- Configuration Lexer
  *
- *     (c) 1998--1999 Martin Mares <mj@ucw.cz>
+ *     (c) 1998--2000 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -19,6 +19,7 @@
 #include "filter/filter.h"
 #include "conf/conf.h"
 #include "conf/cf-parse.tab.h"
+#include "lib/string.h"
 
 static struct keyword {
   byte *name;
@@ -231,19 +232,24 @@ cf_find_symbol(byte *c)
 }
 
 struct symbol *
-cf_default_name(char *prefix, int *counter)
+cf_default_name(char *template, int *counter)
 {
   char buf[32];
   struct symbol *s;
+  char *perc = strchr(template, '%');
 
-  do
+  for(;;)
     {
-      sprintf(buf, "%s%d", prefix, ++(*counter));
+      bsprintf(buf, template, ++(*counter));
       s = cf_find_sym(buf, cf_hash(buf));
-      if (!s) cf_error("Unable to generate default name");
+      if (!s)
+       break;
+      if (s->class == SYM_VOID)
+       return s;
+      if (!perc)
+       break;
     }
-  while (s->class != SYM_VOID);
-  return s;
+  cf_error("Unable to generate default name");
 }
 
 void
index 9fe133ee417a85f29e31258553d74ab34a47549c..178cdb6e06b7070d7f64d15bd35f29940d815610 100644 (file)
@@ -90,7 +90,7 @@ extern int conf_lino;
 int cf_lex(void);
 void cf_lex_init(int is_cli);
 struct symbol *cf_find_symbol(byte *c);
-struct symbol *cf_default_name(char *prefix, int *counter);
+struct symbol *cf_default_name(char *template, int *counter);
 void cf_define_symbol(struct symbol *symbol, int type, void *def);
 void cf_push_scope(struct symbol *);
 void cf_pop_scope(void);
index 0cb11080949f908f2920630194cad363941f6843..4bccc1665f85334304fa34859b9ae8b6bad40322 100644 (file)
@@ -76,7 +76,7 @@ proto_start: PROTOCOL
 
 proto_name:
    /* EMPTY */ {
-     struct symbol *s = cf_default_name(this_proto->protocol->name, &this_proto->protocol->name_counter);
+     struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
      s->class = SYM_PROTO;
      s->def = this_proto;
      this_proto->name = s->name;
index d5b5810ab5333138a6ab3f9d1074bc933516b2d7..815a7a7b592d0b87d589e84328bc8c7d0fc03396 100644 (file)
@@ -33,6 +33,7 @@ struct symbol;
 struct protocol {
   node n;
   char *name;
+  char *template;                      /* Template for automatic generation of names */
   unsigned debug;                      /* Default debugging flags */
   int priority;                                /* Protocol priority (usually 0) */
   int name_counter;                    /* Counter for automatic name generation */
index 23d9b5651c7cefa8376266362be9ceb29c85ace0..89b2250226d188c8dec3f231923652c55dcb9bef 100644 (file)
@@ -88,6 +88,7 @@ dev_reconfigure(struct proto *p, struct proto_config *new)
 
 struct protocol proto_device = {
   name:                "Direct",
+  template:    "direct%d",
   priority:    90,
   init:                dev_init,
   reconfigure: dev_reconfigure
index db773369ebcd9b98b785df7d800eb9fd13848186..e8704a7f11e9a7f95c1212e977b78ff058d62120 100644 (file)
@@ -90,6 +90,7 @@ ospf_postconfig(struct proto_config *c)
 
 struct protocol proto_ospf = {
   name:                "OSPF",
+  template:    "ospf%d",
   init:                ospf_init,
   dump:                ospf_dump,
   start:       ospf_start,
index f439a15435d8339548193338c55f72721ed94246..f1a190f904d8b1b104427e11826706d675ded53d 100644 (file)
@@ -163,6 +163,7 @@ pipe_reconfigure(struct proto *p, struct proto_config *new)
 
 struct protocol proto_pipe = {
   name:                "Pipe",
+  template:    "pipe%d",
   postconfig:  pipe_postconfig,
   init:                pipe_init,
   start:       pipe_start,
index d863fa383cbde5298fc249e4dcfd8750851ac8c1..b8338a5eb4d102293e68b767ddefd41c1874a39b 100644 (file)
@@ -789,6 +789,7 @@ rip_postconfig(struct proto_config *c)
 
 struct protocol proto_rip = {
   name: "RIP",
+  template: "rip%d",
   preconfig: rip_preconfig,
   postconfig: rip_postconfig,
   get_route_info: rip_get_route_info,
index 4217ad037fa776e4a69c06f46dc9033e5627921c..c006daf06c77265283e8e1c6fafff02728316905 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     BIRD -- Static Route Generator
  *
- *     (c) 1998--1999 Martin Mares <mj@ucw.cz>
+ *     (c) 1998--2000 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -175,11 +175,19 @@ static_init(struct proto_config *c)
   return p;
 }
 
+static int
+static_reconfigure(struct proto *p, struct proto_config *new)
+{
+  return 0;
+}
+
 struct protocol proto_static = {
   name:                "Static",
+  template:    "static%d",
   init:                static_init,
   dump:                static_dump,
   start:       static_start,
+  reconfigure: static_reconfigure,
 };
 
 static void
index 66451183f9a1567287876aca258e8f438ce58814..5d2bd21897cb249eaa26ba27abe4fff007cacfc7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     BIRD -- Static Route Generator
  *
- *     (c) 1998 Martin Mares <mj@ucw.cz>
+ *     (c) 1998--2000 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
index 50f31bbaf9be092bd55ba5783ccf88df8137302d..01264d55d6396fae3db3c5e5237fcd08d955ade1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     BIRD -- UNIX Kernel Syncer Configuration
  *
- *     (c) 1998--1999 Martin Mares <mj@ucw.cz>
+ *     (c) 1998--2000 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -70,7 +70,7 @@ kif_proto_start: proto_start DEVICE {
    }
  ;
 
-CF_ADDTO(kif_proto, kif_proto_start '{')
+CF_ADDTO(kif_proto, kif_proto_start proto_name '{')
 CF_ADDTO(kif_proto, kif_proto proto_item ';')
 CF_ADDTO(kif_proto, kif_proto kif_item ';')
 
index bbca8cfa36f0820c1e11a8c147c90519b7a3a71d..b321729b527bab8cd588b3666ec86c962e7cfb2b 100644 (file)
@@ -160,6 +160,7 @@ kif_reconfigure(struct proto *p, struct proto_config *new)
 
 struct protocol proto_unix_iface = {
   name:                "Device",
+  template:    "device%d",
   priority:    100,
   preconfig:   kif_preconfig,
   init:                kif_init,
@@ -786,6 +787,7 @@ krt_init(struct proto_config *c)
 
 struct protocol proto_unix_kernel = {
   name:                "Kernel",
+  template:    "kernel%d",
   priority:    80,
   preconfig:   krt_preconfig,
   postconfig:  krt_postconfig,