blob: 75a39cc0c153f4defb7cc98d3bb7afb24a992933 [file] [log] [blame]
Miroslav Zagorac70230c62020-12-09 16:54:31 +01001/***
2 * Copyright 2020 HAProxy Technologies
3 *
4 * This file is part of the HAProxy OpenTracing filter.
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 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#ifndef _OPENTRACING_PARSER_H_
21#define _OPENTRACING_PARSER_H_
22
23#define FLT_OT_SCOPE "OT"
24
25/*
26 * filter FLT_OT_OPT_NAME FLT_OT_OPT_FILTER_ID <FLT_OT_OPT_FILTER_ID_DEFAULT> FLT_OT_OPT_CONFIG <file>
27 */
28#define FLT_OT_OPT_NAME "opentracing"
29#define FLT_OT_OPT_FILTER_ID "id"
30#define FLT_OT_OPT_FILTER_ID_DEFAULT "ot-filter"
31#define FLT_OT_OPT_CONFIG "config"
32
33#define FLT_OT_PARSE_SECTION_TRACER_ID "ot-tracer"
34#define FLT_OT_PARSE_SECTION_GROUP_ID "ot-group"
35#define FLT_OT_PARSE_SECTION_SCOPE_ID "ot-scope"
36
37#define FLT_OT_PARSE_SPAN_ROOT "root"
38#define FLT_OT_PARSE_SPAN_REF_CHILD "child-of"
39#define FLT_OT_PARSE_SPAN_REF_FOLLOWS "follows-from"
40#define FLT_OT_PARSE_CTX_AUTONAME "-"
Miroslav Zagoraca8bdf2b2021-04-14 11:47:28 +020041#define FLT_OT_PARSE_CTX_IGNORE_NAME '-'
Miroslav Zagorac70230c62020-12-09 16:54:31 +010042#define FLT_OT_PARSE_CTX_USE_HEADERS "use-headers"
43#define FLT_OT_PARSE_CTX_USE_VARS "use-vars"
44#define FLT_OT_PARSE_OPTION_HARDERR "hard-errors"
45#define FLT_OT_PARSE_OPTION_DISABLED "disabled"
46#define FLT_OT_PARSE_OPTION_NOLOGNORM "dontlog-normal"
47
48/*
49 * A description of the macro arguments can be found in the structure
50 * flt_ot_parse_data definition
51 */
52#define FLT_OT_PARSE_TRACER_DEFINES \
53 FLT_OT_PARSE_TRACER_DEF( ID, 0, 1, 2, 2, "ot-tracer", " <name>") \
54 FLT_OT_PARSE_TRACER_DEF( ACL, 0, 1, 3, 0, "acl", " <name> <criterion> [flags] [operator] <value> ...") \
55 FLT_OT_PARSE_TRACER_DEF( LOG, 0, 1, 2, 0, "log", " { global | <addr> [len <len>] [format <fmt>] <facility> [<level> [<minlevel>]] }") \
56 FLT_OT_PARSE_TRACER_DEF( CONFIG, 0, 0, 2, 2, "config", " <file>") \
57 FLT_OT_PARSE_TRACER_DEF( PLUGIN, 0, 0, 2, 2, "plugin", " <file>") \
58 FLT_OT_PARSE_TRACER_DEF( GROUPS, 0, 0, 2, 0, "groups", " <name> ...") \
59 FLT_OT_PARSE_TRACER_DEF( SCOPES, 0, 0, 2, 0, "scopes", " <name> ...") \
60 FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, 0, 2, 2, "rate-limit", " <value>") \
61 FLT_OT_PARSE_TRACER_DEF( OPTION, 0, 0, 2, 2, "option", " { disabled | dontlog-normal | hard-errors }") \
62 FLT_OT_PARSE_TRACER_DEF(DEBUG_LEVEL, 0, 0, 2, 2, "debug-level", " <value>")
63
64#define FLT_OT_PARSE_GROUP_DEFINES \
65 FLT_OT_PARSE_GROUP_DEF( ID, 0, 1, 2, 2, "ot-group", " <name>") \
66 FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, 0, 2, 0, "scopes", " <name> ...")
67
68#define FLT_OT_PARSE_SCOPE_DEFINES \
69 FLT_OT_PARSE_SCOPE_DEF( ID, 0, 1, 2, 2, "ot-scope", " <name>") \
70 FLT_OT_PARSE_SCOPE_DEF( SPAN, 0, 0, 2, 5, "span", " <name> [<reference>] [root]") \
71 FLT_OT_PARSE_SCOPE_DEF( TAG, 1, 0, 3, 0, "tag", " <name> <sample> ...") \
72 FLT_OT_PARSE_SCOPE_DEF( LOG, 1, 0, 3, 0, "log", " <name> <sample> ...") \
73 FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, 4, 3, 0, "baggage", " <name> <sample> ...") \
74 FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, 3, 2, 4, "inject", " <name-prefix> [use-vars] [use-headers]") \
75 FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, 3, 2, 3, "extract", " <name-prefix> [use-vars | use-headers]") \
76 FLT_OT_PARSE_SCOPE_DEF( FINISH, 0, 0, 2, 0, "finish", " <name> ...") \
77 FLT_OT_PARSE_SCOPE_DEF( ACL, 0, 1, 3, 0, "acl", " <name> <criterion> [flags] [operator] <value> ...") \
78 FLT_OT_PARSE_SCOPE_DEF( EVENT, 0, 0, 2, 0, "event", " <name> [{ if | unless } <condition>]")
79
80enum FLT_OT_PARSE_TRACER_enum {
81#define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_TRACER_##a,
82 FLT_OT_PARSE_TRACER_DEFINES
83#undef FLT_OT_PARSE_TRACER_DEF
84};
85
86enum FLT_OT_PARSE_GROUP_enum {
87#define FLT_OT_PARSE_GROUP_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_GROUP_##a,
88 FLT_OT_PARSE_GROUP_DEFINES
89#undef FLT_OT_PARSE_GROUP_DEF
90};
91
92enum FLT_OT_PARSE_SCOPE_enum {
93#define FLT_OT_PARSE_SCOPE_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_SCOPE_##a,
94 FLT_OT_PARSE_SCOPE_DEFINES
95#undef FLT_OT_PARSE_SCOPE_DEF
96};
97
98enum FLT_OT_CTX_USE_enum {
99 FLT_OT_CTX_USE_VARS = 1 << 0,
100 FLT_OT_CTX_USE_HEADERS = 1 << 1,
101};
102
103struct flt_ot_parse_data {
104 int keyword; /* Keyword index. */
105 bool flag_check_id; /* Whether the group ID must be defined for the keyword. */
106 int check_name; /* Checking allowed characters in the name. */
107 int args_min; /* The minimum number of arguments required. */
108 int args_max; /* The maximum number of arguments allowed. */
109 const char *name; /* Keyword name. */
110 const char *usage; /* Usage text to be printed in case of an error. */
111};
112
113#define FLT_OT_PARSE_WARNING(f, ...) \
114 ha_warning("parsing [%s:%d] : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'" f "'\n", ##__VA_ARGS__);
115#define FLT_OT_PARSE_ALERT(f, ...) \
116 do { \
117 ha_alert("parsing [%s:%d] : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'" f "'\n", ##__VA_ARGS__); \
118 \
119 retval |= ERR_ABORT | ERR_ALERT; \
120 } while (0)
121#define FLT_OT_POST_PARSE_ALERT(f, ...) \
122 FLT_OT_PARSE_ALERT(f, flt_ot_current_config->cfg_file, ##__VA_ARGS__)
123
124#define FLT_OT_PARSE_ERR(e,f, ...) \
125 do { \
126 if (*(e) == NULL) \
127 (void)memprintf((e), f, ##__VA_ARGS__); \
128 \
129 retval |= ERR_ABORT | ERR_ALERT; \
130 } while (0)
131#define FLT_OT_PARSE_IFERR_ALERT() \
132 do { \
133 if (err == NULL) \
134 break; \
135 \
136 FLT_OT_PARSE_ALERT("%s", file, linenum, err); \
137 FLT_OT_ERR_FREE(err); \
138 } while (0)
139
140#endif /* _OPENTRACING_PARSER_H_ */
141
142/*
143 * Local variables:
144 * c-indent-level: 8
145 * c-basic-offset: 8
146 * End:
147 *
148 * vi: noexpandtab shiftwidth=8 tabstop=8
149 */