MINOR: tools: add several PA_O_PORT_* flags in str2sa_range() callers
These flags indicate what is expected regarding port specifications. Some
callers accept none, some need fixed ports, some have it mandatory, some
support ranges, and some take an offset. Each possibilty is reflected by
an option. For now they are not exploited, but the goal is to instrument
str2sa_range() to properly parse that.
diff --git a/include/haproxy/tools-t.h b/include/haproxy/tools-t.h
index b3f2f62..cb33610 100644
--- a/include/haproxy/tools-t.h
+++ b/include/haproxy/tools-t.h
@@ -87,6 +87,10 @@
/* Address parsing options for use with str2sa_range() */
#define PA_O_RESOLVE 0x00000001 /* do resolve the FQDN to an IP address */
+#define PA_O_PORT_OK 0x00000002 /* ports are supported */
+#define PA_O_PORT_MAND 0x00000004 /* ports are mandatory */
+#define PA_O_PORT_RANGE 0x00000008 /* port ranges are supported */
+#define PA_O_PORT_OFS 0x00000010 /* port offsets are supported */
/* UTF-8 decoder status */
#define UTF8_CODE_OK 0x00
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 8fc3f46..f0c250d 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -2600,7 +2600,7 @@
else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
err_code |= ERR_WARN;
- sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@@ -2872,7 +2872,7 @@
curproxy->conn_src.iface_name = NULL;
curproxy->conn_src.iface_len = 0;
- sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[0], args[1], errmsg);
@@ -2957,7 +2957,7 @@
} else {
struct sockaddr_storage *sk;
- sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 287efb1..fa143c0 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -129,7 +129,7 @@
ss2 = str2sa_range(str, NULL, &port, &end, err,
curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
- NULL, PA_O_RESOLVE);
+ NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE);
if (!ss2)
goto fail;
@@ -1034,7 +1034,7 @@
newnameserver->conf.line = linenum;
newnameserver->id = strdup(args[1]);
- sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@@ -1424,7 +1424,7 @@
newmailer->id = strdup(args[1]);
- sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
diff --git a/src/hlua.c b/src/hlua.c
index 491bc93..9a06956 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2534,7 +2534,7 @@
}
/* Parse ip address. */
- addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, 0);
+ addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, PA_O_PORT_OK);
if (!addr) {
xref_unlock(&socket->xref, peer);
WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));
diff --git a/src/log.c b/src/log.c
index 53b97aa..1a00ae0 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1021,7 +1021,7 @@
if (strncmp(args[1], "fd@", 3) == 0)
logsrv->type = LOG_TARGET_FD;
- sk = str2sa_range(args[1], NULL, &port1, &port2, err, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[1], NULL, &port1, &port2, err, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK);
if (!sk)
goto error;
logsrv->addr = *sk;
diff --git a/src/server.c b/src/server.c
index d8f14e5..b9ac32e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -659,7 +659,7 @@
}
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_RANGE);
if (!sk) {
memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg);
goto err;
@@ -756,7 +756,7 @@
int port1, port2;
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(args[*cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK);
if (!sk) {
ha_alert("'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg);
goto err;
@@ -857,7 +857,7 @@
}
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND);
if (!sk) {
memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg);
goto err;
@@ -2054,7 +2054,7 @@
if (!parse_addr)
goto skip_addr;
- sk = str2sa_range(args[cur_arg], &port, &port1, &port2, &errmsg, NULL, &fqdn, initial_resolve ? PA_O_RESOLVE : 0);
+ sk = str2sa_range(args[cur_arg], &port, &port1, &port2, &errmsg, NULL, &fqdn, (initial_resolve ? PA_O_RESOLVE : 0) | PA_O_PORT_OK | PA_O_PORT_OFS);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index 2cd0bee..f1382f7 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -2224,7 +2224,7 @@
goto error;
}
- sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, PA_O_RESOLVE);
+ sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK);
if (!sk) {
memprintf(errmsg, "'%s' : %s.", args[cur_arg], *errmsg);
goto error;