]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stconn: Use a dedicated function to get the opposite sedesc
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Jul 2024 08:24:06 +0000 (10:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Jul 2024 13:27:04 +0000 (15:27 +0200)
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.

include/haproxy/stconn.h
src/applet.c
src/mux_h1.c
src/mux_pt.c
src/stconn.c

index e6548a6226c6548ef454bdff7de1beeb82fd683c..223b3b10a2f80e531ad6f1b1689e47439e77b093 100644 (file)
@@ -27,6 +27,7 @@
 #include <haproxy/htx-t.h>
 #include <haproxy/obj_type.h>
 #include <haproxy/stconn-t.h>
+#include <haproxy/xref.h>
 
 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)
 {
index 2bc3eb5ee5afd7c8e817391198892aa9aec47d35..ee1732ff46af14b687d894f8c71df9458abcaf48 100644 (file)
@@ -25,7 +25,6 @@
 #include <haproxy/task.h>
 #include <haproxy/trace.h>
 #include <haproxy/vecpair.h>
-#include <haproxy/xref.h>
 
 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;
index ed503f565a361194627426efc535ee376d275a97..4e0d4348a811695eaa594990ca2e0c7f8eb498d8 100644 (file)
@@ -31,7 +31,6 @@
 #include <haproxy/stconn.h>
 #include <haproxy/stream.h>
 #include <haproxy/trace.h>
-#include <haproxy/xref.h>
 
 /* 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)
index b3f850906e871ebf9c68e4bcbabdb7332c09658b..46e1d2e94e6cdd1a8ef47a3a1e877cf92818af9a 100644 (file)
@@ -19,7 +19,6 @@
 #include <haproxy/stream.h>
 #include <haproxy/task.h>
 #include <haproxy/trace.h>
-#include <haproxy/xref.h>
 
 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)
index 21284dc12f2f9afba01243d6c98cff99c782f33a..093ffcb55213f7b1a8d05f54172639b1cfa560c4 100644 (file)
@@ -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);