]>
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
;
31 config_alloc(byte
*name
)
33 pool
*p
= rp_new(&root_pool
, "Config");
34 linpool
*l
= lp_new(p
, 4080);
35 struct config
*c
= lp_allocz(l
, sizeof(struct config
));
39 c
->file_name
= cfg_strdup(name
);
44 config_parse(struct config
*c
)
46 DBG("Parsing configuration file `%s'\n", c
->file_name
);
49 if (setjmp(conf_jmpbuf
))
56 filters_postconfig(); /* FIXME: Do we really need this? */
60 cf_error("Router ID must be configured manually on IPv6 routers");
66 cli_parse(struct config
*c
)
69 c
->sym_fallback
= config
->sym_hash
;
71 if (setjmp(conf_jmpbuf
))
79 config_free(struct config
*c
)
85 config_add_obstacle(struct config
*c
)
87 DBG("+++ adding obstacle %d\n", c
->obstacle_count
);
92 config_del_obstacle(struct config
*c
)
94 DBG("+++ deleting obstacle %d\n", c
->obstacle_count
);
96 if (!c
->obstacle_count
)
99 ev_schedule(config_event
);
104 global_commit(struct config
*new, struct config
*old
)
109 new->router_id
= old
->router_id
;
110 if (new->router_id
!= old
->router_id
)
116 config_do_commit(struct config
*c
)
118 int force_restart
, nobs
;
122 config
= new_config
= c
;
124 old_config
->obstacle_count
++;
125 DBG("sysdep_commit\n");
126 force_restart
= sysdep_commit(c
, old_config
);
127 DBG("global_commit\n");
128 force_restart
|= global_commit(c
, old_config
);
130 rt_commit(c
, old_config
);
131 DBG("protos_commit\n");
132 protos_commit(c
, old_config
, force_restart
);
133 new_config
= NULL
; /* Just to be sure nobody uses that now */
135 nobs
= --old_config
->obstacle_count
;
138 DBG("do_commit finished with %d obstacles remaining\n", nobs
);
143 config_done(void *unused
)
147 DBG("config_done\n");
150 if (config
->shutdown
)
151 sysdep_shutdown_done();
152 log(L_INFO
"Reconfigured");
155 config_free(old_config
);
161 future_config
= NULL
;
162 log(L_INFO
"Switching to queued configuration...");
163 if (!config_do_commit(c
))
170 config_commit(struct config
*c
)
172 if (!config
) /* First-time configuration */
177 if (old_config
) /* Reconfiguration already in progress */
181 log(L_INFO
"New configuration discarded due to shutdown");
183 return CONF_SHUTDOWN
;
187 log(L_INFO
"Queueing new configuration, ignoring the one already queued");
188 config_free(future_config
);
191 log(L_INFO
"Queued new configuration");
195 if (config_do_commit(c
))
202 config_event
= ev_new(&root_pool
);
203 config_event
->hook
= config_done
;
205 return CONF_PROGRESS
;
215 log(L_INFO
"Shutting down");
216 c
= lp_alloc(config
->mem
, sizeof(struct config
));
217 memcpy(c
, config
, sizeof(struct config
));
218 init_list(&c
->protos
);
219 init_list(&c
->tables
);
226 cf_error(char *msg
, ...)
232 if (bvsnprintf(buf
, sizeof(buf
), msg
, args
) < 0)
233 strcpy(buf
, "<bug: error message too long>");
234 new_config
->err_msg
= cfg_strdup(buf
);
235 new_config
->err_lino
= conf_lino
;
236 longjmp(conf_jmpbuf
, 1);
242 int l
= strlen(c
) + 1;
243 char *z
= cfg_allocu(l
);