]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: detect stream vs dgram conflict during parsing
authorWilly Tarreau <w@1wt.eu>
Fri, 20 May 2022 14:20:52 +0000 (16:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 May 2022 16:41:55 +0000 (18:41 +0200)
Now that we have a function to parse all bind keywords, and that we
know what types of sock-level and xprt-level protocols a bind_conf
is using, it's easier to centralize the check for stream vs dgram
conflict by putting it directly at the end of the args parser. This
way it also works for peers, provides better precision in the report,
and will also allow to validate transport layers. The check was even
extended to detect inconsistencies between xprt layer (which were not
covered before). It can even detect that there are two incompatible
"bind" lines in a single peers section.

src/cfgparse.c
src/listener.c

index d48efac9c8c844a64a24876f16bd65308f995d67..3fb0fb4a279196ed2c59d61eba2aa9163a189806 100644 (file)
@@ -3762,23 +3762,6 @@ out_uri_auth_compat:
                list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
                        int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
                        const struct mux_proto_list *mux_ent;
-                       const struct listener *l;
-                       int types = 0;
-
-                       /* check that the mux is compatible with all listeners'
-                        * protocol types (dgram or stream).
-                        */
-                       list_for_each_entry(l, &bind_conf->listeners, by_bind)
-                               types |= 1 << l->rx.proto->proto_type;
-
-                       if (atleast2(types)) {
-                               ha_alert("%s '%s' : cannot mix datagram and stream protocols "
-                                        "for 'bind %s' at [%s:%d].\n",
-                                        proxy_type_str(curproxy), curproxy->id,
-                                        bind_conf->arg, bind_conf->file, bind_conf->line);
-                               cfgerr++;
-                               continue;
-                       }
 
                        if (!bind_conf->mux_proto)
                                continue;
index 6c71c1b4b85b3361113db11cca9a7ae46229cea2..e5cb867ba984bd1b8358d8dc1f33d886acfcc354 100644 (file)
@@ -1631,6 +1631,15 @@ int bind_parse_args_list(struct bind_conf *bind_conf, char **args, int cur_arg,
                err_code |= ERR_ALERT | ERR_FATAL;
                goto out;
        }
+
+       if ((bind_conf->options & (BC_O_USE_SOCK_DGRAM|BC_O_USE_SOCK_STREAM)) == (BC_O_USE_SOCK_DGRAM|BC_O_USE_SOCK_STREAM) ||
+           (bind_conf->options & (BC_O_USE_XPRT_DGRAM|BC_O_USE_XPRT_STREAM)) == (BC_O_USE_XPRT_DGRAM|BC_O_USE_XPRT_STREAM)) {
+               ha_alert("parsing [%s:%d] : '%s %s' in section '%s' : cannot mix datagram and stream protocols.\n",
+                        file, linenum, args[0], args[1], section);
+               err_code |= ERR_ALERT | ERR_FATAL;
+               goto out;
+       }
+
  out:
        return err_code;
 }