]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Rely on applet flag to detect the new api
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Jul 2025 06:13:07 +0000 (08:13 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 25 Aug 2025 09:11:05 +0000 (11:11 +0200)
Instead of setting a flag on the applet context by checking the defined
callback functions of the applet to know if an applet is using the new API
or not, we can now rely on the applet flags itself. By checking
APPLET_FL_NEW_API flag, it does the job. APPCTX_FL_INOUT_BUFS flag is thus
removed.

include/haproxy/applet-t.h
include/haproxy/applet.h
include/haproxy/sc_strm.h
src/applet.c
src/stconn.c

index 8b31e02bcac991e93146bb7ac37d85e9f6550738..da6dc5024c865fbc815b97dd32fc10e87a891f93 100644 (file)
@@ -47,7 +47,7 @@
 #define APPCTX_FL_ERROR          0x00000080
 #define APPCTX_FL_SHUTDOWN       0x00000100  /* applet was shut down (->release() called if any). No more data exchange with SCs */
 #define APPCTX_FL_WANT_DIE       0x00000200  /* applet was running and requested to die */
-#define APPCTX_FL_INOUT_BUFS     0x00000400  /* applet uses its own buffers */
+/* unused: 0x00000400 */
 #define APPCTX_FL_FASTFWD        0x00000800  /* zero-copy forwarding is in-use, don't fill the outbuf */
 #define APPCTX_FL_IN_MAYALLOC    0x00001000  /* applet may try again to allocate its inbuf */
 #define APPCTX_FL_OUT_MAYALLOC   0x00002000  /* applet may try again to allocate its outbuf */
@@ -73,8 +73,8 @@ static forceinline char *appctx_show_flags(char *buf, size_t len, const char *de
        _(APPCTX_FL_OUTBLK_ALLOC, _(APPCTX_FL_OUTBLK_FULL,
        _(APPCTX_FL_EOI, _(APPCTX_FL_EOS,
        _(APPCTX_FL_ERR_PENDING, _(APPCTX_FL_ERROR,
-       _(APPCTX_FL_SHUTDOWN, _(APPCTX_FL_WANT_DIE, _(APPCTX_FL_INOUT_BUFS,
-       _(APPCTX_FL_FASTFWD, _(APPCTX_FL_IN_MAYALLOC, _(APPCTX_FL_OUT_MAYALLOC))))))))))))));
+       _(APPCTX_FL_SHUTDOWN, _(APPCTX_FL_WANT_DIE,
+       _(APPCTX_FL_FASTFWD, _(APPCTX_FL_IN_MAYALLOC, _(APPCTX_FL_OUT_MAYALLOC)))))))))))));
        /* epilogue */
        _(~0U);
        return buf;
index 6856a3b289ad61328e322b057a3c6b650cb9cd18..0df52d8546701e29bc1d63ef77d92c566c0b7203 100644 (file)
@@ -288,7 +288,7 @@ static inline void applet_expect_data(struct appctx *appctx)
  */
 static inline struct buffer *applet_get_inbuf(struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC) || !appctx_get_buf(appctx, &appctx->inbuf))
                        return NULL;
                return &appctx->inbuf;
@@ -303,7 +303,7 @@ static inline struct buffer *applet_get_inbuf(struct appctx *appctx)
  */
 static inline struct buffer *applet_get_outbuf(struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC|APPCTX_FL_OUTBLK_FULL) ||
                    !appctx_get_buf(appctx, &appctx->outbuf))
                        return NULL;
@@ -316,7 +316,7 @@ static inline struct buffer *applet_get_outbuf(struct appctx *appctx)
 /* Returns the amount of data in the input buffer (see applet_get_inbuf) */
 static inline size_t applet_input_data(const struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS)
+       if (appctx->applet->flags & APPLET_FL_NEW_API)
                return b_data(&appctx->inbuf);
        else
                return co_data(sc_oc(appctx_sc(appctx)));
