From: Christopher Faulet Date: Thu, 4 Jul 2024 08:24:06 +0000 (+0200) Subject: MINOR: stconn: Use a dedicated function to get the opposite sedesc X-Git-Tag: v3.1-dev4~83 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51ebf644e5b07b35c190047c38d803f0a7ff56f8;p=thirdparty%2Fhaproxy.git MINOR: stconn: Use a dedicated function to get the opposite sedesc se_opposite() function is added to let an endpoint retrieve the opposite endpoint descriptor. Muxes supportng the zero-copy forwarding can now use it. The se_shutdown() function too. This will be use by the SPOP multiplexer to be able to retrieve the SPOE agent configuration attached to the applet on client side. The related issue is #2502. --- diff --git a/include/haproxy/stconn.h b/include/haproxy/stconn.h index e6548a6226..223b3b10a2 100644 --- a/include/haproxy/stconn.h +++ b/include/haproxy/stconn.h @@ -27,6 +27,7 @@ #include #include #include +#include struct buffer; struct session; @@ -134,6 +135,19 @@ static inline size_t se_ff_data(struct sedesc *se) return (se->iobuf.data + (se->iobuf.pipe ? se->iobuf.pipe->data : 0)); } + +static inline struct sedesc *se_opposite(struct sedesc *se) +{ + struct xref *peer = xref_get_peer_and_lock(&se->xref); + struct sedesc *seo = NULL;; + + if (peer) { + seo = container_of(peer, struct sedesc, xref); + xref_unlock(&se->xref, peer); + } + return seo; +} + /* stream connector version */ static forceinline void sc_ep_zero(struct stconn *sc) { diff --git a/src/applet.c b/src/applet.c index 2bc3eb5ee5..ee1732ff46 100644 --- a/src/applet.c +++ b/src/applet.c @@ -25,7 +25,6 @@ #include #include #include -#include unsigned int nb_applets = 0; @@ -646,7 +645,6 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags) { struct appctx *appctx = __sc_appctx(sc); - struct xref *peer; struct sedesc *sdo = NULL; unsigned int len, nego_flags = NEGO_FF_FL_NONE; int ret = 0; @@ -661,13 +659,11 @@ int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags) return -1; } - peer = xref_get_peer_and_lock(&appctx->sedesc->xref); - if (!peer) { + sdo = se_opposite(appctx->sedesc); + if (!sdo) { TRACE_STATE("Opposite endpoint not available yet", APPLET_EV_RECV, appctx); goto end; } - sdo = container_of(peer, struct sedesc, xref); - xref_unlock(&appctx->sedesc->xref, peer); if (appctx->to_forward && count > appctx->to_forward) { count = appctx->to_forward; diff --git a/src/mux_h1.c b/src/mux_h1.c index ed503f565a..4e0d4348a8 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -31,7 +31,6 @@ #include #include #include -#include /* H1 connection descriptor */ struct h1c { @@ -4603,16 +4602,7 @@ static size_t h1_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, in static inline struct sedesc *h1s_opposite_sd(struct h1s *h1s) { - struct xref *peer; - struct sedesc *sdo; - - peer = xref_get_peer_and_lock(&h1s->sd->xref); - if (!peer) - return NULL; - - sdo = container_of(peer, struct sedesc, xref); - xref_unlock(&h1s->sd->xref, peer); - return sdo; + return se_opposite(h1s->sd); } static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count, unsigned int flags) diff --git a/src/mux_pt.c b/src/mux_pt.c index b3f850906e..46e1d2e94e 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -19,7 +19,6 @@ #include #include #include -#include struct mux_pt_ctx { struct sedesc *sd; @@ -561,16 +560,7 @@ static size_t mux_pt_snd_buf(struct stconn *sc, struct buffer *buf, size_t count static inline struct sedesc *mux_pt_opposite_sd(struct mux_pt_ctx *ctx) { - struct xref *peer; - struct sedesc *sdo; - - peer = xref_get_peer_and_lock(&ctx->sd->xref); - if (!peer) - return NULL; - - sdo = container_of(peer, struct sedesc, xref); - xref_unlock(&ctx->sd->xref, peer); - return sdo; + return se_opposite(ctx->sd); } static size_t mux_pt_nego_ff(struct stconn *sc, struct buffer *input, size_t count, unsigned int flags) diff --git a/src/stconn.c b/src/stconn.c index 21284dc12f..093ffcb552 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -141,6 +141,8 @@ void sedesc_free(struct sedesc *sedesc) */ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode) { + struct sedesc *sdo; + struct se_abort_info *reason = NULL; unsigned int flags = 0; if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW)) @@ -153,16 +155,9 @@ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode) if (flags) { if (mux && mux->shut) { - struct se_abort_info *reason = NULL; - struct xref *peer = xref_get_peer_and_lock(&sedesc->xref); - - if (peer) { - struct sedesc *sdo = container_of(peer, struct sedesc, xref); - + sdo = se_opposite(sedesc); + if (sdo) reason = &sdo->abort_info; - xref_unlock(&sedesc->xref, peer); - } - mux->shut(sedesc->sc, mode, reason); } se_fl_set(sedesc, flags); @@ -173,16 +168,9 @@ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode) if (flags) { if (appctx->applet->shut) { - struct se_abort_info *reason = NULL; - struct xref *peer = xref_get_peer_and_lock(&sedesc->xref); - - if (peer) { - struct sedesc *sdo = container_of(peer, struct sedesc, xref); - + sdo = se_opposite(sedesc); + if (sdo) reason = &sdo->abort_info; - xref_unlock(&sedesc->xref, peer); - } - appctx->applet->shut(appctx, mode, reason); } se_fl_set(sedesc, flags);