]> git.ipfire.org Git - thirdparty/bird.git/blob - conf/conf.c
Moved initialization of protocol list to proto.c.
[thirdparty/bird.git] / conf / conf.c
1 /*
2 * BIRD Internet Routing Daemon -- Configuration File Handling
3 *
4 * (c) 1999 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #include <setjmp.h>
10 #include <stdarg.h>
11
12 #include "nest/bird.h"
13 #include "nest/route.h"
14 #include "nest/protocol.h"
15 #include "nest/iface.h"
16 #include "lib/resource.h"
17 #include "lib/string.h"
18 #include "conf/conf.h"
19 #include "filter/filter.h"
20
21 static jmp_buf conf_jmpbuf;
22
23 struct config *config, *new_config;
24
25 struct config *
26 config_alloc(byte *name)
27 {
28 pool *p = rp_new(&root_pool, "Config");
29 linpool *l = lp_new(p, 4080);
30 struct config *c = lp_allocz(l, sizeof(struct config));
31
32 c->pool = p;
33 cfg_mem = c->mem = l;
34 c->file_name = cfg_strdup(name);
35 return c;
36 }
37
38 int
39 config_parse(struct config *c)
40 {
41 debug("Parsing configuration file `%s'\n", c->file_name);
42 new_config = c;
43 cfg_mem = c->mem;
44 if (setjmp(conf_jmpbuf))
45 return 0;
46 cf_lex_init(0);
47 sysdep_preconfig(c);
48 protos_preconfig(c);
49 rt_preconfig(c);
50 cf_parse();
51 filters_postconfig(); /* FIXME: Do we really need this? */
52 protos_postconfig(c);
53 #ifdef IPV6
54 if (!c->router_id)
55 cf_error("Router ID must be configured manually on IPv6 routers");
56 #endif
57 return 1;
58 }
59
60 int
61 cli_parse(struct config *c)
62 {
63 new_config = c;
64 c->sym_fallback = config->sym_hash;
65 cfg_mem = c->mem;
66 if (setjmp(conf_jmpbuf))
67 return 0;
68 cf_lex_init(1);
69 cf_parse();
70 return 1;
71 }
72
73 void
74 config_free(struct config *c)
75 {
76 rfree(c->pool);
77 }
78
79 void
80 config_commit(struct config *c)
81 {
82 config = c;
83 sysdep_commit(c);
84 rt_commit(c);
85 protos_commit(c);
86 }
87
88 void
89 cf_error(char *msg, ...)
90 {
91 char buf[1024];
92 va_list args;
93
94 va_start(args, msg);
95 if (bvsnprintf(buf, sizeof(buf), msg, args) < 0)
96 strcpy(buf, "<bug: error message too long>");
97 new_config->err_msg = cfg_strdup(buf);
98 new_config->err_lino = conf_lino;
99 longjmp(conf_jmpbuf, 1);
100 }
101
102 char *
103 cfg_strdup(char *c)
104 {
105 int l = strlen(c) + 1;
106 char *z = cfg_allocu(l);
107 memcpy(z, c, l);
108 return z;
109 }