@@ -325,7 +325,7 @@ static inline size_t applet_input_data(const struct appctx *appctx)
 /* Returns the amount of HTX data in the input buffer (see applet_get_inbuf) */
 static inline size_t applet_htx_input_data(const struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS)
+       if (appctx->applet->flags & APPLET_FL_NEW_API)
                return htx_used_space(htxbuf(&appctx->inbuf));
        else
                return co_data(sc_oc(appctx_sc(appctx)));
@@ -340,7 +340,7 @@ static inline size_t applet_htx_input_data(const struct appctx *appctx)
  */
 static inline void applet_skip_input(struct appctx *appctx, size_t len)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                b_del(&appctx->inbuf, len);
                applet_fl_clr(appctx, APPCTX_FL_INBLK_FULL);
        }
@@ -352,7 +352,7 @@ static inline void applet_skip_input(struct appctx *appctx, size_t len)
  */
 static inline void applet_reset_input(struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                b_reset(&appctx->inbuf);
                applet_fl_clr(appctx, APPCTX_FL_INBLK_FULL);
        }
@@ -364,7 +364,7 @@ static inline void applet_reset_input(struct appctx *appctx)
  */
 static inline size_t applet_output_room(const struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS)
+       if (appctx->applet->flags & APPLET_FL_NEW_API)
                return b_room(&appctx->outbuf);
        else
                return channel_recv_max(sc_ic(appctx_sc(appctx)));
@@ -374,7 +374,7 @@ static inline size_t applet_output_room(const struct appctx *appctx)
  */
 static inline size_t applet_htx_output_room(const struct appctx *appctx)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS)
+       if (appctx->applet->flags & APPLET_FL_NEW_API)
                return htx_free_data_space(htxbuf(&appctx->outbuf));
        else
                return channel_recv_max(sc_ic(appctx_sc(appctx)));
@@ -390,7 +390,7 @@ static inline size_t applet_htx_output_room(const struct appctx *appctx)
  */
 static inline void applet_need_room(struct appctx *appctx, size_t room_needed)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS)
+       if (appctx->applet->flags & APPLET_FL_NEW_API)
                applet_have_more_data(appctx);
        else
                sc_need_room(appctx_sc(appctx), room_needed);
