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