blob: 4d438c108970b598fcb3464b79a98e09d1557d42 [file] [log] [blame]
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02001/*
2 * include/types/action.h
Thierry FOURNIER322a1242015-08-19 09:07:47 +02003 * This file contains actions definitions.
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004 *
5 * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _TYPES_ACTION_H
23#define _TYPES_ACTION_H
24
25#include <types/stick_table.h>
26
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020027enum act_from {
28 ACT_F_TCP_REQ_CON, /* tcp-request connection */
29 ACT_F_TCP_REQ_CNT, /* tcp-request content */
30 ACT_F_TCP_RES_CNT, /* tcp-response content */
31 ACT_F_HTTP_REQ, /* http-request */
32 ACT_F_HTTP_RES, /* http-response */
33};
34
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020035enum act_return {
36 ACT_RET_CONT, /* continue processing. */
37 ACT_RET_YIELD, /* call me again. */
38 ACT_RET_ERR, /* processing error. */
39};
40
Thierry FOURNIERafa80492015-08-19 09:04:15 +020041enum act_parse_ret {
42 ACT_RET_PRS_OK, /* continue processing. */
43 ACT_RET_PRS_ERR, /* abort processing. */
44};
45
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020046enum act_name {
47 ACT_ACTION_CONT = 0,
48 ACT_ACTION_STOP,
49
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020050 /* common action */
51 ACT_ACTION_ALLOW,
52 ACT_ACTION_DENY,
53
54 /* common http actions .*/
55 ACT_HTTP_ADD_HDR,
56 ACT_HTTP_REPLACE_HDR,
57 ACT_HTTP_REPLACE_VAL,
58 ACT_HTTP_SET_HDR,
59 ACT_HTTP_DEL_HDR,
60 ACT_HTTP_REDIR,
61 ACT_HTTP_SET_NICE,
62 ACT_HTTP_SET_LOGL,
63 ACT_HTTP_SET_TOS,
64 ACT_HTTP_SET_MARK,
65 ACT_HTTP_ADD_ACL,
66 ACT_HTTP_DEL_ACL,
67 ACT_HTTP_DEL_MAP,
68 ACT_HTTP_SET_MAP,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020069
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020070 /* http request actions. */
71 ACT_HTTP_REQ_TARPIT,
72 ACT_HTTP_REQ_AUTH,
73 ACT_HTTP_REQ_SET_SRC,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020074
75 /* tcp actions */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020076 ACT_TCP_EXPECT_PX,
77 ACT_TCP_CLOSE, /* close at the sender's */
78 ACT_TCP_CAPTURE, /* capture a fetched sample */
79
80 /* track stick counters */
81 ACT_ACTION_TRK_SC0,
82 /* SC1, SC2, ... SCn */
83 ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020084};
85
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020086struct act_rule {
87 struct list list;
88 struct acl_cond *cond; /* acl condition to meet */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020089 enum act_name action; /* ACT_ACTION_* */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020090 enum act_from from; /* ACT_F_* */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020091 short deny_status; /* HTTP status to return to user when denying */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020092 enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px,
93 struct session *sess, struct stream *s); /* ptr to custom action */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020094 union {
95 struct {
96 char *realm;
97 } auth; /* arg used by "auth" */
98 struct {
99 char *name; /* header name */
100 int name_len; /* header name's length */
101 struct list fmt; /* log-format compatible expression */
102 struct my_regex re; /* used by replace-header and replace-value */
103 } hdr_add; /* args used by "add-header" and "set-header" */
104 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +0200105 int nice; /* nice value for ACT_HTTP_SET_NICE */
106 int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */
107 int tos; /* tos value for ACT_HTTP_SET_TOS */
108 int mark; /* nfmark value for ACT_HTTP_SET_MARK */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200109 struct {
110 char *ref; /* MAP or ACL file name to update */
111 struct list key; /* pattern to retrieve MAP or ACL key */
112 struct list value; /* pattern to retrieve MAP value */
113 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200114 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200115 struct {
116 struct list logfmt;
117 int action;
118 } http;
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200119 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200120 struct sample_expr *expr; /* expression used as the key */
121 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200122 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200123 struct {
124 struct sample_expr *expr;
125 int idx;
126 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200127 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200128 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200129 struct sample_expr *expr;
130 const char *name;
131 enum vars_scope scope;
132 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200133 struct {
134 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200135 } gpc;
136 struct {
137 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200138 long long int value;
139 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200140 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200141 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200142 void *p[4];
143 } act; /* generic pointers to be used by custom actions */
144 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200145};
146
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200147struct action_kw {
148 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200149 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
150 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200151 int match_pfx;
152};
153
154struct action_kw_list {
155 struct list list;
156 struct action_kw kw[VAR_ARRAY];
157};
158
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200159#endif /* _TYPES_ACTION_H */