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/obj_type.h>
20 #include <proto/proxy.h>
21 #include <proto/stick_table.h>
22 #include <proto/task.h>
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 */
check_trk_action(struct act_rule * rule,struct proxy * px,char ** err)31 int check_trk_action(struct act_rule *rule, struct proxy *px, char **err)
32 {
33 struct stktable *target;
34
35 if (rule->arg.trk_ctr.table.n)
36 target = stktable_find_by_name(rule->arg.trk_ctr.table.n);
37 else
38 target = px->table;
39
40 if (!target) {
41 memprintf(err, "unable to find table '%s' referenced by track-sc%d",
42 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id,
43 trk_idx(rule->action));
44 return 0;
45 }
46
47 if (!stktable_compatible_sample(rule->arg.trk_ctr.expr, target->type)) {
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 }
53 else if (target->proxy && (px->bind_proc & ~target->proxy->bind_proc)) {
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 }
58 else {
59 if (!in_proxies_list(target->proxies_list, px)) {
60 px->next_stkt_ref = target->proxies_list;
61 target->proxies_list = px;
62 }
63 free(rule->arg.trk_ctr.table.n);
64 rule->arg.trk_ctr.table.t = target;
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
act_resolution_cb(struct dns_requester * requester,struct dns_nameserver * nameserver)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
act_resolution_error_cb(struct dns_requester * requester,int error_code)89 int 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
105