blob: 0854208132c8f6fa7f900c46c4c6aff81b0f846c [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
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020013#include <haproxy/api.h>
Christopher Faulet78880fb2017-09-18 14:43:55 +020014#include <common/memory.h>
15#include <common/mini-clist.h>
16#include <common/standard.h>
17
18#include <proto/action.h>
Christopher Fauletac98d812019-12-18 09:20:16 +010019#include <proto/log.h>
Baptiste Assmann333939c2019-01-21 08:34:50 +010020#include <proto/obj_type.h>
Christopher Faulet78880fb2017-09-18 14:43:55 +020021#include <proto/proxy.h>
22#include <proto/stick_table.h>
Baptiste Assmann333939c2019-01-21 08:34:50 +010023#include <proto/task.h>
Christopher Faulet78880fb2017-09-18 14:43:55 +020024
25
Christopher Fauletac98d812019-12-18 09:20:16 +010026/* Find and check the target table used by an action track-sc*. This
Christopher Faulet78880fb2017-09-18 14:43:55 +020027 * function should be called during the configuration validity check.
28 *
29 * The function returns 1 in success case, otherwise, it returns 0 and err is
30 * filled.
31 */
32int check_trk_action(struct act_rule *rule, struct proxy *px, char **err)
33{
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010034 struct stktable *target;
Christopher Faulet78880fb2017-09-18 14:43:55 +020035
36 if (rule->arg.trk_ctr.table.n)
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010037 target = stktable_find_by_name(rule->arg.trk_ctr.table.n);
Christopher Faulet78880fb2017-09-18 14:43:55 +020038 else
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010039 target = px->table;
Christopher Faulet78880fb2017-09-18 14:43:55 +020040
41 if (!target) {
42 memprintf(err, "unable to find table '%s' referenced by track-sc%d",
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010043 rule->arg.trk_ctr.table.n ? rule->arg.trk_ctr.table.n : px->id,
Christopher Fauletac98d812019-12-18 09:20:16 +010044 rule->action);
Christopher Faulet78880fb2017-09-18 14:43:55 +020045 return 0;
46 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010047
48 if (!stktable_compatible_sample(rule->arg.trk_ctr.expr, target->type)) {
Christopher Faulet78880fb2017-09-18 14:43:55 +020049 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,
Christopher Fauletac98d812019-12-18 09:20:16 +010051 rule->action);
Christopher Faulet78880fb2017-09-18 14:43:55 +020052 return 0;
53 }
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010054 else if (target->proxy && (px->bind_proc & ~target->proxy->bind_proc)) {
Willy Tarreau151e1ca2019-02-05 11:38:38 +010055 memprintf(err, "stick-table '%s' referenced by 'track-sc%d' rule not present on all processes covered by proxy '%s'",
Christopher Fauletac98d812019-12-18 09:20:16 +010056 target->id, rule->action, px->id);
Willy Tarreau151e1ca2019-02-05 11:38:38 +010057 return 0;
58 }
Christopher Faulet78880fb2017-09-18 14:43:55 +020059 else {
Frédéric Lécaillebe367932019-08-07 09:28:39 +020060 if (!in_proxies_list(target->proxies_list, px)) {
Frédéric Lécaille015e4d72019-03-19 14:55:01 +010061 px->next_stkt_ref = target->proxies_list;
62 target->proxies_list = px;
63 }
Christopher Faulet78880fb2017-09-18 14:43:55 +020064 free(rule->arg.trk_ctr.table.n);
Frédéric Lécaille1b8e68e2019-03-14 07:07:41 +010065 rule->arg.trk_ctr.table.t = target;
Christopher Faulet78880fb2017-09-18 14:43:55 +020066 /* Note: if we decide to enhance the track-sc syntax, we may be
67 * able to pass a list of counters to track and allocate them
68 * right here using stktable_alloc_data_type().
69 */
70 }
Christopher Fauletac98d812019-12-18 09:20:16 +010071
72 if (rule->from == ACT_F_TCP_REQ_CNT && (px->cap & PR_CAP_FE) && !px->tcp_req.inspect_delay &&
73 !(rule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) {
74 ha_warning("config : %s '%s' : a 'tcp-request content track-sc*' rule explicitly depending on request"
75 " contents without any 'tcp-request inspect-delay' setting."
76 " This means that this rule will randomly find its contents. This can be fixed by"
77 " setting the tcp-request inspect-delay.\n",
78 proxy_type_str(px), px->id);
79 }
80
Christopher Faulet78880fb2017-09-18 14:43:55 +020081 return 1;
82}
83
Christopher Fauletd73b96d2019-12-19 17:27:03 +010084/* check a capture rule. This function should be called during the configuration
85 * validity check.
86 *
87 * The function returns 1 in success case, otherwise, it returns 0 and err is
88 * filled.
89 */
90int check_capture(struct act_rule *rule, struct proxy *px, char **err)
91{
92 if (rule->from == ACT_F_TCP_REQ_CNT && (px->cap & PR_CAP_FE) && !px->tcp_req.inspect_delay &&
93 !(rule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) {
94 ha_warning("config : %s '%s' : a 'tcp-request capture' rule explicitly depending on request"
95 " contents without any 'tcp-request inspect-delay' setting."
96 " This means that this rule will randomly find its contents. This can be fixed by"
97 " setting the tcp-request inspect-delay.\n",
98 proxy_type_str(px), px->id);
99 }
100
101 return 1;
102}
103
Baptiste Assmann333939c2019-01-21 08:34:50 +0100104int act_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver)
105{
106 struct stream *stream;
107
108 if (requester->resolution == NULL)
109 return 0;
110
111 stream = objt_stream(requester->owner);
112 if (stream == NULL)
113 return 0;
114
115 task_wakeup(stream->task, TASK_WOKEN_MSG);
116
117 return 0;
118}
119
120int act_resolution_error_cb(struct dns_requester *requester, int error_code)
121{
122 struct stream *stream;
123
124 if (requester->resolution == NULL)
125 return 0;
126
127 stream = objt_stream(requester->owner);
128 if (stream == NULL)
129 return 0;
130
131 task_wakeup(stream->task, TASK_WOKEN_MSG);
132
133 return 0;
134}
135