]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock: distinguish dgram from stream types when retrieving old sockets
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Aug 2020 17:20:23 +0000 (19:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Aug 2020 17:26:39 +0000 (19:26 +0200)
For now we still don't retrieve dgram sockets, but the code must be able
to distinguish them before we switch to receivers. This adds a new flag
to the xfer_sock_list indicating that a socket is of type SOCK_DGRAM. The
way to set the flag for now is by looking at the dummy address family which
equals AF_CUST_UDP{4,6} in this case (given that other dgram sockets are not
yet supported).

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

index 7d66d198277098490880bb089ef54a0257adabac..1a49dfa44460b2d018a6b2ab86fb70ee4d1551dd 100644 (file)
@@ -29,6 +29,7 @@
 
 #define SOCK_XFER_OPT_FOREIGN 0x000000001
 #define SOCK_XFER_OPT_V6ONLY  0x000000002
+#define SOCK_XFER_OPT_DGRAM   0x000000004
 
 /* The list used to transfer sockets between old and new processes */
 struct xfer_sock_list {
index 894f48506f51350cc3acb1aec4c7f4d7b8080511..1614d954271554fee78bf03c8ad3236fe8edb806 100644 (file)
@@ -296,6 +296,10 @@ int sock_get_old_sockets(const char *unixsocket)
                if (sock_inet_is_foreign(fd, xfer_sock->addr.ss_family))
                        xfer_sock->options |= SOCK_XFER_OPT_FOREIGN;
 
+               socklen = sizeof(val);
+               if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &val, &socklen) == 0 && val == SOCK_DGRAM)
+                       xfer_sock->options |= SOCK_XFER_OPT_DGRAM;
+
 #if defined(IPV6_V6ONLY)
                /* keep only the v6only flag depending on what's currently
                 * active on the socket, and always drop the v4v6 one.
@@ -362,6 +366,12 @@ int sock_find_compatible_fd(const struct listener *l)
        if (!l->proto->addrcmp)
                return -1;
 
+       /* WT: this is not the right way to do it, it is temporary for the
+        *     transition to receivers.
+        */
+       if (l->addr.ss_family == AF_CUST_UDP4 || l->addr.ss_family == AF_CUST_UDP6)
+               options |= SOCK_XFER_OPT_DGRAM;
+
        if (l->options & LI_O_FOREIGN)
                options |= SOCK_XFER_OPT_FOREIGN;