]>
Commit | Line | Data |
---|---|---|
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 | 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 | { | |
42 | debug("Parsing configuration file `%s'\n", c->file_name); | |
43 | new_config = c; | |
44 | cfg_mem = c->mem; | |
45 | if (setjmp(conf_jmpbuf)) | |
46 | return 0; | |
47 | cf_lex_init(0); | |
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 | rt_commit(c); | |
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 | } |