MINOR: tools: make str2sa_range() return the port in a separate argument

This will be needed so that we're don't have to extract it from the
returned address where it will not always be anymore (eg: for unresolved
servers).
This commit is contained in:
Willy Tarreau 2017-01-06 18:32:38 +01:00
parent 04276f3d6e
commit 48ef4c95b6
5 changed files with 21 additions and 16 deletions

View File

@ -280,7 +280,10 @@ extern const char *invalid_domainchar(const char *name);
* address (typically the path to a unix socket). If use_dns is not true,
* the funtion cannot accept the DNS resolution.
*/
struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx, char **fqdn, int use_dns);
struct sockaddr_storage *str2sa_range(const char *str,
int *port, int *low, int *high,
char **err, const char *pfx,
char **fqdn, int resolve);
/* 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

View File

@ -237,7 +237,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
*next++ = 0;
}
ss2 = str2sa_range(str, &port, &end, err,
ss2 = str2sa_range(str, NULL, &port, &end, err,
curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
NULL, 1);
if (!ss2)
@ -1443,7 +1443,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
}
}
sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -1972,7 +1972,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
newpeer->last_change = now.tv_sec;
newpeer->id = strdup(args[1]);
sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -2186,7 +2186,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
newnameserver->conf.line = linenum;
newnameserver->id = strdup(args[1]);
sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -2402,7 +2402,7 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
newmailer->id = strdup(args[1]);
sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -5666,7 +5666,7 @@ stats_error_parsing:
else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
err_code |= ERR_WARN;
sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -5996,7 +5996,7 @@ stats_error_parsing:
}
}
sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -6048,7 +6048,7 @@ stats_error_parsing:
curproxy->conn_src.iface_name = NULL;
curproxy->conn_src.iface_len = 0;
sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[0], args[1], errmsg);
@ -6133,7 +6133,7 @@ stats_error_parsing:
} else {
struct sockaddr_storage *sk;
sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg);

View File

@ -2198,7 +2198,7 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
conn->target = socket->s->target;
/* Parse ip address. */
addr = str2sa_range(ip, &low, &high, NULL, NULL, NULL, 0);
addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, 0);
if (!addr)
WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));
if (low != high)

View File

@ -1005,7 +1005,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
* - IP:+N => port=+N, relative
* - IP:-N => port=-N, relative
*/
sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, &fqdn, 0);
sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, &fqdn, 0);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
@ -1391,7 +1391,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
int port1, port2;
struct protocol *proto;
sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s' : %s\n",
file, linenum, args[cur_arg], errmsg);
@ -1603,7 +1603,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
}
newsrv->conn_src.opts |= CO_SRC_BIND;
sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[cur_arg + 1], NULL, &port_low, &port_high, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
@ -1703,7 +1703,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
struct sockaddr_storage *sk;
int port1, port2;
sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
if (!sk) {
Alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg);

View File

@ -816,7 +816,7 @@ struct sockaddr_storage *str2ip2(const char *str, struct sockaddr_storage *sa, i
* 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_UNSPEC.
*/
struct sockaddr_storage *str2sa_range(const char *str, 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, int resolve)
{
static struct sockaddr_storage ss;
struct sockaddr_storage *ret = NULL;
@ -983,6 +983,8 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char
ret = &ss;
out:
if (port)
*port = porta;
if (low)
*low = portl;
if (high)