Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Stream filters related variables and functions. |
| 3 | * |
| 4 | * Copyright (C) 2015 Qualys Inc., Christopher Faulet <cfaulet@qualys.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 13 | #include <ctype.h> |
| 14 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 15 | #include <haproxy/api.h> |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 16 | #include <haproxy/channel-t.h> |
Willy Tarreau | c7babd8 | 2020-06-04 21:29:29 +0200 | [diff] [blame] | 17 | #include <haproxy/filters.h> |
Willy Tarreau | c2b1ff0 | 2020-06-04 21:21:03 +0200 | [diff] [blame] | 18 | #include <haproxy/http_ana-t.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 19 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 20 | #include <haproxy/htx.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame^] | 21 | #include <haproxy/log.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 22 | #include <haproxy/tools.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 23 | #include <haproxy/time.h> |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 25 | #include <haproxy/global.h> |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 26 | #include <types/proxy.h> |
| 27 | #include <types/stream.h> |
| 28 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 29 | #include <proto/stream.h> |
| 30 | |
Christopher Faulet | f4a4ef7 | 2018-12-07 17:39:53 +0100 | [diff] [blame] | 31 | const char *trace_flt_id = "trace filter"; |
| 32 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 33 | struct flt_ops trace_ops; |
| 34 | |
| 35 | struct trace_config { |
| 36 | struct proxy *proxy; |
| 37 | char *name; |
| 38 | int rand_parsing; |
| 39 | int rand_forwarding; |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 40 | int hexdump; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 43 | #define FLT_TRACE(conf, fmt, ...) \ |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 44 | fprintf(stderr, "%d.%06d [%-20s] " fmt "\n", \ |
| 45 | (int)now.tv_sec, (int)now.tv_usec, (conf)->name, \ |
| 46 | ##__VA_ARGS__) |
| 47 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 48 | #define FLT_STRM_TRACE(conf, strm, fmt, ...) \ |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 49 | fprintf(stderr, "%d.%06d [%-20s] [strm %p(%x) 0x%08x 0x%08x] " fmt "\n", \ |
| 50 | (int)now.tv_sec, (int)now.tv_usec, (conf)->name, \ |
| 51 | strm, (strm ? ((struct stream *)strm)->uniq_id : ~0U), \ |
| 52 | (strm ? strm->req.analysers : 0), (strm ? strm->res.analysers : 0), \ |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 53 | ##__VA_ARGS__) |
| 54 | |
| 55 | |
| 56 | static const char * |
| 57 | channel_label(const struct channel *chn) |
| 58 | { |
| 59 | return (chn->flags & CF_ISRESP) ? "RESPONSE" : "REQUEST"; |
| 60 | } |
| 61 | |
| 62 | static const char * |
| 63 | proxy_mode(const struct stream *s) |
| 64 | { |
| 65 | struct proxy *px = (s->flags & SF_BE_ASSIGNED ? s->be : strm_fe(s)); |
| 66 | |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 67 | return ((px->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static const char * |
| 71 | stream_pos(const struct stream *s) |
| 72 | { |
| 73 | return (s->flags & SF_BE_ASSIGNED) ? "backend" : "frontend"; |
| 74 | } |
| 75 | |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 76 | static const char * |
| 77 | filter_type(const struct filter *f) |
| 78 | { |
| 79 | return (f->flags & FLT_FL_IS_BACKEND_FILTER) ? "backend" : "frontend"; |
| 80 | } |
| 81 | |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 82 | static void |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 83 | trace_hexdump(struct ist ist) |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 84 | { |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 85 | int i, j, padding; |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 86 | |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 87 | padding = ((ist.len % 16) ? (16 - ist.len % 16) : 0); |
| 88 | for (i = 0; i < ist.len + padding; i++) { |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 89 | if (!(i % 16)) |
| 90 | fprintf(stderr, "\t0x%06x: ", i); |
| 91 | else if (!(i % 8)) |
| 92 | fprintf(stderr, " "); |
| 93 | |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 94 | if (i < ist.len) |
| 95 | fprintf(stderr, "%02x ", (unsigned char)*(ist.ptr+i)); |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 96 | else |
| 97 | fprintf(stderr, " "); |
| 98 | |
| 99 | /* print ASCII dump */ |
| 100 | if (i % 16 == 15) { |
| 101 | fprintf(stderr, " |"); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 102 | for(j = i - 15; j <= i && j < ist.len; j++) |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 103 | fprintf(stderr, "%c", (isprint((unsigned char)*(ist.ptr+j)) ? *(ist.ptr+j) : '.')); |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 104 | fprintf(stderr, "|\n"); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 109 | static void |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 110 | trace_raw_hexdump(struct buffer *buf, unsigned int offset, unsigned int len) |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 111 | { |
| 112 | unsigned char p[len]; |
| 113 | int block1, block2; |
| 114 | |
| 115 | block1 = len; |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 116 | if (block1 > b_contig_data(buf, offset)) |
| 117 | block1 = b_contig_data(buf, offset); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 118 | block2 = len - block1; |
| 119 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 120 | memcpy(p, b_peek(buf, offset), block1); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 121 | memcpy(p+block1, b_orig(buf), block2); |
| 122 | trace_hexdump(ist2(p, len)); |
| 123 | } |
| 124 | |
| 125 | static void |
| 126 | trace_htx_hexdump(struct htx *htx, unsigned int offset, unsigned int len) |
| 127 | { |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 128 | struct htx_blk *blk; |
| 129 | |
Christopher Faulet | ee847d4 | 2019-05-23 11:55:33 +0200 | [diff] [blame] | 130 | for (blk = htx_get_first_blk(htx); blk && len; blk = htx_get_next_blk(htx, blk)) { |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 131 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | ee847d4 | 2019-05-23 11:55:33 +0200 | [diff] [blame] | 132 | uint32_t sz = htx_get_blksz(blk); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 133 | struct ist v; |
| 134 | |
Christopher Faulet | ee847d4 | 2019-05-23 11:55:33 +0200 | [diff] [blame] | 135 | if (offset >= sz) { |
| 136 | offset -= sz; |
| 137 | continue; |
| 138 | } |
| 139 | |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 140 | v = htx_get_blk_value(htx, blk); |
| 141 | v.ptr += offset; |
| 142 | v.len -= offset; |
| 143 | offset = 0; |
| 144 | |
| 145 | if (v.len > len) |
| 146 | v.len = len; |
| 147 | len -= v.len; |
Christopher Faulet | 2d7c539 | 2019-06-03 10:41:26 +0200 | [diff] [blame] | 148 | if (type == HTX_BLK_DATA) |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 149 | trace_hexdump(v); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 153 | static unsigned int |
| 154 | trace_get_htx_datalen(struct htx *htx, unsigned int offset, unsigned int len) |
| 155 | { |
| 156 | struct htx_blk *blk; |
Christopher Faulet | 24598a4 | 2020-02-26 22:06:11 +0100 | [diff] [blame] | 157 | struct htx_ret htxret = htx_find_offset(htx, offset); |
| 158 | uint32_t data = 0; |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 159 | |
Christopher Faulet | 24598a4 | 2020-02-26 22:06:11 +0100 | [diff] [blame] | 160 | blk = htxret.blk; |
| 161 | if (blk && htxret.ret && htx_get_blk_type(blk) == HTX_BLK_DATA) { |
| 162 | data += htxret.ret; |
| 163 | blk = htx_get_next_blk(htx, blk); |
| 164 | } |
| 165 | while (blk) { |
| 166 | if (htx_get_blk_type(blk) == HTX_BLK_UNUSED) |
| 167 | goto next; |
| 168 | else if (htx_get_blk_type(blk) != HTX_BLK_DATA) |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 169 | break; |
Christopher Faulet | 24598a4 | 2020-02-26 22:06:11 +0100 | [diff] [blame] | 170 | data += htx_get_blksz(blk); |
| 171 | next: |
| 172 | blk = htx_get_next_blk(htx, blk); |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 173 | } |
| 174 | return data; |
| 175 | } |
| 176 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 177 | /*************************************************************************** |
| 178 | * Hooks that manage the filter lifecycle (init/check/deinit) |
| 179 | **************************************************************************/ |
| 180 | /* Initialize the filter. Returns -1 on error, else 0. */ |
| 181 | static int |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 182 | trace_init(struct proxy *px, struct flt_conf *fconf) |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 183 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 184 | struct trace_config *conf = fconf->conf; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 185 | |
| 186 | if (conf->name) |
| 187 | memprintf(&conf->name, "%s/%s", conf->name, px->id); |
| 188 | else |
| 189 | memprintf(&conf->name, "TRACE/%s", px->id); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 190 | |
Christopher Faulet | 6e54095 | 2018-12-03 22:43:41 +0100 | [diff] [blame] | 191 | fconf->flags |= FLT_CFG_FL_HTX; |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 192 | fconf->conf = conf; |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 193 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 194 | FLT_TRACE(conf, "filter initialized [read random=%s - fwd random=%s - hexdump=%s]", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 195 | (conf->rand_parsing ? "true" : "false"), |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 196 | (conf->rand_forwarding ? "true" : "false"), |
| 197 | (conf->hexdump ? "true" : "false")); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | /* Free ressources allocated by the trace filter. */ |
| 202 | static void |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 203 | trace_deinit(struct proxy *px, struct flt_conf *fconf) |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 204 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 205 | struct trace_config *conf = fconf->conf; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 206 | |
| 207 | if (conf) { |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 208 | FLT_TRACE(conf, "filter deinitialized"); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 209 | free(conf->name); |
| 210 | free(conf); |
| 211 | } |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 212 | fconf->conf = NULL; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* Check configuration of a trace filter for a specified proxy. |
| 216 | * Return 1 on error, else 0. */ |
| 217 | static int |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 218 | trace_check(struct proxy *px, struct flt_conf *fconf) |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 219 | { |
| 220 | return 0; |
| 221 | } |
| 222 | |
Christopher Faulet | f227372 | 2017-07-27 16:58:42 +0200 | [diff] [blame] | 223 | /* Initialize the filter for each thread. Return -1 on error, else 0. */ |
| 224 | static int |
| 225 | trace_init_per_thread(struct proxy *px, struct flt_conf *fconf) |
| 226 | { |
| 227 | struct trace_config *conf = fconf->conf; |
| 228 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 229 | FLT_TRACE(conf, "filter initialized for thread tid %u", tid); |
Christopher Faulet | f227372 | 2017-07-27 16:58:42 +0200 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* Free ressources allocate by the trace filter for each thread. */ |
| 234 | static void |
| 235 | trace_deinit_per_thread(struct proxy *px, struct flt_conf *fconf) |
| 236 | { |
| 237 | struct trace_config *conf = fconf->conf; |
| 238 | |
| 239 | if (conf) |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 240 | FLT_TRACE(conf, "filter deinitialized for thread tid %u", tid); |
Christopher Faulet | f227372 | 2017-07-27 16:58:42 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 243 | /************************************************************************** |
| 244 | * Hooks to handle start/stop of streams |
| 245 | *************************************************************************/ |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 246 | /* Called when a filter instance is created and attach to a stream */ |
| 247 | static int |
| 248 | trace_attach(struct stream *s, struct filter *filter) |
| 249 | { |
| 250 | struct trace_config *conf = FLT_CONF(filter); |
| 251 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 252 | FLT_STRM_TRACE(conf, s, "%-25s: filter-type=%s", |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 253 | __FUNCTION__, filter_type(filter)); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 254 | |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | /* Called when a filter instance is detach from a stream, just before its |
| 259 | * destruction */ |
| 260 | static void |
| 261 | trace_detach(struct stream *s, struct filter *filter) |
| 262 | { |
| 263 | struct trace_config *conf = FLT_CONF(filter); |
| 264 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 265 | FLT_STRM_TRACE(conf, s, "%-25s: filter-type=%s", |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 266 | __FUNCTION__, filter_type(filter)); |
| 267 | } |
| 268 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 269 | /* Called when a stream is created */ |
| 270 | static int |
| 271 | trace_stream_start(struct stream *s, struct filter *filter) |
| 272 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 273 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 274 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 275 | FLT_STRM_TRACE(conf, s, "%-25s", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 276 | __FUNCTION__); |
| 277 | return 0; |
| 278 | } |
| 279 | |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 280 | |
| 281 | /* Called when a backend is set for a stream */ |
| 282 | static int |
| 283 | trace_stream_set_backend(struct stream *s, struct filter *filter, |
| 284 | struct proxy *be) |
| 285 | { |
| 286 | struct trace_config *conf = FLT_CONF(filter); |
| 287 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 288 | FLT_STRM_TRACE(conf, s, "%-25s: backend=%s", |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 289 | __FUNCTION__, be->id); |
| 290 | return 0; |
| 291 | } |
| 292 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 293 | /* Called when a stream is destroyed */ |
| 294 | static void |
| 295 | trace_stream_stop(struct stream *s, struct filter *filter) |
| 296 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 297 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 298 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 299 | FLT_STRM_TRACE(conf, s, "%-25s", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 300 | __FUNCTION__); |
| 301 | } |
| 302 | |
Christopher Faulet | a00d817 | 2016-11-10 14:58:05 +0100 | [diff] [blame] | 303 | /* Called when the stream is woken up because of an expired timer */ |
| 304 | static void |
| 305 | trace_check_timeouts(struct stream *s, struct filter *filter) |
| 306 | { |
| 307 | struct trace_config *conf = FLT_CONF(filter); |
| 308 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 309 | FLT_STRM_TRACE(conf, s, "%-25s", |
Christopher Faulet | a00d817 | 2016-11-10 14:58:05 +0100 | [diff] [blame] | 310 | __FUNCTION__); |
| 311 | } |
| 312 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 313 | /************************************************************************** |
| 314 | * Hooks to handle channels activity |
| 315 | *************************************************************************/ |
| 316 | /* Called when analyze starts for a given channel */ |
| 317 | static int |
| 318 | trace_chn_start_analyze(struct stream *s, struct filter *filter, |
| 319 | struct channel *chn) |
| 320 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 321 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 322 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 323 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 324 | __FUNCTION__, |
| 325 | channel_label(chn), proxy_mode(s), stream_pos(s)); |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 326 | filter->pre_analyzers |= (AN_REQ_ALL | AN_RES_ALL); |
| 327 | filter->post_analyzers |= (AN_REQ_ALL | AN_RES_ALL); |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 328 | register_data_filter(s, chn, filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | /* Called before a processing happens on a given channel */ |
| 333 | static int |
| 334 | trace_chn_analyze(struct stream *s, struct filter *filter, |
| 335 | struct channel *chn, unsigned an_bit) |
| 336 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 337 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 338 | char *ana; |
| 339 | |
| 340 | switch (an_bit) { |
| 341 | case AN_REQ_INSPECT_FE: |
| 342 | ana = "AN_REQ_INSPECT_FE"; |
| 343 | break; |
| 344 | case AN_REQ_WAIT_HTTP: |
| 345 | ana = "AN_REQ_WAIT_HTTP"; |
| 346 | break; |
| 347 | case AN_REQ_HTTP_BODY: |
| 348 | ana = "AN_REQ_HTTP_BODY"; |
| 349 | break; |
| 350 | case AN_REQ_HTTP_PROCESS_FE: |
| 351 | ana = "AN_REQ_HTTP_PROCESS_FE"; |
| 352 | break; |
| 353 | case AN_REQ_SWITCHING_RULES: |
| 354 | ana = "AN_REQ_SWITCHING_RULES"; |
| 355 | break; |
| 356 | case AN_REQ_INSPECT_BE: |
| 357 | ana = "AN_REQ_INSPECT_BE"; |
| 358 | break; |
| 359 | case AN_REQ_HTTP_PROCESS_BE: |
| 360 | ana = "AN_REQ_HTTP_PROCESS_BE"; |
| 361 | break; |
| 362 | case AN_REQ_SRV_RULES: |
| 363 | ana = "AN_REQ_SRV_RULES"; |
| 364 | break; |
| 365 | case AN_REQ_HTTP_INNER: |
| 366 | ana = "AN_REQ_HTTP_INNER"; |
| 367 | break; |
| 368 | case AN_REQ_HTTP_TARPIT: |
| 369 | ana = "AN_REQ_HTTP_TARPIT"; |
| 370 | break; |
| 371 | case AN_REQ_STICKING_RULES: |
| 372 | ana = "AN_REQ_STICKING_RULES"; |
| 373 | break; |
| 374 | case AN_REQ_PRST_RDP_COOKIE: |
| 375 | ana = "AN_REQ_PRST_RDP_COOKIE"; |
| 376 | break; |
| 377 | case AN_REQ_HTTP_XFER_BODY: |
| 378 | ana = "AN_REQ_HTTP_XFER_BODY"; |
| 379 | break; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 380 | case AN_RES_INSPECT: |
| 381 | ana = "AN_RES_INSPECT"; |
| 382 | break; |
| 383 | case AN_RES_WAIT_HTTP: |
| 384 | ana = "AN_RES_WAIT_HTTP"; |
| 385 | break; |
| 386 | case AN_RES_HTTP_PROCESS_FE: // AN_RES_HTTP_PROCESS_BE |
| 387 | ana = "AN_RES_HTTP_PROCESS_FE/BE"; |
| 388 | break; |
| 389 | case AN_RES_STORE_RULES: |
| 390 | ana = "AN_RES_STORE_RULES"; |
| 391 | break; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 392 | case AN_RES_HTTP_XFER_BODY: |
| 393 | ana = "AN_RES_HTTP_XFER_BODY"; |
| 394 | break; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 395 | default: |
| 396 | ana = "unknown"; |
| 397 | } |
| 398 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 399 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - " |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 400 | "analyzer=%s - step=%s", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 401 | __FUNCTION__, |
| 402 | channel_label(chn), proxy_mode(s), stream_pos(s), |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 403 | ana, ((chn->analysers & an_bit) ? "PRE" : "POST")); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 404 | return 1; |
| 405 | } |
| 406 | |
| 407 | /* Called when analyze ends for a given channel */ |
| 408 | static int |
| 409 | trace_chn_end_analyze(struct stream *s, struct filter *filter, |
| 410 | struct channel *chn) |
| 411 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 412 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 413 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 414 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 415 | __FUNCTION__, |
| 416 | channel_label(chn), proxy_mode(s), stream_pos(s)); |
| 417 | return 1; |
| 418 | } |
| 419 | |
| 420 | /************************************************************************** |
| 421 | * Hooks to filter HTTP messages |
| 422 | *************************************************************************/ |
| 423 | static int |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 424 | trace_http_headers(struct stream *s, struct filter *filter, |
| 425 | struct http_msg *msg) |
| 426 | { |
| 427 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 428 | struct htx *htx = htxbuf(&msg->chn->buf); |
| 429 | struct htx_sl *sl = http_get_stline(htx); |
| 430 | int32_t pos; |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 431 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 432 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)\t%.*s %.*s %.*s", |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 433 | __FUNCTION__, |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 434 | channel_label(msg->chn), proxy_mode(s), stream_pos(s), |
| 435 | HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), |
| 436 | HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), |
| 437 | HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 438 | |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 439 | for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { |
| 440 | struct htx_blk *blk = htx_get_blk(htx, pos); |
| 441 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 442 | struct ist n, v; |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 443 | |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 444 | if (type == HTX_BLK_EOH) |
| 445 | break; |
| 446 | if (type != HTX_BLK_HDR) |
| 447 | continue; |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 448 | |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 449 | n = htx_get_blk_name(htx, blk); |
| 450 | v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 451 | FLT_STRM_TRACE(conf, s, "\t%.*s: %.*s", |
Christopher Faulet | 386a0cd | 2019-07-15 21:22:44 +0200 | [diff] [blame] | 452 | (int)n.len, n.ptr, (int)v.len, v.ptr); |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 453 | } |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 454 | return 1; |
| 455 | } |
| 456 | |
| 457 | static int |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 458 | trace_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg, |
| 459 | unsigned int offset, unsigned int len) |
| 460 | { |
| 461 | struct trace_config *conf = FLT_CONF(filter); |
| 462 | int ret = len; |
| 463 | |
Christopher Faulet | 0bdeeaa | 2019-06-04 22:09:53 +0200 | [diff] [blame] | 464 | if (ret && conf->rand_forwarding) { |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 465 | unsigned int data = trace_get_htx_datalen(htxbuf(&msg->chn->buf), offset, len); |
Christopher Faulet | 0bdeeaa | 2019-06-04 22:09:53 +0200 | [diff] [blame] | 466 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 467 | if (data) { |
Willy Tarreau | 52bf839 | 2020-03-08 00:42:37 +0100 | [diff] [blame] | 468 | ret = ha_random() % (ret+1); |
Christopher Faulet | 647fe1d | 2019-06-12 16:07:48 +0200 | [diff] [blame] | 469 | if (!ret || ret >= data) |
| 470 | ret = len; |
| 471 | } |
Christopher Faulet | 0bdeeaa | 2019-06-04 22:09:53 +0200 | [diff] [blame] | 472 | } |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 473 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 474 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - " |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 475 | "offset=%u - len=%u - forward=%d", |
| 476 | __FUNCTION__, |
| 477 | channel_label(msg->chn), proxy_mode(s), stream_pos(s), |
| 478 | offset, len, ret); |
| 479 | |
| 480 | if (conf->hexdump) |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 481 | trace_htx_hexdump(htxbuf(&msg->chn->buf), offset, ret); |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 482 | |
| 483 | if (ret != len) |
| 484 | task_wakeup(s->task, TASK_WOKEN_MSG); |
| 485 | return ret; |
| 486 | } |
| 487 | |
| 488 | static int |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 489 | trace_http_end(struct stream *s, struct filter *filter, |
| 490 | struct http_msg *msg) |
| 491 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 492 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 493 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 494 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 495 | __FUNCTION__, |
| 496 | channel_label(msg->chn), proxy_mode(s), stream_pos(s)); |
| 497 | return 1; |
| 498 | } |
| 499 | |
| 500 | static void |
| 501 | trace_http_reset(struct stream *s, struct filter *filter, |
| 502 | struct http_msg *msg) |
| 503 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 504 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 505 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 506 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 507 | __FUNCTION__, |
| 508 | channel_label(msg->chn), proxy_mode(s), stream_pos(s)); |
| 509 | } |
| 510 | |
| 511 | static void |
| 512 | trace_http_reply(struct stream *s, struct filter *filter, short status, |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 513 | const struct buffer *msg) |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 514 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 515 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 516 | |
Christopher Faulet | a3ed271 | 2019-11-04 11:35:42 +0100 | [diff] [blame] | 517 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s)", |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 518 | __FUNCTION__, "-", proxy_mode(s), stream_pos(s)); |
| 519 | } |
| 520 | |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 521 | /************************************************************************** |
| 522 | * Hooks to filter TCP data |
| 523 | *************************************************************************/ |
| 524 | static int |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 525 | trace_tcp_payload(struct stream *s, struct filter *filter, struct channel *chn, |
| 526 | unsigned int offset, unsigned int len) |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 527 | { |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 528 | struct trace_config *conf = FLT_CONF(filter); |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 529 | int ret = len; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 530 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 531 | if (s->flags & SF_HTX) { |
| 532 | if (ret && conf->rand_forwarding) { |
| 533 | unsigned int data = trace_get_htx_datalen(htxbuf(&chn->buf), offset, len); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 534 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 535 | if (data) { |
Willy Tarreau | 52bf839 | 2020-03-08 00:42:37 +0100 | [diff] [blame] | 536 | ret = ha_random() % (ret+1); |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 537 | if (!ret || ret >= data) |
| 538 | ret = len; |
| 539 | } |
| 540 | } |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 541 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 542 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - " |
| 543 | "offset=%u - len=%u - forward=%d", |
| 544 | __FUNCTION__, |
| 545 | channel_label(chn), proxy_mode(s), stream_pos(s), |
| 546 | offset, len, ret); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 547 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 548 | if (conf->hexdump) |
| 549 | trace_htx_hexdump(htxbuf(&chn->buf), offset, ret); |
| 550 | } |
| 551 | else { |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 552 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 553 | if (ret && conf->rand_forwarding) |
Willy Tarreau | 52bf839 | 2020-03-08 00:42:37 +0100 | [diff] [blame] | 554 | ret = ha_random() % (ret+1); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 555 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 556 | FLT_STRM_TRACE(conf, s, "%-25s: channel=%-10s - mode=%-5s (%s) - " |
| 557 | "offset=%u - len=%u - forward=%d", |
| 558 | __FUNCTION__, |
| 559 | channel_label(chn), proxy_mode(s), stream_pos(s), |
| 560 | offset, len, ret); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 561 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 562 | if (conf->hexdump) |
| 563 | trace_raw_hexdump(&chn->buf, offset, ret); |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 566 | if (ret != len) |
| 567 | task_wakeup(s->task, TASK_WOKEN_MSG); |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 568 | return ret; |
| 569 | } |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 570 | /******************************************************************** |
| 571 | * Functions that manage the filter initialization |
| 572 | ********************************************************************/ |
| 573 | struct flt_ops trace_ops = { |
| 574 | /* Manage trace filter, called for each filter declaration */ |
Christopher Faulet | f227372 | 2017-07-27 16:58:42 +0200 | [diff] [blame] | 575 | .init = trace_init, |
| 576 | .deinit = trace_deinit, |
| 577 | .check = trace_check, |
| 578 | .init_per_thread = trace_init_per_thread, |
| 579 | .deinit_per_thread = trace_deinit_per_thread, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 580 | |
| 581 | /* Handle start/stop of streams */ |
Christopher Faulet | 31ed32d | 2016-06-21 11:42:37 +0200 | [diff] [blame] | 582 | .attach = trace_attach, |
| 583 | .detach = trace_detach, |
| 584 | .stream_start = trace_stream_start, |
| 585 | .stream_set_backend = trace_stream_set_backend, |
| 586 | .stream_stop = trace_stream_stop, |
Christopher Faulet | a00d817 | 2016-11-10 14:58:05 +0100 | [diff] [blame] | 587 | .check_timeouts = trace_check_timeouts, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 588 | |
| 589 | /* Handle channels activity */ |
| 590 | .channel_start_analyze = trace_chn_start_analyze, |
Christopher Faulet | 3a394fa | 2016-05-11 17:13:39 +0200 | [diff] [blame] | 591 | .channel_pre_analyze = trace_chn_analyze, |
| 592 | .channel_post_analyze = trace_chn_analyze, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 593 | .channel_end_analyze = trace_chn_end_analyze, |
| 594 | |
| 595 | /* Filter HTTP requests and responses */ |
Christopher Faulet | 1339d74 | 2016-05-11 16:48:33 +0200 | [diff] [blame] | 596 | .http_headers = trace_http_headers, |
Christopher Faulet | e0aa6f7 | 2018-11-30 22:23:32 +0100 | [diff] [blame] | 597 | .http_payload = trace_http_payload, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 598 | .http_end = trace_http_end, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 599 | .http_reset = trace_http_reset, |
| 600 | .http_reply = trace_http_reply, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 601 | |
| 602 | /* Filter TCP data */ |
Christopher Faulet | b2e5849 | 2019-11-12 11:13:01 +0100 | [diff] [blame] | 603 | .tcp_payload = trace_tcp_payload, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | /* Return -1 on error, else 0 */ |
| 607 | static int |
| 608 | parse_trace_flt(char **args, int *cur_arg, struct proxy *px, |
Thierry Fournier | 3610c39 | 2016-04-13 18:27:51 +0200 | [diff] [blame] | 609 | struct flt_conf *fconf, char **err, void *private) |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 610 | { |
| 611 | struct trace_config *conf; |
| 612 | int pos = *cur_arg; |
| 613 | |
| 614 | conf = calloc(1, sizeof(*conf)); |
| 615 | if (!conf) { |
| 616 | memprintf(err, "%s: out of memory", args[*cur_arg]); |
| 617 | return -1; |
| 618 | } |
| 619 | conf->proxy = px; |
| 620 | |
| 621 | if (!strcmp(args[pos], "trace")) { |
| 622 | pos++; |
| 623 | |
| 624 | while (*args[pos]) { |
| 625 | if (!strcmp(args[pos], "name")) { |
| 626 | if (!*args[pos + 1]) { |
| 627 | memprintf(err, "'%s' : '%s' option without value", |
| 628 | args[*cur_arg], args[pos]); |
| 629 | goto error; |
| 630 | } |
| 631 | conf->name = strdup(args[pos + 1]); |
| 632 | if (!conf->name) { |
| 633 | memprintf(err, "%s: out of memory", args[*cur_arg]); |
| 634 | goto error; |
| 635 | } |
| 636 | pos++; |
| 637 | } |
| 638 | else if (!strcmp(args[pos], "random-parsing")) |
| 639 | conf->rand_parsing = 1; |
| 640 | else if (!strcmp(args[pos], "random-forwarding")) |
| 641 | conf->rand_forwarding = 1; |
Christopher Faulet | fcd99f8 | 2016-10-31 11:27:21 +0100 | [diff] [blame] | 642 | else if (!strcmp(args[pos], "hexdump")) |
| 643 | conf->hexdump = 1; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 644 | else |
| 645 | break; |
| 646 | pos++; |
| 647 | } |
| 648 | *cur_arg = pos; |
Christopher Faulet | f4a4ef7 | 2018-12-07 17:39:53 +0100 | [diff] [blame] | 649 | fconf->id = trace_flt_id; |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 650 | fconf->ops = &trace_ops; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 651 | } |
| 652 | |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 653 | fconf->conf = conf; |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 654 | return 0; |
| 655 | |
| 656 | error: |
| 657 | if (conf->name) |
| 658 | free(conf->name); |
| 659 | free(conf); |
| 660 | return -1; |
| 661 | } |
| 662 | |
| 663 | /* Declare the filter parser for "trace" keyword */ |
| 664 | static struct flt_kw_list flt_kws = { "TRACE", { }, { |
Thierry Fournier | 3610c39 | 2016-04-13 18:27:51 +0200 | [diff] [blame] | 665 | { "trace", parse_trace_flt, NULL }, |
| 666 | { NULL, NULL, NULL }, |
Christopher Faulet | e6c3b69 | 2015-09-02 17:15:16 +0200 | [diff] [blame] | 667 | } |
| 668 | }; |
| 669 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 670 | INITCALL1(STG_REGISTER, flt_register_keywords, &flt_kws); |