]>
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 "lib/timer.h"
22 #include "conf/conf.h"
23 #include "filter/filter.h"
25 static jmp_buf conf_jmpbuf
;
27 struct config
*config
, *new_config
, *old_config
, *future_config
;
28 static event
*config_event
;
30 bird_clock_t boot_time
;
33 config_alloc(byte
*name
)
35 pool
*p
= rp_new(&root_pool
, "Config");
36 linpool
*l
= lp_new(p
, 4080);
37 struct config
*c
= lp_allocz(l
, sizeof(struct config
));
41 c
->file_name
= cfg_strdup(name
);
49 config_parse(struct config
*c
)
51 DBG("Parsing configuration file `%s'\n", c
->file_name
);
54 if (setjmp(conf_jmpbuf
))
61 filters_postconfig(); /* FIXME: Do we really need this? */
65 cf_error("Router ID must be configured manually on IPv6 routers");
71 cli_parse(struct config
*c
)
74 c
->sym_fallback
= config
->sym_hash
;
76 if (setjmp(conf_jmpbuf
))
84 config_free(struct config
*c
)
90 config_add_obstacle(struct config
*c
)
92 DBG("+++ adding obstacle %d\n", c
->obstacle_count
);
97 config_del_obstacle(struct config
*c
)
99 DBG("+++ deleting obstacle %d\n", c
->obstacle_count
);
101 if (!c
->obstacle_count
)
103 ASSERT(config_event
);
104 ev_schedule(config_event
);
109 global_commit(struct config
*new, struct config
*old
)
114 new->router_id
= old
->router_id
;
115 if (new->router_id
!= old
->router_id
)
121 config_do_commit(struct config
*c
)
123 int force_restart
, nobs
;
127 config
= new_config
= c
;
129 old_config
->obstacle_count
++;
130 DBG("sysdep_commit\n");
131 force_restart
= sysdep_commit(c
, old_config
);
132 DBG("global_commit\n");
133 force_restart
|= global_commit(c
, old_config
);
135 rt_commit(c
, old_config
);
136 DBG("protos_commit\n");
137 protos_commit(c
, old_config
, force_restart
);
138 new_config
= NULL
; /* Just to be sure nobody uses that now */
140 nobs
= --old_config
->obstacle_count
;
143 DBG("do_commit finished with %d obstacles remaining\n", nobs
);
148 config_done(void *unused
)
152 DBG("config_done\n");
155 if (config
->shutdown
)
156 sysdep_shutdown_done();
157 log(L_INFO
"Reconfigured");
160 config_free(old_config
);
166 future_config
= NULL
;
167 log(L_INFO
"Switching to queued configuration...");
168 if (!config_do_commit(c
))
174 config_commit(struct config
*c
)
176 if (!config
) /* First-time configuration */
181 if (old_config
) /* Reconfiguration already in progress */
185 log(L_INFO
"New configuration discarded due to shutdown");
187 return CONF_SHUTDOWN
;
191 log(L_INFO
"Queueing new configuration, ignoring the one already queued");
192 config_free(future_config
);
195 log(L_INFO
"Queued new configuration");
199 if (config_do_commit(c
))
206 config_event
= ev_new(&root_pool
);
207 config_event
->hook
= config_done
;
209 return CONF_PROGRESS
;
219 log(L_INFO
"Shutting down");
220 c
= lp_alloc(config
->mem
, sizeof(struct config
));
221 memcpy(c
, config
, sizeof(struct config
));
222 init_list(&c
->protos
);
223 init_list(&c
->tables
);
230 cf_error(char *msg
, ...)
236 if (bvsnprintf(buf
, sizeof(buf
), msg
, args
) < 0)
237 strcpy(buf
, "<bug: error message too long>");
238 new_config
->err_msg
= cfg_strdup(buf
);
239 new_config
->err_lino
= conf_lino
;
240 longjmp(conf_jmpbuf
, 1);
246 int l
= strlen(c
) + 1;
247 char *z
= cfg_allocu(l
);