From: Willy Tarreau Date: Mon, 23 Jun 2025 13:42:32 +0000 (+0200) Subject: MAJOR: cfgparse: make sure server names are unique within a backend X-Git-Tag: v3.3-dev2~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7fad1320eae7efba98135628d0c04af6e15495e;p=thirdparty%2Fhaproxy.git MAJOR: cfgparse: make sure server names are unique within a backend There was already a check for this but there used to be an exception that allowed duplicate server names only in case where their IDs were explicit and different. This has been emitting a warning since 3.1 and planned for removal in 3.3, so let's do it now. The doc was updated, though it never mentioned this unicity constraint, so that was added. Only the check for the exception was removed, the rest of the code that is currently made to deal with duplicate server names was not cleaned yet (e.g. the tree doesn't need to support dups anymore, and this could be done at insertion time). This may be a subject for future cleanups. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 74cd88098..4dfd53bc2 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -11722,6 +11722,7 @@ server
[:[port]] [param*] is the internal name assigned to this server. This name will appear in logs and alerts. If "http-send-name-header" is set, it will be added to the request header sent to the server. + This name must be unique within the backend section.
is the IPv4 or IPv6 address of the server. Alternatively, a resolvable hostname is supported, but this name will be resolved diff --git a/src/cfgparse.c b/src/cfgparse.c index 3b8eedcfb..a1ea79c5c 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3691,13 +3691,11 @@ out_uri_auth_compat: } /* Check that no server name conflicts. This causes trouble in the stats. - * We only emit a warning for the first conflict affecting each server, + * We only emit an error for the first conflict affecting each server, * in order to avoid combinatory explosion if all servers have the same - * name. We do that only for servers which do not have an explicit ID, - * because these IDs were made also for distinguishing them and we don't - * want to annoy people who correctly manage them. Since servers names - * are stored in a tree before landing here, we simply have to check for - * the current server's duplicates to spot conflicts. + * name. Since servers names are stored in a tree before landing here, + * we simply have to check for the current server's duplicates to spot + * conflicts. */ for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { struct server *other_srv; @@ -3711,19 +3709,12 @@ out_uri_auth_compat: for (other_srv = newsrv; (other_srv = container_of_safe(ebpt_prev_dup(&other_srv->conf.name), struct server, conf.name)); ) { - if (!newsrv->puid && !other_srv->puid) { - ha_alert("parsing [%s:%d] : %s '%s', another server named '%s' was already defined at line %d, please use distinct names.\n", - newsrv->conf.file, newsrv->conf.line, - proxy_type_str(curproxy), curproxy->id, - newsrv->id, other_srv->conf.line); - cfgerr++; - break; - } - - ha_warning("parsing [%s:%d] : %s '%s', another server named '%s' was already defined at line %d. This is dangerous and will not be supported anymore in version 3.3. Please use distinct names.\n", - newsrv->conf.file, newsrv->conf.line, - proxy_type_str(curproxy), curproxy->id, - newsrv->id, other_srv->conf.line); + ha_alert("parsing [%s:%d] : %s '%s', another server named '%s' was already defined at line %d, please use distinct names.\n", + newsrv->conf.file, newsrv->conf.line, + proxy_type_str(curproxy), curproxy->id, + newsrv->id, other_srv->conf.line); + cfgerr++; + break; } }