summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2022-11-09 21:09:16 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2022-11-09 21:54:45 +0100
commit371eb49043d225d2bab8149187b813a14b4b86d2 (patch)
tree4b25595f3d68b2d0a64cbfbf2ab2987e9b8b163e
parent84545a26cc3f7ce68408a663c1ad4a50edccdacc (diff)
Conf: Free stored old config before parsing new one
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.
-rw-r--r--conf/conf.c17
-rw-r--r--conf/conf.h1
-rw-r--r--doc/bird.sgml5
-rw-r--r--sysdep/unix/main.c4
4 files changed, 27 insertions, 0 deletions
diff --git a/conf/conf.c b/conf/conf.c
index 11c136e7..4e31de29 100644
--- a/conf/conf.c
+++ b/conf/conf.c
@@ -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)
{
diff --git a/conf/conf.h b/conf/conf.h
index 5ec924b0..b409750e 100644
--- a/conf/conf.h
+++ b/conf/conf.h
@@ -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);
diff --git a/doc/bird.sgml b/doc/bird.sgml
index c78b8300..47848f82 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -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
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 84e7d889..18cc091f 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -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;