]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stconn/connection: Move shut modes at the SE descriptor level
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 16 Apr 2024 06:51:56 +0000 (08:51 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 19 Apr 2024 14:24:46 +0000 (16:24 +0200)
CO_SHR_* and CO_SHW_* modes are in fact used by the stream-connectors to
instruct the muxes how streams must be shut done. It is then the mux
responsibility to decide if it must be propagated to the connection layer or
not. And in this case, the modes above are only tested to pass a boolean
(clean or not).

So, it is not consistant to still use connection related modes for
information set at an upper layer and never used by the connection layer
itself.

These modes are thus moved at the sedesc level and merged into a single
enum. Idea is to add more modes, not necessarily mutually exclusive, to pass
more info to the muxes. For now, it is a one-for-one renaming.

include/haproxy/connection-t.h
include/haproxy/stconn-t.h
include/haproxy/stconn.h
src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/mux_pt.c
src/mux_quic.c
src/stconn.c

index 5adf3cf2dd2cf2f1e2aa97163e64d8a47713e49b..bfaece231b27373c72cadca027a0b51824b685f9 100644 (file)
@@ -37,6 +37,7 @@
 #include <haproxy/port_range-t.h>
 #include <haproxy/protocol-t.h>
 #include <haproxy/show_flags-t.h>
+#include <haproxy/stconn-t.h>
 #include <haproxy/task-t.h>
 #include <haproxy/thread-t.h>
 
@@ -281,18 +282,6 @@ enum {
        CO_SFL_LAST_DATA   = 0x0003,    /* Sent data are the last ones, shutdown is pending */
 };
 
-/* mux->shutr() modes */
-enum co_shr_mode {
-       CO_SHR_DRAIN        = 0,           /* read shutdown, drain any extra stuff */
-       CO_SHR_RESET        = 1,           /* read shutdown, reset any extra stuff */
-};
-
-/* mux->shutw() modes */
-enum co_shw_mode {
-       CO_SHW_NORMAL       = 0,           /* regular write shutdown */
-       CO_SHW_SILENT       = 1,           /* imminent close, don't notify peer */
-};
-
 /* known transport layers (for ease of lookup) */
 enum {
        XPRT_RAW = 0,
@@ -422,8 +411,8 @@ struct mux_ops {
        size_t (*done_fastfwd)(struct stconn *sc); /* Callback to terminate fast data forwarding */
        int (*fastfwd)(struct stconn *sc, unsigned int count, unsigned int flags); /* Callback to init fast data forwarding */
        int (*resume_fastfwd)(struct stconn *sc, unsigned int flags); /* Callback to resume fast data forwarding */
-       void (*shutr)(struct stconn *sc, enum co_shr_mode);     /* shutr function */
-       void (*shutw)(struct stconn *sc, enum co_shw_mode);     /* shutw function */
+       void (*shutr)(struct stconn *sc, enum se_shut_mode);     /* shutr function */
+       void (*shutw)(struct stconn *sc, enum se_shut_mode);     /* shutw function */
 
        int (*attach)(struct connection *conn, struct sedesc *, struct session *sess); /* attach a stconn to an outgoing connection */
        struct stconn *(*get_first_sc)(const struct connection *); /* retrieves any valid stconn from this connection */
index ee1cdd423b4c1e8fc59e8da3a0f08571c557d155..50645d0acaf4b1af948f88e3906227f45dd780c0 100644 (file)
@@ -26,6 +26,7 @@
 #include <haproxy/connection-t.h>
 #include <haproxy/pipe-t.h>
 #include <haproxy/show_flags-t.h>
+#include <haproxy/task-t.h>
 #include <haproxy/xref-t.h>
 
 enum iobuf_flags {
@@ -114,6 +115,14 @@ enum se_flags {
        SE_FL_APPLET_NEED_CONN = 0x80000000,  /* applet is waiting for the other side to (fail to) connect */
 };
 
+/* Shutdown modes */
+enum se_shut_mode {
+       SE_SHR_DRAIN  = 0x00000001, /* read shutdown, drain any extra stuff */
+       SE_SHR_RESET  = 0x00000002, /* read shutdown, reset any extra stuff */
+       SE_SHW_NORMAL = 0x00000004, /* regular write shutdown */
+       SE_SHW_SILENT = 0x00000008, /* imminent close, don't notify peer */
+};
+
 /* This function is used to report flags in debugging tools. Please reflect
  * below any single-bit flag addition above in the same order via the
  * __APPEND_FLAG macro. The new end of the buffer is returned.
index c28edc2c39d3cd5a3c319227b2a7aeb342d6fa36..039055c9a6e1535d9ff4b959bbf09971e895a8e3 100644 (file)
@@ -319,7 +319,7 @@ static inline const char *sc_get_data_name(const struct stconn *sc)
 }
 
 /* shut read */
-static inline void sc_conn_shutr(struct stconn *sc, enum co_shr_mode mode)
+static inline void sc_conn_shutr(struct stconn *sc, enum se_shut_mode mode)
 {
        const struct mux_ops *mux;
 
@@ -332,11 +332,11 @@ static inline void sc_conn_shutr(struct stconn *sc, enum co_shr_mode mode)
        mux = sc_mux_ops(sc);
        if (mux && mux->shutr)
                mux->shutr(sc, mode);
-       sc_ep_set(sc, (mode == CO_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
+       sc_ep_set(sc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
 }
 
 /* shut write */
-static inline void sc_conn_shutw(struct stconn *sc, enum co_shw_mode mode)
+static inline void sc_conn_shutw(struct stconn *sc, enum se_shut_mode mode)
 {
        const struct mux_ops *mux;
 
@@ -349,21 +349,21 @@ static inline void sc_conn_shutw(struct stconn *sc, enum co_shw_mode mode)
        mux = sc_mux_ops(sc);
        if (mux && mux->shutw)
                mux->shutw(sc, mode);
-       sc_ep_set(sc, (mode == CO_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
+       sc_ep_set(sc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
 }
 
 /* completely close a stream connector (but do not detach it) */
 static inline void sc_conn_shut(struct stconn *sc)
 {
-       sc_conn_shutw(sc, CO_SHW_SILENT);
-       sc_conn_shutr(sc, CO_SHR_RESET);
+       sc_conn_shutw(sc, SE_SHW_SILENT);
+       sc_conn_shutr(sc, SE_SHR_RESET);
 }
 
 /* completely close a stream connector after draining possibly pending data (but do not detach it) */
 static inline void sc_conn_drain_and_shut(struct stconn *sc)
 {
-       sc_conn_shutw(sc, CO_SHW_SILENT);
-       sc_conn_shutr(sc, CO_SHR_DRAIN);
+       sc_conn_shutw(sc, SE_SHW_SILENT);
+       sc_conn_shutr(sc, SE_SHR_DRAIN);
 }
 
 /* Returns non-zero if the stream connector's Rx path is blocked because of
index cca3e93d72c63667db461e614e2352e7a8cba636..3562663c443317370bf75b86b3abd5a6204c55a6 100644 (file)
@@ -3792,18 +3792,17 @@ struct task *fcgi_deferred_shut(struct task *t, void *ctx, unsigned int state)
 }
 
 /* shutr() called by the stream connector (mux_ops.shutr) */
-static void fcgi_shutr(struct stconn *sc, enum co_shr_mode mode)
+static void fcgi_shutr(struct stconn *sc, enum se_shut_mode mode)
 {
        struct fcgi_strm *fstrm = __sc_mux_strm(sc);
 
        TRACE_POINT(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm);
-       if (!mode)
-               return;
-       fcgi_do_shutr(fstrm);
+       if (mode & SE_SHR_RESET)
+               fcgi_do_shutr(fstrm);
 }
 
 /* shutw() called by the stream connector (mux_ops.shutw) */
-static void fcgi_shutw(struct stconn *sc, enum co_shw_mode mode)
+static void fcgi_shutw(struct stconn *sc, enum se_shut_mode mode)
 {
        struct fcgi_strm *fstrm = __sc_mux_strm(sc);
 
index f26b4dc1c8a7b96e53e7497a35cb4e48ed28c40d..881fff77bb62a6be22fd31517d3c2f237133cd83 100644 (file)
@@ -4292,7 +4292,7 @@ static void h1_detach(struct sedesc *sd)
 }
 
 
-static void h1_shutr(struct stconn *sc, enum co_shr_mode mode)
+static void h1_shutr(struct stconn *sc, enum se_shut_mode mode)
 {
        struct h1s *h1s = __sc_mux_strm(sc);
        struct h1c *h1c;
@@ -4304,7 +4304,7 @@ static void h1_shutr(struct stconn *sc, enum co_shr_mode mode)
        TRACE_POINT(H1_EV_STRM_SHUT, h1c->conn, h1s, 0, (size_t[]){mode});
 }
 
-static void h1_shutw(struct stconn *sc, enum co_shw_mode mode)
+static void h1_shutw(struct stconn *sc, enum se_shut_mode mode)
 {
        struct h1s *h1s = __sc_mux_strm(sc);
        struct h1c *h1c;
@@ -4320,7 +4320,7 @@ static void h1_shutw(struct stconn *sc, enum co_shw_mode mode)
 
   do_shutw:
        h1_close(h1c);
-       if (mode != CO_SHW_NORMAL)
+       if (mode & SE_SHW_NORMAL)
                h1c->flags |= H1C_F_SILENT_SHUT;
 
        if (!b_data(&h1c->obuf))
index c01f61dcd9aaf3d61518a67b553d878e1d399e5d..f76685593f6bb490733fe9913bd241f5897cf0f2 100644 (file)
@@ -5080,18 +5080,18 @@ struct task *h2_deferred_shut(struct task *t, void *ctx, unsigned int state)
 }
 
 /* shutr() called by the stream connector (mux_ops.shutr) */
-static void h2_shutr(struct stconn *sc, enum co_shr_mode mode)
+static void h2_shutr(struct stconn *sc, enum se_shut_mode mode)
 {
        struct h2s *h2s = __sc_mux_strm(sc);
 
        TRACE_ENTER(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s);
-       if (mode)
+       if (mode & SE_SHR_RESET)
                h2_do_shutr(h2s);
        TRACE_LEAVE(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s);
 }
 
 /* shutw() called by the stream connector (mux_ops.shutw) */
-static void h2_shutw(struct stconn *sc, enum co_shw_mode mode)
+static void h2_shutw(struct stconn *sc, enum se_shut_mode mode)
 {
        struct h2s *h2s = __sc_mux_strm(sc);
 
index 77fd9897d152e0407dfa62b3216fb9b84d9261d8..2e961abeb5320f4255f64a8f07eda515dfd6abb6 100644 (file)
@@ -462,7 +462,7 @@ static int mux_pt_avail_streams(struct connection *conn)
        return 1 - mux_pt_used_streams(conn);
 }
 
-static void mux_pt_shutr(struct stconn *sc, enum co_shr_mode mode)
+static void mux_pt_shutr(struct stconn *sc, enum se_shut_mode mode)
 {
        struct connection *conn = __sc_conn(sc);
        struct mux_pt_ctx *ctx = conn->ctx;
@@ -472,8 +472,8 @@ static void mux_pt_shutr(struct stconn *sc, enum co_shr_mode mode)
        se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
        if (conn_xprt_ready(conn) && conn->xprt->shutr)
                conn->xprt->shutr(conn, conn->xprt_ctx,
-                   (mode == CO_SHR_DRAIN));
-       else if (mode == CO_SHR_DRAIN)
+                   (mode & SE_SHR_DRAIN));
+       else if (mode & SE_SHR_DRAIN)
                conn_ctrl_drain(conn);
        if (conn->flags & CO_FL_SOCK_WR_SH)
                conn_full_close(conn);
@@ -481,7 +481,7 @@ static void mux_pt_shutr(struct stconn *sc, enum co_shr_mode mode)
        TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc);
 }
 
-static void mux_pt_shutw(struct stconn *sc, enum co_shw_mode mode)
+static void mux_pt_shutw(struct stconn *sc, enum se_shut_mode mode)
 {
        struct connection *conn = __sc_conn(sc);
 
@@ -489,9 +489,9 @@ static void mux_pt_shutw(struct stconn *sc, enum co_shw_mode mode)
 
        if (conn_xprt_ready(conn) && conn->xprt->shutw)
                conn->xprt->shutw(conn, conn->xprt_ctx,
-                   (mode == CO_SHW_NORMAL));
+                   (mode & SE_SHW_NORMAL));
        if (!(conn->flags & CO_FL_SOCK_RD_SH))
-               conn_sock_shutw(conn, (mode == CO_SHW_NORMAL));
+               conn_sock_shutw(conn, (mode & SE_SHW_NORMAL));
        else
                conn_full_close(conn);
 
index 8cb2759e4a405d848495b152a314c9ef49f5ee29..4e803838078cec98dc3c5d0515a15c1b89695fff 100644 (file)
@@ -3095,7 +3095,7 @@ static int qmux_wake(struct connection *conn)
        return 1;
 }
 
-static void qmux_strm_shutw(struct stconn *sc, enum co_shw_mode mode)
+static void qmux_strm_shutw(struct stconn *sc, enum se_shut_mode mode)
 {
        struct qcs *qcs = __sc_mux_strm(sc);
        struct qcc *qcc = qcs->qcc;
index 7cdc9ff3048e26faa68a6e1d272d75682e902a2a..805080fb46d2839cca6243c95c812dbe869c889f 100644 (file)
@@ -743,7 +743,7 @@ static void sc_app_shut_conn(struct stconn *sc)
                         * option abortonclose. No need for the TLS layer to try to
                         * emit a shutdown message.
                         */
-                       sc_conn_shutw(sc, CO_SHW_SILENT);
+                       sc_conn_shutw(sc, SE_SHW_SILENT);
                }
                else {
                        /* clean data-layer shutdown. This only happens on the
@@ -752,7 +752,7 @@ static void sc_app_shut_conn(struct stconn *sc)
                         * while option abortonclose is set. We want the TLS
                         * layer to try to signal it to the peer before we close.
                         */
-                       sc_conn_shutw(sc, CO_SHW_NORMAL);
+                       sc_conn_shutw(sc, SE_SHW_NORMAL);
 
                        if (!(sc->flags & (SC_FL_EOS|SC_FL_ABRT_DONE)) && !(ic->flags & CF_DONT_READ))
                                return;
@@ -1194,7 +1194,7 @@ static void sc_conn_eos(struct stconn *sc)
        if (sc_cond_forward_shut(sc)) {
                /* we want to immediately forward this close to the write side */
                /* force flag on ssl to keep stream in cache */
-               sc_conn_shutw(sc, CO_SHW_SILENT);
+               sc_conn_shutw(sc, SE_SHW_SILENT);
                goto do_close;
        }