From: Willy Tarreau Date: Fri, 3 Jan 2014 11:14:34 +0000 (+0100) Subject: MEDIUM: config: report a warning when multiple servers have the same name X-Git-Tag: v1.5-dev22~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17edc81e7ec5972305f819a08ff2574839d7a53a;p=thirdparty%2Fhaproxy.git MEDIUM: config: report a warning when multiple servers have the same name A config where multiple servers have the same name in the same backend is prone to a number of issues : logs are not really exploitable, stats get really tricky and even harder to change, etc... In fact, it can be safe to have the same name between multiple servers only when their respective IDs are known and used. So now we detect this situation and emit a warning for the first conflict detected per server if any of the servers uses an automatic ID. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 864a9fb9ba..e11730e5ab 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -6937,6 +6937,30 @@ out_uri_auth_compat: curproxy->srv = next; } + /* Check that no server name conflicts. This causes trouble in the stats. + * We only emit a warning 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. + */ + for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { + struct server *other_srv; + + if (newsrv->puid) + continue; + + for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { + if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { + Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", + newsrv->conf.file, newsrv->conf.line, + proxy_type_str(curproxy), curproxy->id, + newsrv->id, other_srv->conf.line); + break; + } + } + } + /* assign automatic UIDs to servers which don't have one yet */ next_id = 1; newsrv = curproxy->srv;