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