diff options
author | Willy Tarreau <w@1wt.eu> | 2020-08-27 08:16:52 +0200 |
---|---|---|
committer | Willy Tarreau <w@1wt.eu> | 2020-09-01 09:58:05 +0200 |
commit | 2ba70568955a6f12b351f33774044d40ef646321 (patch) | |
tree | 8f2d79427832880279c319877af919f1ab0f9d2d | |
parent | 50c11c1ed8dfed4482eafc01a7cc075a87024794 (diff) | |
download | haproxy-2ba70568955a6f12b351f33774044d40ef646321.tar.gz |
REORG: listeners: move the receiving FD to struct receiver
The listening socket is represented by its file descriptor, which is
generic to all receivers and not just listeners, so it must move to
the rx struct.
It's worth noting that in order to extend receivers and listeners to
other protocols such as QUIC, we'll need other handles than file
descriptors here, and that either a union or a cast to uintptr_t
will have to be used. This was not done yet and the field was
preserved under the name "fd" to avoid adding confusion.
-rw-r--r-- | include/haproxy/listener-t.h | 3 | ||||
-rw-r--r-- | src/frontend.c | 6 | ||||
-rw-r--r-- | src/haproxy.c | 2 | ||||
-rw-r--r-- | src/listener.c | 26 | ||||
-rw-r--r-- | src/proto_sockpair.c | 4 | ||||
-rw-r--r-- | src/proto_tcp.c | 14 | ||||
-rw-r--r-- | src/proto_udp.c | 2 | ||||
-rw-r--r-- | src/proto_uxst.c | 9 | ||||
-rw-r--r-- | src/proxy.c | 2 |
9 files changed, 33 insertions, 35 deletions
diff --git a/include/haproxy/listener-t.h b/include/haproxy/listener-t.h index 16e5bc082..c13499df0 100644 --- a/include/haproxy/listener-t.h +++ b/include/haproxy/listener-t.h @@ -189,8 +189,8 @@ struct bind_conf { /* This describes a receiver with all its characteristics (address, options, etc) */ struct receiver { + int fd; /* handle we receive from (fd only for now) */ int options; /* receiver options (RX_O_*) */ - char *interface; /* interface name or NULL */ const struct netns_entry *netns; /* network namespace of the receiving socket */ /* warning: this struct is huge, keep it at the bottom */ @@ -205,7 +205,6 @@ struct listener { enum obj_type obj_type; /* object type = OBJ_TYPE_LISTENER */ enum li_state state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */ short int nice; /* nice value to assign to the instantiated tasks */ - int fd; /* the listen socket */ int luid; /* listener universally unique ID, used for SNMP */ int options; /* socket options : LI_O_* */ struct fe_counters *counters; /* statistics counters */ diff --git a/src/frontend.c b/src/frontend.c index 5658a5f58..3da48f2a4 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -111,20 +111,20 @@ int frontend_accept(struct stream *s) if (!conn_get_src(conn)) { chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n", - s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd, + s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, l->luid, alpn); } else switch (addr_to_str(conn->src, pn, sizeof(pn))) { case AF_INET: case AF_INET6: chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n", - s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd, + s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, pn, get_host_port(conn->src), alpn); break; case AF_UNIX: /* UNIX socket, only the destination is known */ chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d] ALPN=%s\n", - s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd, + s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, l->luid, alpn); break; } diff --git a/src/haproxy.c b/src/haproxy.c index e2bb99d75..969c9ad25 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2588,7 +2588,7 @@ void deinit(void) * Close it and give the listener its real state. */ if (p->state == PR_STSTOPPED && l->state >= LI_ZOMBIE) { - close(l->fd); + close(l->rx.fd); l->state = LI_INIT; } unbind_listener(l); diff --git a/src/listener.c b/src/listener.c index d23f4f83a..5317ca30c 100644 --- a/src/listener.c +++ b/src/listener.c @@ -247,7 +247,7 @@ static void enable_listener(struct listener *listener) } } else if (!listener->maxconn || listener->nbconn < listener->maxconn) { - fd_want_recv(listener->fd); + fd_want_recv(listener->rx.fd); listener->state = LI_READY; } else { @@ -273,7 +273,7 @@ static void disable_listener(struct listener *listener) if (listener->state < LI_READY) goto end; if (listener->state == LI_READY) - fd_stop_recv(listener->fd); + fd_stop_recv(listener->rx.fd); MT_LIST_DEL(&listener->wait_queue); listener->state = LI_LISTEN; end: @@ -312,7 +312,7 @@ int pause_listener(struct listener *l) MT_LIST_DEL(&l->wait_queue); - fd_stop_recv(l->fd); + fd_stop_recv(l->rx.fd); l->state = LI_PAUSED; end: HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock); @@ -368,7 +368,7 @@ int resume_listener(struct listener *l) if (l->proto->sock_prot == IPPROTO_TCP && l->state == LI_PAUSED && - listen(l->fd, listener_backlog(l)) != 0) { + listen(l->rx.fd, listener_backlog(l)) != 0) { ret = 0; goto end; } @@ -392,7 +392,7 @@ int resume_listener(struct listener *l) goto end; } - fd_want_recv(l->fd); + fd_want_recv(l->rx.fd); l->state = LI_READY; end: HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock); @@ -408,7 +408,7 @@ static void listener_full(struct listener *l) if (l->state >= LI_READY) { MT_LIST_DEL(&l->wait_queue); if (l->state != LI_FULL) { - fd_stop_recv(l->fd); + fd_stop_recv(l->rx.fd); l->state = LI_FULL; } } @@ -423,7 +423,7 @@ static void limit_listener(struct listener *l, struct mt_list *list) HA_SPIN_LOCK(LISTENER_LOCK, &l->lock); if (l->state == LI_READY) { MT_LIST_TRY_ADDQ(list, &l->wait_queue); - fd_stop_recv(l->fd); + fd_stop_recv(l->rx.fd); l->state = LI_LIMITED; } HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock); @@ -496,16 +496,16 @@ void dequeue_proxy_listeners(struct proxy *px) void do_unbind_listener(struct listener *listener, int do_close) { if (listener->state == LI_READY && fd_updt) - fd_stop_recv(listener->fd); + fd_stop_recv(listener->rx.fd); MT_LIST_DEL(&listener->wait_queue); if (listener->state >= LI_PAUSED) { listener->state = LI_ASSIGNED; - fd_stop_both(listener->fd); + fd_stop_both(listener->rx.fd); if (do_close) { - fd_delete(listener->fd); - listener->fd = -1; + fd_delete(listener->rx.fd); + listener->rx.fd = -1; } } } @@ -580,7 +580,7 @@ int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss, LIST_ADDQ(&bc->listeners, &l->by_bind); l->bind_conf = bc; - l->fd = fd; + l->rx.fd = fd; memcpy(&l->rx.addr, ss, sizeof(*ss)); MT_LIST_INIT(&l->wait_queue); l->state = LI_INIT; @@ -1075,7 +1075,7 @@ void listener_accept(int fd) else fd_done_recv(fd); } else if (l->state > LI_ASSIGNED) { - fd_stop_recv(l->fd); + fd_stop_recv(l->rx.fd); } HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock); return; diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index 835ce8fe0..85705971b 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -119,7 +119,7 @@ static int sockpair_bind_listeners(struct protocol *proto, char *errmsg, int err */ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen) { - int fd = listener->fd; + int fd = listener->rx.fd; int err; const char *msg = NULL; @@ -132,7 +132,7 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e if (listener->state != LI_ASSIGNED) return ERR_NONE; /* already bound */ - if (listener->fd == -1) { + if (listener->rx.fd == -1) { err |= ERR_FATAL | ERR_ALERT; msg = "sockpair can be only used with inherited FDs"; goto err_return; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index d95ec5f7e..aef168a06 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -574,15 +574,15 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) err = ERR_NONE; - if (listener->fd == -1) - listener->fd = sock_find_compatible_fd(listener); + if (listener->rx.fd == -1) + listener->rx.fd = sock_find_compatible_fd(listener); /* 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 * to create a new socket. However we still want to set a few flags on * the socket. */ - fd = listener->fd; + fd = listener->rx.fd; ext = (fd >= 0); if (!ext) { @@ -769,7 +769,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) #endif /* the socket is ready */ - listener->fd = fd; + listener->rx.fd = fd; listener->state = LI_LISTEN; fd_insert(fd, listener, listener->proto->accept, @@ -857,13 +857,13 @@ static void tcpv6_add_listener(struct listener *listener, int port) */ int tcp_pause_listener(struct listener *l) { - if (shutdown(l->fd, SHUT_WR) != 0) + if (shutdown(l->rx.fd, SHUT_WR) != 0) return -1; /* Solaris dies here */ - if (listen(l->fd, listener_backlog(l)) != 0) + if (listen(l->rx.fd, listener_backlog(l)) != 0) return -1; /* OpenBSD dies here */ - if (shutdown(l->fd, SHUT_RD) != 0) + if (shutdown(l->rx.fd, SHUT_RD) != 0) return -1; /* should always be OK */ return 1; } diff --git a/src/proto_udp.c b/src/proto_udp.c index db058ccb9..3aec94c68 100644 --- a/src/proto_udp.c +++ b/src/proto_udp.c @@ -279,7 +279,7 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen) } /* the socket is ready */ - listener->fd = fd; + listener->rx.fd = fd; listener->state = LI_LISTEN; if (listener->bind_conf->frontend->mode == PR_MODE_SYSLOG) diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 2c65fb484..3d078e018 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -113,9 +113,8 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle if (listener->state != LI_ASSIGNED) return ERR_NONE; /* already bound */ - if (listener->fd == -1) - listener->fd = sock_find_compatible_fd(listener); - + if (listener->rx.fd == -1) + listener->rx.fd = sock_find_compatible_fd(listener); path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path; maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path)); @@ -125,7 +124,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle * to create a new socket. However we still want to set a few flags on * the socket. */ - fd = listener->fd; + fd = listener->rx.fd; ext = (fd >= 0); if (ext) goto fd_ready; @@ -263,7 +262,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle unlink(backname); /* the socket is now listening */ - listener->fd = fd; + listener->rx.fd = fd; listener->state = LI_LISTEN; fd_insert(fd, listener, listener->proto->accept, diff --git a/src/proxy.c b/src/proxy.c index c2d90b9cb..561107b7e 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1292,7 +1292,7 @@ void soft_stop(void) struct listener *l; list_for_each_entry(l, &p->conf.listeners, by_fe) { if (l->state > LI_ASSIGNED) - close(l->fd); + close(l->rx.fd); l->state = LI_INIT; } } |