@@ -402,7 +402,7 @@ static inline int _applet_putchk(struct appctx *appctx, struct buffer *chunk,
 {
        int ret;
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (unlikely(stress) ?
                    b_data(&appctx->outbuf) :
                    b_data(chunk) > b_room(&appctx->outbuf)) {
@@ -457,7 +457,7 @@ static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
 {
        int ret;
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (len > b_room(&appctx->outbuf)) {
                        applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
                        ret = -1;
@@ -493,7 +493,7 @@ static inline int applet_putstr(struct appctx *appctx, const char *str)
 {
        int ret;
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                int len = strlen(str);
 
                if (len > b_room(&appctx->outbuf)) {
@@ -529,7 +529,7 @@ static inline int applet_putchr(struct appctx *appctx, char chr)
 {
        int ret;
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (b_full(&appctx->outbuf)) {
                        applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
                        ret = -1;
@@ -558,7 +558,7 @@ static inline int applet_putchr(struct appctx *appctx, char chr)
 
 static inline int applet_may_get(const struct appctx *appctx, size_t len)
 {
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (len > b_data(&appctx->inbuf)) {
                        if (se_fl_test(appctx->sedesc, SE_FL_SHW))
                                return -1;
@@ -593,7 +593,7 @@ static inline int applet_getchar(const struct appctx *appctx, char *c)
        ret = applet_may_get(appctx, 1);
        if (ret <= 0)
                return ret;
-       *c = ((appctx->flags & APPCTX_FL_INOUT_BUFS)
+       *c = ((appctx->applet->flags & APPLET_FL_NEW_API)
              ? *(b_head(&appctx->inbuf))
              : *(co_head(sc_oc(appctx_sc(appctx)))));
 
@@ -622,7 +622,7 @@ static inline int applet_getblk(const struct appctx *appctx, char *blk, int len,
        if (ret <= 0)
                return ret;
 
-       buf = ((appctx->flags & APPCTX_FL_INOUT_BUFS)
+       buf = ((appctx->applet->flags & APPLET_FL_NEW_API)
               ? &appctx->inbuf
               : sc_ob(appctx_sc(appctx)));
        return b_getblk(buf, blk, len, offset);
@@ -654,7 +654,7 @@ static inline int applet_getword(const struct appctx *appctx, char *str, int len
        if (ret <= 0)
                goto out;
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                buf = &appctx->inbuf;
                input = b_data(buf);
        }
@@ -681,7 +681,7 @@ static inline int applet_getword(const struct appctx *appctx, char *str, int len
                p = b_next(buf, p);
        }
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (ret < len && (ret < input || b_room(buf)) &&
                    !se_fl_test(appctx->sedesc, SE_FL_SHW))
                        ret = 0;
@@ -741,7 +741,7 @@ static inline int applet_getblk_nc(const struct appctx *appctx, const char **blk
        if (ret <= 0)
                return ret;
 
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                buf = &appctx->inbuf;
                max = b_data(buf);
        }
@@ -797,7 +797,7 @@ static inline int applet_getword_nc(const struct appctx *appctx, const char **bl
         * the resulting string is made of the concatenation of the pending
         * blocks (1 or 2).
         */
-       if (appctx->flags & APPCTX_FL_INOUT_BUFS) {
+       if (appctx->applet->flags & APPLET_FL_NEW_API) {
                if (b_full(&appctx->inbuf) || se_fl_test(appctx->sedesc, SE_FL_SHW))
                        return ret;
        }
index 996b7ea88b5d49bfa3abfe5e158f72097b3d45ac..61b72a9fdbfbc5646215277087bf4aeeafbb5535 100644 (file)
@@ -386,7 +386,7 @@ static inline int sc_is_send_allowed(const struct stconn *sc)
        if (sc->flags & SC_FL_SHUT_DONE)
                return 0;
 
-       if (!sc_appctx(sc) || !(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
+       if (!sc_appctx(sc) || !(__sc_appctx(sc)->applet->flags & APPLET_FL_NEW_API))
                return !sc_ep_test(sc, SE_FL_WAIT_DATA | SE_FL_WONT_CONSUME);
 
        if (sc_ep_test(sc, SE_FL_WONT_CONSUME))
index 584d2b9f097a05a7afd56484879cb93d3675c439..e60ff8b18b1a6f6bb705914d63de81f5bd250b60 100644 (file)
@@ -274,12 +274,9 @@ struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int t
        appctx->outbuf = BUF_NULL;
        appctx->to_forward = 0;
 
-       if (applet->rcv_buf != NULL && applet->snd_buf != NULL) {
-               appctx->t->process = task_process_applet;
-               applet_fl_set(appctx, APPCTX_FL_INOUT_BUFS);
-       }
-       else
-               appctx->t->process = task_run_applet;
+       appctx->t->process = ((applet->flags & APPLET_FL_NEW_API)
+                             ? task_process_applet
+                             : task_run_applet);
        appctx->t->context = appctx;
 
        LIST_INIT(&appctx->buffer_wait.list);
index a9ce03d4d7b442d70178f16681ca288a4cd2bc72..646c4ca6e54571bbc24d5f7650de20b37f946012 100644 (file)
@@ -2194,7 +2194,7 @@ int sc_applet_recv(struct stconn *sc)
  */
 int sc_applet_sync_recv(struct stconn *sc)
 {
-       if (!(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
+       if (!(__sc_appctx(sc)->applet->flags & APPLET_FL_NEW_API))
                return 0;
 
        if (!sc_state_in(sc->state, SC_SB_RDY|SC_SB_EST))
@@ -2295,7 +2295,7 @@ void sc_applet_sync_send(struct stconn *sc)
 
        oc->flags &= ~CF_WRITE_EVENT;
 
-       if (!(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
+       if (!(__sc_appctx(sc)->applet->flags & APPLET_FL_NEW_API))
                return;
 
        if (sc->flags & SC_FL_SHUT_DONE)