From: Christopher Faulet Date: Thu, 23 Jul 2026 09:05:53 +0000 (+0200) Subject: MEDIUM: htx/tree-wide: Remove tests on HTX_BLK_UNUSED when possible X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=d8792523dfb2c358694e96405d79b443d40b9196;p=haproxy.git MEDIUM: htx/tree-wide: Remove tests on HTX_BLK_UNUSED when possible 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. --- diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index b48d87df6..fac0dc72d 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -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 . -1 means * the first block is unset or the HTS is empty. */ diff --git a/src/cache.c b/src/cache.c index b9fa2d45a..e20d8a5f0 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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); diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 922483248..7fa3d9623 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -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; diff --git a/src/flt_trace.c b/src/flt_trace.c index 77577ecf5..cd9e5dbc3 100644 --- a/src/flt_trace.c +++ b/src/flt_trace.c @@ -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; diff --git a/src/h3.c b/src/h3.c index d11005eb0..838a86151 100644 --- 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; diff --git a/src/hlua.c b/src/hlua.c index 7bdd3d4b7..99318b330 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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 diff --git a/src/htx.c b/src/htx.c index fff828932..f6bb60e41 100644 --- 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) diff --git a/src/mux_h1.c b/src/mux_h1.c index 81ac9b371..6c37b5d19 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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; diff --git a/src/mux_h2.c b/src/mux_h2.c index 6b1dcbc3f..af8f84b02 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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) {