Adds support for soft reconfiguration.

This commit is contained in:
Ondrej Zajicek 2009-06-19 23:49:34 +02:00
parent 789772ed45
commit bf1aec970e
7 changed files with 36 additions and 25 deletions

View file

@ -189,7 +189,7 @@ global_commit(struct config *new, struct config *old)
} }
static int static int
config_do_commit(struct config *c) config_do_commit(struct config *c, int type)
{ {
int force_restart, nobs; int force_restart, nobs;
@ -205,7 +205,7 @@ config_do_commit(struct config *c)
DBG("rt_commit\n"); DBG("rt_commit\n");
rt_commit(c, old_config); rt_commit(c, old_config);
DBG("protos_commit\n"); DBG("protos_commit\n");
protos_commit(c, old_config, force_restart); protos_commit(c, old_config, force_restart, type);
new_config = NULL; /* Just to be sure nobody uses that now */ new_config = NULL; /* Just to be sure nobody uses that now */
if (old_config) if (old_config)
nobs = --old_config->obstacle_count; nobs = --old_config->obstacle_count;
@ -236,7 +236,7 @@ config_done(void *unused UNUSED)
c = future_config; c = future_config;
future_config = NULL; future_config = NULL;
log(L_INFO "Switching to queued configuration..."); log(L_INFO "Switching to queued configuration...");
if (!config_do_commit(c)) if (!config_do_commit(c, RECONFIG_HARD))
break; break;
} }
} }
@ -244,6 +244,7 @@ config_done(void *unused UNUSED)
/** /**
* config_commit - commit a configuration * config_commit - commit a configuration
* @c: new configuration * @c: new configuration
* @type: type of reconfiguration (RECONFIG_SOFT or RECONFIG_HARD)
* *
* When a configuration is parsed and prepared for use, the * When a configuration is parsed and prepared for use, the
* config_commit() function starts the process of reconfiguration. * config_commit() function starts the process of reconfiguration.
@ -263,11 +264,11 @@ config_done(void *unused UNUSED)
* are accepted. * are accepted.
*/ */
int int
config_commit(struct config *c) config_commit(struct config *c, int type)
{ {
if (!config) /* First-time configuration */ if (!config) /* First-time configuration */
{ {
config_do_commit(c); config_do_commit(c, RECONFIG_HARD);
return CONF_DONE; return CONF_DONE;
} }
if (old_config) /* Reconfiguration already in progress */ if (old_config) /* Reconfiguration already in progress */
@ -288,7 +289,7 @@ config_commit(struct config *c)
future_config = c; future_config = c;
return CONF_QUEUED; return CONF_QUEUED;
} }
if (config_do_commit(c)) if (config_do_commit(c, type))
{ {
config_done(NULL); config_done(NULL);
return CONF_DONE; return CONF_DONE;
@ -321,7 +322,7 @@ order_shutdown(void)
init_list(&c->tables); init_list(&c->tables);
c->shutdown = 1; c->shutdown = 1;
shutting_down = 1; shutting_down = 1;
config_commit(c); config_commit(c, RECONFIG_HARD);
shutting_down = 2; shutting_down = 2;
} }

View file

@ -50,7 +50,9 @@ struct config *config_alloc(byte *name);
int config_parse(struct config *); int config_parse(struct config *);
int cli_parse(struct config *); int cli_parse(struct config *);
void config_free(struct config *); void config_free(struct config *);
int config_commit(struct config *); int config_commit(struct config *, int type);
#define RECONFIG_HARD 0
#define RECONFIG_SOFT 1
void cf_error(char *msg, ...) NORET; void cf_error(char *msg, ...) NORET;
void config_add_obstacle(struct config *); void config_add_obstacle(struct config *);
void config_del_obstacle(struct config *); void config_del_obstacle(struct config *);

View file

