Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 29 | int 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 | } |
Willy Tarreau | 151e1ca | 2019-02-05 11:38:38 +0100 | [diff] [blame] | 54 | else if (px->bind_proc & ~target->bind_proc) { |
| 55 | memprintf(err, "stick-table '%s' referenced by 'track-sc%d' rule not present on all processes covered by proxy '%s'", |
| 56 | target->id, trk_idx(rule->action), px->id); |
| 57 | return 0; |
| 58 | } |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 59 | else { |
| 60 | free(rule->arg.trk_ctr.table.n); |
| 61 | rule->arg.trk_ctr.table.t = &target->table; |
| 62 | /* Note: if we decide to enhance the track-sc syntax, we may be |
| 63 | * able to pass a list of counters to track and allocate them |
| 64 | * right here using stktable_alloc_data_type(). |
| 65 | */ |
| 66 | } |
| 67 | return 1; |
| 68 | } |
| 69 | |