From: Willy Tarreau Date: Fri, 4 Sep 2020 13:53:16 +0000 (+0200) Subject: MINOR: tools: add several PA_O_* flags in str2sa_range() callers X-Git-Tag: v2.3-dev5~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=328199348b4b968c988065f0bba4e07b66ed74d2;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/tools-t.h b/include/haproxy/tools-t.h index cb336101a4..3c8091b59a 100644 --- a/include/haproxy/tools-t.h +++ b/include/haproxy/tools-t.h @@ -91,6 +91,11 @@ #define PA_O_PORT_MAND 0x00000004 /* ports are mandatory */ #define PA_O_PORT_RANGE 0x00000008 /* port ranges 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 */ #define UTF8_CODE_OK 0x00 diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 72fd3fa6ca..2819ad9e3c 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -2600,7 +2600,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], 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) { ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); err_code |= ERR_ALERT | ERR_FATAL; @@ -2858,7 +2858,7 @@ stats_error_parsing: curproxy->conn_src.iface_name = NULL; 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) { ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); @@ -2936,7 +2936,7 @@ stats_error_parsing: } else { 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) { 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 660c308c61..864c5820e4 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -129,7 +129,8 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, ss2 = str2sa_range(str, NULL, &port, &end, err, 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) goto fail; @@ -1011,7 +1012,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], 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) { ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); 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]); - 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) { 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 423cb4dccc..21978da509 100644 --- a/src/check.c +++ b/src/check.c @@ -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, - PA_O_RESOLVE | PA_O_PORT_OK); + PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM); if (!sk) { memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg); goto error; diff --git a/src/cli.c b/src/cli.c index 977d857102..55d2a034af 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2475,7 +2475,7 @@ int mworker_cli_proxy_create() newsrv->conf.line = 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; } free(msg); diff --git a/src/hlua.c b/src/hlua.c index 331fed9788..b3b93e8d0a 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2534,7 +2534,7 @@ __LJMP static int hlua_socket_connect(struct lua_State *L) } /* 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) { xref_unlock(&socket->xref, peer); WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip)); diff --git a/src/log.c b/src/log.c index 491b149f66..e31d85b700 100644 --- a/src/log.c +++ b/src/log.c @@ -1021,7 +1021,7 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err) if (strncmp(args[1], "fd@", 3) == 0) 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) goto error; logsrv->addr = *sk; diff --git a/src/server.c b/src/server.c index c60834538c..5c457186f4 100644 --- a/src/server.c +++ b/src/server.c @@ -659,7 +659,7 @@ static int srv_parse_source(char **args, int *cur_arg, } /* '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) { memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg); goto err; @@ -744,7 +744,7 @@ static int srv_parse_source(char **args, int *cur_arg, 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, 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) { ha_alert("'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg); 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 = 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) { memprintf(err, "'%s %s' : %s\n", args[*cur_arg], args[*cur_arg + 1], errmsg); goto err; @@ -2027,7 +2027,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr if (!parse_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) { 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 1663ad83eb..abd92cf15c 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -2224,7 +2224,7 @@ struct tcpcheck_rule *parse_tcpcheck_connect(char **args, int cur_arg, struct pr 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) { memprintf(errmsg, "'%s' : %s.", args[cur_arg], *errmsg); goto error;