]>
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
))
64 cf_error("Router ID must be configured manually on IPv6 routers");
70 cli_parse(struct config
*c
)
73 c
->sym_fallback
= config
->sym_hash
;
75 if (setjmp(conf_jmpbuf
))
83 config_free(struct config
*c
)
89 config_add_obstacle(struct config
*c
)
91 DBG("+++ adding obstacle %d\n", c
->obstacle_count
);
96 config_del_obstacle(struct config
*c
)
98 DBG("+++ deleting obstacle %d\n", c
->obstacle_count
);
100 if (!c
->obstacle_count
)
102 ASSERT(config_event
);
103 ev_schedule(config_event
);
108 global_commit(struct config
*new, struct config
*old
)
113 new->router_id
= old
->router_id
;
114 if (new->router_id
!= old
->router_id
)
120 config_do_commit(struct config
*c
)
122 int force_restart
, nobs
;
126 config
= new_config
= c
;
128 old_config
->obstacle_count
++;
129 DBG("sysdep_commit\n");
130 force_restart
= sysdep_commit(c
, old_config
);
131 DBG("global_commit\n");
132 force_restart
|= global_commit(c
, old_config
);
134 rt_commit(c
, old_config
);
135 DBG("protos_commit\n");
136 protos_commit(c
, old_config
, force_restart
);
137 new_config
= NULL
; /* Just to be sure nobody uses that now */
139 nobs
= --old_config
->obstacle_count
;
142 DBG("do_commit finished with %d obstacles remaining\n", nobs
);
147 config_done(void *unused
)
151 DBG("config_done\n");
154 if (config
->shutdown
)
155 sysdep_shutdown_done();
156 log(L_INFO
"Reconfigured");
159 config_free(old_config
);
165 future_config
= NULL
;
166 log(L_INFO
"Switching to queued configuration...");
167 if (!config_do_commit(c
))
173 config_commit(struct config
*c
)
175 if (!config
) /* First-time configuration */
180 if (old_config
) /* Reconfiguration already in progress */
184 log(L_INFO
"New configuration discarded due to shutdown");
186 return CONF_SHUTDOWN
;
190 log(L_INFO
"Queueing new configuration, ignoring the one already queued");
191 config_free(future_config
);
194 log(L_INFO
"Queued new configuration");
198 if (config_do_commit(c
))
205 config_event
= ev_new(&root_pool
);
206 config_event
->hook
= config_done
;
208 return CONF_PROGRESS
;
218 log(L_INFO
"Shutting down");
219 c
= lp_alloc(config
->mem
, sizeof(struct config
));
220 memcpy(c
, config
, sizeof(struct config
));
221 init_list(&c
->protos
);
222 init_list(&c
->tables
);
229 cf_error(char *msg
, ...)
235 if (bvsnprintf(buf
, sizeof(buf
), msg
, args
) < 0)
236 strcpy(buf
, "<bug: error message too long>");
237 new_config
->err_msg
= cfg_strdup(buf
);
238 new_config
->err_lino
= conf_lino
;
239 longjmp(conf_jmpbuf
, 1);
245 int l
= strlen(c
) + 1;
246 char *z
= cfg_allocu(l
);