]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse/peers: provide more info when ignoring invalid "peer" or "server...
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 7 Mar 2025 08:30:47 +0000 (09:30 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 7 Mar 2025 08:39:51 +0000 (09:39 +0100)
Invalid (incomplete) "server" or "peer" lines under peers section are now
properly ignored. For completeness, in this patch we add some reports so
that the user knows that incomplete lines were ignored.

For an incomplete server line, since it is tolerated (see GH #565), we
only emit a diag warning.

For an incomplete peer line, we report a real warning, as it is not
expected to have a peer line without an address:port specified.

Also, 'newpeer == curpeers->local' check could be simplified since
we already have the 'local_peer' variable which tells us that the
parsed line refers to a local peer.

src/cfgparse.c

index ab49a73b3c86aa193006046a5dd74b4cd1333e0c..a498f69cd457acd05855ea0caa36d071fa890cc8 100644 (file)
@@ -895,12 +895,28 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                         */
                        struct peer *p;
 
+                       /* while it is tolerated to have a "server" line without address, it isn't
+                        * the case for a "peer" line
+                        */
+                       if (peer) {
+                               ha_warning("parsing [%s:%d] : '%s %s' : ignoring invalid peer definition (missing address:port)\n",
+                                          file, linenum, args[0], args[1]);
+                               err_code |= ERR_WARN;
+                       }
+                       else {
+                               ha_diag_warning("parsing [%s:%d] : '%s %s' : ignoring server (not a local peer, valid address:port is expected)\n",
+                                               file, linenum, args[0], args[1]);
+                       }
+
                        p = curpeers->remote;
                        curpeers->remote = curpeers->remote->next;
                        free(p->id);
                        free(p);
-                       if (newpeer == curpeers->local) {
-                               /* reset curpeers and curpeers fields
+                       if (local_peer) {
+                               /* we only get there with incomplete "peer"
+                                * line for local peer (missing address):
+                                *
+                                * reset curpeers and curpeers fields
                                 * that are local peer related
                                 */
                                curpeers->local = NULL;