From 3de6c375aa3eac6422369df309e272c8ff1f47d4 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 29 Jul 2025 08:13:07 +0200 Subject: [PATCH] MINOR: applet: Rely on applet flag to detect the new api 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 | 6 +++--- include/haproxy/applet.h | 40 +++++++++++++++++++------------------- include/haproxy/sc_strm.h | 2 +- src/applet.c | 9 +++------ src/stconn.c | 4 ++-- 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index 8b31e02bc..da6dc5024 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -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; diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 6856a3b28..0df52d854 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -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; } diff --git a/include/haproxy/sc_strm.h b/include/haproxy/sc_strm.h index 996b7ea88..61b72a9fd 100644 --- a/include/haproxy/sc_strm.h +++ b/include/haproxy/sc_strm.h @@ -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)) diff --git a/src/applet.c b/src/applet.c index 584d2b9f0..e60ff8b18 100644 --- a/src/applet.c +++ b/src/applet.c @@ -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); diff --git a/src/stconn.c b/src/stconn.c index a9ce03d4d..646c4ca6e 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -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)