]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: flt_trace/htx: Only apply the random forwarding on the message body.
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 4 Jun 2019 20:09:53 +0000 (22:09 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Jun 2019 08:12:11 +0000 (10:12 +0200)
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

index 4eb8d5fe6aad67f912d0f638ba0bed7144ac57a1..e001d7b370381d015b8e04ee9ab89b6bd1004f08 100644 (file)
@@ -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",