mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-18 18:19:39 -05:00
MINOR: flt-trace: Add an option to limit the amount of data forwarded
"max-fwd <max>" option can now be used to limit the maximum amount of data forwarded at a time by the filter. It could be handy to make tests.
This commit is contained in:
parent
92307b5fec
commit
829002d459
2 changed files with 32 additions and 3 deletions
|
|
@ -29778,7 +29778,7 @@ See also : "filter"
|
|||
9.1. Trace
|
||||
----------
|
||||
|
||||
filter trace [name <name>] [random-forwarding] [hexdump]
|
||||
filter trace [name <name>] [random-forwarding] [max-fwd <max>] [hexdump]
|
||||
|
||||
Arguments:
|
||||
<name> is an arbitrary name that will be reported in
|
||||
|
|
@ -29791,6 +29791,11 @@ filter trace [name <name>] [random-forwarding] [hexdump]
|
|||
data. With this parameter, it only forwards a random
|
||||
amount of the parsed data.
|
||||
|
||||
<max> is the maximum amount of data that can be forwarded at
|
||||
a time. "max-fwd" option can be combined with the
|
||||
random forwarding. <max> must be an positive integer.
|
||||
0 means there is no limit.
|
||||
|
||||
<hexdump> dumps all forwarded data to the server and the client.
|
||||
|
||||
This filter can be used as a base to develop new filters. It defines all
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ struct trace_config {
|
|||
struct proxy *proxy;
|
||||
char *name;
|
||||
unsigned int flags;
|
||||
unsigned int max_fwd;
|
||||
};
|
||||
|
||||
#define FLT_TRACE(conf, fmt, ...) \
|
||||
|
|
@ -194,10 +195,11 @@ trace_init(struct proxy *px, struct flt_conf *fconf)
|
|||
fconf->flags |= FLT_CFG_FL_HTX;
|
||||
fconf->conf = conf;
|
||||
|
||||
FLT_TRACE(conf, "filter initialized [quiet=%s - fwd random=%s - hexdump=%s]",
|
||||
FLT_TRACE(conf, "filter initialized [quiet=%s - fwd random=%s - hexdump=%s - max fwd=%u]",
|
||||
((conf->flags & TRACE_F_QUIET) ? "true" : "false"),
|
||||
((conf->flags & TRACE_F_RAND_FWD) ? "true" : "false"),
|
||||
((conf->flags & TRACE_F_HEXDUMP) ? "true" : "false"));
|
||||
((conf->flags & TRACE_F_HEXDUMP) ? "true" : "false"),
|
||||
conf->max_fwd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -473,6 +475,8 @@ trace_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg
|
|||
ret = len;
|
||||
}
|
||||
}
|
||||
if (conf->max_fwd && ret > conf->max_fwd)
|
||||
ret = conf->max_fwd;
|
||||
|
||||
FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - "
|
||||
"offset=%u - len=%u - forward=%d",
|
||||
|
|
@ -541,6 +545,8 @@ trace_tcp_payload(struct stream *s, struct filter *filter, struct channel *chn,
|
|||
ret = len;
|
||||
}
|
||||
}
|
||||
if (conf->max_fwd && ret > conf->max_fwd)
|
||||
ret = conf->max_fwd;
|
||||
|
||||
FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - "
|
||||
"offset=%u - len=%u - forward=%d",
|
||||
|
|
@ -555,6 +561,8 @@ trace_tcp_payload(struct stream *s, struct filter *filter, struct channel *chn,
|
|||
|
||||
if (ret && (conf->flags & TRACE_F_RAND_FWD))
|
||||
ret = ha_random() % (ret+1);
|
||||
if (conf->max_fwd && ret > conf->max_fwd)
|
||||
ret = conf->max_fwd;
|
||||
|
||||
FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - "
|
||||
"offset=%u - len=%u - forward=%d",
|
||||
|
|
@ -651,6 +659,22 @@ parse_trace_flt(char **args, int *cur_arg, struct proxy *px,
|
|||
conf->flags |= TRACE_F_RAND_FWD;
|
||||
else if (strcmp(args[pos], "hexdump") == 0)
|
||||
conf->flags |= TRACE_F_HEXDUMP;
|
||||
else if (strcmp(args[pos], "max-fwd") == 0) {
|
||||
long long max;
|
||||
if (!*args[pos + 1]) {
|
||||
memprintf(err, "'%s' : '%s' option without value",
|
||||
args[*cur_arg], args[pos]);
|
||||
goto error;
|
||||
}
|
||||
max = atoll(args[pos + 1]);
|
||||
if (max < 0 || max > UINT_MAX) {
|
||||
memprintf(err, "'%s' : '%s' expect unsigned integer (0 to 4294967295 expected)",
|
||||
args[*cur_arg], args[pos]);
|
||||
goto error;
|
||||
}
|
||||
conf->max_fwd = max;
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
pos++;
|
||||
|
|
|
|||
Loading…
Reference in a new issue