]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: implement "from none"
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 29 Jul 2026 13:42:16 +0000 (15:42 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 3 Aug 2026 14:52:09 +0000 (16:52 +0200)
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, <from> output return is set to NULL, which will
cause the server to be initialized via srv_settings_init().

doc/configuration.txt
reg-tests/server/from_keyword.vtc
src/server.c

index b8a5704665cfa48f12eee518442e41741863db8c..c13837f7c026020acd090ca79266cb595966372f 100644 (file)
@@ -7374,6 +7374,14 @@ default-server [from <origin>] [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 <origin>
   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,
index cf48f2fb32084b3958cdffb76c03239ecfdc10db..155507ebec1a2f00daab8608e71606c9302be31b 100644 (file)
@@ -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
index ec86c30b1b57c81d98e8c389cb0875641d7e8fc9..56639185f24404a0e315f98da6bd9264cb99e357 100644 (file)
@@ -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;