blob: 54d27a0f41c82b0e5c8f25ac6554c16ec2f4f9df [file] [log] [blame]
Christopher Faulet78880fb2017-09-18 14:43:55 +02001/*
2 * Action management functions.
3 *
4 * Copyright 2017 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.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
13#include <common/config.h>
14#include <common/memory.h>
15#include <common/mini-clist.h>
16#include <common/standard.h>
17
18#include <proto/action.h>
19#include <proto/proxy.h>
20#include <proto/stick_table.h>
21
22
23/* Find and check the target table used by an action ACT_ACTION_TRK_*. This
24 * function should be called during the configuration validity check.
25 *
26 * The function returns 1 in success case, otherwise, it returns 0 and err is
27 * filled.
28 */
29int check_trk_action(struct act_rule *rule, struct proxy *px, char **err)
30{
31 struct proxy *target;
32
33 if (rule->arg.trk_ctr.table.n)
34 target = proxy_tbl_by_name(rule->arg.trk_ctr.table.n);
35 else
36 target = px;
37
38 if (!target) {
39 memprintf(err, "unable to find table '%s' referenced by track-sc%d",
40 rule->arg.trk_ctr.table.n, trk_idx(rule->action));
41 return 0;
42 }
43 else if (target->table.size == 0) {
44 memprintf(err, "table '%s' used but not configured",
45 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id);
46 return 0;
47 }
48 else if (!stktable_compatible_sample(rule->arg.trk_ctr.expr, target->table.type)) {
49 memprintf(err, "stick-table '%s' uses a type incompatible with the 'track-sc%d' rule",
50 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id,
51 trk_idx(rule->action));
52 return 0;
53 }
54 else {
55 free(rule->arg.trk_ctr.table.n);
56 rule->arg.trk_ctr.table.t = &target->table;
57 /* Note: if we decide to enhance the track-sc syntax, we may be
58 * able to pass a list of counters to track and allocate them
59 * right here using stktable_alloc_data_type().
60 */
61 }
62 return 1;
63}
64