]> git.kaiwu.me - haproxy.git/commitdiff
MEDIUM: htx/tree-wide: Remove tests on HTX_BLK_UNUSED when possible
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 23 Jul 2026 09:05:53 +0000 (11:05 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 24 Jul 2026 09:58:25 +0000 (11:58 +0200)
Thanks to previous changes, it is possible to remove all tests on
HTX_BLK_UNUSED outside of the HTX API. Indeed, because htx_get_*_blk() and
htx_remove_blk() functions are now skipping automatically unused blocks, we
are sure to never get such blocks from outside.

include/haproxy/htx.h
src/cache.c
src/flt_http_comp.c
src/flt_trace.c
src/h3.c
src/hlua.c
src/htx.c
src/mux_h1.c
src/mux_h2.c

index b48d87df64e6b04ddcc0a28a74e9693e51141e02..fac0dc72d984e466e632b1ca546116fe47368ab5 100644 (file)
@@ -319,7 +319,6 @@ static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
        return nblk;
 }
 
-
 /* Returns the position of the first block in the HTX message <htx>. -1 means
  * the first block is unset or the HTS is empty.
  */
index b9fa2d45a91c3641b78440fbac2ff1ced142fccd..e20d8a5f0da7ec9b7f064ced75cb814b75586e00 100644 (file)
@@ -830,9 +830,6 @@ cache_store_http_payload(struct stream *s, struct filter *filter, struct http_ms
                struct ist v;
 
                switch (type) {
-                       case HTX_BLK_UNUSED:
-                               break;
-
                        case HTX_BLK_DATA:
                                v = htx_get_blk_value(htx, blk);
                                v = istadv(v, offset);
index 92248324805970b9d450ee765f4ed3359c401f57..7fa3d9623471870e7fc823a5c020eed08b0d1705 100644 (file)
@@ -285,8 +285,6 @@ comp_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg,
                struct ist v;
 
                next = htx_get_next_blk(htx, blk);
-               while (next && htx_get_blk_type(next) == HTX_BLK_UNUSED)
-                       next = htx_get_next_blk(htx, next);
 
                if (!(st->flags & COMP_STATE_PROCESSING))
                        goto consume;
index 77577ecf5806513e681a790fb62ddb70d9dada8d..cd9e5dbc373cbe3fc1c581760b6271aaf1a689c1 100644 (file)
@@ -167,12 +167,9 @@ trace_get_htx_datalen(struct htx *htx, unsigned int offset, unsigned int len)
                blk = htx_get_next_blk(htx, blk);
        }
        while (blk) {
-               if (htx_get_blk_type(blk) == HTX_BLK_UNUSED)
-                       goto next;
-               else if (htx_get_blk_type(blk) != HTX_BLK_DATA)
+               if (htx_get_blk_type(blk) != HTX_BLK_DATA)
                        break;
                data += htx_get_blksz(blk);
-         next:
                blk = htx_get_next_blk(htx, blk);
        }
        return data;
index d11005eb011266a140a9d3b13b449ccaaaf33d45..838a861513edd4306020db5c1cb3a0801d6c461c 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -2286,8 +2286,6 @@ static int h3_req_headers_send(struct qcs *qcs, struct htx *htx)
                switch (type) {
                case HTX_BLK_EOH:
                        goto end_loop;
-               case HTX_BLK_UNUSED:
-                       break;
 
                case HTX_BLK_REQ_SL:
                        BUG_ON(sl); /* Only one start-line expected */
@@ -2507,9 +2505,6 @@ static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx)
        for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
                type = htx_get_blk_type(blk);
 
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                if (type == HTX_BLK_EOH)
                        break;
 
@@ -2744,9 +2739,6 @@ static int h3_resp_trailers_send(struct qcs *qcs, struct htx *htx)
        for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
                type = htx_get_blk_type(blk);
 
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                if (type == HTX_BLK_EOT)
                        break;
 
index 7bdd3d4b75d21b0872046e39c7cfe4cbab3de8cf..99318b3301357a3a030cf120a1f7807c26896161 100644 (file)
@@ -5825,9 +5825,6 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
 
                vlen = sz;
                switch (type) {
-                       case HTX_BLK_UNUSED:
-                               break;
-
                        case HTX_BLK_DATA:
                                v = htx_get_blk_value(htx, blk);
                                vlen = v.len;
@@ -5925,9 +5922,6 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
 
                vlen = sz;
                switch (type) {
-                       case HTX_BLK_UNUSED:
-                               break;
-
                        case HTX_BLK_DATA:
                                v = htx_get_blk_value(htx, blk);
                                vlen = v.len;
@@ -7329,9 +7323,6 @@ static int _hlua_http_msg_dup(struct http_msg *msg, lua_State *L, size_t offset,
                struct ist v;
 
                switch (type) {
-                       case HTX_BLK_UNUSED:
-                               break;
-
                        case HTX_BLK_DATA:
                                v = htx_get_blk_value(htx, blk);
                                v = istadv(v, offset);
@@ -7465,9 +7456,6 @@ static void _hlua_http_msg_delete(struct http_msg *msg, struct filter *filter, s
                uint32_t sz = htx_get_blksz(blk);
 
                switch (type) {
-                       case HTX_BLK_UNUSED:
-                               break;
-
                        case HTX_BLK_DATA:
                                if (len < sz) {
                                        /* don't discard whole blk, only part of it
index fff8289321c3a201c8bc353510f911f6d4672cc1..f6bb60e41ab48011e9f3762ae03027fa65ebeb92 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -534,10 +534,6 @@ struct htx_ret htx_drain(struct htx *htx, uint32_t count)
                uint32_t sz = htx_get_blksz(blk);
                enum htx_blk_type type = htx_get_blk_type(blk);
 
-               /* Ignore unused block */
-               if (type == HTX_BLK_UNUSED)
-                       goto next;
-
                if (sz > count) {
                        if (type == HTX_BLK_DATA) {
                                htx_cut_data_blk(htx, blk, count);
@@ -547,7 +543,6 @@ struct htx_ret htx_drain(struct htx *htx, uint32_t count)
                }
                count -= sz;
                htxret.ret += sz;
-         next:
                blk = htx_remove_blk(htx, blk);
        }
        htxret.blk = blk;
@@ -780,8 +775,6 @@ size_t htx_xfer(struct htx *dst, struct htx *src, size_t count, unsigned int fla
 
                /* Ignore unused block */
                type = htx_get_blk_type(blk);
-               if (type == HTX_BLK_UNUSED)
-                       continue;
 
                if ((flags & HTX_XFER_HDRS_ONLY) &&
                    type != HTX_BLK_REQ_SL && type != HTX_BLK_RES_SL &&
@@ -1246,10 +1239,6 @@ int htx_append_msg(struct htx *dst, const struct htx *src)
 
        for (blk = htx_get_head_blk(src); blk; blk = htx_get_next_blk(src, blk)) {
                type = htx_get_blk_type(blk);
-
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                blksz = htx_get_blksz(blk);
                newblk = htx_add_blk(dst, type, blksz);
                if (!newblk)
index 81ac9b371fef08dd48e2ed7f6e5e8823e2c38596..6c37b5d19568895fda40173ae31893aad4440432 100644 (file)
@@ -1923,10 +1923,6 @@ static int h1_search_websocket_key(struct h1s *h1s, struct h1m *h1m, struct htx
        blk = htx_get_head_blk(htx); // returns the SL that we skip
        for (blk = htx_get_next_blk(htx, blk); blk; blk = htx_get_next_blk(htx, blk)) {
                type = htx_get_blk_type(blk);
-
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                if (type != HTX_BLK_HDR)
                        break;
 
@@ -2473,10 +2469,6 @@ static size_t h1_make_reqline(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
                        goto end;
                type = htx_get_blk_type(blk);
                sz = htx_get_blksz(blk);
-               if (type == HTX_BLK_UNUSED) {
-                       htx_remove_blk(htx, blk);
-                       continue;
-               }
                if (type != HTX_BLK_REQ_SL || sz > count)
                        goto error;
                break;
@@ -2563,11 +2555,6 @@ static size_t h1_make_stline(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
 
                type = htx_get_blk_type(blk);
                sz = htx_get_blksz(blk);
-
-               if (type == HTX_BLK_UNUSED) {
-                       htx_remove_blk(htx, blk);
-                       continue;
-               }
                if (type != HTX_BLK_RES_SL || sz > count)
                        goto error;
                break;
@@ -2731,8 +2718,6 @@ static size_t h1_make_headers(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
                        h1m->state = H1_MSG_LAST_LF;
                        break; /* Do not consume this block */
                 }
-               else if (type == HTX_BLK_UNUSED)
-                       goto nextblk;
                else
                        goto error;
 
@@ -2788,9 +2773,6 @@ static size_t h1_make_eoh(struct h1s *h1s, struct h1m *h1m, struct htx *htx, siz
 
                type = htx_get_blk_type(blk);
                sz = htx_get_blksz(blk);
-
-                if (type == HTX_BLK_UNUSED)
-                       continue;
                if (type != HTX_BLK_EOH || sz > count)
                        goto error;
                break;
@@ -3262,8 +3244,6 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf,
                        h1m->state = H1_MSG_TRAILERS;
                        break;
                }
-               else if (type == HTX_BLK_UNUSED)
-                       goto nextblk;
                else
                        goto error;
 
@@ -3381,8 +3361,6 @@ static size_t h1_make_tunnel(struct h1s *h1s, struct h1m *h1m, struct buffer *bu
                        if (!h1_format_htx_data(v, &outbuf, 0))
                                goto full;
                }
-               else if (type == HTX_BLK_UNUSED)
-                       goto nextblk;
                else
                        goto error;
 
@@ -3482,8 +3460,6 @@ static size_t h1_make_trailers(struct h1s *h1s, struct h1m *h1m, struct htx *htx
                        }
                        h1m->state = H1_MSG_DONE;
                }
-               else if (type == HTX_BLK_UNUSED)
-                       goto nextblk;
                else
                        goto error;
 
index 6b1dcbc3f2342c6be9f4dc9ecfcad204409b9e4b..af8f84b02d4ca6da125addde3c5e7195e8312de2 100644 (file)
@@ -6659,9 +6659,6 @@ static size_t h2s_snd_fhdrs(struct h2s *h2s, struct htx *htx)
        for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
                type = htx_get_blk_type(blk);
 
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                if (type == HTX_BLK_EOH)
                        break;
 
@@ -6931,9 +6928,6 @@ static size_t h2s_snd_bhdrs(struct h2s *h2s, struct htx *htx)
        for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
                type = htx_get_blk_type(blk);
 
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                if (type == HTX_BLK_EOH)
                        break;
 
@@ -7737,9 +7731,6 @@ static size_t h2s_make_trailers(struct h2s *h2s, struct htx *htx)
        for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
                type = htx_get_blk_type(blk);
 
-               if (type == HTX_BLK_UNUSED)
-                       continue;
-
                if (type == HTX_BLK_EOT)
                        break;
                if (type == HTX_BLK_TLR) {