From: Amaury Denoyelle Date: Wed, 29 Jul 2026 13:42:16 +0000 (+0200) Subject: MINOR: server: implement "from none" X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89af722c489f1d8c872cfa3bab9d35094a0a4e40;p=thirdparty%2Fhaproxy.git MINOR: server: implement "from none" Implement "from none" on a server line. This instructs to not preset server settings via another instance, instead relying on documented default values. This is useful to change the default behavior for static servers to prevent them from reusing a default-server instance. A secondary usage of this value is on a default-server. This reset the default-server to the documented default settings. This is implemented by extending _srv_parse_from() to parse "none" value. In this case, output return is set to NULL, which will cause the server to be initialized via srv_settings_init(). --- diff --git a/doc/configuration.txt b/doc/configuration.txt index b8a570466..c13837f7c 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -7374,6 +7374,14 @@ default-server [from ] [param*] Example : default-server inter 1000 weight 13 + Multiple default-server lines can be specified in the same backend with each + new line completing the previous one. This set of options can be reset by + using the "from none" keyword value. + + A default-server with no parameter set will automatically be purged after + parsing. As such, a final "default-server from none" statement will be + sufficient to release this unused memory. + See also: "server" and section 5 about server options @@ -18188,9 +18196,17 @@ its settings. from Preinitialize the server settings by copying values from another server or - default-server instance. + default-server instance. This keyword is positional : it must be specified + before any other server settings. Here is the list of the supported values for the "from" keyword : + - none + resets all settings to the documented defaults. This prevents a server + defined in the configuration from automatically reusing a default-server + instance. This is already the default behavior for dynamically created + servers. This value is also directly useful on a default-server line, + to reset its set of options to their documented values, before eventually + configuring new settings. The currently supported server settings are the following ones. Note that all these settings are supported both by "server" and "default-server" keywords, diff --git a/reg-tests/server/from_keyword.vtc b/reg-tests/server/from_keyword.vtc index cf48f2fb3..155507ebe 100644 --- a/reg-tests/server/from_keyword.vtc +++ b/reg-tests/server/from_keyword.vtc @@ -30,12 +30,28 @@ haproxy h1 -conf { default-server inter 5s server srvconf1 ${s1_addr}:${s1_port} + server srvconf2 ${s1_addr}:${s1_port} from none + + # reset the default-server + default-server from none + server srvconf3 ${s1_addr}:${s1_port} + + # configure new default-server settings used for dynamic servers + default-server weight 10 } -start haproxy h1 -cli { # static server uses by default the default-server send "get weight be/srvconf1" expect ~ "10 \\(initial 10\\)" + + # from none keyword + send "get weight be/srvconf2" + expect ~ "1 \\(initial 1\\)" + + # check from none on default-server + send "get weight be/srvconf3" + expect ~ "1 \\(initial 1\\)" } # dynamic servers diff --git a/src/server.c b/src/server.c index ec86c30b1..56639185f 100644 --- a/src/server.c +++ b/src/server.c @@ -3942,6 +3942,9 @@ static int _srv_parse_from(struct server *srv, char **args, int *cur_arg, err_code |= ERR_FATAL | ERR_ALERT; goto out; } + else if (strcmp(args[*cur_arg + 1], "none") == 0) { + *from = NULL; + } else { ha_alert("invalid '%s' value for 'from' keyword.\n", args[*cur_arg + 1]); err_code |= ERR_FATAL | ERR_ALERT;