From: Christopher Faulet Date: Tue, 16 Apr 2024 06:51:56 +0000 (+0200) Subject: MINOR: stconn/connection: Move shut modes at the SE descriptor level X-Git-Tag: v3.0-dev8~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d2c3f8dde7c2474616c0ea51234e6ba9433a4bc1;p=thirdparty%2Fhaproxy.git MINOR: stconn/connection: Move shut modes at the SE descriptor level 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. --- diff --git a/include/haproxy/connection-t.h b/include/haproxy/connection-t.h index 5adf3cf2dd..bfaece231b 100644 --- a/include/haproxy/connection-t.h +++ b/include/haproxy/connection-t.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -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 */ diff --git a/include/haproxy/stconn-t.h b/include/haproxy/stconn-t.h index ee1cdd423b..50645d0aca 100644 --- a/include/haproxy/stconn-t.h +++ b/include/haproxy/stconn-t.h @@ -26,6 +26,7 @@ #include #include #include +#include #include 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. diff --git a/include/haproxy/stconn.h b/include/haproxy/stconn.h index c28edc2c39..039055c9a6 100644 --- a/include/haproxy/stconn.h +++ b/include/haproxy/stconn.h @@ -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 diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index cca3e93d72..3562663c44 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -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); diff --git a/src/mux_h1.c b/src/mux_h1.c index f26b4dc1c8..881fff77bb 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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)) diff --git a/src/mux_h2.c b/src/mux_h2.c index c01f61dcd9..f76685593f 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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); diff --git a/src/mux_pt.c b/src/mux_pt.c index 77fd9897d1..2e961abeb5 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -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); diff --git a/src/mux_quic.c b/src/mux_quic.c index 8cb2759e4a..4e80383807 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -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; diff --git a/src/stconn.c b/src/stconn.c index 7cdc9ff304..805080fb46 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -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; }