From a953535b1820ec6f738652c30ad0b9e4a74faf60 Mon Sep 17 00:00:00 2001
From: Alexander Zubkov <green@qrator.net>
Date: Mon, 3 Jan 2022 12:16:09 +0100
Subject: [PATCH 2/3] Conf: add RECONFIG_KEEP flag to keep runtime states
 during reconfig


diff --git a/conf/conf.h b/conf/conf.h
index 61009b73..9f5010c1 100644
--- a/conf/conf.h
+++ b/conf/conf.h
@@ -83,8 +83,9 @@ void order_shutdown(int gr);
 
 #define RECONFIG_NONE	0
 #define RECONFIG_DO	1
-#define RECONFIG_SOFT	2
+#define RECONFIG_SOFT	2	/* do not restart protocols when filters changed */
 #define RECONFIG_UNDO	4
+#define RECONFIG_KEEP	8	/* keep runtime states of protocols etc. */
 /* RECONFIG flag combinations */
 #define RECONFIG_DO_HARD	RECONFIG_DO
 #define RECONFIG_DO_SOFT	(RECONFIG_DO|RECONFIG_SOFT)
diff --git a/nest/proto.c b/nest/proto.c
index e28035ce..2bac5698 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -1278,6 +1278,13 @@ protos_commit(struct config *new, struct config *old, int force_reconfig, int ty
 	nc = sym->proto;
 	nc->proto = p;
 
+	/* Keep protocol state if RECONFIG_KEEP flag is set */
+	if (type & RECONFIG_KEEP && (p->disabled != nc->disabled))
+	{
+	  log(L_INFO "Keeping state of protocol %s", p->name);
+	  nc->disabled = p->disabled;
+	}
+
 	/* We will try to reconfigure protocol p */
 	if (! force_reconfig && proto_reconfigure(p, oc, nc, type))
 	  continue;
-- 
2.34.0

