]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: add several PA_O_* flags in str2sa_range() callers
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Sep 2020 13:53:16 +0000 (15:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 20:08:08 +0000 (22:08 +0200)
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.

include/haproxy/tools-t.h
src/cfgparse-listen.c
src/cfgparse.c
src/check.c
src/cli.c
src/hlua.c
src/log.c
src/server.c
src/tcpcheck.c

index cb336101a42713ea59b27a3df088fad672967484..3c8091b59ac1e935813874ee9d5f575b02b27944 100644 (file)
 #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
index 72fd3fa6ca16e8c0b1511b16f9b257349ed97ff3..2819ad9e3cd46388e2b330c386e5e1860699750f 100644 (file)
@@ -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);
index 660c308c616a732d1f30739106ab8bd29d0f3047..864c5820e45f4ce15fa5a2ce42368172c6cd0364 100644 (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,
                                   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;
index 423cb4dccc3016653230c4023cccd823efd7ec51..21978da50979f6b6714dfd14231609f285448f4d 100644 (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,
-                         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;
index 977d857102788cc662cc3b75d1bee3d3f1ab2f3d..55d2a034afa58181bbb1f1c9b469d4767a7a8411 100644 (file)
--- 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);
index 331fed97887ce4f5caab27d7e41d890c1abe48a6..b3b93e8d0a62615fe2ab807dc5233777b31204ae 100644 (file)
@@ -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));
index 491b149f66acb013b7b888d5d365ca45891bf684..e31d85b700ef08f41dad9698ab08c8d23631171b 100644 (file)
--- 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;
index c60834538ca7bb18351a17644b2eebfaf9cdde63..5c457186f449fbccadbf2fee67904819a697ebd8 100644 (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 = 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;
index 1663ad83eb8fb76545d473616c0907bbfa8299d5..abd92cf15cb9a6115bab36a5d4c1e11ef37f697c 100644 (file)
@@ -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;