]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: remove all checks for missing/invalid ports/ranges
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Sep 2020 09:52:23 +0000 (11:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 20:08:08 +0000 (22:08 +0200)
Now that str2sa_range() checks for appropriate port specification, we
don't need to implement adhoc test cases in every call place, if the
result is valid, the conditions are met otherwise the error message is
appropriately filled.

src/cfgparse-listen.c
src/cfgparse.c
src/check.c
src/hlua.c
src/log.c
src/server.c
src/tcpcheck.c

index f0c250d98ace00394193a879e4a776499d3d40de..72fd3fa6ca16e8c0b1511b16f9b257349ed97ff3 100644 (file)
@@ -2615,20 +2615,6 @@ stats_error_parsing:
                        goto out;
                }
 
-               if (port1 != port2) {
-                       ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
-                                file, linenum, args[0], args[1]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
-               if (!port1) {
-                       ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
-                                file, linenum, args[0], args[1]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
 
@@ -2888,13 +2874,6 @@ stats_error_parsing:
                        goto out;
                }
 
-               if (port1 != port2) {
-                       ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
-                                file, linenum, args[0], args[1]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
                curproxy->conn_src.source_addr = *sk;
                curproxy->conn_src.opts |= CO_SRC_BIND;
 
@@ -2973,12 +2952,6 @@ stats_error_parsing:
                                                goto out;
                                        }
 
-                                       if (port1 != port2) {
-                                               ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
-                                                        file, linenum, args[cur_arg], args[cur_arg + 1]);
-                                               err_code |= ERR_ALERT | ERR_FATAL;
-                                               goto out;
-                                       }
                                        curproxy->conn_src.tproxy_addr = *sk;
                                        curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
                                }
index fa143c00db474d225aa133c3ba32944fa6ebb5f1..660c308c616a732d1f30739106ab8bd29d0f3047 100644 (file)
@@ -133,30 +133,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
                if (!ss2)
                        goto fail;
 
