]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listeners: split do_unbind_listener() in two
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 15:18:29 +0000 (17:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 16:44:37 +0000 (18:44 +0200)
The inner part now goes into the protocol and is used to decide how to
unbind a given protocol's listener. The existing code which is able to
also unbind the receiver was provided as a default function that we
currently use everywhere. Some complex listeners like QUIC will use this
to decide how to unbind without impacting existing connections, possibly
by setting up other incoming paths for the traffic.

include/haproxy/listener.h
include/haproxy/protocol-t.h
src/listener.c
src/proto_sockpair.c
src/proto_tcp.c
src/proto_udp.c
src/proto_uxst.c

index c30dc73fd93cd83d3510427aa3d730c0fe5b4cad..399e2669a3f5432f7d5326f4e59ad1a4cd52a322 100644 (file)
@@ -124,6 +124,12 @@ int listener_backlog(const struct listener *l);
  */
 void listener_release(struct listener *l);
 
+/* default function used to unbind a listener. This is for use by standard
+ * protocols working on top of accepted sockets. The receiver's rx_unbind()
+ * will automatically be used after the listener is disabled if the socket is
+ * still bound. This must be used under the listener's lock.
+ */
+void default_unbind_listener(struct listener *listener);
 /*
  * Registers the bind keyword list <kwl> as a list of valid keywords for next
  * parsing sessions.
index 7411d6d3d0ac0bc4556778be528f0b8531dc6d02..a7d2429899d1ed4747b4af3b803fd039a4b22aec 100644 (file)
@@ -91,6 +91,7 @@ struct protocol {
        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 */
+       void (*unbind)(struct listener *l);             /* unbind the listener and possibly its receiver */
 
        /* functions acting on the receiver */
        void (*rx_enable)(struct receiver *rx);         /* enable receiving on the receiver */
index b1c64371b1d173bb5269ac1590d3b38a74168c12..3e305c73a95ef0eba5498d0e04781d036730730a 100644 (file)
@@ -538,18 +538,14 @@ void dequeue_proxy_listeners(struct proxy *px)
        }
 }
 
-/* This function closes the listening socket for the specified listener,
- * provided that it's already in a listening state. The listener enters the
- * LI_ASSIGNED state, except if the FD is not closed, in which case it may
- * remain in LI_LISTEN. Depending on the process' status (master or worker),
- * the listener's bind options and the receiver's origin, it may or may not
- * close the receiver's FD, according to what is provided at the receiver
- * level. Must be called with the lock held.
+
+/* default function used to unbind a listener. This is for use by standard
+ * protocols working on top of accepted sockets. The receiver's rx_unbind()
+ * will automatically be used after the listener is disabled if the socket is
+ * still bound. This must be used under the listener's lock.
  */
-void do_unbind_listener(struct listener *listener)
+void default_unbind_listener(struct listener *listener)
 {
-       MT_LIST_DEL(&listener->wait_queue);
-
        if (listener->state <= LI_ASSIGNED)
                goto out_close;
 
@@ -567,6 +563,20 @@ void do_unbind_listener(struct listener *listener)
  out_close:
        if (listener->rx.flags & RX_F_BOUND)
                listener->rx.proto->rx_unbind(&listener->rx);
+}
+
+/* This function closes the listening socket for the specified listener,
+ * provided that it's already in a listening state. The protocol's unbind()
+ * is called to put the listener into LI_ASSIGNED or LI_LISTEN and handle
+ * the unbinding tasks. The listener enters then the LI_ASSIGNED state if
+ * the receiver is unbound. Must be called with the lock held.
+ */
+void do_unbind_listener(struct listener *listener)
+{
+       MT_LIST_DEL(&listener->wait_queue);
+
+       if (listener->rx.proto->unbind)
+               listener->rx.proto->unbind(listener);
 
        /* we may have to downgrade the listener if the rx was closed */
        if (!(listener->rx.flags & RX_F_BOUND) && listener->state > LI_ASSIGNED)
index 9eac2cc2c16bc9e17e75f180964fe8cf1fee7739..4ac5b7642a900583a2d0089cd1ab736deb17c7c2 100644 (file)
@@ -72,6 +72,7 @@ static struct protocol proto_sockpair = {
        .listen = sockpair_bind_listener,
        .enable = sockpair_enable_listener,
        .disable = sockpair_disable_listener,
+       .unbind = default_unbind_listener,
        .rx_unbind = sock_unbind,
        .rx_enable = sock_enable,
        .rx_disable = sock_disable,
index 33eacbce0be6d2cdf6d8b1390e4cf526a9a00577..71d13c8b772b64b8fc552a9713e4eb4fe697a5dd 100644 (file)
@@ -64,6 +64,7 @@ static struct protocol proto_tcpv4 = {
        .listen = tcp_bind_listener,
        .enable = tcp_enable_listener,
        .disable = tcp_disable_listener,
+       .unbind = default_unbind_listener,
        .rx_enable = sock_enable,
        .rx_disable = sock_disable,
        .rx_unbind = sock_unbind,
@@ -89,6 +90,7 @@ static struct protocol proto_tcpv6 = {
        .listen = tcp_bind_listener,
        .enable = tcp_enable_listener,
        .disable = tcp_disable_listener,
+       .unbind = default_unbind_listener,
        .rx_enable = sock_enable,
        .rx_disable = sock_disable,
        .rx_unbind = sock_unbind,
index 8c53c6201bc50eea20177c0107a1c1a873fcaaed..1c2477e719a7c256eb56e79fb11e3716e054967c 100644 (file)
@@ -60,6 +60,7 @@ static struct protocol proto_udp4 = {
        .listen = udp_bind_listener,
        .enable = udp_enable_listener,
        .disable = udp_disable_listener,
+       .unbind = default_unbind_listener,
        .rx_enable = sock_enable,
        .rx_disable = sock_disable,
        .rx_unbind = sock_unbind,
@@ -83,6 +84,7 @@ static struct protocol proto_udp6 = {
        .listen = udp_bind_listener,
        .enable = udp_enable_listener,
        .disable = udp_disable_listener,
+       .unbind = default_unbind_listener,
        .rx_enable = sock_enable,
        .rx_disable = sock_disable,
        .rx_unbind = sock_unbind,
index 77415867afc339743c563cc883bd15148123556a..04f12faa02299a825fb8c42a47cf0d5d858a1d75 100644 (file)
@@ -59,6 +59,7 @@ static struct protocol proto_unix = {
        .listen = uxst_bind_listener,
        .enable = uxst_enable_listener,
        .disable = uxst_disable_listener,
+       .unbind = default_unbind_listener,
        .rx_enable = sock_enable,
        .rx_disable = sock_disable,
        .rx_unbind = sock_unbind,