MINOR: tools: make str2sa_range() take more options than just resolve
We currently have an argument to require that the address is resolved
but we'll soon add more, so let's turn it into a bit field. The old
"resolve" boolean is now PA_O_RESOLVE.
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 82e8cf9..8fc3f46 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, 1);
+ sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
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, 1);
+ sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
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, 1);
+ sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
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 8effc83..287efb1 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, 1);
+ NULL, PA_O_RESOLVE);
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, 1);
+ sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
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, 1);
+ sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
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/check.c b/src/check.c
index 4d6b75b..c326c00 100644
--- a/src/check.c
+++ b/src/check.c
@@ -2638,7 +2638,7 @@
goto error;
}
- sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, 1);
+ sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, PA_O_RESOLVE);
if (!sk) {
memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg);
goto error;
diff --git a/src/log.c b/src/log.c
index e125713..53b97aa 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, 1);
+ sk = str2sa_range(args[1], NULL, &port1, &port2, err, NULL, NULL, PA_O_RESOLVE);
if (!sk)
goto error;
logsrv->addr = *sk;
diff --git a/src/server.c b/src/server.c
index 12755cd..d8f14e5 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, 1);
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, PA_O_RESOLVE);
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, 1);
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE);
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, 1);
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, PA_O_RESOLVE);
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);
+ sk = str2sa_range(args[cur_arg], &port, &port1, &port2, &errmsg, NULL, &fqdn, initial_resolve ? PA_O_RESOLVE : 0);
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 6597239..2cd0bee 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, 1);
+ sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, PA_O_RESOLVE);
if (!sk) {
memprintf(errmsg, "'%s' : %s.", args[cur_arg], *errmsg);
goto error;
diff --git a/src/tools.c b/src/tools.c
index 1fdfed6..29526c2 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -855,16 +855,16 @@
* that the caller will have to free(),
* - NULL if there was an explicit address that doesn't require resolution.
*
- * Hostnames are only resolved if <resolve> is non-null. Note that if <resolve>
- * is null, <fqdn> is still honnored so it is possible for the caller to know
- * whether a resolution failed by setting <resolve> to null and checking if
- * <fqdn> was filled, indicating the need for a resolution.
+ * Hostnames are only resolved if <opts> has PA_O_RESOLVE. Otherwise <fqdn> is
+ * still honored so it is possible for the caller to know whether a resolution
+ * failed by clearing this flag and checking if <fqdn> was filled, indicating
+ * the need for a resolution.
*
* When a file descriptor is passed, its value is put into the s_addr part of
* the address when cast to sockaddr_in and the address family is
* AF_CUST_EXISTING_FD.
*/
-struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, char **err, const char *pfx, char **fqdn, int resolve)
+struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, char **err, const char *pfx, char **fqdn, unsigned int opts)
{
static THREAD_LOCAL struct sockaddr_storage ss;
struct sockaddr_storage *ret = NULL;
@@ -1036,11 +1036,11 @@
/* first try to parse the IP without resolving. If it fails, it
* tells us we need to keep a copy of the FQDN to resolve later
* and to enable DNS. In this case we can proceed if <fqdn> is
- * set or if resolve is set, otherwise it's an error.
+ * set or if PA_O_RESOLVE is set, otherwise it's an error.
*/
if (str2ip2(str2, &ss, 0) == NULL) {
- if ((!resolve && !fqdn) ||
- (resolve && str2ip2(str2, &ss, 1) == NULL)) {
+ if ((!(opts & PA_O_RESOLVE) && !fqdn) ||
+ ((opts & PA_O_RESOLVE) && str2ip2(str2, &ss, 1) == NULL)) {
memprintf(err, "invalid address: '%s' in '%s'\n", str2, str);
goto out;
}