MEDIUM: config: remove all checks for missing/invalid ports/ranges

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.
This commit is contained in:
Willy Tarreau 2020-09-15 11:52:23 +02:00
parent 7f96a8474c
commit 8b0fa8f0ab
7 changed files with 1 additions and 133 deletions

View 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;
}

View 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);

View 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;

View 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) {

View File

@ -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);

View 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) {

View 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) {