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