MEDIUM: proxy: only take defaults when a default proxy is passed.
The proxy initialization code relies on three phases, allocation,
pre-initialization, and assignments from defaults. This last part is
entirely taken from the defaults proxy when arguments are set. This
sensibly complexifies the initialization code as it requires to always
have a default proxy.
This patch instead first applies the original default settings on a
proxy, and then uses those from a default proxy only if one such is
used. This will allow to initialize a proxy out of any default proxy
while still using valid defaults. A careful inspection of the function
showed that only 4 fields used to be set regardless of the default
proxy, and those were moved to init_new_proxy() where they ought to
have been in the first place.
diff --git a/src/proxy.c b/src/proxy.c
index 394ba14..6a1c9df 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1037,6 +1037,11 @@
LIST_INIT(&p->filter_configs);
LIST_INIT(&p->tcpcheck_rules.preset_vars);
+ p->defsrv.id = "default-server";
+ p->conf.used_listener_id = EB_ROOT;
+ p->conf.used_server_id = EB_ROOT;
+ p->used_server_addr = EB_ROOT_UNIQUE;
+
/* Timeouts are defined as -1 */
proxy_reset_timeouts(p);
p->tcp_rep.inspect_delay = TICK_ETERNITY;
@@ -1097,7 +1102,8 @@
/* Allocates a new proxy <name> of type <cap> found at position <file:linenum>,
* preset it from the defaults of <defproxy> and returns it. Un case of error,
* an alert is printed and NULL is returned. If <errmsg> is not NULL, an error
- * message will be returned there in case of fatal error.
+ * message will be returned there in case of fatal error. If <defproxy> is NULL,
+ * the documented default settings will be used instead.
*/
struct proxy *alloc_new_proxy(const char *name, unsigned int cap, const char *file, int linenum, const struct proxy *defproxy, char **errmsg)
{
@@ -1118,9 +1124,13 @@
curproxy->cap = cap;
proxy_store_name(curproxy);
+ if (!defproxy) {
+ proxy_preset_defaults(curproxy);
+ goto done;
+ }
+
- /* set default values */
+ /* set default values from the specified default proxy */
memcpy(&curproxy->defsrv, &defproxy->defsrv, sizeof(curproxy->defsrv));
- curproxy->defsrv.id = "default-server";
curproxy->disabled = defproxy->disabled;
curproxy->options = defproxy->options;
@@ -1334,9 +1344,6 @@
}
curproxy->grace = defproxy->grace;
- curproxy->conf.used_listener_id = EB_ROOT;
- curproxy->conf.used_server_id = EB_ROOT;
- curproxy->used_server_addr = EB_ROOT_UNIQUE;
if (defproxy->check_path)
curproxy->check_path = strdup(defproxy->check_path);
@@ -1353,6 +1360,8 @@
curproxy->email_alert.myhostname = strdup(defproxy->email_alert.myhostname);
curproxy->email_alert.level = defproxy->email_alert.level;
curproxy->email_alert.set = defproxy->email_alert.set;
+
+ done:
return curproxy;
fail:
/* Note: in case of fatal error here, we WILL make valgrind unhappy,