MINOR: sock: make sock_find_compatible_fd() only take a receiver

We don't need to have a listener anymore to find an fd, a receiver with
its settings properly set is enough now.
This commit is contained in:
Willy Tarreau 2020-09-01 15:20:52 +02:00
parent 3fd3bdc836
commit c049c0d5ad
4 changed files with 18 additions and 18 deletions

View 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_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_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
int sock_get_old_sockets(const char *unixsocket); 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 */ #endif /* _HAPROXY_SOCK_H */

View File

@ -573,7 +573,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
goto bound; goto bound;
if (listener->rx.fd == -1) 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 /* 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 * fd by an external process (most likely the parent), and we don't want

View File

@ -113,7 +113,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
goto bound; goto bound;
if (listener->rx.fd == -1) 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; path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path;
maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path)); maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path));

View File

@ -347,7 +347,7 @@ out:
return (ret2); 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 * 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 * 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 * 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 * socket is automatically removed from the list so that it's not proposed
* anymore. * 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; struct xfer_sock_list *xfer_sock = xfer_sock_list;
int options = 0; int options = 0;
@ -363,41 +363,41 @@ int sock_find_compatible_fd(const struct listener *l)
int ns_namelen = 0; int ns_namelen = 0;
int ret = -1; int ret = -1;
if (!l->rx.proto->addrcmp) if (!rx->proto->addrcmp)
return -1; return -1;
if (l->rx.proto->sock_type == SOCK_DGRAM) if (rx->proto->sock_type == SOCK_DGRAM)
options |= SOCK_XFER_OPT_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; 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 /* 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 * that sadly the two options are not exclusive to each other and that
* v6only is stronger than v4v6. * v6only is stronger than v4v6.
*/ */
if ((l->rx.settings->options & RX_O_V6ONLY) || if ((rx->settings->options & RX_O_V6ONLY) ||
(sock_inet6_v6only_default && !(l->rx.settings->options & RX_O_V4V6))) (sock_inet6_v6only_default && !(rx->settings->options & RX_O_V4V6)))
options |= SOCK_XFER_OPT_V6ONLY; options |= SOCK_XFER_OPT_V6ONLY;
} }
if (l->rx.settings->interface) if (rx->settings->interface)
if_namelen = strlen(l->rx.settings->interface); if_namelen = strlen(rx->settings->interface);
#ifdef USE_NS #ifdef USE_NS
if (l->rx.settings->netns) if (rx->settings->netns)
ns_namelen = l->rx.settings->netns->name_len; ns_namelen = rx->settings->netns->name_len;
#endif #endif
while (xfer_sock) { while (xfer_sock) {
if ((options == xfer_sock->options) && if ((options == xfer_sock->options) &&
(if_namelen == xfer_sock->if_namelen) && (if_namelen == xfer_sock->if_namelen) &&
(ns_namelen == xfer_sock->ns_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 #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 #endif
l->rx.proto->addrcmp(&xfer_sock->addr, &l->rx.addr) == 0) rx->proto->addrcmp(&xfer_sock->addr, &rx->addr) == 0)
break; break;
xfer_sock = xfer_sock->next; xfer_sock = xfer_sock->next;
} }