From 0bdeeaacbbd2341a49af1b1d193a8b714e66cb69 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 4 Jun 2019 22:09:53 +0200 Subject: [PATCH] BUG/MINOR: flt_trace/htx: Only apply the random forwarding on the message body. In the function trace_http_payload(), when the random forwarding is enabled, only blocks of type HTX_BLK_DATA must be considered. Because other blocks must be forwarding in one time. This patch must be backported to 1.9. But it will have to be adapted. Because several changes on the HTX in the 2.0 are missing in the 1.9. --- src/flt_trace.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/flt_trace.c b/src/flt_trace.c index 4eb8d5fe6a..e001d7b370 100644 --- a/src/flt_trace.c +++ b/src/flt_trace.c @@ -464,8 +464,32 @@ trace_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg struct trace_config *conf = FLT_CONF(filter); int ret = len; - if (ret && conf->rand_forwarding) + if (ret && conf->rand_forwarding) { + struct htx *htx = htxbuf(&msg->chn->buf); + struct htx_blk *blk; + uint32_t sz, data = 0; + + for (blk = htx_get_first_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) { + if (htx_get_blk_type(blk) != HTX_BLK_DATA) + break; + + sz = htx_get_blksz(blk); + if (offset >= sz) { + offset -= sz; + continue; + } + data += sz - offset; + offset = 0; + if (data > len) { + data = len; + break; + } + } + ret = random() % (ret+1); + if (ret > data) + ret = len; + } STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - " "offset=%u - len=%u - forward=%d", -- 2.39.5