From 8b0fa8f0ab79188bd1f9ea4f5dc1347d0d72b4e9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 15 Sep 2020 11:52:23 +0200 Subject: [PATCH] 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. --- src/cfgparse-listen.c | 27 ---------------------- src/cfgparse.c | 53 +------------------------------------------ src/check.c | 6 ----- src/hlua.c | 4 ---- src/log.c | 4 ---- src/server.c | 34 --------------------------- src/tcpcheck.c | 6 ----- 7 files changed, 1 insertion(+), 133 deletions(-) diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index f0c250d98..72fd3fa6c 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -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', 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; } diff --git a/src/cfgparse.c b/src/cfgparse.c index fa143c00d..660c308c6 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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); diff --git a/src/check.c b/src/check.c index 1d3a307b6..423cb4dcc 100644 --- a/src/check.c +++ b/src/check.c @@ -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; diff --git a/src/hlua.c b/src/hlua.c index 9a0695648..331fed978 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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) { diff --git a/src/log.c b/src/log.c index 1a00ae0fb..491b149f6 100644 --- 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); diff --git a/src/server.c b/src/server.c index b9ac32eb0..c60834538 100644 --- a/src/server.c +++ b/src/server.c @@ -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) { diff --git a/src/tcpcheck.c b/src/tcpcheck.c index f1382f768..1663ad83e 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -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) {