From: Amaury Denoyelle Date: Mon, 23 Nov 2026 08:53:09 +0000 (+0100) Subject: MINOR: server: lookup defaults section on "from srv:" X-Git-Url: https://git.kaiwu.me/http/ngx_http_access_module.html?a=commitdiff_plain;h=5ae25c5fb7a78ab846c57d511dd1a24e47690198;p=haproxy.git MINOR: server: lookup defaults section on "from srv:" When defining a server, notation 'from srv:/' can be specified to inherit from a server or default-server defined in another backend instance. Extend this to also look up in defaults sections. This is safe as proxies and defaults sections cannot have the same name since 3.3. Without this patch, a named default-server in a named defaults section is unusable as it cannot be referenced by the existing syntax. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 67754a261..7065b72a0 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -19320,11 +19320,14 @@ from is mostly useful for dynamic servers created on the CLI which by default ignore any default-server, which is equivalent to the "none" value. - srv:[/] - instructs to reuse the settings from the designated backend's server or named - default-server resulting from the processing of all its default-server - directives using the same name. The backend name is optional. If unset, - this designates the proxy where the currently newly defined server will - be attached. + instructs to reuse the settings from the designated backend's server or + named default-server resulting from the processing of all its + default-server directives using the same name. The backend name is + optional. If unset, this designates the proxy where the currently newly + defined server will be attached. Alternatively, a named defaults section + can also be specified to inherit from a named default-server. Only a + server or named default-server directly declared in the target backend or + defaults section can be specified; inherited entries are not resolved. 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 78a5e9570..e138d6caf 100644 --- a/reg-tests/server/from_keyword.vtc +++ b/reg-tests/server/from_keyword.vtc @@ -14,6 +14,9 @@ haproxy h1 -conf { thread-groups 1 .endif + defaults defpx + default-server name srv weight 20 + defaults mode http timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" @@ -55,6 +58,9 @@ haproxy h1 -conf { default-server name other weight 5 server srvconf7 ${s1_addr}:${s1_port} from srv:other + # inherit from a defaults section + server srvconf8 ${s1_addr}:${s1_port} from srv:defpx/srv + backend be_defempty default-server check # reset default-server will be purged on post parsing @@ -88,6 +94,9 @@ haproxy h1 -cli { send "get weight be/srvconf7" expect ~ "5 \\(initial 5\\)" + + send "get weight be/srvconf8" + expect ~ "20 \\(initial 20\\)" } # dynamic servers diff --git a/src/server.c b/src/server.c index 86918ce04..4129e8223 100644 --- a/src/server.c +++ b/src/server.c @@ -4061,13 +4061,18 @@ static struct server *lookup_srv_be_arg(struct ist sv_name, { struct server *srv; struct ist be_name; + const char *be_name0; struct proxy *px = curproxy; if (istchr(sv_name, '/')) { be_name = istsplit(&sv_name, '/'); - px = proxy_be_by_name(ist0(be_name)); + be_name0 = ist0(be_name); + + px = proxy_be_by_name(be_name0); + if (!px) + px = proxy_find_by_name(be_name0, PR_CAP_DEF, 0); if (!px) { - memprintf(msg, "unknown backend '%s'", istptr(be_name)); + memprintf(msg, "unknown backend or defaults '%s'", istptr(be_name)); return NULL; } }