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-Tag: v3.5-dev8~173 X-Git-Url: https://git.kaiwu.me/$%7BGITURL%7D$%7Bcid%7D?a=commitdiff_plain;h=83024657c8a15ef257effb0ede2cdf128a91bd00;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 885b5115d..0d745b851 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 b1a9803d6..dd49c66e6 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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); diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 534ee5f38..3267a0ba6 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -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; 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 b6176cd4a..ac55b7a89 100644 --- 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; diff --git a/src/hlua.c b/src/hlua.c index 67f13483d..f1a73733d 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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 diff --git a/src/htx.c b/src/htx.c index 3e5681357..dc6854dc6 100644 --- 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) diff --git a/src/mux_h1.c b/src/mux_h1.c index f19113512..a58bf353f 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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; diff --git a/src/mux_h2.c b/src/mux_h2.c index 21cd83b3e..2459ff792 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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) {