blob: 5dec8629d46b9fc2b4e7dbc3fec3fee652825beb [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#include "include.h"
21
22
23#ifdef DEBUG_OT
24struct flt_ot_debug flt_ot_debug;
25THREAD_LOCAL int dbg_indent_level = 0;
26#endif
27
28#ifdef OTC_DBG_MEM
29static struct otc_dbg_mem_data dbg_mem_data[1000000];
30static struct otc_dbg_mem dbg_mem;
31#endif
32
33static struct flt_ot_conf *flt_ot_current_config = NULL;
34static struct flt_ot_conf_tracer *flt_ot_current_tracer = NULL;
35static struct flt_ot_conf_group *flt_ot_current_group = NULL;
36static struct flt_ot_conf_scope *flt_ot_current_scope = NULL;
37static struct flt_ot_conf_span *flt_ot_current_span = NULL;
38
39
40/***
41 * NAME
42 * flt_ot_parse_strdup -
43 *
44 * ARGUMENTS
45 * ptr -
46 * str -
47 * err -
48 * err_msg -
49 *
50 * DESCRIPTION
51 * -
52 *
53 * RETURN VALUE
54 * Returns ERR_NONE (== 0) in case of success,
55 * or a combination of ERR_* flags if an error is encountered.
56 */
57static int flt_ot_parse_strdup(char **ptr, const char *str, char **err, const char *err_msg)
58{
59 int retval = ERR_NONE;
60
61 FLT_OT_FUNC("%p:%p, %p, %p:%p, \"%s\"", FLT_OT_DPTR_ARGS(ptr), str, FLT_OT_DPTR_ARGS(err), err_msg);
62
63 *ptr = FLT_OT_STRDUP(str);
64 if (*ptr == NULL) {
65 FLT_OT_PARSE_ERR(err, "'%s' : out of memory", err_msg);
66
67 retval |= ERR_ABORT | ERR_ALERT;
68 }
69
70 FLT_OT_RETURN(retval);
71}
72
73
74/***
75 * NAME
76 * flt_ot_parse_keyword -
77 *
78 * ARGUMENTS
79 * ptr -
80 * args -
81 * cur_arg -
82 * pos -
83 * err -
84 * err_msg -
85 *
86 * DESCRIPTION
87 * -
88 *
89 * RETURN VALUE
90 * Returns ERR_NONE (== 0) in case of success,
91 * or a combination of ERR_* flags if an error is encountered.
92 */
93static int flt_ot_parse_keyword(char **ptr, char **args, int cur_arg, int pos, char **err, const char *err_msg)
94{
95 int retval = ERR_NONE;
96
97 FLT_OT_FUNC("%p:%p, %p, %d, %d, %p:%p, \"%s\"", FLT_OT_DPTR_ARGS(ptr), args, cur_arg, pos, FLT_OT_DPTR_ARGS(err), err_msg);
98
99 if (*ptr != NULL) {
100 if (cur_arg == pos)
101 FLT_OT_PARSE_ERR(err, FLT_OT_FMT_TYPE "%s already set", err_msg);
102 else
103 FLT_OT_PARSE_ERR(err, "'%s' : %s already set", args[cur_arg], err_msg);
104 }
105 else if (!FLT_OT_ARG_ISVALID(pos + 1)) {
106 if (cur_arg == pos)
107 FLT_OT_PARSE_ERR(err, FLT_OT_FMT_TYPE "no %s set", err_msg);
108 else
109 FLT_OT_PARSE_ERR(err, "'%s' : no %s set", args[cur_arg], err_msg);
110 }
111 else {
112 retval = flt_ot_parse_strdup(ptr, args[pos + 1], err, args[cur_arg]);
113 }
114
115 FLT_OT_RETURN(retval);
116}
117
118
119/***
120 * NAME
121 * flt_ot_parse_invalid_char -
122 *
123 * ARGUMENTS
124 * name -
125 * type -
126 *
127 * DESCRIPTION
128 * -
129 *
130 * RETURN VALUE
131 * -
132 */
133static const char *flt_ot_parse_invalid_char(const char *name, int type)
134{
135 const char *retptr = NULL;
136
137 FLT_OT_FUNC("\"%s\", %d", name, type);
138
139 if (!FLT_OT_STR_ISVALID(name))
140 FLT_OT_RETURN(retptr);
141
142 if (type == 1) {
143 retptr = invalid_char(name);
144 }
145 else if (type == 2) {
146 retptr = invalid_domainchar(name);
147 }
148 else if (type == 3) {
149 retptr = invalid_prefix_char(name);
150 }
151 else if (type == 4) {
152 retptr = name;
153
154 /*
155 * Allowed characters are letters, numbers and '_', the first
156 * character in the string must not be a number.
157 */
158 if (!isdigit(*retptr))
159 for (++retptr; (*retptr == '_') || isalnum(*retptr); retptr++);
160
161 if (*retptr == '\0')
162 retptr = NULL;
163 }
164
165 FLT_OT_RETURN(retptr);
166}
167
168
169/***
170 * NAME
171 * flt_ot_parse_cfg_check -
172 *
173 * ARGUMENTS
174 * file -
175 * linenum -
176 * args -
177 * id -
178 * parse_data -
179 * parse_data_size -
180 * pdata -
181 * err -
182 *
183 * DESCRIPTION
184 * -
185 *
186 * RETURN VALUE
187 * Returns ERR_NONE (== 0) in case of success,
188 * or a combination of ERR_* flags if an error is encountered.
189 */
190static int flt_ot_parse_cfg_check(const char *file, int linenum, char **args, const void *id, const struct flt_ot_parse_data *parse_data, size_t parse_data_size, const struct flt_ot_parse_data **pdata, char **err)
191{
Miroslav Zagorac4b3eb0a2021-04-14 11:44:58 +0200192 int i, argc, retval = ERR_NONE;
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100193
194 FLT_OT_FUNC("\"%s\", %d, %p, %p, %p, %zu, %p:%p, %p:%p", file, linenum, args, id, parse_data, parse_data_size, FLT_OT_DPTR_ARGS(pdata), FLT_OT_DPTR_ARGS(err));
195
196 FLT_OT_ARGS_DUMP();
197
198 *pdata = NULL;
199
Miroslav Zagorac4b3eb0a2021-04-14 11:44:58 +0200200 /* First check here if args[0] is the correct keyword. */
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100201 for (i = 0; (*pdata == NULL) && (i < parse_data_size); i++)
202 if (strcmp(parse_data[i].name, args[0]) == 0)
203 *pdata = parse_data + i;
204
205 if (*pdata == NULL)
206 FLT_OT_PARSE_ERR(err, "'%s' : unknown keyword", args[0]);
Miroslav Zagorac4b3eb0a2021-04-14 11:44:58 +0200207 else
208 argc = flt_ot_args_count(args);
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100209
210 if ((retval & ERR_CODE) || (id == NULL))
211 /* Do nothing. */;
212 else if ((id != flt_ot_current_tracer) && (flt_ot_current_config->tracer == NULL))
213 FLT_OT_PARSE_ERR(err, "tracer not defined");
214
215 /*
216 * Checking that fewer arguments are specified in the configuration
217 * line than is required.
218 */
219 if (!(retval & ERR_CODE))
Miroslav Zagorac4b3eb0a2021-04-14 11:44:58 +0200220 if (argc < (*pdata)->args_min)
221 FLT_OT_PARSE_ERR(err, "'%s' : too few arguments (use '%s%s')", args[0], (*pdata)->name, (*pdata)->usage);
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100222
223 /*
224 * Checking that more arguments are specified in the configuration
225 * line than the maximum allowed.
226 */
Miroslav Zagorac4b3eb0a2021-04-14 11:44:58 +0200227 if (!(retval & ERR_CODE) && ((*pdata)->args_max > 0))
228 if (argc > (*pdata)->args_max)
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100229 FLT_OT_PARSE_ERR(err, "'%s' : too many arguments (use '%s%s')", args[0], (*pdata)->name, (*pdata)->usage);
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100230
231 /* Checking that the first argument has only allowed characters. */
232 if (!(retval & ERR_CODE) && ((*pdata)->check_name > 0)) {
233 const char *ic;
234
235 ic = flt_ot_parse_invalid_char(args[1], (*pdata)->check_name);
236 if (ic != NULL)
237 FLT_OT_PARSE_ERR(err, "%s '%s' : invalid character '%c'", args[0], args[1], *ic);
238 }
239
240 /* Checking that the data group name is defined. */
241 if (!(retval & ERR_CODE) && (*pdata)->flag_check_id && (id == NULL))
242 FLT_OT_PARSE_ERR(err, "'%s' : %s ID not set (use '%s%s')", args[0], parse_data[1].name, parse_data[1].name, parse_data[1].usage);
243
244 FLT_OT_RETURN(retval);
245}
246
247
248/***
249 * NAME
250 * flt_ot_parse_cfg_sample_expr -
251 *
252 * ARGUMENTS
253 * file -
254 * linenum -
255 * args -
256 * idx -
257 * head -
258 * err -
259 *
260 * DESCRIPTION
261 * -
262 *
263 * RETURN VALUE
264 * Returns ERR_NONE (== 0) in case of success,
265 * or a combination of ERR_* flags if an error is encountered.
266 */
267static int flt_ot_parse_cfg_sample_expr(const char *file, int linenum, char **args, int *idx, struct list *head, char **err)
268{
269 struct flt_ot_conf_sample_expr *expr;
270 int retval = ERR_NONE;
271
272 FLT_OT_FUNC("\"%s\", %d, %p, %p, %p, %p:%p", file, linenum, args, idx, head, FLT_OT_DPTR_ARGS(err));
273
274 expr = flt_ot_conf_sample_expr_init(args[*idx], linenum, head, err);
275 if (expr != NULL) {
276 expr->expr = sample_parse_expr(args, idx, file, linenum, err, &(flt_ot_current_config->proxy->conf.args), NULL);
277 if (expr->expr != NULL)
278 FLT_OT_DBG(3, "sample expression '%s' added", expr->value);
279 else
280 retval |= ERR_ABORT | ERR_ALERT;
281 } else {
282 retval |= ERR_ABORT | ERR_ALERT;
283 }
284
285 if (retval & ERR_CODE)
286 flt_ot_conf_sample_expr_free(&expr);
287
288 FLT_OT_RETURN(retval);
289}
290
291
292/***
293 * NAME
294 * flt_ot_parse_cfg_sample -
295 *
296 * ARGUMENTS
297 * file -
298 * linenum -
299 * args -
300 * head -
301 * err -
302 *
303 * DESCRIPTION
304 * -
305 *
306 * RETURN VALUE
307 * Returns ERR_NONE (== 0) in case of success,
308 * or a combination of ERR_* flags if an error is encountered.
309 */
310static int flt_ot_parse_cfg_sample(const char *file, int linenum, char **args, struct list *head, char **err)
311{
312 struct flt_ot_conf_sample *sample;
313 int idx = 2, retval = ERR_NONE;
314
315 FLT_OT_FUNC("\"%s\", %d, %p, %p, %p:%p", file, linenum, args, head, FLT_OT_DPTR_ARGS(err));
316
317 sample = flt_ot_conf_sample_init(args, linenum, head, err);
318 if (sample == NULL)
319 FLT_OT_PARSE_ERR(err, "'%s' : out of memory", args[0]);
320
321 if (!(retval & ERR_CODE)) {
322 flt_ot_current_config->proxy->conf.args.ctx = ARGC_OT;
323 flt_ot_current_config->proxy->conf.args.file = file;
324 flt_ot_current_config->proxy->conf.args.line = linenum;
325
326 while (!(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(idx))
327 retval = flt_ot_parse_cfg_sample_expr(file, linenum, args, &idx, &(sample->exprs), err);
328
329 flt_ot_current_config->proxy->conf.args.file = NULL;
330 flt_ot_current_config->proxy->conf.args.line = 0;
331 }
332
333 if (retval & ERR_CODE)
334 flt_ot_conf_sample_free(&sample);
335 else
336 FLT_OT_DBG(3, "sample '%s' -> '%s' added", sample->key, sample->value);
337
338 FLT_OT_RETURN(retval);
339}
340
341
342/***
343 * NAME
344 * flt_ot_parse_cfg_str -
345 *
346 * ARGUMENTS
347 * file -
348 * linenum -
349 * args -
350 * head -
351 * err -
352 *
353 * DESCRIPTION
354 * -
355 *
356 * RETURN VALUE
357 * Returns ERR_NONE (== 0) in case of success,
358 * or a combination of ERR_* flags if an error is encountered.
359 */
360static int flt_ot_parse_cfg_str(const char *file, int linenum, char **args, struct list *head, char **err)
361{
362 struct flt_ot_conf_str *str = NULL;
363 int i, retval = ERR_NONE;
364
365 FLT_OT_FUNC("\"%s\", %d, %p, %p, %p:%p", file, linenum, args, head, FLT_OT_DPTR_ARGS(err));
366
367 for (i = 1; !(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(i); i++)
368 if (flt_ot_conf_str_init(args[i], linenum, head, err) == NULL)
369 retval |= ERR_ABORT | ERR_ALERT;
370
371 if (retval & ERR_CODE)
372 flt_ot_conf_str_free(&str);
373
374 FLT_OT_RETURN(retval);
375}
376
377
378/***
379 * NAME
380 * flt_ot_parse_cfg_file -
381 *
382 * ARGUMENTS
383 * ptr -
384 * file -
385 * linenum -
386 * args -
387 * err -
388 * err_msg -
389 *
390 * DESCRIPTION
391 * -
392 *
393 * RETURN VALUE
394 * Returns ERR_NONE (== 0) in case of success,
395 * or a combination of ERR_* flags if an error is encountered.
396 */
397static int flt_ot_parse_cfg_file(char **ptr, const char *file, int linenum, char **args, char **err, const char *err_msg)
398{
399 int retval = ERR_NONE;
400
401 FLT_OT_FUNC("%p:%p, \"%s\", %d, %p, %p:%p, \"%s\"", FLT_OT_DPTR_ARGS(ptr), file, linenum, args, FLT_OT_DPTR_ARGS(err), err_msg);
402
403 if (!FLT_OT_ARG_ISVALID(1))
404 FLT_OT_PARSE_ERR(err, "'%s' : no %s specified", flt_ot_current_tracer->id, err_msg);
405 else if (alertif_too_many_args(1, file, linenum, args, &retval))
406 retval |= ERR_ABORT | ERR_ALERT;
407 else if (access(args[1], R_OK) == -1)
408 FLT_OT_PARSE_ERR(err, "'%s' : %s", args[1], strerror(errno));
409 else
410 retval = flt_ot_parse_keyword(ptr, args, 0, 0, err, err_msg);
411
412 FLT_OT_RETURN(retval);
413}
414
415
416/***
417 * NAME
418 * flt_ot_parse_check_scope -
419 *
420 * ARGUMENTS
421 * This function takes no arguments.
422 *
423 * DESCRIPTION
424 * -
425 *
426 * RETURN VALUE
427 * Returns TRUE in case the configuration is not in the currently defined
428 * scope, FALSE otherwise.
429 */
430static bool flt_ot_parse_check_scope(void)
431{
432 bool retval = 0;
433
434 if ((cfg_scope != NULL) && (flt_ot_current_config->id != NULL) && (strcmp(flt_ot_current_config->id, cfg_scope) != 0)) {
435 FLT_OT_DBG(1, "cfg_scope: '%s', id: '%s'", cfg_scope, flt_ot_current_config->id);
436
437 retval = 1;
438 }
439
440 return retval;
441}
442
443
444/***
445 * NAME
446 * flt_ot_parse_cfg_tracer -
447 *
448 * ARGUMENTS
449 * file -
450 * linenum -
451 * args -
452 * kw_mod -
453 *
454 * DESCRIPTION
455 * -
456 *
457 * RETURN VALUE
458 * Returns ERR_NONE (== 0) in case of success,
459 * or a combination of ERR_* flags if an error is encountered.
460 */
461static int flt_ot_parse_cfg_tracer(const char *file, int linenum, char **args, int kw_mod)
462{
463#define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_TRACER_##a, b, c, d, e, f, g },
464 static const struct flt_ot_parse_data parse_data[] = { FLT_OT_PARSE_TRACER_DEFINES };
465#undef FLT_OT_PARSE_TRACER_DEF
466 const struct flt_ot_parse_data *pdata = NULL;
467 char *err = NULL, *err_log = NULL;
468 int i, retval = ERR_NONE;
469
470 FLT_OT_FUNC("\"%s\", %d, %p, 0x%08x", file, linenum, args, kw_mod);
471
472 if (flt_ot_parse_check_scope())
473 FLT_OT_RETURN(retval);
474
475 retval = flt_ot_parse_cfg_check(file, linenum, args, flt_ot_current_tracer, parse_data, FLT_OT_TABLESIZE(parse_data), &pdata, &err);
476 if (retval & ERR_CODE) {
477 FLT_OT_PARSE_IFERR_ALERT();
478
479 FLT_OT_RETURN(retval);
480 }
481
482 if (pdata->keyword == FLT_OT_PARSE_TRACER_ID) {
483 if (flt_ot_current_config->tracer != NULL) {
484 FLT_OT_PARSE_ERR(&err, "'%s' : tracer can be defined only once", args[1]);
485 } else {
486 flt_ot_current_tracer = flt_ot_conf_tracer_init(args[1], linenum, &err);
487 if (flt_ot_current_tracer == NULL)
488 retval |= ERR_ABORT | ERR_ALERT;
489 }
490 }
491 else if (pdata->keyword == FLT_OT_PARSE_TRACER_LOG) {
Miroslav Zagorac98272252021-04-07 11:14:23 +0200492 if (parse_logsrv(args, &(flt_ot_current_tracer->proxy_log.logsrvs), kw_mod == KWM_NO, file, linenum, &err_log) == 0) {
Miroslav Zagorac70230c62020-12-09 16:54:31 +0100493 FLT_OT_PARSE_ERR(&err, "'%s %s ...' : %s", args[0], args[1], err_log);
494 FLT_OT_FREE_CLEAR(err_log);
495
496 retval |= ERR_ABORT | ERR_ALERT;
497 } else {
498 flt_ot_current_tracer->logging |= FLT_OT_LOGGING_ON;
499 }
500 }
501 else if (pdata->keyword == FLT_OT_PARSE_TRACER_CONFIG) {
502 retval = flt_ot_parse_cfg_file(&(flt_ot_current_tracer->config), file, linenum, args, &err, "configuration file");
503 }
504 else if (pdata->keyword == FLT_OT_PARSE_TRACER_PLUGIN) {
505 retval = flt_ot_parse_cfg_file(&(flt_ot_current_tracer->plugin), file, linenum, args, &err, "plugin library");
506 }
507 else if (pdata->keyword == FLT_OT_PARSE_TRACER_GROUPS) {
508 for (i = 1; !(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(i); i++)
509 if (flt_ot_conf_ph_init(args[i], linenum, &(flt_ot_current_tracer->ph_groups), &err) == NULL)
510 retval |= ERR_ABORT | ERR_ALERT;
511 }
512 else if (pdata->keyword == FLT_OT_PARSE_TRACER_SCOPES) {
513 for (i = 1; !(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(i); i++)
514 if (flt_ot_conf_ph_init(args[i], linenum, &(flt_ot_current_tracer->ph_scopes), &err) == NULL)
515 retval |= ERR_ABORT | ERR_ALERT;
516 }
517 else if (pdata->keyword == FLT_OT_PARSE_TRACER_ACL) {
518 if (strcasecmp(args[1], "or") == 0)
519 FLT_OT_PARSE_ERR(&err, "'%s %s ...' : invalid ACL name", args[0], args[1]);
520 else if (parse_acl((const char **)args + 1, &(flt_ot_current_tracer->acls), &err, &(flt_ot_current_config->proxy->conf.args), file, linenum) == NULL)
521 retval |= ERR_ABORT | ERR_ALERT;
522 }
523 else if (pdata->keyword == FLT_OT_PARSE_TRACER_RATE_LIMIT) {
524 flt_ot_current_tracer->rate_limit = FLT_OT_FLOAT_U32(flt_ot_strtod(args[1], 0.0, FLT_OT_RATE_LIMIT_MAX, &err), FLT_OT_RATE_LIMIT_MAX);
525 }
526 else if (pdata->keyword == FLT_OT_PARSE_TRACER_OPTION) {
527 if (strcmp(args[1], FLT_OT_PARSE_OPTION_DISABLED) == 0) {
528 flt_ot_current_tracer->flag_disabled = (kw_mod == KWM_NO) ? 0 : 1;
529 }
530 else if (strcmp(args[1], FLT_OT_PARSE_OPTION_HARDERR) == 0) {
531 flt_ot_current_tracer->flag_harderr = (kw_mod == KWM_NO) ? 0 : 1;
532 }
533 else if (strcmp(args[1], FLT_OT_PARSE_OPTION_NOLOGNORM) == 0) {
534 if (kw_mod == KWM_NO)
535 flt_ot_current_tracer->logging &= ~FLT_OT_LOGGING_NOLOGNORM;
536 else
537 flt_ot_current_tracer->logging |= FLT_OT_LOGGING_NOLOGNORM;
538 }
539 else
540 FLT_OT_PARSE_ERR(&err, "'%s' : unknown option '%s'", args[0], args[1]);
541 }
542#ifdef DEBUG_OT
543 else if (pdata->keyword == FLT_OT_PARSE_TRACER_DEBUG_LEVEL) {
544 flt_ot_debug.level = flt_ot_strtoll(args[1], 0, 255, &err);
545 }
546#else
547 else {
548 FLT_OT_PARSE_WARNING("'%s' : keyword ignored", file, linenum, args[0]);
549 }
550#endif
551
552 FLT_OT_PARSE_IFERR_ALERT();
553
554 if ((retval & ERR_CODE) && (flt_ot_current_tracer != NULL))
555 flt_ot_conf_tracer_free(&flt_ot_current_tracer);
556
557 FLT_OT_RETURN(retval);
558}
559
560
561/***
562 * NAME
563 * flt_ot_post_parse_cfg_tracer -
564 *
565 * ARGUMENTS
566 * This function takes no arguments.
567 *
568 * DESCRIPTION
569 * -
570 *
571 * RETURN VALUE
572 * Returns ERR_NONE (== 0) in case of success,
573 * or a combination of ERR_* flags if an error is encountered.
574 */
575static int flt_ot_post_parse_cfg_tracer(void)
576{
577 int retval = ERR_NONE;
578
579 FLT_OT_FUNC("");
580
581 if (flt_ot_current_tracer == NULL)
582 FLT_OT_RETURN(retval);
583
584 flt_ot_current_config->tracer = flt_ot_current_tracer;
585
586 if (flt_ot_current_tracer->id == NULL)
587 FLT_OT_RETURN(retval);
588
589 if (flt_ot_current_tracer->config == NULL)
590 FLT_OT_POST_PARSE_ALERT("tracer '%s' has no configuration file specified", flt_ot_current_tracer->cfg_line, flt_ot_current_tracer->id);
591
592 if (flt_ot_current_tracer->plugin == NULL)
593 FLT_OT_POST_PARSE_ALERT("tracer '%s' has no plugin library specified", flt_ot_current_tracer->cfg_line, flt_ot_current_tracer->id);
594
595 flt_ot_current_tracer = NULL;
596
597 FLT_OT_RETURN(retval);
598}
599
600
601/***
602 * NAME
603 * flt_ot_parse_cfg_group -
604 *
605 * ARGUMENTS
606 * file -
607 * linenum -
608 * args -
609 * kw_mod -
610 *
611 * DESCRIPTION
612 * -
613 *
614 * RETURN VALUE
615 * Returns ERR_NONE (== 0) in case of success,
616 * or a combination of ERR_* flags if an error is encountered.
617 */
618static int flt_ot_parse_cfg_group(const char *file, int linenum, char **args, int kw_mod)
619{
620#define FLT_OT_PARSE_GROUP_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_GROUP_##a, b, c, d, e, f, g },
621 static const struct flt_ot_parse_data parse_data[] = { FLT_OT_PARSE_GROUP_DEFINES };
622#undef FLT_OT_PARSE_GROUP_DEF
623 const struct flt_ot_parse_data *pdata = NULL;
624 char *err = NULL;
625 int i, retval = ERR_NONE;
626
627 FLT_OT_FUNC("\"%s\", %d, %p, 0x%08x", file, linenum, args, kw_mod);
628
629 if (flt_ot_parse_check_scope())
630 FLT_OT_RETURN(retval);
631
632 retval = flt_ot_parse_cfg_check(file, linenum, args, flt_ot_current_group, parse_data, FLT_OT_TABLESIZE(parse_data), &pdata, &err);
633 if (retval & ERR_CODE) {
634 FLT_OT_PARSE_IFERR_ALERT();
635
636 FLT_OT_RETURN(retval);
637 }
638
639 if (pdata->keyword == FLT_OT_PARSE_GROUP_ID) {
640 flt_ot_current_group = flt_ot_conf_group_init(args[1], linenum, &(flt_ot_current_config->groups), &err);
641 if (flt_ot_current_config == NULL)
642 retval |= ERR_ABORT | ERR_ALERT;
643 }
644 else if (pdata->keyword == FLT_OT_PARSE_GROUP_SCOPES) {
645 for (i = 1; !(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(i); i++)
646 if (flt_ot_conf_ph_init(args[i], linenum, &(flt_ot_current_group->ph_scopes), &err) == NULL)
647 retval |= ERR_ABORT | ERR_ALERT;
648 }
649
650 FLT_OT_PARSE_IFERR_ALERT();
651
652 if ((retval & ERR_CODE) && (flt_ot_current_group != NULL))
653 flt_ot_conf_group_free(&flt_ot_current_group);
654
655 FLT_OT_RETURN(retval);
656}
657
658
659/***
660 * NAME
661 * flt_ot_post_parse_cfg_group -
662 *
663 * ARGUMENTS
664 * This function takes no arguments.
665 *
666 * DESCRIPTION
667 * -
668 *
669 * RETURN VALUE
670 * Returns ERR_NONE (== 0) in case of success,
671 * or a combination of ERR_* flags if an error is encountered.
672 */
673static int flt_ot_post_parse_cfg_group(void)
674{
675 int retval = ERR_NONE;
676
677 FLT_OT_FUNC("");
678
679 if (flt_ot_current_group == NULL)
680 FLT_OT_RETURN(retval);
681
682 /* Check that the group has at least one scope defined. */
683 if (LIST_ISEMPTY(&(flt_ot_current_group->ph_scopes)))
684 FLT_OT_POST_PARSE_ALERT("group '%s' has no defined scope(s)", flt_ot_current_group->cfg_line, flt_ot_current_group->id);
685
686 flt_ot_current_group = NULL;
687
688 FLT_OT_RETURN(retval);
689}
690
691
692/***
693 * NAME
694 * flt_ot_parse_cfg_scope_ctx -
695 *
696 * ARGUMENTS
697 * args -
698 * cur_arg -
699 * err -
700 *
701 * DESCRIPTION
702 * -
703 *
704 * RETURN VALUE
705 * Returns ERR_NONE (== 0) in case of success,
706 * or a combination of ERR_* flags if an error is encountered.
707 */
708static int flt_ot_parse_cfg_scope_ctx(char **args, int cur_arg, char **err)
709{
710 uint8_t flags = 0;
711 int retval = ERR_NONE;
712
713 FLT_OT_FUNC("%p, %d, %p:%p", args, cur_arg, FLT_OT_DPTR_ARGS(err));
714
715 if (strcmp(args[cur_arg], FLT_OT_PARSE_CTX_USE_HEADERS) == 0)
716 flags = FLT_OT_CTX_USE_HEADERS;
717 else if (strcmp(args[cur_arg], FLT_OT_PARSE_CTX_USE_VARS) == 0)
718 flags = FLT_OT_CTX_USE_VARS;
719 else
720 FLT_OT_PARSE_ERR(err, "'%s' : invalid context storage type", args[0]);
721
722 if (flags == 0)
723 /* Do nothing. */;
724 else if (flt_ot_current_span->ctx_flags & flags)
725 FLT_OT_PARSE_ERR(err, "'%s' : %s already used", args[0], args[cur_arg]);
726 else
727 flt_ot_current_span->ctx_flags |= flags;
728
729 FLT_OT_DBG(2, "ctx_flags: 0x%02hhx (0x%02hhx)", flt_ot_current_span->ctx_flags, flags);
730
731 FLT_OT_RETURN(retval);
732}
733
734
735/***
736 * NAME
737 * flt_ot_parse_acl -
738 *
739 * ARGUMENTS
740 * file -
741 * linenum -
742 * px -
743 * args -
744 * err -
745 * head -
746 *
747 * DESCRIPTION
748 * -
749 *
750 * RETURN VALUE
751 * -
752 */
753static struct acl_cond *flt_ot_parse_acl(const char *file, int linenum, struct proxy *px, const char **args, char **err, struct list *head, ...)
754{
755 va_list ap;
756 int n = 0;
757 struct acl_cond *retptr = NULL;
758
759 FLT_OT_FUNC("\"%s\", %d, %p, %p, %p:%p, %p, ...", file, linenum, px, args, FLT_OT_DPTR_ARGS(err), head);
760
761 for (va_start(ap, head); (retptr == NULL) && (head != NULL); head = va_arg(ap, typeof(head)), n++) {
762 retptr = build_acl_cond(file, linenum, head, px, args, (n == 0) ? err : NULL);
763 if (retptr != NULL)
764 FLT_OT_DBG(2, "ACL build done, using list %p %d", head, n);
765 }
766 va_end(ap);
767
768 if ((retptr != NULL) && (err != NULL))
769 FLT_OT_FREE_CLEAR(*err);
770
771 FLT_OT_RETURN(retptr);
772}
773
774
775/***
776 * NAME
777 * flt_ot_parse_cfg_scope -
778 *
779 * ARGUMENTS
780 * file -
781 * linenum -
782 * args -
783 * kw_mod -
784 *
785 * DESCRIPTION
786 * Function used to load the scope block configuration.
787 *
788 * RETURN VALUE
789 * Returns ERR_NONE (== 0) in case of success,
790 * or a combination of ERR_* flags if an error is encountered.
791 */
792static int flt_ot_parse_cfg_scope(const char *file, int linenum, char **args, int kw_mod)
793{
794#define FLT_OT_PARSE_SCOPE_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_SCOPE_##a, b, c, d, e, f, g },
795 static const struct flt_ot_parse_data parse_data[] = { FLT_OT_PARSE_SCOPE_DEFINES };
796#undef FLT_OT_PARSE_SCOPE_DEF
797 const struct flt_ot_parse_data *pdata = NULL;
798 char *err = NULL;
799 int i, retval = ERR_NONE;
800
801 FLT_OT_FUNC("\"%s\", %d, %p, 0x%08x", file, linenum, args, kw_mod);
802
803 if (flt_ot_parse_check_scope())
804 FLT_OT_RETURN(retval);
805
806 retval = flt_ot_parse_cfg_check(file, linenum, args, flt_ot_current_span, parse_data, FLT_OT_TABLESIZE(parse_data), &pdata, &err);
807 if (retval & ERR_CODE) {
808 FLT_OT_PARSE_IFERR_ALERT();
809
810 FLT_OT_RETURN(retval);
811 }
812
813 if (pdata->keyword == FLT_OT_PARSE_SCOPE_ID) {
814 /* Initialization of a new scope. */
815 flt_ot_current_scope = flt_ot_conf_scope_init(args[1], linenum, &(flt_ot_current_config->scopes), &err);
816 if (flt_ot_current_scope == NULL)
817 retval |= ERR_ABORT | ERR_ALERT;
818 }
819 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_SPAN) {
820 /*
821 * Checking if this is the beginning of the definition of
822 * a new span.
823 */
824 if (flt_ot_current_span != NULL) {
825 FLT_OT_DBG(3, "span '%s' (done)", flt_ot_current_span->id);
826
827 flt_ot_current_span = NULL;
828 }
829
830 /* Initialization of a new span. */
831 flt_ot_current_span = flt_ot_conf_span_init(args[1], linenum, &(flt_ot_current_scope->spans), &err);
832
833 /*
834 * In case the span has a defined reference,
835 * the correctness of the arguments is checked here.
836 */
837 if (flt_ot_current_span == NULL) {
838 retval |= ERR_ABORT | ERR_ALERT;
839 }
840 else if (FLT_OT_ARG_ISVALID(2)) {
841 for (i = 2; (i < pdata->args_max) && FLT_OT_ARG_ISVALID(i); i++)
842 if (strcmp(args[i], FLT_OT_PARSE_SPAN_ROOT) == 0) {
843 if (flt_ot_current_span->flag_root)
844 FLT_OT_PARSE_ERR(&err, "'%s' : already set (use '%s%s')", args[i], pdata->name, pdata->usage);
845 else
846 flt_ot_current_span->flag_root = 1;
847 }
848 else if ((strcmp(args[i], FLT_OT_PARSE_SPAN_REF_CHILD) == 0) || (strcmp(args[i], FLT_OT_PARSE_SPAN_REF_FOLLOWS) == 0)) {
849 if (!FLT_OT_ARG_ISVALID(i + 1)) {
850 FLT_OT_PARSE_ERR(&err, "'%s' : too few arguments (use '%s%s')", args[i], pdata->name, pdata->usage);
851 }
852 else if (strcmp(args[i++], FLT_OT_PARSE_SPAN_REF_CHILD) == 0) {
853 flt_ot_current_span->ref_type = otc_span_reference_child_of;
854 flt_ot_current_span->ref_id_len = strlen(args[i]);
855
856 retval = flt_ot_parse_strdup(&(flt_ot_current_span->ref_id), args[i], &err, args[1]);
857 }
858 else {
859 flt_ot_current_span->ref_type = otc_span_reference_follows_from;
860 flt_ot_current_span->ref_id_len = strlen(args[i]);
861
862 retval = flt_ot_parse_strdup(&(flt_ot_current_span->ref_id), args[i], &err, args[1]);
863 }
864 }
865 else {
866 FLT_OT_PARSE_ERR(&err, "'%s' : invalid argument (use '%s%s')", args[i], pdata->name, pdata->usage);
867 }
868 }
869 else {
870 /*
871 * This is not a faulty configuration, only such a case
872 * will be logged.
873 */
874 FLT_OT_DBG(3, "new span '%s' without reference", flt_ot_current_span->id);
875 }
876 }
877 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_TAG) {
878 retval = flt_ot_parse_cfg_sample(file, linenum, args, &(flt_ot_current_span->tags), &err);
879 }
880 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_LOG) {
881 retval = flt_ot_parse_cfg_sample(file, linenum, args, &(flt_ot_current_span->logs), &err);
882 }
883 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_BAGGAGE) {
884 retval = flt_ot_parse_cfg_sample(file, linenum, args, &(flt_ot_current_span->baggages), &err);
885 }
886 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_INJECT) {
887 /*
888 * Automatic context name generation can be specified here
889 * if the contents of the FLT_OT_PARSE_CTX_AUTONAME macro
890 * are used as the name. In that case, if the context is
891 * after a particular event, it gets its name; otherwise
892 * it gets the name of the current span.
893 */
894 if (flt_ot_current_span->ctx_id != NULL)
895 FLT_OT_PARSE_ERR(&err, "'%s' : only one context per span is allowed", args[1]);
896 else if (strcmp(args[1], FLT_OT_PARSE_CTX_AUTONAME) != 0)
897 retval = flt_ot_parse_strdup(&(flt_ot_current_span->ctx_id), args[1], &err, args[0]);
898 else if (flt_ot_current_scope->event != FLT_OT_EVENT_REQ_NONE)
899 retval = flt_ot_parse_strdup(&(flt_ot_current_span->ctx_id), flt_ot_event_data[flt_ot_current_scope->event].name, &err, args[0]);
900 else
901 retval = flt_ot_parse_strdup(&(flt_ot_current_span->ctx_id), flt_ot_current_span->id, &err, args[0]);
902
903 if (flt_ot_current_span->ctx_id != NULL) {
904 flt_ot_current_span->ctx_id_len = strlen(flt_ot_current_span->ctx_id);
905
906 /*
907 * Here is checked the context storage type; which, if
908 * not explicitly specified, is set to HTTP headers.
909 *
910 * It is possible to use both types of context storage
911 * at the same time.
912 */
913 if (FLT_OT_ARG_ISVALID(2)) {
914 retval = flt_ot_parse_cfg_scope_ctx(args, 2, &err);
915 if (!(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(3))
916 retval = flt_ot_parse_cfg_scope_ctx(args, 3, &err);
917 } else {
918 flt_ot_current_span->ctx_flags = FLT_OT_CTX_USE_HEADERS;
919 }
920 }
921 }
922 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_EXTRACT) {
923 struct flt_ot_conf_context *conf_ctx;
924
925 /*
926 * Here is checked the context storage type; which, if
927 * not explicitly specified, is set to HTTP headers.
928 */
929 conf_ctx = flt_ot_conf_context_init(args[1], linenum, &(flt_ot_current_scope->contexts), &err);
930 if (conf_ctx == NULL)
931 retval |= ERR_ABORT | ERR_ALERT;
932 else if (!FLT_OT_ARG_ISVALID(2))
933 conf_ctx->flags = FLT_OT_CTX_USE_HEADERS;
934 else if (strcmp(args[2], FLT_OT_PARSE_CTX_USE_HEADERS) == 0)
935 conf_ctx->flags = FLT_OT_CTX_USE_HEADERS;
936 else if (strcmp(args[2], FLT_OT_PARSE_CTX_USE_VARS) == 0)
937 conf_ctx->flags = FLT_OT_CTX_USE_VARS;
938 else
939 FLT_OT_PARSE_ERR(&err, "'%s' : invalid context storage type", args[2]);
940 }
941 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_FINISH) {
942 retval = flt_ot_parse_cfg_str(file, linenum, args, &(flt_ot_current_scope->finish), &err);
943 }
944 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_ACL) {
945 if (strcasecmp(args[1], "or") == 0)
946 FLT_OT_PARSE_ERR(&err, "'%s %s ...' : invalid ACL name", args[0], args[1]);
947 else if (parse_acl((const char **)args + 1, &(flt_ot_current_scope->acls), &err, &(flt_ot_current_config->proxy->conf.args), file, linenum) == NULL)
948 retval |= ERR_ABORT | ERR_ALERT;
949 }
950 else if (pdata->keyword == FLT_OT_PARSE_SCOPE_EVENT) {
951 /* Scope can only have one event defined. */
952 if (flt_ot_current_scope->event != FLT_OT_EVENT_REQ_NONE) {
953 FLT_OT_PARSE_ERR(&err, "'%s' : event already set", flt_ot_current_scope->id);
954 } else {
955 /* Check the event name. */
956 for (i = 0; i < FLT_OT_TABLESIZE(flt_ot_event_data); i++)
957 if (strcmp(flt_ot_event_data[i].name, args[1]) == 0) {
958 flt_ot_current_scope->event = i;
959
960 break;
961 }
962
963 /*
964 * The event can have some condition defined and this
965 * is checked here.
966 */
967 if (flt_ot_current_scope->event == FLT_OT_EVENT_REQ_NONE) {
968 FLT_OT_PARSE_ERR(&err, "'%s' : unknown event", args[1]);
969 }
970 else if (!FLT_OT_ARG_ISVALID(2)) {
971 /* Do nothing. */
972 }
973 else if ((strcmp(args[2], FLT_OT_CONDITION_IF) == 0) || (strcmp(args[2], FLT_OT_CONDITION_UNLESS) == 0)) {
974 /*
975 * We will first try to build ACL condition using
976 * local settings and then if that fails, using
977 * global settings (from tracer block). If it
978 * also fails, then try to use ACL defined in
979 * the HAProxy configuration.
980 */
981 flt_ot_current_scope->cond = flt_ot_parse_acl(file, linenum, flt_ot_current_config->proxy, (const char **)args + 2, &err, &(flt_ot_current_scope->acls), &(flt_ot_current_config->tracer->acls), &(flt_ot_current_config->proxy->acl), NULL);
982 if (flt_ot_current_scope->cond == NULL)
983 retval |= ERR_ABORT | ERR_ALERT;
984 }
985 else {
986 FLT_OT_PARSE_ERR(&err, "'%s' : expects either 'if' or 'unless' followed by a condition but found '%s'", args[1], args[2]);
987 }
988
989 if (!(retval & ERR_CODE))
990 FLT_OT_DBG(3, "event '%s'", args[1]);
991 }
992 }
993
994 FLT_OT_PARSE_IFERR_ALERT();
995
996 if ((retval & ERR_CODE) && (flt_ot_current_scope != NULL)) {
997 flt_ot_conf_scope_free(&flt_ot_current_scope);
998
999 flt_ot_current_span = NULL;
1000 }
1001
1002 FLT_OT_RETURN(retval);
1003}
1004
1005
1006/***
1007 * NAME
1008 * flt_ot_post_parse_cfg_scope -
1009 *
1010 * ARGUMENTS
1011 * This function takes no arguments.
1012 *
1013 * DESCRIPTION
1014 * In this function the correctness of the complete scope block is examined.
1015 * This does not mean that all elements are checked here, but only those for
1016 * which it has not been possible to establish their complete correctness in
1017 * the function flt_ot_parse_cfg_scope().
1018 *
1019 * RETURN VALUE
1020 * Returns ERR_NONE (== 0) in case of success,
1021 * or a combination of ERR_* flags if an error is encountered.
1022 */
1023static int flt_ot_post_parse_cfg_scope(void)
1024{
1025 struct flt_ot_conf_span *conf_span;
1026 int retval = ERR_NONE;
1027
1028 FLT_OT_FUNC("");
1029
1030 if (flt_ot_current_scope == NULL)
1031 FLT_OT_RETURN(retval);
1032
1033 /* If span context inject is used, check that this is possible. */
1034 list_for_each_entry(conf_span, &(flt_ot_current_scope->spans), list)
1035 if ((conf_span->ctx_id != NULL) && (conf_span->ctx_flags & FLT_OT_CTX_USE_HEADERS))
1036 if (!flt_ot_event_data[flt_ot_current_scope->event].flag_http_inject)
1037 FLT_OT_POST_PARSE_ALERT("inject '%s' : cannot use on this event", conf_span->cfg_line, conf_span->ctx_id);
1038
1039 if (retval & ERR_CODE)
1040 flt_ot_conf_scope_free(&flt_ot_current_scope);
1041
1042 flt_ot_current_scope = NULL;
1043 flt_ot_current_span = NULL;
1044
1045 FLT_OT_RETURN(retval);
1046}
1047
1048
1049/***
1050 * NAME
1051 * flt_ot_parse_cfg -
1052 *
1053 * ARGUMENTS
1054 * conf -
1055 * flt_name -
1056 * err -
1057 *
1058 * DESCRIPTION
1059 * -
1060 *
1061 * RETURN VALUE
1062 * Returns ERR_NONE (== 0) in case of success,
1063 * or a combination of ERR_* flags if an error is encountered.
1064 */
1065static int flt_ot_parse_cfg(struct flt_ot_conf *conf, const char *flt_name, char **err)
1066{
1067 struct list backup_sections;
1068 int retval = ERR_ABORT | ERR_ALERT;
1069
1070 FLT_OT_FUNC("%p, \"%s\", %p:%p", conf, flt_name, FLT_OT_DPTR_ARGS(err));
1071
1072 flt_ot_current_config = conf;
1073
1074 /* Backup sections. */
1075 LIST_INIT(&backup_sections);
1076 cfg_backup_sections(&backup_sections);
1077
1078 /* Register new OT sections and parse the OT filter configuration file. */
1079 if (!cfg_register_section(FLT_OT_PARSE_SECTION_TRACER_ID, flt_ot_parse_cfg_tracer, flt_ot_post_parse_cfg_tracer))
1080 /* Do nothing. */;
1081 else if (!cfg_register_section(FLT_OT_PARSE_SECTION_GROUP_ID, flt_ot_parse_cfg_group, flt_ot_post_parse_cfg_group))
1082 /* Do nothing. */;
1083 else if (!cfg_register_section(FLT_OT_PARSE_SECTION_SCOPE_ID, flt_ot_parse_cfg_scope, flt_ot_post_parse_cfg_scope))
1084 /* Do nothing. */;
1085 else if (access(conf->cfg_file, R_OK) == -1)
1086 FLT_OT_PARSE_ERR(err, "'%s' : %s", conf->cfg_file, strerror(errno));
1087 else
1088 retval = readcfgfile(conf->cfg_file);
1089
1090 /* Unregister OT sections and restore previous sections. */
1091 cfg_unregister_sections();
1092 cfg_restore_sections(&backup_sections);
1093
1094 flt_ot_current_config = NULL;
1095
1096 FLT_OT_RETURN(retval);
1097}
1098
1099
1100/***
1101 * NAME
1102 * flt_ot_parse -
1103 *
1104 * ARGUMENTS
1105 * args -
1106 * cur_arg -
1107 * px -
1108 * fconf -
1109 * err -
1110 * private -
1111 *
1112 * DESCRIPTION
1113 * -
1114 *
1115 * RETURN VALUE
1116 * Returns ERR_NONE (== 0) in case of success,
1117 * or a combination of ERR_* flags if an error is encountered.
1118 */
1119static int flt_ot_parse(char **args, int *cur_arg, struct proxy *px, struct flt_conf *fconf, char **err, void *private)
1120{
1121 struct flt_ot_conf *conf = NULL;
1122 int pos, retval = ERR_NONE;
1123
1124#ifdef DEBUG_OT
1125 FLT_OT_RUN_ONCE(
1126# ifndef DEBUG_OT_SYSTIME
1127 (void)memcpy(&(flt_ot_debug.start), &now, sizeof(flt_ot_debug.start));
1128# endif
1129
1130 flt_ot_debug.level = FLT_OT_DEBUG_LEVEL;
1131 );
1132#endif
1133
1134 FLT_OT_FUNC("%p, %p, %p, %p, %p:%p, %p", args, cur_arg, px, fconf, FLT_OT_DPTR_ARGS(err), private);
1135
1136#ifdef OTC_DBG_MEM
1137 FLT_OT_RUN_ONCE(
1138 if (otc_dbg_mem_init(&dbg_mem, dbg_mem_data, FLT_OT_TABLESIZE(dbg_mem_data), 0xff) == -1) {
1139 FLT_OT_PARSE_ERR(err, "cannot initialize memory debugger");
1140
1141 FLT_OT_RETURN(retval);
1142 }
1143 );
1144#endif
1145
1146 FLT_OT_ARGS_DUMP();
1147
1148 conf = flt_ot_conf_init(px);
1149 if (conf == NULL) {
1150 FLT_OT_PARSE_ERR(err, "'%s' : out of memory", args[*cur_arg]);
1151
1152 FLT_OT_RETURN(retval);
1153 }
1154
1155 for (pos = *cur_arg + 1; !(retval & ERR_CODE) && FLT_OT_ARG_ISVALID(pos); pos++) {
1156 FLT_OT_DBG(3, "args[%d:2] : { '%s' '%s' }", pos, args[pos], args[pos + 1]);
1157
1158 if (strcmp(args[pos], FLT_OT_OPT_FILTER_ID) == 0) {
1159 retval = flt_ot_parse_keyword(&(conf->id), args, *cur_arg, pos, err, "name");
1160 pos++;
1161 }
1162 else if (strcmp(args[pos], FLT_OT_OPT_CONFIG) == 0) {
1163 retval = flt_ot_parse_keyword(&(conf->cfg_file), args, *cur_arg, pos, err, "configuration file");
1164 if (!(retval & ERR_CODE))
1165 retval = flt_ot_parse_cfg(conf, args[*cur_arg], err);
1166 pos++;
1167 }
1168 else {
1169 FLT_OT_PARSE_ERR(err, "'%s' : unknown keyword '%s'", args[*cur_arg], args[pos]);
1170 }
1171 }
1172
1173 /* If the OpenTracing filter ID is not set, use default name. */
1174 if (!(retval & ERR_CODE) && (conf->id == NULL)) {
1175 ha_warning("parsing : " FLT_OT_FMT_TYPE FLT_OT_FMT_NAME "'no filter id set, using default id '%s'\n", FLT_OT_OPT_FILTER_ID_DEFAULT);
1176
1177 retval = flt_ot_parse_strdup(&(conf->id), FLT_OT_OPT_FILTER_ID_DEFAULT, err, args[*cur_arg]);
1178 }
1179
1180 if (!(retval & ERR_CODE) && (conf->cfg_file == NULL))
1181 FLT_OT_PARSE_ERR(err, "'%s' : no configuration file specified", args[*cur_arg]);
1182
1183 if (retval & ERR_CODE) {
1184 flt_ot_conf_free(&conf);
1185 } else {
1186 fconf->id = ot_flt_id;
1187 fconf->ops = &flt_ot_ops;
1188 fconf->conf = conf;
1189
1190 *cur_arg = pos;
1191
1192 FLT_OT_DBG(3, "filter set: id '%s', config '%s'", conf->id, conf->cfg_file);
1193 }
1194
1195 FLT_OT_RETURN(retval);
1196}
1197
1198
1199/* Declare the filter parser for FLT_OT_OPT_NAME keyword. */
1200static struct flt_kw_list flt_kws = { FLT_OT_SCOPE, { }, {
1201 { FLT_OT_OPT_NAME, flt_ot_parse, NULL },
1202 { NULL, NULL, NULL },
1203 }
1204};
1205
1206INITCALL1(STG_REGISTER, flt_register_keywords, &flt_kws);
1207
1208/*
1209 * Local variables:
1210 * c-indent-level: 8
1211 * c-basic-offset: 8
1212 * End:
1213 *
1214 * vi: noexpandtab shiftwidth=8 tabstop=8
1215 */