]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: use the new bind_parse_args_list() to parse a "bind" line
authorWilly Tarreau <w@1wt.eu>
Fri, 20 May 2022 13:44:17 +0000 (15:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 May 2022 16:39:43 +0000 (18:39 +0200)
This now makes sure that both the peers' "bind" line and the regular one
will use the exact same parser with the exact same behavior. Note that
the parser applies after the address and that it could be factored
further, since the peers one still does quite a bit of duplicated work.

src/cfgparse-listen.c
src/cfgparse.c

index 1bff2cdd2dcf0d892780d9f6961a99ecbd247c31..c4b33f75e22d854bc724ab7354cefebf4ddf38b5 100644 (file)
@@ -507,59 +507,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                }
 
                cur_arg = 2;
-               while (*(args[cur_arg])) {
-                       struct bind_kw *kw;
-                       const char *best;
-
-                       kw = bind_find_kw(args[cur_arg]);
-                       if (kw) {
-                               char *err = NULL;
-                               int code;
-
-                               if (!kw->parse) {
-                                       ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
-                                                file, linenum, args[0], args[1], args[cur_arg]);
-                                       cur_arg += 1 + kw->skip ;
-                                       err_code |= ERR_ALERT | ERR_FATAL;
-                                       goto out;
-                               }
-
-                               code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
-                               err_code |= code;
-
-                               if (code) {
-                                       if (err && *err) {
-                                               indent_msg(&err, 2);
-                                               if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN))
-                                                       ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
-                                               else
-                                                       ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
-                                       }
-                                       else
-                                               ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
-                                                        file, linenum, args[0], args[1], args[cur_arg]);
-                                       if (code & ERR_FATAL) {
-                                               free(err);
-                                               cur_arg += 1 + kw->skip;
-                                               goto out;
-                                       }
-                               }
-                               free(err);
-                               cur_arg += 1 + kw->skip;
-                               continue;
-                       }
-
-                       best = bind_find_best_kw(args[cur_arg]);
-                       if (best)
-                               ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'; did you mean '%s' maybe ?\n",
-                                        file, linenum, args[0], args[1], args[cur_arg], best);
-                       else
-                               ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.\n",
-                                        file, linenum, args[0], args[1], args[cur_arg]);
-
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
+               err_code |= bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
                goto out;
        }
        else if (strcmp(args[0], "monitor-net") == 0) {  /* set the range of IPs to ignore */
index d8412239793bd8b6e14256af31a79cd88fab3e1b..1e0f5edb1cc696d6cd30e474a4bfb32364cfb8aa 100644 (file)
@@ -693,7 +693,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
        if (strcmp(args[0], "bind") == 0 || strcmp(args[0], "default-bind") == 0) {
                int cur_arg;
                struct bind_conf *bind_conf;
-               struct bind_kw *kw;
+               int ret;
 
                cur_arg = 1;
 
@@ -752,35 +752,10 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        cur_arg++;
                }
 
-               while (*args[cur_arg] && (kw = bind_find_kw(args[cur_arg]))) {
-                       int ret;
-
-                       ret = kw->parse(args, cur_arg, curpeers->peers_fe, bind_conf, &errmsg);
-                       err_code |= ret;
-                       if (ret) {
-                               if (errmsg && *errmsg) {
-                                       indent_msg(&errmsg, 2);
-                                       ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
-                               }
-                               else
-                                       ha_alert("parsing [%s:%d]: error encountered while processing '%s'\n",
-                                                file, linenum, args[cur_arg]);
-                               if (ret & ERR_FATAL)
-                                       goto out;
-                       }
-                       cur_arg += 1 + kw->skip;
-               }
-               if (*args[cur_arg] != 0) {
-                       const char *best = bind_find_best_kw(args[cur_arg]);
-                       if (best)
-                               ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n",
-                                        file, linenum, args[cur_arg], cursection, best);
-                       else
-                               ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section.\n",
-                                        file, linenum, args[cur_arg], cursection);
-                       err_code |= ERR_ALERT | ERR_FATAL;
+               ret = bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum);
+               err_code |= ret;
+               if (ret != 0)
                        goto out;
-               }
        }
        else if (strcmp(args[0], "default-server") == 0) {
                if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {