1999-02-06 05:37:34 +08:00
|
|
|
/*
|
|
|
|
* 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"
|
1999-05-18 04:14:52 +08:00
|
|
|
#include "nest/route.h"
|
1999-02-06 05:37:34 +08:00
|
|
|
#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");
|
1999-04-06 04:06:02 +08:00
|
|
|
linpool *l = lp_new(p, 4080);
|
1999-02-06 05:37:34 +08:00
|
|
|
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)
|
|
|
|
{
|
1999-03-02 21:15:35 +08:00
|
|
|
debug("Parsing configuration file `%s'\n", c->file_name);
|
1999-02-06 05:37:34 +08:00
|
|
|
new_config = c;
|
|
|
|
cfg_mem = c->mem;
|
|
|
|
if (setjmp(conf_jmpbuf))
|
|
|
|
return 0;
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-11-01 01:47:47 +08:00
|
|
|
cf_lex_init(0);
|
1999-02-06 05:37:34 +08:00
|
|
|
protos_preconfig(c);
|
1999-05-18 04:14:52 +08:00
|
|
|
rt_preconfig(c);
|
1999-02-06 05:37:34 +08:00
|
|
|
cf_parse();
|
|
|
|
filters_postconfig(); /* FIXME: Do we really need this? */
|
|
|
|
protos_postconfig(c);
|
1999-08-04 03:36:06 +08:00
|
|
|
#ifdef IPV6
|
|
|
|
if (!c->router_id)
|
|
|
|
cf_error("Router ID must be configured manually on IPv6 routers");
|
|
|
|
#endif
|
1999-02-06 05:37:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-11-01 01:47:47 +08:00
|
|
|
int
|
|
|
|
cli_parse(struct config *c)
|
|
|
|
{
|
|
|
|
new_config = c;
|
1999-11-30 22:03:36 +08:00
|
|
|
c->sym_fallback = config->sym_hash;
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-11-01 01:47:47 +08:00
|
|
|
cfg_mem = c->mem;
|
|
|
|
if (setjmp(conf_jmpbuf))
|
|
|
|
return 0;
|
|
|
|
cf_lex_init(1);
|
|
|
|
cf_parse();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-02-06 05:37:34 +08:00
|
|
|
void
|
|
|
|
config_free(struct config *c)
|
|
|
|
{
|
|
|
|
rfree(c->pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
config_commit(struct config *c)
|
|
|
|
{
|
|
|
|
config = c;
|
1999-05-18 04:14:52 +08:00
|
|
|
rt_commit(c);
|
1999-02-06 05:37:34 +08:00
|
|
|
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;
|
|
|
|
}
|