blob: 9b6dcfd80c2501876098dd5ec62cbcf1c72b586a [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{
33 struct proxy *target;
34
35 if (rule->arg.trk_ctr.table.n)
36 target = proxy_tbl_by_name(rule->arg.trk_ctr.table.n);
37 else
38 target = px;
39
40 if (!target) {
41 memprintf(err, "unable to find table '%s' referenced by track-sc%d",
42 rule->arg.trk_ctr.table.n, trk_idx(rule->action));
43 return 0;
44 }
45 else if (target->table.size == 0) {
46 memprintf(err, "table '%s' used but not configured",
47 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id);
48 return 0;
49 }
50 else if (!stktable_compatible_sample(rule->arg.trk_ctr.expr, target->table.type)) {
51 memprintf(err, "stick-table '%s' uses a type incompatible with the 'track-sc%d' rule",
52 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id,
53 trk_idx(rule->action));
54 return 0;
55 }
Willy Tarreau151e1ca2019-02-05 11:38:38 +010056 else if (px->bind_proc & ~target->bind_proc) {
57 memprintf(err, "stick-table '%s' referenced by 'track-sc%d' rule not present on all processes covered by proxy '%s'",
58 target->id, trk_idx(rule->action), px->id);
59 return 0;
60 }
Christopher Faulet78880fb2017-09-18 14:43:55 +020061 else {
62 free(rule->arg.trk_ctr.table.n);
63 rule->arg.trk_ctr.table.t = &target->table;
64 /* Note: if we decide to enhance the track-sc syntax, we may be
65 * able to pass a list of counters to track and allocate them
66 * right here using stktable_alloc_data_type().
67 */
68 }
69 return 1;
70}
71
Baptiste Assmann333939c2019-01-21 08:34:50 +010072int act_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver)
73{
74 struct stream *stream;
75
76 if (requester->resolution == NULL)
77 return 0;
78
79 stream = objt_stream(requester->owner);
80 if (stream == NULL)
81 return 0;
82
83 task_wakeup(stream->task, TASK_WOKEN_MSG);
84
85 return 0;
86}
87
88int act_resolution_error_cb(struct dns_requester *requester, int error_code)
89{
90 struct stream *stream;
91
92 if (requester->resolution == NULL)
93 return 0;
94
95 stream = objt_stream(requester->owner);
96 if (stream == NULL)
97 return 0;
98
99 task_wakeup(stream->task, TASK_WOKEN_MSG);
100
101 return 0;
102}
103