blob: b7e1063cc555ae5e5cd62eacfa4ae964e4db9f36 [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
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020049enum act_name {
Thierry FOURNIER42148732015-09-02 17:17:33 +020050 ACT_CUSTOM = 0,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020051
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020052 /* common action */
53 ACT_ACTION_ALLOW,
54 ACT_ACTION_DENY,
55
56 /* common http actions .*/
57 ACT_HTTP_ADD_HDR,
58 ACT_HTTP_REPLACE_HDR,
59 ACT_HTTP_REPLACE_VAL,
60 ACT_HTTP_SET_HDR,
61 ACT_HTTP_DEL_HDR,
62 ACT_HTTP_REDIR,
63 ACT_HTTP_SET_NICE,
64 ACT_HTTP_SET_LOGL,
65 ACT_HTTP_SET_TOS,
66 ACT_HTTP_SET_MARK,
67 ACT_HTTP_ADD_ACL,
68 ACT_HTTP_DEL_ACL,
69 ACT_HTTP_DEL_MAP,
70 ACT_HTTP_SET_MAP,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020071
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020072 /* http request actions. */
73 ACT_HTTP_REQ_TARPIT,
74 ACT_HTTP_REQ_AUTH,
75 ACT_HTTP_REQ_SET_SRC,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020076
77 /* tcp actions */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020078 ACT_TCP_EXPECT_PX,
79 ACT_TCP_CLOSE, /* close at the sender's */
80 ACT_TCP_CAPTURE, /* capture a fetched sample */
81
82 /* track stick counters */
83 ACT_ACTION_TRK_SC0,
84 /* SC1, SC2, ... SCn */
85 ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020086};
87
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020088struct act_rule {
89 struct list list;
90 struct acl_cond *cond; /* acl condition to meet */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020091 enum act_name action; /* ACT_ACTION_* */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +020092 enum act_from from; /* ACT_F_* */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020093 short deny_status; /* HTTP status to return to user when denying */
Thierry FOURNIER24ff6c62015-08-06 08:52:53 +020094 enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px,
95 struct session *sess, struct stream *s); /* ptr to custom action */
Thierry FOURNIER85c6c972015-09-22 19:14:35 +020096 struct action_kw *kw;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020097 union {
98 struct {
99 char *realm;
100 } auth; /* arg used by "auth" */
101 struct {
102 char *name; /* header name */
103 int name_len; /* header name's length */
104 struct list fmt; /* log-format compatible expression */
105 struct my_regex re; /* used by replace-header and replace-value */
106 } hdr_add; /* args used by "add-header" and "set-header" */
107 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +0200108 int nice; /* nice value for ACT_HTTP_SET_NICE */
109 int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */
110 int tos; /* tos value for ACT_HTTP_SET_TOS */
111 int mark; /* nfmark value for ACT_HTTP_SET_MARK */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200112 struct {
113 char *ref; /* MAP or ACL file name to update */
114 struct list key; /* pattern to retrieve MAP or ACL key */
115 struct list value; /* pattern to retrieve MAP value */
116 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200117 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200118 struct {
119 struct list logfmt;
120 int action;
121 } http;
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200122 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200123 struct sample_expr *expr; /* expression used as the key */
124 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200125 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200126 struct {
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +0200127 unsigned int code; /* HTTP status code */
128 } status;
129 struct {
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200130 struct sample_expr *expr;
131 int idx;
132 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200133 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200134 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200135 struct sample_expr *expr;
136 const char *name;
137 enum vars_scope scope;
138 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200139 struct {
140 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200141 } gpc;
142 struct {
143 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200144 long long int value;
145 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200146 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200147 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200148 void *p[4];
149 } act; /* generic pointers to be used by custom actions */
150 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200151};
152
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200153struct action_kw {
154 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200155 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
156 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200157 int match_pfx;
Thierry FOURNIER7ea160c2015-09-22 18:26:42 +0200158 void *private;
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200159};
160
161struct action_kw_list {
162 struct list list;
163 struct action_kw kw[VAR_ARRAY];
164};
165
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200166#endif /* _TYPES_ACTION_H */