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> |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 19 | #include <proto/obj_type.h> |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 20 | #include <proto/proxy.h> |
| 21 | #include <proto/stick_table.h> |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 22 | #include <proto/task.h> |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /* Find and check the target table used by an action ACT_ACTION_TRK_*. This |
| 26 | * function should be called during the configuration validity check. |
| 27 | * |
| 28 | * The function returns 1 in success case, otherwise, it returns 0 and err is |
| 29 | * filled. |
| 30 | */ |
| 31 | int check_trk_action(struct act_rule *rule, struct proxy *px, char **err) |
| 32 | { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 33 | struct stktable *target; |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 34 | |
| 35 | if (rule->arg.trk_ctr.table.n) |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 36 | target = stktable_find_by_name(rule->arg.trk_ctr.table.n); |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 37 | else |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 38 | target = px->table; |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 39 | |
| 40 | if (!target) { |
| 41 | memprintf(err, "unable to find table '%s' referenced by track-sc%d", |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 42 | rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id, |
| 43 | trk_idx(rule->action)); |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 44 | return 0; |
| 45 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 46 | |
| 47 | if (!stktable_compatible_sample(rule->arg.trk_ctr.expr, target->type)) { |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 48 | memprintf(err, "stick-table '%s' uses a type incompatible with the 'track-sc%d' rule", |
| 49 | rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id, |
| 50 | trk_idx(rule->action)); |
| 51 | return 0; |
| 52 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 53 | else if (target->proxy && (px->bind_proc & ~target->proxy->bind_proc)) { |
Willy Tarreau | 151e1ca | 2019-02-05 11:38:38 +0100 | [diff] [blame] | 54 | memprintf(err, "stick-table '%s' referenced by 'track-sc%d' rule not present on all processes covered by proxy '%s'", |
| 55 | target->id, trk_idx(rule->action), px->id); |
| 56 | return 0; |
| 57 | } |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 58 | else { |
Frédéric Lécaille | eca6087 | 2019-08-07 09:28:39 +0200 | [diff] [blame] | 59 | if (!in_proxies_list(target->proxies_list, px)) { |
Frédéric Lécaille | 015e4d7 | 2019-03-19 14:55:01 +0100 | [diff] [blame] | 60 | px->next_stkt_ref = target->proxies_list; |
| 61 | target->proxies_list = px; |
| 62 | } |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 63 | free(rule->arg.trk_ctr.table.n); |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 64 | rule->arg.trk_ctr.table.t = target; |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 65 | /* Note: if we decide to enhance the track-sc syntax, we may be |
| 66 | * able to pass a list of counters to track and allocate them |
| 67 | * right here using stktable_alloc_data_type(). |
| 68 | */ |
| 69 | } |
| 70 | return 1; |
| 71 | } |
| 72 | |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 73 | int act_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver) |
| 74 | { |
| 75 | struct stream *stream; |
| 76 | |
| 77 | if (requester->resolution == NULL) |
| 78 | return 0; |
| 79 | |
| 80 | stream = objt_stream(requester->owner); |
| 81 | if (stream == NULL) |
| 82 | return 0; |
| 83 | |
| 84 | task_wakeup(stream->task, TASK_WOKEN_MSG); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Emeric Brun | a289367 | 2021-06-10 15:25:25 +0200 | [diff] [blame] | 89 | /* |
| 90 | * Do resolve error management callback |
| 91 | * returns: |
| 92 | * 0 if we can trash answser items. |
| 93 | * 1 when safely ignored and we must kept answer items |
| 94 | */ |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 95 | int act_resolution_error_cb(struct dns_requester *requester, int error_code) |
| 96 | { |
| 97 | struct stream *stream; |
| 98 | |
| 99 | if (requester->resolution == NULL) |
| 100 | return 0; |
| 101 | |
| 102 | stream = objt_stream(requester->owner); |
| 103 | if (stream == NULL) |
| 104 | return 0; |
| 105 | |
| 106 | task_wakeup(stream->task, TASK_WOKEN_MSG); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |