]> 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, 18 Sep 2026 15:05:18 +0000 (17:05 +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 885b5115df30b17cbde03217c4ea3cd7f687120e..0d745b851f9dd8c2b252823dfc4cb3312cc59c4a 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 b1a9803d6b9ccb43369efd5bdaa1d2370266c6d5..dd49c66e6b8f3a291912711cf95229658f3f083a 100644 (file)
@@ -851,9 +851,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 534ee5f38fd2d886783fc55ebce857badac50d47..3267a0ba6fa7e540928509b19ad53fdb52e7fc23 100644 (file)
@@ -302,8 +302,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 b6176cd4a116dcfe88945fe66869a65a0ccba15a..ac55b7a89514b650c80a9ade46862e0374018c30 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -2408,8 +2408,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 */
@@ -2629,9 +2627,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;
 
@@ -2866,9 +2861,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 67f13483d761cb71ad215151d2a228a4cccca08b..f1a73733dc6c890c0b051f1bc85e3f98e6f98963 100644 (file)
@@ -5837,9 +5837,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;
@@ -5937,9 +5934,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;
@@ -7341,9 +7335,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);
@@ -7477,9 +7468,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 3e5681357ac219f4f324e483aec6dbf86b2e2561..dc6854dc6dc5889f2c66089e9994d526f23e5dc7 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -538,10 +538,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);
@@ -551,7 +547,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;
@@ -793,8 +788,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 &&
@@ -1262,10 +1255,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 f19113512105c9bded9aa760257abaa5f653e1f4..a58bf353f028d67536da5d4ddac658286b472790 100644 (file)
@@ -1932,10 +1932,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;
 
@@ -2482,10 +2478,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;
@@ -2572,11 +2564,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;
@@ -2740,8 +2727,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;
 
@@ -2797,9 +2782,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;
@@ -3277,8 +3259,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;
 
@@ -3396,8 +3376,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;
 
@@ -3497,8 +3475,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 21cd83b3e8a96c77825deb5aa0a88755b9a6043a..2459ff7928e54a255a5c8ab4c76235d469ca8bf0 100644 (file)
@@ -6713,9 +6713,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;
 
@@ -6985,9 +6982,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;
 
@@ -7797,9 +7791,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) {