blob: 9fc9ec8f45c9bbd4a00777911529685f38d72825 [file] [log] [blame]
Willy Tarreau8a8d83b2015-04-13 13:24:54 +02001/*
2 * include/types/applet.h
3 * This file describes the applet struct and associated constants.
4 *
5 * Copyright (C) 2000-2015 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_APPLET_H
23#define _TYPES_APPLET_H
24
25#include <types/hlua.h>
26#include <types/obj_type.h>
Thierry FOURNIERc069cfd2015-09-11 08:50:34 +020027#include <types/proxy.h>
28#include <types/stream.h>
Christopher Fauleta73e59b2016-12-09 17:30:18 +010029#include <common/buffer.h>
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020030#include <common/chunk.h>
31#include <common/config.h>
Thierry FOURNIER2da788e2017-09-11 18:37:23 +020032#include <common/xref.h>
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020033
34struct appctx;
35
36/* Applet descriptor */
Willy Tarreau30576452015-04-13 13:50:30 +020037struct applet {
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020038 enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */
39 /* 3 unused bytes here */
40 char *name; /* applet's name to report in logs */
Thierry FOURNIERc069cfd2015-09-11 08:50:34 +020041 int (*init)(struct appctx *, struct proxy *px, struct stream *strm); /* callback to init ressources, may be NULL.
42 expect 1 if ok, 0 if an error occurs, -1 if miss data. */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020043 void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */
44 void (*release)(struct appctx *); /* callback to release resources, may be NULL */
Thierry FOURNIER1245a832015-09-22 00:02:58 +020045 unsigned int timeout; /* execution timeout. */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020046};
47
Olivier Houchard673867c2018-05-25 16:58:52 +020048#define APPLET_WANT_DIE 0x01 /* applet was running and requested to die */
Emeric Brunc7306062017-06-26 16:36:53 +020049
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +020050#define APPCTX_CLI_ST1_PROMPT (1 << 0)
51#define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
52
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020053/* Context of a running applet. */
54struct appctx {
55 enum obj_type obj_type; /* OBJ_TYPE_APPCTX */
56 /* 3 unused bytes here */
Emeric Brunc7306062017-06-26 16:36:53 +020057 unsigned short state; /* Internal appctx state */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020058 unsigned int st0; /* CLI state for stats, session state for peers */
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +020059 unsigned int st1; /* prompt/payload (bitwise OR of APPCTX_CLI_ST1_*) for stats, session error for peers */
Willy Tarreau83061a82018-07-13 11:56:34 +020060 struct buffer *chunk; /* used to store unfinished commands */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020061 unsigned int st2; /* output state for stats, unused by peers */
Willy Tarreau30576452015-04-13 13:50:30 +020062 struct applet *applet; /* applet this context refers to */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020063 void *owner; /* pointer to upper layer's entity (eg: stream interface) */
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020064 struct act_rule *rule; /* rule associated with the applet. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +010065 int (*io_handler)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK */
66 void (*io_release)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK,
Thierry FOURNIER / OZON.IO6a22dcb2016-11-12 10:51:33 +010067 if the command is terminated or the session released */
Andjelko Iharosc4df59e2017-07-20 11:59:48 +020068 int cli_severity_output; /* used within the cli_io_handler to format severity output of informational feedback */
William Lallemandf630d012018-12-13 09:05:44 +010069 int cli_level; /* the level of CLI which can be lowered dynamically */
Christopher Fauleta73e59b2016-12-09 17:30:18 +010070 struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
Willy Tarreauf65610a2017-10-31 16:06:06 +010071 unsigned long thread_mask; /* mask of thread IDs authorized to process the applet */
Olivier Houchard673867c2018-05-25 16:58:52 +020072 struct task *t; /* task associated to the applet */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020073
74 union {
75 struct {
Emeric Brun80527f52017-06-19 17:46:37 +020076 void *ptr; /* current peer or NULL, do not use for something else */
Willy Tarreauebec3512016-12-16 12:14:12 +010077 } peers; /* used by the peers applet */
78 struct {
79 int connected;
Thierry FOURNIER2da788e2017-09-11 18:37:23 +020080 struct xref xref; /* cross reference with the Lua object owner. */
Willy Tarreauebec3512016-12-16 12:14:12 +010081 struct list wake_on_read;
82 struct list wake_on_write;
Thierry FOURNIERb13b20a2017-07-16 20:48:54 +020083 int die;
Willy Tarreauebec3512016-12-16 12:14:12 +010084 } hlua_cosocket; /* used by the Lua cosockets */
85 struct {
86 struct hlua *hlua;
87 int flags;
88 struct task *task;
89 } hlua_apptcp; /* used by the Lua TCP services */
90 struct {
91 struct hlua *hlua;
92 int left_bytes; /* The max amount of bytes that we can read. */
93 int flags;
94 int status;
Robin H. Johnson52f5db22017-01-01 13:10:52 -080095 const char *reason;
Willy Tarreauebec3512016-12-16 12:14:12 +010096 struct task *task;
97 } hlua_apphttp; /* used by the Lua HTTP services */
98 struct {
Christopher Faulet42bfa462017-01-04 14:14:19 +010099 void *ptr; /* private pointer for SPOE filter */
Willy Tarreauebec3512016-12-16 12:14:12 +0100100 } spoe; /* used by SPOE filter */
101 struct {
102 const char *msg; /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
Andjelko Iharosc4df59e2017-07-20 11:59:48 +0200103 int severity; /* severity of the message to be returned according to (syslog) rfc5424 */
Willy Tarreauebec3512016-12-16 12:14:12 +0100104 char *err; /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
Willy Tarreaua2d58722016-12-16 12:37:03 +0100105 void *p0, *p1; /* general purpose pointers and integers for registered commands, initialized */
106 int i0, i1; /* to 0 by the CLI before first invocation of the keyword parser. */
Willy Tarreauebec3512016-12-16 12:14:12 +0100107 } cli; /* context used by the CLI */
William Lallemand77c11972017-10-31 20:43:01 +0100108 struct {
Frédéric Lécaille8df65ae2018-10-22 18:01:48 +0200109 struct cache_entry *entry; /* Entry to be sent from cache. */
Christopher Faulet54a8d5a2018-12-07 12:21:11 +0100110 unsigned int sent; /* The number of bytes already sent for this cache entry. */
111 unsigned int offset; /* start offset of remaining data relative to beginning of the next block */
Frédéric Lécaille8df65ae2018-10-22 18:01:48 +0200112 struct shared_block *next; /* The next block of data to be sent for this cache entry. */
William Lallemand77c11972017-10-31 20:43:01 +0100113 } cache;
Willy Tarreauebec3512016-12-16 12:14:12 +0100114 /* all entries below are used by various CLI commands, please
115 * keep the grouped together and avoid adding new ones.
116 */
117 struct {
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200118 struct proxy *px;
119 struct server *sv;
120 void *l;
121 int scope_str; /* limit scope to a frontend/backend substring */
122 int scope_len; /* length of the string above in the buffer */
123 int px_st; /* STAT_PX_ST* */
124 unsigned int flags; /* STAT_* */
125 int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */
126 int st_code; /* the status code returned by an action */
127 } stats;
128 struct {
129 struct bref bref; /* back-reference from the session being dumped */
130 void *target; /* session we want to dump, or NULL for all */
131 unsigned int uid; /* if non-null, the uniq_id of the session being dumped */
132 int section; /* section of the session being dumped */
133 int pos; /* last position of the current session's buffer */
134 } sess;
135 struct {
136 int iid; /* if >= 0, ID of the proxy to filter on */
137 struct proxy *px; /* current proxy being dumped, NULL = not started yet. */
Willy Tarreau35069f82016-11-25 09:16:37 +0100138 unsigned int flag; /* bit0: buffer being dumped, 0 = req, 1 = resp ; bit1=skip req ; bit2=skip resp. */
Willy Tarreau5865a8f2018-09-07 11:51:51 +0200139 unsigned int ev_id; /* event ID of error being dumped */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200140 int ptr; /* <0: headers, >=0 : text pointer to restart from */
141 int bol; /* pointer to beginning of current line */
142 } errors;
143 struct {
144 void *target; /* table we want to dump, or NULL for all */
145 struct proxy *proxy; /* table being currently dumped (first if NULL) */
146 struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */
147 long long value; /* value to compare against */
148 signed char data_type; /* type of data to compare, or -1 if none */
149 signed char data_op; /* operator (STD_OP_*) when data_type set */
Willy Tarreaua24bc782016-12-14 15:50:35 +0100150 char action; /* action on the table : one of STK_CLI_ACT_* */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200151 } table;
152 struct {
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200153 unsigned int display_flags;
154 struct pat_ref *ref;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200155 struct bref bref; /* back-reference from the pat_ref_elt being dumped */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200156 struct pattern_expr *expr;
Willy Tarreau83061a82018-07-13 11:56:34 +0200157 struct buffer chunk;
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200158 } map;
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200159 struct {
Thierry FOURNIERebed6e92016-12-16 11:54:07 +0100160 struct hlua *hlua;
Thierry FOURNIER / OZON.IOa44fdd92016-11-13 13:19:20 +0100161 struct task *task;
Willy Tarreau8ae4f752016-12-14 15:41:45 +0100162 struct hlua_function *fcn;
Thierry FOURNIER / OZON.IOa44fdd92016-11-13 13:19:20 +0100163 } hlua_cli;
Willy Tarreauebec3512016-12-16 12:14:12 +0100164 /* NOTE: please add regular applet contexts (ie: not
165 * CLI-specific ones) above, before "cli".
166 */
167 } ctx; /* context-specific variables used by any applet */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200168};
169
170#endif /* _TYPES_APPLET_H */
171
172/*
173 * Local variables:
174 * c-indent-level: 8
175 * c-basic-offset: 8
176 * End:
177 */