From: Emeric Brun Date: Wed, 7 Oct 2020 15:05:59 +0000 (+0200) Subject: BUG/MINOR: proxy/log: frontend/backend and log forward names must differ X-Git-Tag: v2.3-dev6~78 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b0c331f71f5344a3c29d6101f5c592bd2121c528;p=thirdparty%2Fhaproxy.git BUG/MINOR: proxy/log: frontend/backend and log forward names must differ This patch disallow to use same name for a log forward section and a frontend/backend section. --- diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 981086906c..837ae0ccc7 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -169,6 +169,22 @@ static inline int build_logline(struct stream *s, char *dst, size_t maxsize, str struct ist *build_log_header(enum log_fmt format, int level, int facility, struct ist *metadata, size_t *nbelem); +/* + * lookup log forward proxy by name + * Returns NULL if no proxy found. + */ +static inline struct proxy *log_forward_by_name(const char *name) +{ + struct proxy *px = cfg_log_forward; + + while (px) { + if (strcmp(px->id, name) == 0) + return px; + px = px->next; + } + return NULL; +} + #endif /* _HAPROXY_LOG_H */ /* diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index c2db644c8e..665be769ef 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -211,6 +211,14 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_FATAL; } + curproxy = log_forward_by_name(args[1]); + if (curproxy) { + ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n", + file, linenum, proxy_cap_str(rc), args[1], + curproxy->id, curproxy->conf.file, curproxy->conf.line); + err_code |= ERR_ALERT | ERR_FATAL; + } + if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); err_code |= ERR_ALERT | ERR_ABORT; diff --git a/src/log.c b/src/log.c index d29fc7ada8..676d504e55 100644 --- a/src/log.c +++ b/src/log.c @@ -3731,12 +3731,19 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) goto out; } - for (px = cfg_log_forward ; px ; px = px->next) { - if (strcmp(px->id, args[1]) == 0) { - ha_alert("Parsing [%s:%d]: log-forward section '%s' has the same name as another log-forward section declared at %s:%d.\n", - file, linenum, args[1], px->conf.file, px->conf.line); - err_code |= ERR_ALERT | ERR_FATAL; - } + px = log_forward_by_name(args[1]); + if (px) { + ha_alert("Parsing [%s:%d]: log-forward section '%s' has the same name as another log-forward section declared at %s:%d.\n", + file, linenum, args[1], px->conf.file, px->conf.line); + err_code |= ERR_ALERT | ERR_FATAL; + } + + px = proxy_find_by_name(args[1], 0, 0); + if (px) { + ha_alert("Parsing [%s:%d]: log forward section '%s' has the same name as %s '%s' declared at %s:%d.\n", + file, linenum, args[1], proxy_type_str(px), + px->id, px->conf.file, px->conf.line); + err_code |= ERR_ALERT | ERR_FATAL; } px = calloc(1, sizeof *px);