mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: tools: prepare str2sa_range() to return an error message
We'll need str2sa_range() to return address parsing errors if we want to extend its functionalities. Let's do that now eventhough it's not used yet.
This commit is contained in:
parent
3a26918170
commit
df350f1f48
@ -240,7 +240,7 @@ struct sockaddr_storage *str2ip(const char *str);
|
|||||||
* The IPv6 '::' address is IN6ADDR_ANY, so in order to bind to a given port on
|
* The IPv6 '::' address is IN6ADDR_ANY, so in order to bind to a given port on
|
||||||
* IPv6, use ":::port". NULL is returned if the host part cannot be resolved.
|
* IPv6, use ":::port". NULL is returned if the host part cannot be resolved.
|
||||||
*/
|
*/
|
||||||
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high);
|
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err);
|
||||||
|
|
||||||
/* converts <str> to a struct in_addr containing a network mask. It can be
|
/* converts <str> to a struct in_addr containing a network mask. It can be
|
||||||
* passed in dotted form (255.255.255.0) or in CIDR form (24). It returns 1
|
* passed in dotted form (255.255.255.0) or in CIDR form (24). It returns 1
|
||||||
|
@ -239,7 +239,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
|
|||||||
else {
|
else {
|
||||||
struct sockaddr_storage *ss2;
|
struct sockaddr_storage *ss2;
|
||||||
|
|
||||||
ss2 = str2sa_range(str, &port, &end);
|
ss2 = str2sa_range(str, &port, &end, NULL);
|
||||||
if (!ss2) {
|
if (!ss2) {
|
||||||
memprintf(err, "invalid listening address: '%s'\n", str);
|
memprintf(err, "invalid listening address: '%s'\n", str);
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -1156,7 +1156,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|||||||
struct sockaddr_storage *sk;
|
struct sockaddr_storage *sk;
|
||||||
int port1, port2;
|
int port1, port2;
|
||||||
|
|
||||||
sk = str2sa_range(args[1], &port1, &port2);
|
sk = str2sa_range(args[1], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n", file, linenum, args[0], args[1]);
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n", file, linenum, args[0], args[1]);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
@ -1530,7 +1530,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
|||||||
newpeer->last_change = now.tv_sec;
|
newpeer->last_change = now.tv_sec;
|
||||||
newpeer->id = strdup(args[1]);
|
newpeer->id = strdup(args[1]);
|
||||||
|
|
||||||
sk = str2sa_range(args[2], &port1, &port2);
|
sk = str2sa_range(args[2], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s %s' : unknown host in '%s'\n", file, linenum, args[0], args[1], args[2]);
|
Alert("parsing [%s:%d] : '%s %s' : unknown host in '%s'\n", file, linenum, args[0], args[1], args[2]);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
@ -3986,7 +3986,7 @@ stats_error_parsing:
|
|||||||
else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
|
else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
|
||||||
err_code |= ERR_WARN;
|
err_code |= ERR_WARN;
|
||||||
|
|
||||||
sk = str2sa_range(args[1], &port1, &port2);
|
sk = str2sa_range(args[1], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n", file, linenum, args[0], args[1]);
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n", file, linenum, args[0], args[1]);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
@ -4102,7 +4102,7 @@ stats_error_parsing:
|
|||||||
* - IP:+N => port=+N, relative
|
* - IP:+N => port=+N, relative
|
||||||
* - IP:-N => port=-N, relative
|
* - IP:-N => port=-N, relative
|
||||||
*/
|
*/
|
||||||
sk = str2sa_range(args[2], &port1, &port2);
|
sk = str2sa_range(args[2], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]);
|
Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
@ -4269,7 +4269,7 @@ stats_error_parsing:
|
|||||||
struct sockaddr_storage *sk;
|
struct sockaddr_storage *sk;
|
||||||
int port1, port2;
|
int port1, port2;
|
||||||
|
|
||||||
sk = str2sa_range(args[cur_arg + 1], &port1, &port2);
|
sk = str2sa_range(args[cur_arg + 1], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
||||||
file, linenum, args[cur_arg], args[cur_arg + 1]);
|
file, linenum, args[cur_arg], args[cur_arg + 1]);
|
||||||
@ -4461,7 +4461,7 @@ stats_error_parsing:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
newsrv->conn_src.opts |= CO_SRC_BIND;
|
newsrv->conn_src.opts |= CO_SRC_BIND;
|
||||||
sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high);
|
sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]);
|
Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[cur_arg + 1]);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
@ -4559,7 +4559,7 @@ stats_error_parsing:
|
|||||||
struct sockaddr_storage *sk;
|
struct sockaddr_storage *sk;
|
||||||
int port1, port2;
|
int port1, port2;
|
||||||
|
|
||||||
sk = str2sa_range(args[cur_arg + 1], &port1, &port2);
|
sk = str2sa_range(args[cur_arg + 1], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
||||||
file, linenum, args[cur_arg], args[cur_arg + 1]);
|
file, linenum, args[cur_arg], args[cur_arg + 1]);
|
||||||
@ -4887,7 +4887,7 @@ stats_error_parsing:
|
|||||||
struct sockaddr_storage *sk;
|
struct sockaddr_storage *sk;
|
||||||
int port1, port2;
|
int port1, port2;
|
||||||
|
|
||||||
sk = str2sa_range(args[1], &port1, &port2);
|
sk = str2sa_range(args[1], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
||||||
file, linenum, args[0], args[1]);
|
file, linenum, args[0], args[1]);
|
||||||
@ -4937,7 +4937,7 @@ stats_error_parsing:
|
|||||||
curproxy->conn_src.iface_name = NULL;
|
curproxy->conn_src.iface_name = NULL;
|
||||||
curproxy->conn_src.iface_len = 0;
|
curproxy->conn_src.iface_len = 0;
|
||||||
|
|
||||||
sk = str2sa_range(args[1], &port1, &port2);
|
sk = str2sa_range(args[1], &port1, &port2, NULL);
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
||||||
file, linenum, args[0], args[1]);
|
file, linenum, args[0], args[1]);
|
||||||
@ -5020,7 +5020,7 @@ stats_error_parsing:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
struct sockaddr_storage *sk = str2sa_range(args[cur_arg + 1], &port1, &port2);
|
struct sockaddr_storage *sk = str2sa_range(args[cur_arg + 1], &port1, &port2, NULL);
|
||||||
|
|
||||||
if (!sk) {
|
if (!sk) {
|
||||||
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
|
||||||
|
@ -638,7 +638,7 @@ struct sockaddr_storage *str2ip(const char *str)
|
|||||||
* returned if the address cannot be parsed. The <low> and <high> ports are
|
* returned if the address cannot be parsed. The <low> and <high> ports are
|
||||||
* always initialized if non-null.
|
* always initialized if non-null.
|
||||||
*/
|
*/
|
||||||
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high)
|
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage *ret = NULL;
|
struct sockaddr_storage *ret = NULL;
|
||||||
char *str2;
|
char *str2;
|
||||||
@ -648,8 +648,10 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high)
|
|||||||
portl = porth = porta = 0;
|
portl = porth = porta = 0;
|
||||||
|
|
||||||
str2 = strdup(str);
|
str2 = strdup(str);
|
||||||
if (str2 == NULL)
|
if (str2 == NULL) {
|
||||||
|
memprintf(err, "out of memory in '%s'\n", __FUNCTION__);
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
port1 = strrchr(str2, ':');
|
port1 = strrchr(str2, ':');
|
||||||
if (port1)
|
if (port1)
|
||||||
@ -658,8 +660,10 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high)
|
|||||||
port1 = "";
|
port1 = "";
|
||||||
|
|
||||||
ret = str2ip(str2);
|
ret = str2ip(str2);
|
||||||
if (!ret)
|
if (!ret) {
|
||||||
|
memprintf(err, "invalid address: '%s' in '%s'\n", str2, str);
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (isdigit(*port1)) { /* single port or range */
|
if (isdigit(*port1)) { /* single port or range */
|
||||||
port2 = strchr(port1, '-');
|
port2 = strchr(port1, '-');
|
||||||
@ -680,6 +684,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high)
|
|||||||
porta = porth;
|
porta = porth;
|
||||||
}
|
}
|
||||||
else if (*port1) { /* other any unexpected char */
|
else if (*port1) { /* other any unexpected char */
|
||||||
|
memprintf(err, "invalid character '%c' in port number '%s'\n", *port1, port1);
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user