summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2020-09-25 19:27:39 +0200
committerWilly Tarreau <w@1wt.eu>2020-10-07 19:38:05 +0200
commitd1b13e776c41c0bb800e2cbb641a2f422de76544 (patch)
treebcea502b7667ebfe45884f6b0412925e39ec4fb6
parent4b81e9cfaf825d1ede997108cf983f64556d4414 (diff)
downloadhaproxy-d1b13e776c41c0bb800e2cbb641a2f422de76544.tar.gz
MINOR: protocol: add a new pair of enable/disable methods for listeners
These methods will be used to enable/disable accepting new connections so that listeners do not play with FD directly anymore. Since all the currently supported protocols work on socket for now, these are identical to the rx_enable/rx_disable functions. However they were not defined in sock.c since it's likely that some will quickly start to differ. At the moment they're not used. We have to take care of fd_updt before calling fd_{want,stop}_recv() because it's allocated fairly late in the boot process and some such functions may be called very early (e.g. to stop a disabled frontend's listeners).
-rw-r--r--include/haproxy/protocol-t.h2
-rw-r--r--src/proto_sockpair.c22
-rw-r--r--src/proto_tcp.c24
-rw-r--r--src/proto_udp.c24
-rw-r--r--src/proto_uxst.c22
5 files changed, 94 insertions, 0 deletions
diff --git a/include/haproxy/protocol-t.h b/include/haproxy/protocol-t.h
index fbd84193d..c5b93ed2a 100644
--- a/include/haproxy/protocol-t.h
+++ b/include/haproxy/protocol-t.h
@@ -89,6 +89,8 @@ struct protocol {
/* functions acting on the listener */
void (*add)(struct listener *l, int port); /* add a listener for this protocol and port */
int (*listen)(struct listener *l, char *errmsg, int errlen); /* start a listener */
+ void (*enable)(struct listener *l); /* enable receipt of new connections */
+ void (*disable)(struct listener *l); /* disable receipt of new connections */
/* functions acting on the receiver */
void (*rx_enable)(struct receiver *rx); /* enable receiving on the receiver */
diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c
index 4a5701c8c..f43aa8229 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -44,6 +44,8 @@
static void sockpair_add_listener(struct listener *listener, int port);
static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen);
+static void sockpair_enable_listener(struct listener *listener);
+static void sockpair_disable_listener(struct listener *listener);
static int sockpair_connect_server(struct connection *conn, int flags);
struct proto_fam proto_fam_sockpair = {
@@ -68,6 +70,8 @@ static struct protocol proto_sockpair = {
.sock_prot = 0,
.add = sockpair_add_listener,
.listen = sockpair_bind_listener,
+ .enable = sockpair_enable_listener,
+ .disable = sockpair_disable_listener,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.accept = &listener_accept,
@@ -95,6 +99,24 @@ static void sockpair_add_listener(struct listener *listener, int port)
proto_sockpair.nb_receivers++;
}
+/* Enable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void sockpair_enable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_want_recv(l->rx.fd);
+}
+
+/* Disable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void sockpair_disable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_stop_recv(l->rx.fd);
+}
+
/* Binds receiver <rx>, and assigns <handler> and rx->owner as the callback and
* context, respectively, with <tm> as the thread mask. Returns and error code
* made of ERR_* bits on failure or ERR_NONE on success. On failure, an error
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index ae0310d02..fd0952b5e 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -47,6 +47,8 @@
static int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen);
static int tcp_suspend_receiver(struct receiver *rx);
static int tcp_resume_receiver(struct receiver *rx);
+static void tcp_enable_listener(struct listener *listener);
+static void tcp_disable_listener(struct listener *listener);
static void tcpv4_add_listener(struct listener *listener, int port);
static void tcpv6_add_listener(struct listener *listener, int port);
@@ -60,6 +62,8 @@ static struct protocol proto_tcpv4 = {
.sock_prot = IPPROTO_TCP,
.add = tcpv4_add_listener,
.listen = tcp_bind_listener,
+ .enable = tcp_enable_listener,
+ .disable = tcp_disable_listener,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_suspend = tcp_suspend_receiver,
@@ -82,6 +86,8 @@ static struct protocol proto_tcpv6 = {
.sock_prot = IPPROTO_TCP,
.add = tcpv6_add_listener,
.listen = tcp_bind_listener,
+ .enable = tcp_enable_listener,
+ .disable = tcp_disable_listener,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_suspend = tcp_suspend_receiver,
@@ -733,6 +739,24 @@ static void tcpv6_add_listener(struct listener *listener, int port)
proto_tcpv6.nb_receivers++;
}
+/* Enable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void tcp_enable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_want_recv(l->rx.fd);
+}
+
+/* Disable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void tcp_disable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_stop_recv(l->rx.fd);
+}
+
/* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver
* was totally stopped, or > 0 if correctly suspended.
*/
diff --git a/src/proto_udp.c b/src/proto_udp.c
index 31db44298..33a4dca46 100644
--- a/src/proto_udp.c
+++ b/src/proto_udp.c
@@ -42,6 +42,8 @@
static int udp_bind_listener(struct listener *listener, char *errmsg, int errlen);
static int udp_suspend_receiver(struct receiver *rx);
+static void udp_enable_listener(struct listener *listener);
+static void udp_disable_listener(struct listener *listener);
static void udp4_add_listener(struct listener *listener, int port);
static void udp6_add_listener(struct listener *listener, int port);
@@ -55,6 +57,8 @@ static struct protocol proto_udp4 = {
.sock_prot = IPPROTO_UDP,
.add = udp4_add_listener,
.listen = udp_bind_listener,
+ .enable = udp_enable_listener,
+ .disable = udp_disable_listener,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_suspend = udp_suspend_receiver,
@@ -74,6 +78,8 @@ static struct protocol proto_udp6 = {
.sock_prot = IPPROTO_UDP,
.add = udp6_add_listener,
.listen = udp_bind_listener,
+ .enable = udp_enable_listener,
+ .disable = udp_disable_listener,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_suspend = udp_suspend_receiver,
@@ -155,6 +161,24 @@ static void udp6_add_listener(struct listener *listener, int port)
proto_udp6.nb_receivers++;
}
+/* Enable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void udp_enable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_want_recv(l->rx.fd);
+}
+
+/* Disable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void udp_disable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_stop_recv(l->rx.fd);
+}
+
/* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver
* was totally stopped, or > 0 if correctly suspended.
*/
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index 1febe3e5e..4ec672ffc 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -43,6 +43,8 @@
static int uxst_bind_listener(struct listener *listener, char *errmsg, int errlen);
static int uxst_connect_server(struct connection *conn, int flags);
static void uxst_add_listener(struct listener *listener, int port);
+static void uxst_enable_listener(struct listener *listener);
+static void uxst_disable_listener(struct listener *listener);
static int uxst_suspend_receiver(struct receiver *rx);
/* Note: must not be declared <const> as its list will be overwritten */
@@ -55,6 +57,8 @@ static struct protocol proto_unix = {
.sock_prot = 0,
.add = uxst_add_listener,
.listen = uxst_bind_listener,
+ .enable = uxst_enable_listener,
+ .disable = uxst_disable_listener,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_suspend = uxst_suspend_receiver,
@@ -148,6 +152,24 @@ static void uxst_add_listener(struct listener *listener, int port)
proto_unix.nb_receivers++;
}
+/* Enable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void uxst_enable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_want_recv(l->rx.fd);
+}
+
+/* Disable receipt of incoming connections for listener <l>. The receiver must
+ * still be valid. Does nothing in early boot (needs fd_updt).
+ */
+static void uxst_disable_listener(struct listener *l)
+{
+ if (fd_updt)
+ fd_stop_recv(l->rx.fd);
+}
+
/* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver
* was totally stopped, or > 0 if correctly suspended. Nothing is done for
* plain unix sockets since currently it's the new process which handles