From: Christopher Faulet Date: Tue, 15 Sep 2026 11:58:34 +0000 (+0200) Subject: MINOR: htx: Add HTX_BLK_RAW_DATA block type X-Git-Tag: v3.5-dev8~151 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=cfb8f949cbc01e03976bcd546cf3b3b50a3e59a2;p=haproxy.git MINOR: htx: Add HTX_BLK_RAW_DATA block type An HTX message is a partial and stateless representation of an HTTP message. Tunneled data are not part of the HTTP message. However, for now, they are stored in DATA blocks, exactly like the HTTP payload. So there is no way to make the difference between both. A dedicated block type, HTX_BLK_RAW_DATA, is added to fix this. For now, no producer emits such block. Only the HTX API is able to handle it. From this point of view, a RAW_DATA block is exactly the same as a DATA block. Both carry a payload that may be partially consumed. htx_is_data_type() function was added to test this property on a block type. It is important to add the new type in htx_get_blk_value() and htx_set_blk_value_len() switches. Both have a default case silently doing nothing. So a missing entry would lead to an empty payload on one side and to a size never updated on the other side. --- diff --git a/include/haproxy/htx-t.h b/include/haproxy/htx-t.h index af4d14364..70f82f356 100644 --- a/include/haproxy/htx-t.h +++ b/include/haproxy/htx-t.h @@ -209,7 +209,8 @@ enum htx_blk_type { HTX_BLK_DATA = 4, /* data block */ HTX_BLK_TLR = 5, /* trailer name/value block */ HTX_BLK_EOT = 6, /* end-of-trailers block */ - /* 7 .. 14 unused */ + HTX_BLK_RAW_DATA = 7, /* raw data block (tunneled data) */ + /* 8 .. 14 unused */ HTX_BLK_UNUSED = 15, /* unused/removed block */ }; diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index 14f4e3c86..34b9f83ad 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -191,6 +191,14 @@ static inline enum htx_blk_type __htx_blkinfo_size(uint32_t info) } } +/* Returns 1 if is a payload type, i.e. a block carrying data that may be + * partially consumed (HTTP data or tunneled data). Otherwise 0 is returned. + */ +static inline int htx_is_data_type(enum htx_blk_type type) +{ + return (type == HTX_BLK_DATA || type == HTX_BLK_RAW_DATA); +} + /* Returns the size of the block , depending of its type */ static inline uint32_t htx_get_blksz(const struct htx_blk *blk) { @@ -421,6 +429,7 @@ static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen) case HTX_BLK_REQ_SL: case HTX_BLK_RES_SL: case HTX_BLK_DATA: + case HTX_BLK_RAW_DATA: blk->info = (type << 28) + vlen; break; default: @@ -475,6 +484,7 @@ static inline struct ist htx_get_blk_value(const struct htx *htx, const struct h case HTX_BLK_REQ_SL: case HTX_BLK_RES_SL: case HTX_BLK_DATA: + case HTX_BLK_RAW_DATA: ret = ist2(htx_get_blk_ptr(htx, blk), blk->info & 0xfffffff); break; @@ -875,6 +885,7 @@ static inline int htx_set_eom(struct htx *htx) } blk = ASSUME_NONNULL(htx_get_tail_blk(htx)); + BUG_ON(htx_get_blk_type(blk) != HTX_BLK_EOH && htx_get_blk_type(blk) != HTX_BLK_EOT && htx_get_blk_type(blk) != HTX_BLK_DATA); @@ -942,6 +953,7 @@ static inline const char *htx_blk_type_str(enum htx_blk_type type) case HTX_BLK_HDR: return "HTX_BLK_HDR"; case HTX_BLK_EOH: return "HTX_BLK_EOH"; case HTX_BLK_DATA: return "HTX_BLK_DATA"; + case HTX_BLK_RAW_DATA: return "HTX_BLK_RAW_DATA"; case HTX_BLK_TLR: return "HTX_BLK_TLR"; case HTX_BLK_EOT: return "HTX_BLK_EOT"; case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED";