MINOR: tools: add several PA_O_* flags in str2sa_range() callers

These flags indicate whether the call is made to fill a bind or a server
line, or even just send/recv calls (like logs or dns). Some special cases
are made for outgoing FDs (e.g. pipes for logs) or socket FDs (e.g external
listeners), and there's a distinction between stream or dgram usage that's
expected to significantly help str2sa_range() proceed appropriately with
the input information. For now they are not used yet.
This commit is contained in:
Willy Tarreau 2020-09-04 15:53:16 +02:00
parent 8b0fa8f0ab
commit 328199348b
9 changed files with 21 additions and 15 deletions

View File

@ -91,6 +91,11 @@
#define PA_O_PORT_MAND 0x00000004 /* ports are mandatory */ #define PA_O_PORT_MAND 0x00000004 /* ports are mandatory */
#define PA_O_PORT_RANGE 0x00000008 /* port ranges are supported */ #define PA_O_PORT_RANGE 0x00000008 /* port ranges are supported */
#define PA_O_PORT_OFS 0x00000010 /* port offsets are supported */ #define PA_O_PORT_OFS 0x00000010 /* port offsets are supported */
#define PA_O_SOCKET_FD 0x00000020 /* inherited socket FDs are supported */
#define PA_O_RAW_FD 0x00000040 /* inherited raw FDs are supported (pipes, ttys, ...) */
#define PA_O_DGRAM 0x00000080 /* the address will be used for a datagram socket (in or out) */
#define PA_O_STREAM 0x00000100 /* the address will be used for streams (in or out) */
#define PA_O_XPRT 0x00000200 /* transport protocols may be specified */
/* UTF-8 decoder status */ /* UTF-8 decoder status */
#define UTF8_CODE_OK 0x00 #define UTF8_CODE_OK 0x00

View File

@ -2600,7 +2600,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], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND); sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT);
if (!sk) { if (!sk) {
ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;
@ -2858,7 +2858,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], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK); sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM);
if (!sk) { if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[0], args[1], errmsg); file, linenum, args[0], args[1], errmsg);
@ -2936,7 +2936,7 @@ stats_error_parsing:
} else { } else {
struct sockaddr_storage *sk; struct sockaddr_storage *sk;
sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK); sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM);
if (!sk) { if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
file, linenum, args[cur_arg], args[cur_arg+1], errmsg); file, linenum, args[cur_arg], args[cur_arg+1], errmsg);

View File

@ -129,7 +129,8 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
ss2 = str2sa_range(str, NULL, &port, &end, err, ss2 = str2sa_range(str, NULL, &port, &end, err,
curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE); NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
PA_O_SOCKET_FD | PA_O_DGRAM | PA_O_STREAM | PA_O_XPRT);
if (!ss2) if (!ss2)
goto fail; goto fail;
@ -1011,7 +1012,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
newnameserver->conf.line = linenum; newnameserver->conf.line = linenum;
newnameserver->id = strdup(args[1]); newnameserver->id = strdup(args[1]);
sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND); sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_DGRAM);
if (!sk) { if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;
@ -1387,7 +1388,7 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
newmailer->id = strdup(args[1]); newmailer->id = strdup(args[1]);
sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND); sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT);
if (!sk) { if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;

View File

@ -2639,7 +2639,7 @@ static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct
} }
sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK); PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM);
if (!sk) { if (!sk) {
memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg); memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg);
goto error; goto error;

View File

@ -2475,7 +2475,7 @@ int mworker_cli_proxy_create()
newsrv->conf.line = 0; newsrv->conf.line = 0;
memprintf(&msg, "sockpair@%d", child->ipc_fd[0]); memprintf(&msg, "sockpair@%d", child->ipc_fd[0]);
if ((sk = str2sa_range(msg, &port, &port1, &port2, &errmsg, NULL, NULL, 0)) == 0) { if ((sk = str2sa_range(msg, &port, &port1, &port2, &errmsg, NULL, NULL, PA_O_STREAM)) == 0) {
goto error; goto error;
} }
free(msg); free(msg);

View File

@ -2534,7 +2534,7 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
} }
/* Parse ip address. */ /* Parse ip address. */
addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, PA_O_PORT_OK); addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, PA_O_PORT_OK | PA_O_STREAM);
if (!addr) { if (!addr) {
xref_unlock(&socket->xref, peer); xref_unlock(&socket->xref, peer);
WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip)); WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));

View File

@ -1021,7 +1021,7 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
if (strncmp(args[1], "fd@", 3) == 0) if (strncmp(args[1], "fd@", 3) == 0)
logsrv->type = LOG_TARGET_FD; logsrv->type = LOG_TARGET_FD;
sk = str2sa_range(args[1], NULL, &port1, &port2, err, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK); sk = str2sa_range(args[1], NULL, &port1, &port2, err, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_RAW_FD | PA_O_DGRAM);
if (!sk) if (!sk)
goto error; goto error;
logsrv->addr = *sk; logsrv->addr = *sk;

View File

@ -659,7 +659,7 @@ static int srv_parse_source(char **args, int *cur_arg,
} }
/* 'sk' is statically allocated (no need to be freed). */ /* '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 | PA_O_PORT_OK | PA_O_PORT_RANGE); 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 | PA_O_STREAM);
if (!sk) { if (!sk) {
memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg); memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg);
goto err; goto err;
@ -744,7 +744,7 @@ static int srv_parse_source(char **args, int *cur_arg,
int port1, port2; int port1, port2;
/* 'sk' is statically allocated (no need to be freed). */ /* '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 | PA_O_PORT_OK); sk = str2sa_range(args[*cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM);
if (!sk) { if (!sk) {
ha_alert("'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg); ha_alert("'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg);
goto err; goto err;
@ -840,7 +840,7 @@ static int srv_parse_socks4(char **args, int *cur_arg,
} }
/* 'sk' is statically allocated (no need to be freed). */ /* '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 | PA_O_PORT_OK | PA_O_PORT_MAND); 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 | PA_O_STREAM);
if (!sk) { if (!sk) {
memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg); memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg);
goto err; goto err;
@ -2027,7 +2027,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
if (!parse_addr) if (!parse_addr)
goto skip_addr; goto skip_addr;
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); 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 | PA_O_STREAM | PA_O_XPRT);
if (!sk) { if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;

View File

@ -2224,7 +2224,7 @@ struct tcpcheck_rule *parse_tcpcheck_connect(char **args, int cur_arg, struct pr
goto error; goto error;
} }
sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK); sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM);
if (!sk) { if (!sk) {
memprintf(errmsg, "'%s' : %s.", args[cur_arg], *errmsg); memprintf(errmsg, "'%s' : %s.", args[cur_arg], *errmsg);
goto error; goto error;