]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock: make sock_find_compatible_fd() only take a receiver
authorWilly Tarreau <w@1wt.eu>
Tue, 1 Sep 2020 13:20:52 +0000 (15:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 20:08:07 +0000 (22:08 +0200)
We don't need to have a listener anymore to find an fd, a receiver with
its settings properly set is enough now.

include/haproxy/sock.h
src/proto_tcp.c
src/proto_uxst.c
src/sock.c

index c106ffde486b135c2cabfcd4da0fea0372664500..90dbc07ca1c84ea620f11c01151ec4ec14914dba 100644 (file)
@@ -36,7 +36,7 @@ int sock_create_server_socket(struct connection *conn);
 int sock_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
 int sock_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
 int sock_get_old_sockets(const char *unixsocket);
-int sock_find_compatible_fd(const struct listener *l);
+int sock_find_compatible_fd(const struct receiver *rx);
 
 #endif /* _HAPROXY_SOCK_H */
 
index a842e61b8e2ad360fe16de3fe6d5e761877b2824..258a72ddc69ff04abd1763e1f22d37c34cd36c78 100644 (file)
@@ -573,7 +573,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
                goto bound;
 
        if (listener->rx.fd == -1)
-               listener->rx.fd = sock_find_compatible_fd(listener);
+               listener->rx.fd = sock_find_compatible_fd(&listener->rx);
 
        /* if the listener already has an fd assigned, then we were offered the
         * fd by an external process (most likely the parent), and we don't want
index 5cabea226a26b839c3b5186c0ddb5d0a9a55c577..6691e85ab17a34cd99200ded0f42d047235d72ca 100644 (file)
@@ -113,7 +113,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
                goto bound;
 
        if (listener->rx.fd == -1)
-               listener->rx.fd = sock_find_compatible_fd(listener);
+               listener->rx.fd = sock_find_compatible_fd(&listener->rx);
        path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path;
 
        maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path));
index 4077d69a3f1f8d5c30b59c10341c1cc254e8f15c..9431e758253742ef0af5fa132a217162369287a8 100644 (file)
@@ -347,7 +347,7 @@ out:
        return (ret2);
 }
 
-/* When binding the listeners, check if a socket has been sent to us by the
+/* When binding the receivers, check if a socket has been sent to us by the
  * previous process that we could reuse, instead of creating a new one. Note
  * that some address family-specific options are checked on the listener and
  * on the socket. Typically for AF_INET and AF_INET6, we check for transparent
@@ -355,7 +355,7 @@ out:
  * socket is automatically removed from the list so that it's not proposed
  * anymore.
  */
-int sock_find_compatible_fd(const struct listener *l)
+int sock_find_compatible_fd(const struct receiver *rx)
 {
        struct xfer_sock_list *xfer_sock = xfer_sock_list;
        int options = 0;
@@ -363,41 +363,41 @@ int sock_find_compatible_fd(const struct listener *l)
        int ns_namelen = 0;
        int ret = -1;
 
-       if (!l->rx.proto->addrcmp)
+       if (!rx->proto->addrcmp)
                return -1;
 
-       if (l->rx.proto->sock_type == SOCK_DGRAM)
+       if (rx->proto->sock_type == SOCK_DGRAM)
                options |= SOCK_XFER_OPT_DGRAM;
 
-       if (l->rx.settings->options & RX_O_FOREIGN)
+       if (rx->settings->options & RX_O_FOREIGN)
                options |= SOCK_XFER_OPT_FOREIGN;
 
-       if (l->rx.addr.ss_family == AF_INET6) {
+       if (rx->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 ((l->rx.settings->options & RX_O_V6ONLY) ||
-                   (sock_inet6_v6only_default && !(l->rx.settings->options & RX_O_V4V6)))
+               if ((rx->settings->options & RX_O_V6ONLY) ||
+                   (sock_inet6_v6only_default && !(rx->settings->options & RX_O_V4V6)))
                        options |= SOCK_XFER_OPT_V6ONLY;
        }
 
-       if (l->rx.settings->interface)
-               if_namelen = strlen(l->rx.settings->interface);
+       if (rx->settings->interface)
+               if_namelen = strlen(rx->settings->interface);
 #ifdef USE_NS
-       if (l->rx.settings->netns)
-               ns_namelen = l->rx.settings->netns->name_len;
+       if (rx->settings->netns)
+               ns_namelen = rx->settings->netns->name_len;
 #endif
 
        while (xfer_sock) {
                if ((options == xfer_sock->options) &&
                    (if_namelen == xfer_sock->if_namelen) &&
                    (ns_namelen == xfer_sock->ns_namelen) &&
-                   (!if_namelen || strcmp(l->rx.settings->interface, xfer_sock->iface) == 0) &&
+                   (!if_namelen || strcmp(rx->settings->interface, xfer_sock->iface) == 0) &&
 #ifdef USE_NS
-                   (!ns_namelen || strcmp(l->rx.settings->netns->node.key, xfer_sock->namespace) == 0) &&
+                   (!ns_namelen || strcmp(rx->settings->netns->node.key, xfer_sock->namespace) == 0) &&
 #endif
-                   l->rx.proto->addrcmp(&xfer_sock->addr, &l->rx.addr) == 0)
+                   rx->proto->addrcmp(&xfer_sock->addr, &rx->addr) == 0)
                        break;
                xfer_sock = xfer_sock->next;
        }