REORG: move init_default_instance() to proxy.c and pass it the defproxy pointer
init_default_instance() was still left in cfgparse.c which is not the
best place to pre-initialize a proxy. Let's place it in proxy.c just
after init_new_proxy(), take this opportunity for renaming it to
proxy_preset_defaults() and taking out init_new_proxy() from it, and
let's pass it the pointer to the default proxy to be initialized instead
of implicitly assuming defproxy. We'll soon be able to exploit this.
Only two call places had to be updated.
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 80b845a..cdc3f5b 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -526,7 +526,8 @@
deinit_proxy_tcpcheck(&defproxy);
/* we cannot free uri_auth because it might already be used */
- init_default_instance();
+ init_new_proxy(&defproxy);
+ proxy_preset_defaults(&defproxy);
curproxy = &defproxy;
curproxy->conf.args.file = curproxy->conf.file = strdup(file);
curproxy->conf.args.line = curproxy->conf.line = linenum;
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 03405a4..9f76878 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -422,48 +422,6 @@
}
#endif
-void init_default_instance()
-{
- init_new_proxy(&defproxy);
- defproxy.mode = PR_MODE_TCP;
- defproxy.disabled = 0;
- defproxy.maxconn = cfg_maxpconn;
- defproxy.conn_retries = CONN_RETRIES;
- defproxy.redispatch_after = 0;
- defproxy.options = PR_O_REUSE_SAFE;
- defproxy.max_out_conns = MAX_SRV_LIST;
-
- defproxy.defsrv.check.inter = DEF_CHKINTR;
- defproxy.defsrv.check.fastinter = 0;
- defproxy.defsrv.check.downinter = 0;
- defproxy.defsrv.agent.inter = DEF_CHKINTR;
- defproxy.defsrv.agent.fastinter = 0;
- defproxy.defsrv.agent.downinter = 0;
- defproxy.defsrv.check.rise = DEF_RISETIME;
- defproxy.defsrv.check.fall = DEF_FALLTIME;
- defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
- defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
- defproxy.defsrv.check.port = 0;
- defproxy.defsrv.agent.port = 0;
- defproxy.defsrv.maxqueue = 0;
- defproxy.defsrv.minconn = 0;
- defproxy.defsrv.maxconn = 0;
- defproxy.defsrv.max_reuse = -1;
- defproxy.defsrv.max_idle_conns = -1;
- defproxy.defsrv.pool_purge_delay = 5000;
- defproxy.defsrv.slowstart = 0;
- defproxy.defsrv.onerror = DEF_HANA_ONERR;
- defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
- defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
-
- defproxy.email_alert.level = LOG_ALERT;
- defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
-#if defined(USE_QUIC)
- quic_transport_params_init(&defproxy.defsrv.quic_params, 0);
-#endif
-
-}
-
/* Allocate and initialize the frontend of a "peers" section found in
* file <file> at line <linenum> with <id> as ID.
* Return 0 if succeeded, -1 if not.
diff --git a/src/haproxy.c b/src/haproxy.c
index 4172666..1bac1c5 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1822,7 +1822,8 @@
global.maxsock = 10; /* reserve 10 fds ; will be incremented by socket eaters */
- init_default_instance();
+ init_new_proxy(&defproxy);
+ proxy_preset_defaults(&defproxy);
/* in wait mode, we don't try to read the configuration files */
if (!(global.mode & MODE_MWORKER_WAIT)) {
diff --git a/src/proxy.c b/src/proxy.c
index f06b5d5..009ebbc 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1051,6 +1051,47 @@
HA_RWLOCK_INIT(&p->lock);
}
+/* Preset default settings onto proxy <defproxy>. */
+void proxy_preset_defaults(struct proxy *defproxy)
+{
+ defproxy->mode = PR_MODE_TCP;
+ defproxy->disabled = 0;
+ defproxy->maxconn = cfg_maxpconn;
+ defproxy->conn_retries = CONN_RETRIES;
+ defproxy->redispatch_after = 0;
+ defproxy->options = PR_O_REUSE_SAFE;
+ defproxy->max_out_conns = MAX_SRV_LIST;
+
+ defproxy->defsrv.check.inter = DEF_CHKINTR;
+ defproxy->defsrv.check.fastinter = 0;
+ defproxy->defsrv.check.downinter = 0;
+ defproxy->defsrv.agent.inter = DEF_CHKINTR;
+ defproxy->defsrv.agent.fastinter = 0;
+ defproxy->defsrv.agent.downinter = 0;
+ defproxy->defsrv.check.rise = DEF_RISETIME;
+ defproxy->defsrv.check.fall = DEF_FALLTIME;
+ defproxy->defsrv.agent.rise = DEF_AGENT_RISETIME;
+ defproxy->defsrv.agent.fall = DEF_AGENT_FALLTIME;
+ defproxy->defsrv.check.port = 0;
+ defproxy->defsrv.agent.port = 0;
+ defproxy->defsrv.maxqueue = 0;
+ defproxy->defsrv.minconn = 0;
+ defproxy->defsrv.maxconn = 0;
+ defproxy->defsrv.max_reuse = -1;
+ defproxy->defsrv.max_idle_conns = -1;
+ defproxy->defsrv.pool_purge_delay = 5000;
+ defproxy->defsrv.slowstart = 0;
+ defproxy->defsrv.onerror = DEF_HANA_ONERR;
+ defproxy->defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
+ defproxy->defsrv.uweight = defproxy->defsrv.iweight = 1;
+
+ defproxy->email_alert.level = LOG_ALERT;
+ defproxy->load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
+#if defined(USE_QUIC)
+ quic_transport_params_init(&defproxy->defsrv.quic_params, 0);
+#endif
+}
+
/* to be called under the proxy lock after stopping some listeners. This will
* automatically update the p->disabled flag after stopping the last one, and
* will emit a log indicating the proxy's condition. The function is idempotent
diff --git a/src/server.c b/src/server.c
index e13c0df..a77579a 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1784,7 +1784,7 @@
#endif
/* please don't put default server settings here, they are set in
- * init_default_instance().
+ * proxy_preset_defaults().
*/
return srv;
}