@ -269,6 +269,7 @@ proto_init(struct proto_config *c)
* @old: old configuration or %NULL if it's boot time config * @old: old configuration or %NULL if it's boot time config
* @force_reconfig: force restart of all protocols (used for example * @force_reconfig: force restart of all protocols (used for example
* when the router ID changes) * when the router ID changes)
* @type: type of reconfiguration (RECONFIG_SOFT or RECONFIG_HARD)
* *
* Scan differences between @old and @new configuration and adjust all * Scan differences between @old and @new configuration and adjust all
* protocol instances to conform to the new configuration. * protocol instances to conform to the new configuration.
@ -281,15 +282,17 @@ proto_init(struct proto_config *c)
* When a protocol exists in the old configuration, but it doesn't in the * When a protocol exists in the old configuration, but it doesn't in the
* new one, it's shut down and deleted after the shutdown completes. * new one, it's shut down and deleted after the shutdown completes.
* *
* When a protocol exists in both configurations, the core decides whether * When a protocol exists in both configurations, the core decides
* it's possible to reconfigure it dynamically (it checks all the core properties * whether it's possible to reconfigure it dynamically - it checks all
* of the protocol and if they match, it asks the reconfigure() hook of the * the core properties of the protocol (changes in filters are ignored
* protocol to see if the protocol is able to switch to the new configuration). * if type is RECONFIG_SOFT) and if they match, it asks the
* If it isn't possible, the protocol is shut down and a new instance is started * reconfigure() hook of the protocol to see if the protocol is able
* with the new configuration after the shutdown is completed. * to switch to the new configuration. If it isn't possible, the
* protocol is shut down and a new instance is started with the new
* configuration after the shutdown is completed.
*/ */
void void
protos_commit(struct config *new, struct config *old, int force_reconfig) protos_commit(struct config *new, struct config *old, int force_reconfig, int type)
{ {
struct proto_config *oc, *nc; struct proto_config *oc, *nc;
struct proto *p, *n; struct proto *p, *n;
@ -310,8 +313,8 @@ protos_commit(struct config *new, struct config *old, int force_reconfig)
&& nc->preference == oc->preference && nc->preference == oc->preference
&& nc->disabled == oc->disabled && nc->disabled == oc->disabled
&& nc->table->table == oc->table->table && nc->table->table == oc->table->table
&& filter_same(nc->in_filter, oc->in_filter) && ((type == RECONFIG_SOFT) || filter_same(nc->in_filter, oc->in_filter))
&& filter_same(nc->out_filter, oc->out_filter) && ((type == RECONFIG_SOFT) || filter_same(nc->out_filter, oc->out_filter))
&& p->proto_state != PS_DOWN) && p->proto_state != PS_DOWN)
{ {
/* Generic attributes match, try converting them and then ask the protocol */ /* Generic attributes match, try converting them and then ask the protocol */

View file

@ -55,7 +55,7 @@ void protos_build(void);
void proto_build(struct protocol *); void proto_build(struct protocol *);
void protos_preconfig(struct config *); void protos_preconfig(struct config *);
void protos_postconfig(struct config *); void protos_postconfig(struct config *);
void protos_commit(struct config *new, struct config *old, int force_restart); void protos_commit(struct config *new, struct config *old, int force_restart, int type);
void protos_dump_all(void); void protos_dump_all(void);
#define GA_UNKNOWN 0 /* Attribute not recognized */ #define GA_UNKNOWN 0 /* Attribute not recognized */

View file

@ -13,7 +13,7 @@ CF_HDR
CF_DECLS CF_DECLS
CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR) CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR, SOFT)
%type <i> log_mask log_mask_list log_cat %type <i> log_mask log_mask_list log_cat
%type <g> log_file %type <g> log_file
@ -65,8 +65,13 @@ log_cat:
/* Unix specific commands */ /* Unix specific commands */
CF_CLI_HELP(CONFIGURE, [soft] [\"<file>\"], [[Reload configuration]])
CF_CLI(CONFIGURE, cfg_name, [\"<file>\"], [[Reload configuration]]) CF_CLI(CONFIGURE, cfg_name, [\"<file>\"], [[Reload configuration]])
{ cmd_reconfig($2); } ; { cmd_reconfig($2, RECONFIG_HARD); } ;
CF_CLI(CONFIGURE SOFT, cfg_name, [\"<file>\"], [[Reload configuration and ignore changes in filters]])
{ cmd_reconfig($3, RECONFIG_SOFT); } ;
CF_CLI(DOWN,,, [[Shut the daemon down]]) CF_CLI(DOWN,,, [[Shut the daemon down]])
{ cli_msg(7, "Shutdown requested"); order_shutdown(); } ; { cli_msg(7, "Shutdown requested"); order_shutdown(); } ;

View file

@ -115,7 +115,7 @@ read_config(void)
else else
die("Unable to open configuration file %s: %m", config_name); die("Unable to open configuration file %s: %m", config_name);
} }
config_commit(conf); config_commit(conf, RECONFIG_HARD);
} }
void void
@ -133,11 +133,11 @@ async_config(void)
config_free(conf); config_free(conf);
} }
else else
config_commit(conf); config_commit(conf, RECONFIG_HARD);
} }
void void
cmd_reconfig(char *name) cmd_reconfig(char *name, int type)
{ {
struct config *conf; struct config *conf;
@ -154,7 +154,7 @@ cmd_reconfig(char *name)
} }
else else
{ {
switch (config_commit(conf)) switch (config_commit(conf, type))
{ {
case CONF_DONE: case CONF_DONE:
cli_msg(3, "Reconfigured."); cli_msg(3, "Reconfigured.");

View file

@ -16,7 +16,7 @@ struct pool;
void async_config(void); void async_config(void);
void async_dump(void); void async_dump(void);
void async_shutdown(void); void async_shutdown(void);
void cmd_reconfig(char *name); void cmd_reconfig(char *name, int type);
/* io.c */ /* io.c */