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.
This commit is contained in:
Willy Tarreau 2025-06-23 15:42:32 +02:00
parent 067be38c0e
commit d7fad1320e
2 changed files with 11 additions and 19 deletions

View File

@ -11722,6 +11722,7 @@ server <name> <address>[:[port]] [param*]
<name> 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.
<address> is the IPv4 or IPv6 address of the server. Alternatively, a
resolvable hostname is supported, but this name will be resolved

View File

@ -3691,13 +3691,11 @@ int check_config_validity()
}
/* 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 @@ int check_config_validity()
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;
}
}