]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: introduce new option PA_O_DEFAULT_DGRAM on str2sa_range.
authorEmeric Brun <ebrun@haproxy.com>
Mon, 22 Mar 2021 16:17:34 +0000 (17:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 23 Mar 2021 14:32:22 +0000 (15:32 +0100)
str2sa_range function options PA_O_DGRAM and PA_O_STREAM are used to
define the supported address types but also to set the default type
if it is not explicit. If the used address support both STREAM and DGRAM,
the default was always set to STREAM.

This patch introduce a new option PA_O_DEFAULT_DGRAM to force the
default to DGRAM type if it is not explicit in the address field
and both STREAM and DGRAM are supported. If only DGRAM or only STREAM
is supported, it continues to be considered as the default.

include/haproxy/tools-t.h
src/tools.c

index 488b90d863dac598619f75300ae8dbf9a36a2b7a..805ade6a3fcec0fad34895594f541f45a0ab8e3f 100644 (file)
 #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_DGRAM              0x00000080   /* the address can be used for a datagram socket (in or out) */
+#define PA_O_STREAM             0x00000100   /* the address can be used for streams (in or out) */
 #define PA_O_XPRT               0x00000200   /* transport protocols may be specified */
 #define PA_O_CONNECT            0x00000400   /* the protocol must have a ->connect method */
+#define PA_O_DEFAULT_DGRAM      0x00000800   /* by default, this address will be used for a datagram socket */
 
 /* UTF-8 decoder status */
 #define UTF8_CODE_OK       0x00
index f39ec1efc7277569d78e4e1c9387e80e3fec22e0..3f3460d3eaeb1f7aad7f0d4288d9b3ec9462f19c 100644 (file)
@@ -910,7 +910,9 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
        memset(&ss, 0, sizeof(ss));
 
        /* prepare the default socket types */
-       if ((opts & (PA_O_STREAM|PA_O_DGRAM)) == PA_O_DGRAM)
+       if (((opts & (PA_O_STREAM|PA_O_DGRAM)) == PA_O_DGRAM))
+           || (((opts & (PA_O_STREAM|PA_O_DGRAM)) == (PA_O_DGRAM|PA_O_STREAM))
+               && (opts & PA_O_DEFAULT_DGRAM))
                sock_type = ctrl_type = SOCK_DGRAM;
        else
                sock_type = ctrl_type = SOCK_STREAM;