]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: proxy/log: frontend/backend and log forward names must differ
authorEmeric Brun <ebrun@haproxy.com>
Wed, 7 Oct 2020 15:05:59 +0000 (17:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2020 06:53:26 +0000 (08:53 +0200)
This patch disallow to use same name for a log forward section
and a frontend/backend section.

include/haproxy/log.h
src/cfgparse-listen.c
src/log.c

index 981086906cbe0fc0ead4580aeceb773e242cf7f2..837ae0ccc75cc85c883329591dd27152d3ab973c 100644 (file)
@@ -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 */
 
 /*
index c2db644c8ed60f6ae199ad01139e367a04da1a7f..665be769ef117852e5cec0672cffa999c7a6ed2d 100644 (file)
@@ -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;
index d29fc7ada8cd919a9b4af665ad273e9d49aff0f8..676d504e551000cdd49c71402c75f871d17ff9a5 100644 (file)
--- 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);