mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-02-27 04:01:45 +01:00
MINOR: listener: prefer to retrieve the socket's settings via the receiver
Some socket settings used to be retrieved via the listener and the bind_conf. Now instead we use the receiver and its settings whenever appropriate. This will simplify the removal of the dependency on the listener.
This commit is contained in:
parent
eef454224d
commit
818a92e87a
10
src/cli.c
10
src/cli.c
@ -1710,15 +1710,15 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
|
||||
if (fdtab[cur_fd].iocb == listener_accept) {
|
||||
const struct listener *l = fdtab[cur_fd].owner;
|
||||
|
||||
if (l->bind_conf->settings.interface) {
|
||||
if_name = l->bind_conf->settings.interface;
|
||||
if (l->rx.settings->interface) {
|
||||
if_name = l->rx.settings->interface;
|
||||
if_nlen = strlen(if_name);
|
||||
}
|
||||
|
||||
#ifdef USE_NS
|
||||
if (l->bind_conf->settings.netns) {
|
||||
ns_name = l->bind_conf->settings.netns->node.key;
|
||||
ns_nlen = l->bind_conf->settings.netns->name_len;
|
||||
if (l->rx.settings->netns) {
|
||||
ns_name = l->rx.settings->netns->node.key;
|
||||
ns_nlen = l->rx.settings->netns->name_len;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ static void enable_listener(struct listener *listener)
|
||||
HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
|
||||
if (listener->state == LI_LISTEN) {
|
||||
if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
|
||||
!(proc_mask(listener->bind_conf->settings.bind_proc) & pid_bit)) {
|
||||
!(proc_mask(listener->rx.settings->bind_proc) & pid_bit)) {
|
||||
/* we don't want to enable this listener and don't
|
||||
* want any fd event to reach it.
|
||||
*/
|
||||
@ -342,7 +342,7 @@ int resume_listener(struct listener *l)
|
||||
goto end;
|
||||
|
||||
if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
|
||||
!(proc_mask(l->bind_conf->settings.bind_proc) & pid_bit))
|
||||
!(proc_mask(l->rx.settings->bind_proc) & pid_bit))
|
||||
goto end;
|
||||
|
||||
if (l->state == LI_ASSIGNED) {
|
||||
@ -383,11 +383,11 @@ int resume_listener(struct listener *l)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(thread_mask(l->bind_conf->settings.bind_thread) & tid_bit)) {
|
||||
if (!(thread_mask(l->rx.settings->bind_thread) & tid_bit)) {
|
||||
/* we're not allowed to touch this listener's FD, let's requeue
|
||||
* the listener into one of its owning thread's queue instead.
|
||||
*/
|
||||
int first_thread = my_flsl(thread_mask(l->bind_conf->settings.bind_thread) & all_threads_mask) - 1;
|
||||
int first_thread = my_flsl(thread_mask(l->rx.settings->bind_thread) & all_threads_mask) - 1;
|
||||
work_list_add(&local_listener_queue[first_thread], &l->wait_queue);
|
||||
goto end;
|
||||
}
|
||||
@ -875,7 +875,7 @@ void listener_accept(int fd)
|
||||
next_actconn = 0;
|
||||
|
||||
#if defined(USE_THREAD)
|
||||
mask = thread_mask(l->bind_conf->settings.bind_thread) & all_threads_mask;
|
||||
mask = thread_mask(l->rx.settings->bind_thread) & all_threads_mask;
|
||||
if (atleast2(mask) && (global.tune.options & GTUNE_LISTENER_MQ) && !stopping) {
|
||||
struct accept_queue_ring *ring;
|
||||
unsigned int t, t0, t1, t2;
|
||||
|
||||
@ -126,7 +126,7 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e
|
||||
listener->state = LI_LISTEN;
|
||||
|
||||
fd_insert(fd, listener, listener->rx.proto->accept,
|
||||
thread_mask(listener->bind_conf->settings.bind_thread) & all_threads_mask);
|
||||
thread_mask(listener->rx.settings->bind_thread) & all_threads_mask);
|
||||
|
||||
return err;
|
||||
|
||||
|
||||
@ -581,7 +581,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
ext = (fd >= 0);
|
||||
|
||||
if (!ext) {
|
||||
fd = my_socketat(listener->bind_conf->settings.netns, listener->rx.addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
fd = my_socketat(listener->rx.settings->netns, listener->rx.addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if (fd == -1) {
|
||||
err |= ERR_RETRYABLE | ERR_ALERT;
|
||||
@ -649,10 +649,10 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
|
||||
#ifdef SO_BINDTODEVICE
|
||||
/* Note: this might fail if not CAP_NET_RAW */
|
||||
if (!ext && listener->bind_conf->settings.interface) {
|
||||
if (!ext && listener->rx.settings->interface) {
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
listener->bind_conf->settings.interface,
|
||||
strlen(listener->bind_conf->settings.interface) + 1) == -1) {
|
||||
listener->rx.settings->interface,
|
||||
strlen(listener->rx.settings->interface) + 1) == -1) {
|
||||
msg = "cannot bind listener to device";
|
||||
err |= ERR_WARN;
|
||||
}
|
||||
@ -769,7 +769,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
listener->state = LI_LISTEN;
|
||||
|
||||
fd_insert(fd, listener, listener->rx.proto->accept,
|
||||
thread_mask(listener->bind_conf->settings.bind_thread) & all_threads_mask);
|
||||
thread_mask(listener->rx.settings->bind_thread) & all_threads_mask);
|
||||
|
||||
/* for now, all regularly bound TCP listeners are exportable */
|
||||
if (!(listener->options & LI_O_INHERITED))
|
||||
|
||||
@ -200,7 +200,7 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
* IPPROTO (sockaddr is not enough)
|
||||
*/
|
||||
|
||||
fd = my_socketat(listener->bind_conf->settings.netns,
|
||||
fd = my_socketat(listener->rx.settings->netns,
|
||||
listener->rx.proto->sock_family,
|
||||
listener->rx.proto->sock_type,
|
||||
listener->rx.proto->sock_prot);
|
||||
@ -255,10 +255,10 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
|
||||
#ifdef SO_BINDTODEVICE
|
||||
/* Note: this might fail if not CAP_NET_RAW */
|
||||
if (listener->bind_conf->settings.interface) {
|
||||
if (listener->rx.settings->interface) {
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
listener->bind_conf->settings.interface,
|
||||
strlen(listener->bind_conf->settings.interface) + 1) == -1) {
|
||||
listener->rx.settings->interface,
|
||||
strlen(listener->rx.settings->interface) + 1) == -1) {
|
||||
msg = "cannot bind listener to device";
|
||||
err |= ERR_WARN;
|
||||
}
|
||||
@ -283,7 +283,7 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
|
||||
if (listener->bind_conf->frontend->mode == PR_MODE_SYSLOG)
|
||||
fd_insert(fd, listener, syslog_fd_handler,
|
||||
thread_mask(listener->bind_conf->settings.bind_thread) & all_threads_mask);
|
||||
thread_mask(listener->rx.settings->bind_thread) & all_threads_mask);
|
||||
else {
|
||||
err |= ERR_FATAL | ERR_ALERT;
|
||||
msg = "UDP is not yet supported on this proxy mode";
|
||||
|
||||
@ -223,9 +223,9 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
||||
* where it works. We also don't change permissions on abstract sockets.
|
||||
*/
|
||||
if (!ext && path[0] &&
|
||||
(((listener->bind_conf->settings.ux.uid != -1 || listener->bind_conf->settings.ux.gid != -1) &&
|
||||
(chown(tempname, listener->bind_conf->settings.ux.uid, listener->bind_conf->settings.ux.gid) == -1)) ||
|
||||
(listener->bind_conf->settings.ux.mode != 0 && chmod(tempname, listener->bind_conf->settings.ux.mode) == -1))) {
|
||||
(((listener->rx.settings->ux.uid != -1 || listener->rx.settings->ux.gid != -1) &&
|
||||
(chown(tempname, listener->rx.settings->ux.uid, listener->rx.settings->ux.gid) == -1)) ||
|
||||
(listener->rx.settings->ux.mode != 0 && chmod(tempname, listener->rx.settings->ux.mode) == -1))) {
|
||||
err |= ERR_FATAL | ERR_ALERT;
|
||||
msg = "cannot change UNIX socket ownership";
|
||||
goto err_unlink_temp;
|
||||
@ -262,7 +262,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
||||
listener->state = LI_LISTEN;
|
||||
|
||||
fd_insert(fd, listener, listener->rx.proto->accept,
|
||||
thread_mask(listener->bind_conf->settings.bind_thread) & all_threads_mask);
|
||||
thread_mask(listener->rx.settings->bind_thread) & all_threads_mask);
|
||||
|
||||
/* for now, all regularly bound UNIX listeners are exportable */
|
||||
if (!(listener->options & LI_O_INHERITED))
|
||||
|
||||
@ -153,7 +153,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
|
||||
cli_conn->handle.fd = cfd;
|
||||
*cli_conn->src = *addr;
|
||||
cli_conn->flags |= CO_FL_ADDR_FROM_SET;
|
||||
cli_conn->proxy_netns = l->bind_conf->settings.netns;
|
||||
cli_conn->proxy_netns = l->rx.settings->netns;
|
||||
|
||||
conn_prepare(cli_conn, l->rx.proto, l->bind_conf->xprt);
|
||||
conn_ctrl_init(cli_conn);
|
||||
|
||||
12
src/sock.c
12
src/sock.c
@ -382,20 +382,20 @@ int sock_find_compatible_fd(const struct listener *l)
|
||||
options |= SOCK_XFER_OPT_V6ONLY;
|
||||
}
|
||||
|
||||
if (l->bind_conf->settings.interface)
|
||||
if_namelen = strlen(l->bind_conf->settings.interface);
|
||||
if (l->rx.settings->interface)
|
||||
if_namelen = strlen(l->rx.settings->interface);
|
||||
#ifdef USE_NS
|
||||
if (l->bind_conf->settings.netns)
|
||||
ns_namelen = l->bind_conf->settings.netns->name_len;
|
||||
if (l->rx.settings->netns)
|
||||
ns_namelen = l->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->bind_conf->settings.interface, xfer_sock->iface) == 0) &&
|
||||
(!if_namelen || strcmp(l->rx.settings->interface, xfer_sock->iface) == 0) &&
|
||||
#ifdef USE_NS
|
||||
(!ns_namelen || strcmp(l->bind_conf->settings.netns->node.key, xfer_sock->namespace) == 0) &&
|
||||
(!ns_namelen || strcmp(l->rx.settings->netns->node.key, xfer_sock->namespace) == 0) &&
|
||||
#endif
|
||||
l->rx.proto->addrcmp(&xfer_sock->addr, &l->rx.addr) == 0)
|
||||
break;
|
||||
|
||||
@ -137,7 +137,7 @@ int smp_fetch_dst_is_local(const struct arg *args, struct sample *smp, const cha
|
||||
|
||||
smp->data.type = SMP_T_BOOL;
|
||||
smp->flags = 0;
|
||||
smp->data.u.sint = addr_is_local(li->bind_conf->settings.netns, conn->dst);
|
||||
smp->data.u.sint = addr_is_local(li->rx.settings->netns, conn->dst);
|
||||
return smp->data.u.sint >= 0;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ int smp_fetch_src_is_local(const struct arg *args, struct sample *smp, const cha
|
||||
|
||||
smp->data.type = SMP_T_BOOL;
|
||||
smp->flags = 0;
|
||||
smp->data.u.sint = addr_is_local(li->bind_conf->settings.netns, conn->src);
|
||||
smp->data.u.sint = addr_is_local(li->rx.settings->netns, conn->src);
|
||||
return smp->data.u.sint >= 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user