MINOR: flt-trace: Use a bitfield for the trace options
Instead of using a integer for each option, we now use a bitfield. Each option
is represented as a flag now.
diff --git a/src/flt_trace.c b/src/flt_trace.c
index dd93ed4..a79cddc 100644
--- a/src/flt_trace.c
+++ b/src/flt_trace.c
@@ -29,17 +29,19 @@
struct flt_ops trace_ops;
+#define TRACE_F_QUIET 0x00000001
+#define TRACE_F_RAND_FWD 0x00000002
+#define TRACE_F_HEXDUMP 0x00000004
+
struct trace_config {
struct proxy *proxy;
char *name;
- int quiet;
- int rand_forwarding;
- int hexdump;
+ unsigned int flags;
};
#define FLT_TRACE(conf, fmt, ...) \
do { \
- if (!(conf->quiet)) \
+ if (!(conf->flags & TRACE_F_QUIET)) \
fprintf(stderr, "%d.%06d [%-20s] " fmt "\n", \
(int)now.tv_sec, (int)now.tv_usec, (conf)->name,\
##__VA_ARGS__); \
@@ -47,7 +49,7 @@
#define FLT_STRM_TRACE(conf, strm, fmt, ...) \
do { \
- if (!(conf->quiet)) \
+ if (!(conf->flags & TRACE_F_QUIET)) \
fprintf(stderr, "%d.%06d [%-20s] [strm %p(%x) 0x%08x 0x%08x] " fmt "\n", \
(int)now.tv_sec, (int)now.tv_usec, (conf)->name, \
strm, (strm ? ((struct stream *)strm)->uniq_id : ~0U), \
@@ -195,9 +197,9 @@
fconf->conf = conf;
FLT_TRACE(conf, "filter initialized [quiet=%s - fwd random=%s - hexdump=%s]",
- (conf->quiet ? "true" : "false"),
- (conf->rand_forwarding ? "true" : "false"),
- (conf->hexdump ? "true" : "false"));
+ ((conf->flags & TRACE_F_QUIET) ? "true" : "false"),
+ ((conf->flags & TRACE_F_RAND_FWD) ? "true" : "false"),
+ ((conf->flags & TRACE_F_HEXDUMP) ? "true" : "false"));
return 0;
}
@@ -464,7 +466,7 @@
struct trace_config *conf = FLT_CONF(filter);
int ret = len;
- if (ret && conf->rand_forwarding) {
+ if (ret && (conf->flags & TRACE_F_RAND_FWD)) {
unsigned int data = trace_get_htx_datalen(htxbuf(&msg->chn->buf), offset, len);
if (data) {
@@ -480,7 +482,7 @@
channel_label(msg->chn), proxy_mode(s), stream_pos(s),
offset, len, ret);
- if (conf->hexdump)
+ if (conf->flags & TRACE_F_HEXDUMP)
trace_htx_hexdump(htxbuf(&msg->chn->buf), offset, ret);
if (ret != len)
@@ -532,7 +534,7 @@
int ret = len;
if (s->flags & SF_HTX) {
- if (ret && conf->rand_forwarding) {
+ if (ret && (conf->flags & TRACE_F_RAND_FWD)) {
unsigned int data = trace_get_htx_datalen(htxbuf(&chn->buf), offset, len);
if (data) {
@@ -548,12 +550,12 @@
channel_label(chn), proxy_mode(s), stream_pos(s),
offset, len, ret);
- if (conf->hexdump)
+ if (conf->flags & TRACE_F_HEXDUMP)
trace_htx_hexdump(htxbuf(&chn->buf), offset, ret);
}
else {
- if (ret && conf->rand_forwarding)
+ if (ret && (conf->flags & TRACE_F_RAND_FWD))
ret = ha_random() % (ret+1);
FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - "
@@ -562,7 +564,7 @@
channel_label(chn), proxy_mode(s), stream_pos(s),
offset, len, ret);
- if (conf->hexdump)
+ if (conf->flags & TRACE_F_HEXDUMP)
trace_raw_hexdump(&chn->buf, offset, ret);
}
@@ -620,7 +622,7 @@
return -1;
}
conf->proxy = px;
-
+ conf->flags = 0;
if (!strcmp(args[pos], "trace")) {
pos++;
@@ -639,13 +641,13 @@
pos++;
}
else if (!strcmp(args[pos], "quiet"))
- conf->quiet = 1;
+ conf->flags |= TRACE_F_QUIET;
else if (!strcmp(args[pos], "random-parsing"))
continue; // ignore
else if (!strcmp(args[pos], "random-forwarding"))
- conf->rand_forwarding = 1;
+ conf->flags |= TRACE_F_RAND_FWD;
else if (!strcmp(args[pos], "hexdump"))
- conf->hexdump = 1;
+ conf->flags |= TRACE_F_HEXDUMP;
else
break;
pos++;