blob: 742252e1096540b37b20a2ececb340c51d85fb72 [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
Thierry FOURNIER007ff4c2015-09-11 08:33:33 +020025#include <common/regex.h>
26
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020027#include <types/applet.h>
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020028#include <types/stick_table.h>
29
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020030enum act_from {
31 ACT_F_TCP_REQ_CON, /* tcp-request connection */
32 ACT_F_TCP_REQ_CNT, /* tcp-request content */
33 ACT_F_TCP_RES_CNT, /* tcp-response content */
34 ACT_F_HTTP_REQ, /* http-request */
35 ACT_F_HTTP_RES, /* http-response */
36};
37
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020038enum act_return {
39 ACT_RET_CONT, /* continue processing. */
Thierry FOURNIER42148732015-09-02 17:17:33 +020040 ACT_RET_STOP, /* stop processing. */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020041 ACT_RET_YIELD, /* call me again. */
42 ACT_RET_ERR, /* processing error. */
43};
44
Thierry FOURNIERafa80492015-08-19 09:04:15 +020045enum act_parse_ret {
46 ACT_RET_PRS_OK, /* continue processing. */
47 ACT_RET_PRS_ERR, /* abort processing. */
48};
49
Willy Tarreau658b85b2015-09-27 10:00:49 +020050/* flags passed to custom actions */
51enum act_flag {
52 ACT_FLAG_NONE = 0x00000000, /* no flag */
Willy Tarreauc1b10d32015-09-27 10:06:24 +020053 ACT_FLAG_FINAL = 0x00000001, /* last call, cannot yield */
Willy Tarreauacc98002015-09-27 23:34:39 +020054 ACT_FLAG_FIRST = 0x00000002, /* first call for this action */
Willy Tarreau658b85b2015-09-27 10:00:49 +020055};
56
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020057enum act_name {
Thierry FOURNIER42148732015-09-02 17:17:33 +020058 ACT_CUSTOM = 0,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020059
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020060 /* common action */
61 ACT_ACTION_ALLOW,
62 ACT_ACTION_DENY,
63
64 /* common http actions .*/
65 ACT_HTTP_ADD_HDR,
66 ACT_HTTP_REPLACE_HDR,
67 ACT_HTTP_REPLACE_VAL,
68 ACT_HTTP_SET_HDR,
69 ACT_HTTP_DEL_HDR,
70 ACT_HTTP_REDIR,
71 ACT_HTTP_SET_NICE,
72 ACT_HTTP_SET_LOGL,
73 ACT_HTTP_SET_TOS,
74 ACT_HTTP_SET_MARK,
75 ACT_HTTP_ADD_ACL,
76 ACT_HTTP_DEL_ACL,
77 ACT_HTTP_DEL_MAP,
78 ACT_HTTP_SET_MAP,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020079
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020080 /* http request actions. */
81 ACT_HTTP_REQ_TARPIT,
82 ACT_HTTP_REQ_AUTH,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020083
84 /* tcp actions */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020085 ACT_TCP_EXPECT_PX,
86 ACT_TCP_CLOSE, /* close at the sender's */
87 ACT_TCP_CAPTURE, /* capture a fetched sample */
88
89 /* track stick counters */
90 ACT_ACTION_TRK_SC0,
91 /* SC1, SC2, ... SCn */
92 ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020093};
94
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020095struct act_rule {
96 struct list list;
97 struct acl_cond *cond; /* acl condition to meet */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020098 enum act_name action; /* ACT_ACTION_* */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020099 enum act_from from; /* ACT_F_* */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200100 short deny_status; /* HTTP status to return to user when denying */
Willy Tarreau658b85b2015-09-27 10:00:49 +0200101 enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */
102 struct session *sess, struct stream *s, int flags);
Thierry FOURNIER85c6c972015-09-22 19:14:35 +0200103 struct action_kw *kw;
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200104 struct applet applet; /* used for the applet registration. */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200105 union {
106 struct {
107 char *realm;
108 } auth; /* arg used by "auth" */
109 struct {
110 char *name; /* header name */
111 int name_len; /* header name's length */
112 struct list fmt; /* log-format compatible expression */
113 struct my_regex re; /* used by replace-header and replace-value */
114 } hdr_add; /* args used by "add-header" and "set-header" */
115 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +0200116 int nice; /* nice value for ACT_HTTP_SET_NICE */
117 int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */
118 int tos; /* tos value for ACT_HTTP_SET_TOS */
119 int mark; /* nfmark value for ACT_HTTP_SET_MARK */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200120 struct {
121 char *ref; /* MAP or ACL file name to update */
122 struct list key; /* pattern to retrieve MAP or ACL key */
123 struct list value; /* pattern to retrieve MAP value */
124 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200125 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200126 struct {
127 struct list logfmt;
128 int action;
129 } http;
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200130 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200131 struct sample_expr *expr; /* expression used as the key */
132 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200133 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200134 struct {
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +0200135 unsigned int code; /* HTTP status code */
136 } status;
137 struct {
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200138 struct sample_expr *expr;
139 int idx;
140 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200141 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200142 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200143 struct sample_expr *expr;
144 const char *name;
145 enum vars_scope scope;
146 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200147 struct {
148 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200149 } gpc;
150 struct {
151 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200152 long long int value;
153 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200154 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200155 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200156 void *p[4];
157 } act; /* generic pointers to be used by custom actions */
158 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200159};
160
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200161struct action_kw {
162 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200163 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
164 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200165 int match_pfx;
Thierry FOURNIER7ea160c2015-09-22 18:26:42 +0200166 void *private;
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200167};
168
169struct action_kw_list {
170 struct list list;
171 struct action_kw kw[VAR_ARRAY];
172};
173
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200174#endif /* _TYPES_ACTION_H */