diff options
author | Martin Mares <mj@ucw.cz> | 1999-02-05 21:37:34 +0000 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 1999-02-05 21:37:34 +0000 |
commit | 31b3e1bbf5bc823ec5cf6d88931132f00e6c52b9 (patch) | |
tree | b3c3da837ca2079a222dfc99ab479bd040ba21ad /conf | |
parent | c4c63eecc37a744c53c23da89b1ba09b9640cb6e (diff) |
Implemented new configuration/reconfiguration interface and defined protocol
state machines. Full explanation will follow soon.
Diffstat (limited to 'conf')
-rw-r--r-- | conf/Makefile | 2 | ||||
-rw-r--r-- | conf/cf-lex.l | 47 | ||||
-rw-r--r-- | conf/conf.c | 96 | ||||
-rw-r--r-- | conf/conf.h | 28 |
4 files changed, 130 insertions, 43 deletions
diff --git a/conf/Makefile b/conf/Makefile index 270d5567..fdcd4c38 100644 --- a/conf/Makefile +++ b/conf/Makefile @@ -1,4 +1,4 @@ -source=cf-parse.tab.c cf-lex.c +source=cf-parse.tab.c cf-lex.c conf.c root-rel=../ include ../Rules diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 81e3b6a2..791d4adc 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -1,7 +1,7 @@ /* * BIRD -- Configuration Lexer * - * (c) 1998 Martin Mares <mj@ucw.cz> + * (c) 1998--1999 Martin Mares <mj@ucw.cz> * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -15,7 +15,6 @@ #include <stdarg.h> #include "nest/bird.h" -#include "lib/string.h" #include "conf/conf.h" #include "conf/cf-parse.tab.h" @@ -34,9 +33,10 @@ static struct keyword { static struct keyword *kw_hash[KW_HASH_SIZE]; static struct symbol **sym_hash; static int allow_new_symbols; -static int cf_lino; static int default_counter; +int conf_lino; + static int cf_hash(byte *c); static struct symbol *cf_find_sym(byte *c, unsigned int h0); @@ -121,11 +121,11 @@ WHITE [ \t] {WHITE}+ \\\n { - cf_lino++; + conf_lino++; } \n { - cf_lino++; + conf_lino++; return ';'; } @@ -136,14 +136,14 @@ WHITE [ \t] . cf_error("Unknown character"); <COMMENT>\n { - cf_lino++; + conf_lino++; BEGIN(INITIAL); } <COMMENT>. <CCOMM>\*\/ BEGIN(INITIAL); -<CCOMM>\n cf_lino++; +<CCOMM>\n conf_lino++; <CCOMM>\/\* cf_error("Comment nesting not supported"); <CCOMM><<EOF>> cf_error("Unterminated comment"); <CCOMM>. @@ -206,7 +206,7 @@ cf_lex_init(int flag) { if (allow_new_symbols = flag) sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *)); - cf_lino = 1; + conf_lino = 1; default_counter = 1; } @@ -222,34 +222,3 @@ cf_lex_init_tables(void) kw_hash[h] = k; } } - -void -cf_error(char *msg, ...) -{ - /* FIXME */ - - char buf[1024]; - va_list args; - - va_start(args, msg); - bvsprintf(buf, msg, args); - die(PATH_CONFIG ", line %d: %s", cf_lino, buf); -} - -void -cf_allocate(void) -{ - if (cfg_pool) - rfree(cfg_pool); - cfg_pool = rp_new(&root_pool, "Config"); - cfg_mem = lp_new(cfg_pool, 1024); -} - -char * -cfg_strdup(char *c) -{ - int l = strlen(c) + 1; - char *z = cfg_allocu(l); - memcpy(z, c, l); - return z; -} diff --git a/conf/conf.c b/conf/conf.c new file mode 100644 index 00000000..06cd3d19 --- /dev/null +++ b/conf/conf.c @@ -0,0 +1,96 @@ +/* + * BIRD Internet Routing Daemon -- Configuration File Handling + * + * (c) 1999 Martin Mares <mj@ucw.cz> + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#include <setjmp.h> +#include <stdarg.h> + +#include "nest/bird.h" +#include "nest/protocol.h" +#include "nest/iface.h" +#include "lib/resource.h" +#include "lib/string.h" +#include "conf/conf.h" +#include "filter/filter.h" + +static jmp_buf conf_jmpbuf; + +struct config *config, *new_config; + +struct config * +config_alloc(byte *name) +{ + pool *p = rp_new(&root_pool, "Config"); + linpool *l = lp_new(p, 1024); + struct config *c = lp_allocz(l, sizeof(struct config)); + + c->pool = p; + cfg_mem = c->mem = l; + init_list(&c->protos); + c->file_name = cfg_strdup(name); + return c; +} + +int +config_parse(struct config *c) +{ + struct proto_config *p; + + debug("Parsing configuration file <%s>\n", c->file_name); + new_config = c; + cfg_pool = c->pool; + cfg_mem = c->mem; + if (setjmp(conf_jmpbuf)) + return 0; + cf_lex_init(1); + cf_lex_init_tables(); + protos_preconfig(c); + cf_parse(); +#if 0 /* FIXME: We don't have interface list yet :( */ + if (!c->router_id && !(c->router_id = auto_router_id())) + cf_error("Cannot determine router ID (no suitable network interface found), please configure it manually"); +#endif + filters_postconfig(); /* FIXME: Do we really need this? */ + protos_postconfig(c); + return 1; +} + +void +config_free(struct config *c) +{ + rfree(c->pool); +} + +void +config_commit(struct config *c) +{ + config = c; + protos_commit(c); +} + +void +cf_error(char *msg, ...) +{ + char buf[1024]; + va_list args; + + va_start(args, msg); + if (bvsnprintf(buf, sizeof(buf), msg, args) < 0) + strcpy(buf, "<bug: error message too long>"); + new_config->err_msg = cfg_strdup(buf); + new_config->err_lino = conf_lino; + longjmp(conf_jmpbuf, 1); +} + +char * +cfg_strdup(char *c) +{ + int l = strlen(c) + 1; + char *z = cfg_allocu(l); + memcpy(z, c, l); + return z; +} diff --git a/conf/conf.h b/conf/conf.h index 19ed34e9..54f5d5eb 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -1,7 +1,7 @@ /* * BIRD Internet Routing Daemon -- Configuration File Handling * - * (c) 1998 Martin Mares <mj@ucw.cz> + * (c) 1998--1999 Martin Mares <mj@ucw.cz> * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -11,6 +11,28 @@ #include "lib/resource.h" +/* Configuration structure */ + +struct config { + pool *pool; /* Pool the configuration is stored in */ + linpool *mem; /* Linear pool containing configuration data */ + list protos; /* Configured protocol instances (struct proto_config) */ + u32 router_id; /* Our Router ID */ + u16 this_as; /* Our Autonomous System Number */ + char *err_msg; /* Parser error message */ + int err_lino; /* Line containing error */ + char *file_name; /* Name of configuration file */ +}; + +extern struct config *config, *new_config; +/* Please don't use these variables in protocols. Use proto_config->global instead. */ + +struct config *config_alloc(byte *name); +int config_parse(struct config *); +void config_free(struct config *); +void config_commit(struct config *); +void cf_error(char *msg, ...) NORET; + /* Pools */ extern pool *cfg_pool; @@ -41,11 +63,11 @@ struct symbol { #define SYM_FUNCTION 5 #define SYM_FILTER 6 +extern int conf_lino; + void cf_lex_init_tables(void); int cf_lex(void); void cf_lex_init(int flag); -void cf_error(char *msg, ...) NORET; -void cf_allocate(void); struct symbol *cf_default_name(char *prefix); /* Parser */ |