]>
Commit | Line | Data |
---|---|---|
31b3e1bb MM |
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" | |
0e02abfd | 13 | #include "nest/route.h" |
31b3e1bb MM |
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"); | |
d4ff7482 | 29 | linpool *l = lp_new(p, 4080); |
31b3e1bb MM |
30 | struct config *c = lp_allocz(l, sizeof(struct config)); |
31 | ||
32 | c->pool = p; | |
33 | cfg_mem = c->mem = l; | |
34 | init_list(&c->protos); | |
35 | c->file_name = cfg_strdup(name); | |
36 | return c; | |
37 | } | |
38 | ||
39 | int | |
40 | config_parse(struct config *c) | |
41 | { | |
3d8ef0c9 | 42 | debug("Parsing configuration file `%s'\n", c->file_name); |
31b3e1bb | 43 | new_config = c; |
31b3e1bb MM |
44 | cfg_mem = c->mem; |
45 | if (setjmp(conf_jmpbuf)) | |
46 | return 0; | |
bc2fb680 | 47 | cf_lex_init(0); |
31b3e1bb | 48 | protos_preconfig(c); |
0e02abfd | 49 | rt_preconfig(c); |
31b3e1bb | 50 | cf_parse(); |
31b3e1bb MM |
51 | filters_postconfig(); /* FIXME: Do we really need this? */ |
52 | protos_postconfig(c); | |
dce26783 MM |
53 | #ifdef IPV6 |
54 | if (!c->router_id) | |
55 | cf_error("Router ID must be configured manually on IPv6 routers"); | |
56 | #endif | |
31b3e1bb MM |
57 | return 1; |
58 | } | |
59 | ||
bc2fb680 MM |
60 | int |
61 | cli_parse(struct config *c) | |
62 | { | |
63 | new_config = c; | |
c9aae7f4 | 64 | c->sym_fallback = config->sym_hash; |
bc2fb680 MM |
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 | ||
31b3e1bb MM |
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; | |
0e02abfd | 83 | rt_commit(c); |
31b3e1bb MM |
84 | protos_commit(c); |
85 | } | |
86 | ||
87 | void | |
88 | cf_error(char *msg, ...) | |
89 | { | |
90 | char buf[1024]; | |
91 | va_list args; | |
92 | ||
93 | va_start(args, msg); | |
94 | if (bvsnprintf(buf, sizeof(buf), msg, args) < 0) | |
95 | strcpy(buf, "<bug: error message too long>"); | |
96 | new_config->err_msg = cfg_strdup(buf); | |
97 | new_config->err_lino = conf_lino; | |
98 | longjmp(conf_jmpbuf, 1); | |
99 | } | |
100 | ||
101 | char * | |
102 | cfg_strdup(char *c) | |
103 | { | |
104 | int l = strlen(c) + 1; | |
105 | char *z = cfg_allocu(l); | |
106 | memcpy(z, c, l); | |
107 | return z; | |
108 | } |