]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Conf: Free stored old config before parsing new one
authorOndrej Zajicek <santiago@crfreenet.org>
Wed, 9 Nov 2022 20:09:16 +0000 (21:09 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Wed, 9 Nov 2022 20:54:45 +0000 (21:54 +0100)
BIRD keeps a previous (old) configuration for the purpose of undo. The
existing code frees it after a new configuration is successfully parsed
during reconfiguration. That causes memory usage spikes as there are
temporarily three configurations (old, current, and new). The patch
changes it to free the old one before parsing the new one (as user
already requested a new config). The disadvantage is that undo is
not available after failed reconfiguration.

conf/conf.c
conf/conf.h
doc/bird.sgml
sysdep/unix/main.c

index 11c136e77e809b31ca303cb9576b9a686a2f5ae8..4e31de293af7c80f3110f9f4128fd83c5e9e8f72 100644 (file)
@@ -201,6 +201,23 @@ config_free(struct config *c)
     rfree(c->pool);
 }
 
+/**
+ * config_free_old - free stored old configuration
+ *
+ * This function frees the old configuration (%old_config) that is saved for the
+ * purpose of undo. It is useful before parsing a new config when reconfig is
+ * requested, to avoid keeping three (perhaps memory-heavy) configs together.
+ */
+void
+config_free_old(void)
+{
+  tm_stop(config_timer);
+  undo_available = 0;
+
+  config_free(old_config);
+  old_config = NULL;
+}
+
 void
 config_add_obstacle(struct config *c)
 {
index 5ec924b02f942b6a66645cb156e9530a377b4020..b409750e7bcff3d19421af9841f9ce2423c573e2 100644 (file)
@@ -70,6 +70,7 @@ struct config *config_alloc(const char *name);
 int config_parse(struct config *);
 int cli_parse(struct config *);
 void config_free(struct config *);
+void config_free_old(void);
 int config_commit(struct config *, int type, uint timeout);
 int config_confirm(void);
 int config_undo(void);
index c78b83007b9faa5c6b74f6cf06c2c48dd7a84882..47848f826df58d569b39ba542fd3a374ded9d719 100644 (file)
@@ -1173,6 +1173,11 @@ This argument can be omitted if there exists only a single instance.
        restarted otherwise. Changes in filters usually lead to restart of
        affected protocols.
 
+       The previous configuration is saved and the user can switch back to it
+       with <ref id="cli-configure-undo" name="configure undo"> command. The
+       old saved configuration is released (even if the reconfiguration attempt
+       fails due to e.g. a syntax error).
+
        If <cf/soft/ option is used, changes in filters does not cause BIRD to
        restart affected protocols, therefore already accepted routes (according
        to old filters) would be still propagated, but new routes would be
index 84e7d889cba1998fff98d5662b9c5f7e79a2730d..18cc091ff3f1bbcd1cc3e182dcf27e65970c43cd 100644 (file)
@@ -242,6 +242,8 @@ async_config(void)
 {
   struct config *conf;
 
+  config_free_old();
+
   log(L_INFO "Reconfiguration requested by SIGHUP");
   if (!unix_read_config(&conf, config_name))
     {
@@ -324,6 +326,8 @@ cmd_reconfig(const char *name, int type, uint timeout)
   if (cli_access_restricted())
     return;
 
+  config_free_old();
+
   struct config *conf = cmd_read_config(name);
   if (!conf)
     return;