blob: 54542420cf5f10f0469cd719984d86ac14a7fa3c [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>
Baptiste Assmann333939c2019-01-21 08:34:50 +010019#include <proto/obj_type.h>
Christopher Faulet78880fb2017-09-18 14:43:55 +020020#include <proto/proxy.h>
21#include <proto/stick_table.h>
Baptiste Assmann333939c2019-01-21 08:34:50 +010022#include <proto/task.h>
Christopher Faulet78880fb2017-09-18 14:43:55 +020023
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 */
31int check_trk_action(struct act_rule *rule, struct proxy *px, char **err)
32{
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010033 struct stktable *target;
Christopher Faulet78880fb2017-09-18 14:43:55 +020034
35 if (rule->arg.trk_ctr.table.n)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010036 target = stktable_find_by_name(rule->arg.trk_ctr.table.n);
Christopher Faulet78880fb2017-09-18 14:43:55 +020037 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010038 target = px->table;
Christopher Faulet78880fb2017-09-18 14:43:55 +020039
40 if (!target) {
41 memprintf(err, "unable to find table '%s' referenced by track-sc%d",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010042 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id,
43 trk_idx(rule->action));
Christopher Faulet78880fb2017-09-18 14:43:55 +020044 return 0;
45 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010046
47 if (!stktable_compatible_sample(rule->arg.trk_ctr.expr, target->type)) {
Christopher Faulet78880fb2017-09-18 14:43:55 +020048 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écaille1b8e68e2019-03-14 07:07:41 +010053 else if (target->proxy && (px->bind_proc & ~target->proxy->bind_proc)) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +010054 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 Faulet78880fb2017-09-18 14:43:55 +020058 else {
Frédéric Lécaille015e4d72019-03-19 14:55:01 +010059 if (target->proxies_list != px) {
60 px->next_stkt_ref = target->proxies_list;
61 target->proxies_list = px;
62 }
Christopher Faulet78880fb2017-09-18 14:43:55 +020063 free(rule->arg.trk_ctr.table.n);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010064 rule->arg.trk_ctr.table.t = target;
Christopher Faulet78880fb2017-09-18 14:43:55 +020065 /* 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 Assmann333939c2019-01-21 08:34:50 +010073int 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
89int act_resolution_error_cb(struct dns_requester *requester, int error_code)
90{
91 struct stream *stream;
92
93 if (requester->resolution == NULL)
94 return 0;
95
96 stream = objt_stream(requester->owner);
97 if (stream == NULL)
98 return 0;
99
100 task_wakeup(stream->task, TASK_WOKEN_MSG);
101
102 return 0;
103}
104