-               if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6
-                                             || ss2->ss_family == AF_CUST_UDP4
-                                             || ss2->ss_family == AF_CUST_UDP6) {
-                       if (!port && !end) {
-                               memprintf(err, "missing port number: '%s'\n", str);
-                               goto fail;
-                       }
-
-                       if (!port || !end) {
-                               memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str);
-                               goto fail;
-                       }
-
-                       if (port < 1 || port > 65535) {
-                               memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
-                               goto fail;
-                       }
-
-                       if (end < 1 || end > 65535) {
-                               memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str);
-                               goto fail;
-                       }
-               }
-               else if (ss2->ss_family == AF_CUST_EXISTING_FD) {
+               if (ss2->ss_family == AF_CUST_EXISTING_FD) {
                        socklen_t addr_len;
                        inherited = 1;
 
@@ -1055,20 +1032,6 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               if (port1 != port2) {
-                       ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
-                                file, linenum, args[0], args[1], args[2]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
-               if (!port1 && !port2) {
-                       ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n",
-                                file, linenum, args[0], args[1]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
                newnameserver->addr = *sk;
        }
        else if (strcmp(args[0], "parse-resolv-conf") == 0) {
@@ -1439,20 +1402,6 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               if (port1 != port2) {
-                       ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
-                                file, linenum, args[0], args[1], args[2]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
-               if (!port1) {
-                       ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
-                                file, linenum, args[0], args[1], args[2]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
                newmailer->addr = *sk;
                newmailer->proto = proto;
                newmailer->xprt  = xprt_get(XPRT_RAW);
index 1d3a307b63da3823fc9b2f9e644600e16bda4d5c..423cb4dccc3016653230c4023cccd823efd7ec51 100644 (file)
@@ -2652,12 +2652,6 @@ static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct
                goto error;
        }
 
-       if (port1 != port2) {
-               memprintf(errmsg, "'%s' : port ranges and offsets are not allowed in '%s'.",
-                         args[*cur_arg], args[*cur_arg+1]);
-               goto error;
-       }
-
        srv->check.addr = srv->agent.addr = *sk;
        srv->flags |= SRV_F_CHECKADDR;
        srv->flags |= SRV_F_AGENTADDR;
index 9a06956487b02315e2f001547334919d21218d5d..331fed97887ce4f5caab27d7e41d890c1abe48a6 100644 (file)
@@ -2539,10 +2539,6 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
                xref_unlock(&socket->xref, peer);
                WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));
        }
-       if (low != high) {
-               xref_unlock(&socket->xref, peer);
-               WILL_LJMP(luaL_error(L, "connect: port ranges not supported : address '%s'", ip));
-       }
 
        /* Set port. */
        if (low == 0) {
index 1a00ae0fbc60bf41c08a0e7abe1d774056bda726..491b149f66acb013b7b888d5d365ca45891bf684 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1033,10 +1033,6 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
                sk->ss_family = AF_INET6;
 
        if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
-               if (port1 != port2) {
-                       memprintf(err, "port ranges and offsets are not allowed in '%s'", args[1]);
-                       goto error;
-               }
                logsrv->addr = *sk;
                if (!port1)
                        set_host_port(&logsrv->addr, SYSLOG_PORT);
index b9ac32eb08f89d741954aabbeacbb92c5ee8b7d1..c60834538ca7bb18351a17644b2eebfaf9cdde63 100644 (file)
@@ -678,18 +678,6 @@ static int srv_parse_source(char **args, int *cur_arg,
        if (port_low != port_high) {
                int i;
 
-               if (!port_low || !port_high) {
-                       ha_alert("'%s' does not support port offsets (found '%s').\n",
-                                args[*cur_arg], args[*cur_arg + 1]);
-                       goto err;
-               }
-
-               if (port_low  <= 0 || port_low  > 65535 ||
-                       port_high <= 0 || port_high > 65535 ||
-                       port_low > port_high) {
-                       ha_alert("'%s': invalid source port range %d-%d.\n", args[*cur_arg], port_low, port_high);
-                       goto err;
-               }
                newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1);
                for (i = 0; i < newsrv->conn_src.sport_range->size; i++)
                        newsrv->conn_src.sport_range->ports[i] = port_low + i;
@@ -769,11 +757,6 @@ static int srv_parse_source(char **args, int *cur_arg,
                                        goto err;
                                }
 
-                               if (port1 != port2) {
-                                       ha_alert("'%s' : port ranges and offsets are not allowed in '%s'\n",
-                                                args[*cur_arg], args[*cur_arg + 1]);
-                                       goto err;
-                               }
                                newsrv->conn_src.tproxy_addr = *sk;
                                newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR;
                        }
@@ -872,16 +855,6 @@ static int srv_parse_socks4(char **args, int *cur_arg,
        newsrv->flags |= SRV_F_SOCKS4_PROXY;
        newsrv->socks4_addr = *sk;
 
-       if (port_low != port_high) {
-               ha_alert("'%s' does not support port offsets (found '%s').\n", args[*cur_arg], args[*cur_arg + 1]);
-               goto err;
-       }
-
-       if (port_low <= 0 || port_low > 65535) {
-               ha_alert("'%s': invalid port %d.\n", args[*cur_arg], port_low);
-               goto err;
-       }
-
        return 0;
 
  err:
@@ -2073,13 +2046,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                /* no port specified, +offset, -offset */
                                newsrv->flags |= SRV_F_MAPPORTS;
                        }
-                       else if (port1 != port2) {
-                               /* port range */
-                               ha_alert("parsing [%s:%d] : '%s %s' : port ranges are not allowed in '%s'\n",
-                                     file, linenum, args[0], args[1], args[2]);
-                               err_code |= ERR_ALERT | ERR_FATAL;
-                               goto out;
-                       }
 
                        /* save hostname and create associated name resolution */
                        if (fqdn) {
index f1382f768af081a6282eaa6cb0b6c1359aaa3d72..1663ad83eb8fb76545d473616c0907bbfa8299d5 100644 (file)
@@ -2237,12 +2237,6 @@ struct tcpcheck_rule *parse_tcpcheck_connect(char **args, int cur_arg, struct pr
                                goto error;
                        }
 
-                       if (port1 != port2) {
-                               memprintf(errmsg, "'%s' : port ranges and offsets are not allowed in '%s'\n",
-                                         args[cur_arg], args[cur_arg+1]);
-                               goto error;
-                       }
-
                        cur_arg++;
                }
                else if (strcmp(args[cur_arg], "port") == 0) {