MINOR: tools: prepare str2sa_range() to accept a prefix

We'll need str2sa_range() to support a prefix for unix sockets. Since
we don't always want to use it (eg: stats socket), let's not take it
unconditionally from global but let the caller pass it.
This commit is contained in:
Willy Tarreau 2013-03-04 18:22:00 +01:00
parent 8f46ccad27
commit d393a628bb
3 changed files with 18 additions and 13 deletions

View File

@ -239,8 +239,10 @@ struct sockaddr_storage *str2ip(const char *str);
* address wants to ignore port, it must be terminated by a trailing colon (':'). * address wants to ignore port, it must be terminated by a trailing colon (':').
* 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.
* If <pfx> is non-null, it is used as a string prefix before any path-based
* address (typically the path to a unix socket).
*/ */
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err); struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx);
/* 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

View File

@ -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, NULL); ss2 = str2sa_range(str, &port, &end, NULL, 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, NULL); sk = str2sa_range(args[1], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[2], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[1], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[2], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[cur_arg + 1], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, NULL, 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, NULL); sk = str2sa_range(args[cur_arg + 1], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[1], &port1, &port2, NULL, 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, NULL); sk = str2sa_range(args[1], &port1, &port2, NULL, 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, NULL); struct sockaddr_storage *sk = str2sa_range(args[cur_arg + 1], &port1, &port2, NULL, 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",

View File

@ -637,8 +637,11 @@ struct sockaddr_storage *str2ip(const char *str)
* is mandatory after the IP address even when no port is specified. NULL is * is mandatory after the IP address even when no port is specified. NULL is
* 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.
*
* If <pfx> is non-null, it is used as a string prefix before any path-based
* address (typically the path to a unix socket).
*/ */
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err) struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx)
{ {
struct sockaddr_storage *ret = NULL; struct sockaddr_storage *ret = NULL;
char *str2; char *str2;