blob: ca0163fa6e76136f5b4ae373a46a6889851bedb8 [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 FOURNIERa28a9422015-08-04 19:35:46 +020027#include <types/stick_table.h>
28
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020029enum act_from {
30 ACT_F_TCP_REQ_CON, /* tcp-request connection */
31 ACT_F_TCP_REQ_CNT, /* tcp-request content */
32 ACT_F_TCP_RES_CNT, /* tcp-response content */
33 ACT_F_HTTP_REQ, /* http-request */
34 ACT_F_HTTP_RES, /* http-response */
35};
36
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020037enum act_return {
38 ACT_RET_CONT, /* continue processing. */
Thierry FOURNIER42148732015-09-02 17:17:33 +020039 ACT_RET_STOP, /* stop processing. */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020040 ACT_RET_YIELD, /* call me again. */
41 ACT_RET_ERR, /* processing error. */
42};
43
Thierry FOURNIERafa80492015-08-19 09:04:15 +020044enum act_parse_ret {
45 ACT_RET_PRS_OK, /* continue processing. */
46 ACT_RET_PRS_ERR, /* abort processing. */
47};
48
Willy Tarreau658b85b2015-09-27 10:00:49 +020049/* flags passed to custom actions */
50enum act_flag {
51 ACT_FLAG_NONE = 0x00000000, /* no flag */
Willy Tarreauc1b10d32015-09-27 10:06:24 +020052 ACT_FLAG_FINAL = 0x00000001, /* last call, cannot yield */
Willy Tarreauacc98002015-09-27 23:34:39 +020053 ACT_FLAG_FIRST = 0x00000002, /* first call for this action */
Willy Tarreau658b85b2015-09-27 10:00:49 +020054};
55
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020056enum act_name {
Thierry FOURNIER42148732015-09-02 17:17:33 +020057 ACT_CUSTOM = 0,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020058
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020059 /* common action */
60 ACT_ACTION_ALLOW,
61 ACT_ACTION_DENY,
62
63 /* common http actions .*/
64 ACT_HTTP_ADD_HDR,
65 ACT_HTTP_REPLACE_HDR,
66 ACT_HTTP_REPLACE_VAL,
67 ACT_HTTP_SET_HDR,
68 ACT_HTTP_DEL_HDR,
69 ACT_HTTP_REDIR,
70 ACT_HTTP_SET_NICE,
71 ACT_HTTP_SET_LOGL,
72 ACT_HTTP_SET_TOS,
73 ACT_HTTP_SET_MARK,
74 ACT_HTTP_ADD_ACL,
75 ACT_HTTP_DEL_ACL,
76 ACT_HTTP_DEL_MAP,
77 ACT_HTTP_SET_MAP,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020078
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020079 /* http request actions. */
80 ACT_HTTP_REQ_TARPIT,
81 ACT_HTTP_REQ_AUTH,
82 ACT_HTTP_REQ_SET_SRC,
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 FOURNIERa28a9422015-08-04 19:35:46 +0200104 union {
105 struct {
106 char *realm;
107 } auth; /* arg used by "auth" */
108 struct {
109 char *name; /* header name */
110 int name_len; /* header name's length */
111 struct list fmt; /* log-format compatible expression */
112 struct my_regex re; /* used by replace-header and replace-value */
113 } hdr_add; /* args used by "add-header" and "set-header" */
114 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +0200115 int nice; /* nice value for ACT_HTTP_SET_NICE */
116 int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */
117 int tos; /* tos value for ACT_HTTP_SET_TOS */
118 int mark; /* nfmark value for ACT_HTTP_SET_MARK */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200119 struct {
120 char *ref; /* MAP or ACL file name to update */
121 struct list key; /* pattern to retrieve MAP or ACL key */
122 struct list value; /* pattern to retrieve MAP value */
123 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200124 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200125 struct {
126 struct list logfmt;
127 int action;
128 } http;
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200129 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200130 struct sample_expr *expr; /* expression used as the key */
131 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200132 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200133 struct {
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +0200134 unsigned int code; /* HTTP status code */
135 } status;
136 struct {
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200137 struct sample_expr *expr;
138 int idx;
139 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200140 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200141 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200142 struct sample_expr *expr;
143 const char *name;
144 enum vars_scope scope;
145 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200146 struct {
147 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200148 } gpc;
149 struct {
150 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200151 long long int value;
152 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200153 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200154 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200155 void *p[4];
156 } act; /* generic pointers to be used by custom actions */
157 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200158};
159
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200160struct action_kw {
161 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200162 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
163 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200164 int match_pfx;
Thierry FOURNIER7ea160c2015-09-22 18:26:42 +0200165 void *private;
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200166};
167
168struct action_kw_list {
169 struct list list;
170 struct action_kw kw[VAR_ARRAY];
171};
172
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200173#endif /* _TYPES_ACTION_H */