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