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.
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index f0c250d..72fd3fa 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -2615,20 +2615,6 @@
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 @@
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 @@
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;
}
diff --git a/src/cfgparse.c b/src/cfgparse.c
index fa143c0..660c308 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -133,30 +133,7 @@
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 @@
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 @@
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);
diff --git a/src/check.c b/src/check.c
index 1d3a307..423cb4d 100644
--- a/src/check.c
+++ b/src/check.c
@@ -2652,12 +2652,6 @@
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;
diff --git a/src/hlua.c b/src/hlua.c
index 9a06956..331fed9 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2539,10 +2539,6 @@
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) {
diff --git a/src/log.c b/src/log.c
index 1a00ae0..491b149 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1033,10 +1033,6 @@
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);
diff --git a/src/server.c b/src/server.c
index b9ac32e..c608345 100644
--- a/src/server.c
+++ b/src/server.c
@@ -678,18 +678,6 @@
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 @@
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 @@
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 @@
/* 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) {
diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index f1382f7..1663ad8 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -2237,12 +2237,6 @@
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) {