]>
git.ipfire.org Git - thirdparty/bird.git/blob - conf/conf.c
2 * BIRD Internet Routing Daemon -- Configuration File Handling
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
14 #include "nest/bird.h"
15 #include "nest/route.h"
16 #include "nest/protocol.h"
17 #include "nest/iface.h"
18 #include "lib/resource.h"
19 #include "lib/string.h"
20 #include "lib/event.h"
21 #include "conf/conf.h"
22 #include "filter/filter.h"
24 static jmp_buf conf_jmpbuf
;
26 struct config
*config
, *new_config
, *old_config
, *future_config
;
27 static event
*config_event
;
30 config_alloc(byte
*name
)
32 pool
*p
= rp_new(&root_pool
, "Config");
33 linpool
*l
= lp_new(p
, 4080);
34 struct config
*c
= lp_allocz(l
, sizeof(struct config
));
38 c
->file_name
= cfg_strdup(name
);
43 config_parse(struct config
*c
)
45 debug("Parsing configuration file `%s'\n", c
->file_name
);
48 if (setjmp(conf_jmpbuf
))
55 filters_postconfig(); /* FIXME: Do we really need this? */
59 cf_error("Router ID must be configured manually on IPv6 routers");
65 cli_parse(struct config
*c
)
68 c
->sym_fallback
= config
->sym_hash
;
70 if (setjmp(conf_jmpbuf
))
78 config_free(struct config
*c
)
84 config_add_obstacle(struct config
*c
)
86 DBG("+++ adding obstacle %d\n", c
->obstacle_count
);
91 config_del_obstacle(struct config
*c
)
93 DBG("+++ deleting obstacle %d\n", c
->obstacle_count
);
95 if (!c
->obstacle_count
)
98 ev_schedule(config_event
);
103 global_commit(struct config
*c
, struct config
*old
)
107 if (c
->router_id
!= old
->router_id
)
113 config_do_commit(struct config
*c
)
115 int force_restart
, nobs
;
121 old_config
->obstacle_count
++;
122 DBG("sysdep_commit\n");
123 force_restart
= sysdep_commit(c
, old_config
);
124 DBG("global_commit\n");
125 force_restart
|= global_commit(c
, old_config
);
127 rt_commit(c
, old_config
);
128 DBG("protos_commit\n");
129 protos_commit(c
, old_config
, force_restart
);
130 new_config
= NULL
; /* Just to be sure nobody uses that now */
132 nobs
= --old_config
->obstacle_count
;
135 DBG("do_commit finished with %d obstacles remaining\n", nobs
);
140 config_done(void *unused
)
144 DBG("config_done\n");
147 log(L_INFO
"Reconfigured");
150 config_free(old_config
);
156 future_config
= NULL
;
157 log(L_INFO
"Switching to queued configuration...");
158 if (!config_do_commit(c
))
165 config_commit(struct config
*c
)
167 if (!config
) /* First-time configuration */
172 if (old_config
) /* Reconfiguration already in progress */
176 log(L_INFO
"Queueing new configuration, ignoring the one already queued");
177 config_free(future_config
);
180 log(L_INFO
"Queued new configuration");
184 if (config_do_commit(c
))
191 config_event
= ev_new(&root_pool
);
192 config_event
->hook
= config_done
;
194 return CONF_PROGRESS
;
198 cf_error(char *msg
, ...)
204 if (bvsnprintf(buf
, sizeof(buf
), msg
, args
) < 0)
205 strcpy(buf
, "<bug: error message too long>");
206 new_config
->err_msg
= cfg_strdup(buf
);
207 new_config
->err_lino
= conf_lino
;
208 longjmp(conf_jmpbuf
, 1);
214 int l
= strlen(c
) + 1;
215 char *z
= cfg_allocu(l
);