]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock: do not use LI_O_* in xfer_sock_list anymore
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Aug 2020 17:09:19 +0000 (19:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Aug 2020 17:26:38 +0000 (19:26 +0200)
We'll want to store more info there and some info that are not represented
in listener options at the moment (such as dgram vs stream) so let's get
rid of these and instead use a new set of options (SOCK_XFER_OPT_*).

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

index ee803abbdbc1dce59513e37669d34b61116befd3..7d66d198277098490880bb089ef54a0257adabac 100644 (file)
 
 #include <haproxy/api-t.h>
 
+#define SOCK_XFER_OPT_FOREIGN 0x000000001
+#define SOCK_XFER_OPT_V6ONLY  0x000000002
+
 /* The list used to transfer sockets between old and new processes */
 struct xfer_sock_list {
        int fd;
-       int options; /* socket options as LI_O_* */
+       int options; /* socket options as SOCK_XFER_OPT_* */
        char *iface;
        char *namespace;
        int if_namelen;
index b8a729ba62b2897052e3fa650e9b891d5743ac27..894f48506f51350cc3acb1aec4c7f4d7b8080511 100644 (file)
@@ -294,7 +294,7 @@ int sock_get_old_sockets(const char *unixsocket)
 
                /* determine the foreign status directly from the socket itself */
                if (sock_inet_is_foreign(fd, xfer_sock->addr.ss_family))
-                       xfer_sock->options |= LI_O_FOREIGN;
+                       xfer_sock->options |= SOCK_XFER_OPT_FOREIGN;
 
 #if defined(IPV6_V6ONLY)
                /* keep only the v6only flag depending on what's currently
@@ -303,7 +303,7 @@ int sock_get_old_sockets(const char *unixsocket)
                socklen = sizeof(val);
                if (xfer_sock->addr.ss_family == AF_INET6 &&
                    getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, &socklen) == 0 && val > 0)
-                       xfer_sock->options |= LI_O_V6ONLY;
+                       xfer_sock->options |= SOCK_XFER_OPT_V6ONLY;
 #endif
 
                xfer_sock->fd = fd;
@@ -354,7 +354,7 @@ out:
 int sock_find_compatible_fd(const struct listener *l)
 {
        struct xfer_sock_list *xfer_sock = xfer_sock_list;
-       int options = l->options & (LI_O_FOREIGN | LI_O_V6ONLY | LI_O_V4V6);
+       int options = 0;
        int if_namelen = 0;
        int ns_namelen = 0;
        int ret = -1;
@@ -362,17 +362,18 @@ int sock_find_compatible_fd(const struct listener *l)
        if (!l->proto->addrcmp)
                return -1;
 
+       if (l->options & LI_O_FOREIGN)
+               options |= SOCK_XFER_OPT_FOREIGN;
+
        if (l->addr.ss_family == AF_INET6) {
                /* Prepare to match the v6only option against what we really want. Note
                 * that sadly the two options are not exclusive to each other and that
                 * v6only is stronger than v4v6.
                 */
-               if ((options & LI_O_V6ONLY) || (sock_inet6_v6only_default && !(options & LI_O_V4V6)))
-                       options |= LI_O_V6ONLY;
-               else if ((options & LI_O_V4V6) || !sock_inet6_v6only_default)
-                       options &= ~LI_O_V6ONLY;
+               if ((l->options & LI_O_V6ONLY) ||
+                   (sock_inet6_v6only_default && !(l->options & LI_O_V4V6)))
+                       options |= SOCK_XFER_OPT_V6ONLY;
        }
-       options &= ~LI_O_V4V6;
 
        if (l->interface)
                if_namelen = strlen(l->interface);
@@ -382,7 +383,7 @@ int sock_find_compatible_fd(const struct listener *l)
 #endif
 
        while (xfer_sock) {
-               if (((options ^ xfer_sock->options) & (LI_O_FOREIGN | LI_O_V6ONLY)) == 0 &&
+               if ((options == xfer_sock->options) &&
                    (if_namelen == xfer_sock->if_namelen) &&
                    (ns_namelen == xfer_sock->ns_namelen) &&
                    (!if_namelen || strcmp(l->interface, xfer_sock->iface) == 0) &&