blob: fce6bc87bbbd3e2986c4473c13bbcf57b195e956 [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,
Bertrand Jacquin90759682016-06-06 15:35:39 +010086 ACT_TCP_EXPECT_CIP,
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +020087 ACT_TCP_CLOSE, /* close at the sender's */
88 ACT_TCP_CAPTURE, /* capture a fetched sample */
89
90 /* track stick counters */
91 ACT_ACTION_TRK_SC0,
92 /* SC1, SC2, ... SCn */
93 ACT_ACTION_TRK_SCMAX = ACT_ACTION_TRK_SC0 + MAX_SESS_STKCTR - 1,
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020094};
95
Thierry FOURNIERa28a9422015-08-04 19:35:46 +020096struct act_rule {
97 struct list list;
98 struct acl_cond *cond; /* acl condition to meet */
Thierry FOURNIER91f6ba02015-08-06 08:30:11 +020099 enum act_name action; /* ACT_ACTION_* */
Thierry FOURNIER5563e4b2015-08-14 19:20:07 +0200100 enum act_from from; /* ACT_F_* */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200101 short deny_status; /* HTTP status to return to user when denying */
Willy Tarreau658b85b2015-09-27 10:00:49 +0200102 enum act_return (*action_ptr)(struct act_rule *rule, struct proxy *px, /* ptr to custom action */
103 struct session *sess, struct stream *s, int flags);
Thierry FOURNIER85c6c972015-09-22 19:14:35 +0200104 struct action_kw *kw;
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200105 struct applet applet; /* used for the applet registration. */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200106 union {
107 struct {
108 char *realm;
109 } auth; /* arg used by "auth" */
110 struct {
111 char *name; /* header name */
112 int name_len; /* header name's length */
113 struct list fmt; /* log-format compatible expression */
114 struct my_regex re; /* used by replace-header and replace-value */
115 } hdr_add; /* args used by "add-header" and "set-header" */
116 struct redirect_rule *redir; /* redirect rule or "http-request redirect" */
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +0200117 int nice; /* nice value for ACT_HTTP_SET_NICE */
118 int loglevel; /* log-level value for ACT_HTTP_SET_LOGL */
119 int tos; /* tos value for ACT_HTTP_SET_TOS */
120 int mark; /* nfmark value for ACT_HTTP_SET_MARK */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200121 struct {
122 char *ref; /* MAP or ACL file name to update */
123 struct list key; /* pattern to retrieve MAP or ACL key */
124 struct list value; /* pattern to retrieve MAP value */
125 } map;
Thierry FOURNIERa002dc92015-07-31 08:50:51 +0200126 struct sample_expr *expr;
Thierry FOURNIER8855a922015-07-31 08:54:25 +0200127 struct {
128 struct list logfmt;
129 int action;
130 } http;
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200131 struct {
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +0200132 struct sample_expr *expr; /* expression used as the key */
133 struct cap_hdr *hdr; /* the capture storage */
Thierry FOURNIER32b15002015-07-31 08:56:16 +0200134 } cap;
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200135 struct {
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +0200136 unsigned int code; /* HTTP status code */
137 } status;
138 struct {
Thierry FOURNIERe2097972015-07-31 08:56:35 +0200139 struct sample_expr *expr;
140 int idx;
141 } capid;
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200142 struct hlua_rule *hlua_rule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200143 struct {
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200144 struct sample_expr *expr;
145 const char *name;
146 enum vars_scope scope;
147 } vars;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200148 struct {
149 int sc;
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +0200150 } gpc;
151 struct {
152 int sc;
Thierry FOURNIER236657b2015-08-19 08:25:14 +0200153 long long int value;
154 } gpt;
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +0200155 struct track_ctr_prm trk_ctr;
Thierry FOURNIERf8c1dce2015-07-30 19:12:50 +0200156 struct {
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200157 void *p[4];
158 } act; /* generic pointers to be used by custom actions */
159 } arg; /* arguments used by some actions */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200160};
161
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200162struct action_kw {
163 const char *kw;
Thierry FOURNIERafa80492015-08-19 09:04:15 +0200164 enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
165 struct act_rule *rule, char **err);
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200166 int match_pfx;
Thierry FOURNIER7ea160c2015-09-22 18:26:42 +0200167 void *private;
Thierry FOURNIER36481b82015-08-19 09:01:53 +0200168};
169
170struct action_kw_list {
171 struct list list;
172 struct action_kw kw[VAR_ARRAY];
173};
174
Thierry FOURNIERa28a9422015-08-04 19:35:46 +0200175#endif /* _TYPES_ACTION_H */