Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
Willy Tarreau | 22d63a2 | 2019-04-24 08:41:29 +0200 | [diff] [blame] | 25 | #include <types/freq_ctr.h> |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 26 | #include <types/hlua.h> |
| 27 | #include <types/obj_type.h> |
Thierry FOURNIER | c069cfd | 2015-09-11 08:50:34 +0200 | [diff] [blame] | 28 | #include <types/proxy.h> |
| 29 | #include <types/stream.h> |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 30 | #include <common/buffer.h> |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 31 | #include <common/chunk.h> |
| 32 | #include <common/config.h> |
Thierry FOURNIER | 2da788e | 2017-09-11 18:37:23 +0200 | [diff] [blame] | 33 | #include <common/xref.h> |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 34 | |
| 35 | struct appctx; |
| 36 | |
| 37 | /* Applet descriptor */ |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 38 | struct applet { |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 39 | enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */ |
| 40 | /* 3 unused bytes here */ |
| 41 | char *name; /* applet's name to report in logs */ |
Thierry FOURNIER | c069cfd | 2015-09-11 08:50:34 +0200 | [diff] [blame] | 42 | int (*init)(struct appctx *, struct proxy *px, struct stream *strm); /* callback to init ressources, may be NULL. |
| 43 | expect 1 if ok, 0 if an error occurs, -1 if miss data. */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 44 | void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */ |
| 45 | void (*release)(struct appctx *); /* callback to release resources, may be NULL */ |
Thierry FOURNIER | 1245a83 | 2015-09-22 00:02:58 +0200 | [diff] [blame] | 46 | unsigned int timeout; /* execution timeout. */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 49 | #define APPLET_WANT_DIE 0x01 /* applet was running and requested to die */ |
Emeric Brun | c730606 | 2017-06-26 16:36:53 +0200 | [diff] [blame] | 50 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 51 | #define APPCTX_CLI_ST1_PROMPT (1 << 0) |
| 52 | #define APPCTX_CLI_ST1_PAYLOAD (1 << 1) |
William Lallemand | ad03288 | 2019-07-01 10:56:15 +0200 | [diff] [blame] | 53 | #define APPCTX_CLI_ST1_NOLF (1 << 2) |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 55 | /* Context of a running applet. */ |
| 56 | struct appctx { |
| 57 | enum obj_type obj_type; /* OBJ_TYPE_APPCTX */ |
| 58 | /* 3 unused bytes here */ |
Emeric Brun | c730606 | 2017-06-26 16:36:53 +0200 | [diff] [blame] | 59 | unsigned short state; /* Internal appctx state */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 60 | unsigned int st0; /* CLI state for stats, session state for peers */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 61 | unsigned int st1; /* prompt/payload (bitwise OR of APPCTX_CLI_ST1_*) for stats, session error for peers */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 62 | struct buffer *chunk; /* used to store unfinished commands */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 63 | unsigned int st2; /* output state for stats, unused by peers */ |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 64 | struct applet *applet; /* applet this context refers to */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 65 | void *owner; /* pointer to upper layer's entity (eg: stream interface) */ |
Thierry FOURNIER | 5a363e7 | 2015-09-27 19:29:33 +0200 | [diff] [blame] | 66 | struct act_rule *rule; /* rule associated with the applet. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 67 | int (*io_handler)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK */ |
| 68 | void (*io_release)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK, |
Thierry FOURNIER / OZON.IO | 6a22dcb | 2016-11-12 10:51:33 +0100 | [diff] [blame] | 69 | if the command is terminated or the session released */ |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 70 | int cli_severity_output; /* used within the cli_io_handler to format severity output of informational feedback */ |
William Lallemand | f630d01 | 2018-12-13 09:05:44 +0100 | [diff] [blame] | 71 | int cli_level; /* the level of CLI which can be lowered dynamically */ |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 72 | struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */ |
Willy Tarreau | f65610a | 2017-10-31 16:06:06 +0100 | [diff] [blame] | 73 | unsigned long thread_mask; /* mask of thread IDs authorized to process the applet */ |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 74 | struct task *t; /* task associated to the applet */ |
Willy Tarreau | 22d63a2 | 2019-04-24 08:41:29 +0200 | [diff] [blame] | 75 | struct freq_ctr call_rate; /* appctx call rate */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 76 | |
| 77 | union { |
| 78 | struct { |
Emeric Brun | 80527f5 | 2017-06-19 17:46:37 +0200 | [diff] [blame] | 79 | void *ptr; /* current peer or NULL, do not use for something else */ |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 80 | } peers; /* used by the peers applet */ |
| 81 | struct { |
| 82 | int connected; |
Thierry FOURNIER | 2da788e | 2017-09-11 18:37:23 +0200 | [diff] [blame] | 83 | struct xref xref; /* cross reference with the Lua object owner. */ |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 84 | struct list wake_on_read; |
| 85 | struct list wake_on_write; |
Thierry FOURNIER | b13b20a | 2017-07-16 20:48:54 +0200 | [diff] [blame] | 86 | int die; |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 87 | } hlua_cosocket; /* used by the Lua cosockets */ |
| 88 | struct { |
| 89 | struct hlua *hlua; |
| 90 | int flags; |
| 91 | struct task *task; |
| 92 | } hlua_apptcp; /* used by the Lua TCP services */ |
| 93 | struct { |
| 94 | struct hlua *hlua; |
| 95 | int left_bytes; /* The max amount of bytes that we can read. */ |
| 96 | int flags; |
| 97 | int status; |
Robin H. Johnson | 52f5db2 | 2017-01-01 13:10:52 -0800 | [diff] [blame] | 98 | const char *reason; |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 99 | struct task *task; |
| 100 | } hlua_apphttp; /* used by the Lua HTTP services */ |
| 101 | struct { |
Christopher Faulet | 42bfa46 | 2017-01-04 14:14:19 +0100 | [diff] [blame] | 102 | void *ptr; /* private pointer for SPOE filter */ |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 103 | } spoe; /* used by SPOE filter */ |
| 104 | struct { |
| 105 | const char *msg; /* pointer to a persistent message to be returned in CLI_ST_PRINT state */ |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 106 | int severity; /* severity of the message to be returned according to (syslog) rfc5424 */ |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 107 | char *err; /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */ |
Willy Tarreau | 300decc | 2019-08-30 08:05:03 +0200 | [diff] [blame] | 108 | struct list l0; /* General purpose list element, pointers, offsets and integers for... */ |
| 109 | void *p0, *p1; /* ...registered commands, initialized to 0 by the CLI before first... */ |
| 110 | size_t o0, o1; /* ...invocation of the keyword parser, except for the list element which... */ |
| 111 | int i0, i1; /* ...is initialized with LIST_INIT(). */ |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 112 | } cli; /* context used by the CLI */ |
William Lallemand | 77c1197 | 2017-10-31 20:43:01 +0100 | [diff] [blame] | 113 | struct { |
Frédéric Lécaille | 8df65ae | 2018-10-22 18:01:48 +0200 | [diff] [blame] | 114 | struct cache_entry *entry; /* Entry to be sent from cache. */ |
Christopher Faulet | 54a8d5a | 2018-12-07 12:21:11 +0100 | [diff] [blame] | 115 | unsigned int sent; /* The number of bytes already sent for this cache entry. */ |
| 116 | unsigned int offset; /* start offset of remaining data relative to beginning of the next block */ |
Christopher Faulet | 8f3c256 | 2019-06-03 22:19:18 +0200 | [diff] [blame] | 117 | unsigned int rem_data; /* Remaing bytes for the last data block (HTX only, 0 means process next block) */ |
Frédéric Lécaille | 8df65ae | 2018-10-22 18:01:48 +0200 | [diff] [blame] | 118 | struct shared_block *next; /* The next block of data to be sent for this cache entry. */ |
William Lallemand | 77c1197 | 2017-10-31 20:43:01 +0100 | [diff] [blame] | 119 | } cache; |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 120 | /* all entries below are used by various CLI commands, please |
| 121 | * keep the grouped together and avoid adding new ones. |
| 122 | */ |
| 123 | struct { |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 124 | struct proxy *px; |
| 125 | struct server *sv; |
| 126 | void *l; |
| 127 | int scope_str; /* limit scope to a frontend/backend substring */ |
| 128 | int scope_len; /* length of the string above in the buffer */ |
| 129 | int px_st; /* STAT_PX_ST* */ |
| 130 | unsigned int flags; /* STAT_* */ |
| 131 | int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */ |
| 132 | int st_code; /* the status code returned by an action */ |
| 133 | } stats; |
| 134 | struct { |
| 135 | struct bref bref; /* back-reference from the session being dumped */ |
| 136 | void *target; /* session we want to dump, or NULL for all */ |
| 137 | unsigned int uid; /* if non-null, the uniq_id of the session being dumped */ |
| 138 | int section; /* section of the session being dumped */ |
| 139 | int pos; /* last position of the current session's buffer */ |
| 140 | } sess; |
| 141 | struct { |
| 142 | int iid; /* if >= 0, ID of the proxy to filter on */ |
| 143 | struct proxy *px; /* current proxy being dumped, NULL = not started yet. */ |
Willy Tarreau | 35069f8 | 2016-11-25 09:16:37 +0100 | [diff] [blame] | 144 | unsigned int flag; /* bit0: buffer being dumped, 0 = req, 1 = resp ; bit1=skip req ; bit2=skip resp. */ |
Willy Tarreau | 5865a8f | 2018-09-07 11:51:51 +0200 | [diff] [blame] | 145 | unsigned int ev_id; /* event ID of error being dumped */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 146 | int ptr; /* <0: headers, >=0 : text pointer to restart from */ |
| 147 | int bol; /* pointer to beginning of current line */ |
| 148 | } errors; |
| 149 | struct { |
| 150 | void *target; /* table we want to dump, or NULL for all */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 151 | struct stktable *t; /* table being currently dumped (first if NULL) */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 152 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 153 | long long value; /* value to compare against */ |
| 154 | signed char data_type; /* type of data to compare, or -1 if none */ |
| 155 | signed char data_op; /* operator (STD_OP_*) when data_type set */ |
Willy Tarreau | a24bc78 | 2016-12-14 15:50:35 +0100 | [diff] [blame] | 156 | char action; /* action on the table : one of STK_CLI_ACT_* */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 157 | } table; |
| 158 | struct { |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 159 | unsigned int display_flags; |
| 160 | struct pat_ref *ref; |
Emeric Brun | 8d85aa4 | 2017-06-29 15:40:33 +0200 | [diff] [blame] | 161 | struct bref bref; /* back-reference from the pat_ref_elt being dumped */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 162 | struct pattern_expr *expr; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 163 | struct buffer chunk; |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 164 | } map; |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 165 | struct { |
Thierry FOURNIER | ebed6e9 | 2016-12-16 11:54:07 +0100 | [diff] [blame] | 166 | struct hlua *hlua; |
Thierry FOURNIER / OZON.IO | a44fdd9 | 2016-11-13 13:19:20 +0100 | [diff] [blame] | 167 | struct task *task; |
Willy Tarreau | 8ae4f75 | 2016-12-14 15:41:45 +0100 | [diff] [blame] | 168 | struct hlua_function *fcn; |
Thierry FOURNIER / OZON.IO | a44fdd9 | 2016-11-13 13:19:20 +0100 | [diff] [blame] | 169 | } hlua_cli; |
Frédéric Lécaille | 95679dc | 2019-04-15 10:25:27 +0200 | [diff] [blame] | 170 | struct { |
| 171 | void *target; |
| 172 | struct peers *peers; /* "peers" section being currently dumped. */ |
| 173 | struct peer *peer; /* "peer" being currently dumped. */ |
| 174 | } cfgpeers; |
William Lallemand | 8f840d7 | 2019-10-23 10:53:05 +0200 | [diff] [blame] | 175 | struct { |
| 176 | char *path; |
| 177 | int it; |
William Lallemand | bc6ca7c | 2019-10-29 23:48:19 +0100 | [diff] [blame^] | 178 | struct ckch_store *old_ckchs; |
| 179 | struct ckch_store *new_ckchs; |
| 180 | struct ckch_inst *next_ckchi; |
William Lallemand | 8f840d7 | 2019-10-23 10:53:05 +0200 | [diff] [blame] | 181 | } ssl; |
Willy Tarreau | ebec351 | 2016-12-16 12:14:12 +0100 | [diff] [blame] | 182 | /* NOTE: please add regular applet contexts (ie: not |
| 183 | * CLI-specific ones) above, before "cli". |
| 184 | */ |
| 185 | } ctx; /* context-specific variables used by any applet */ |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | #endif /* _TYPES_APPLET_H */ |
| 189 | |
| 190 | /* |
| 191 | * Local variables: |
| 192 | * c-indent-level: 8 |
| 193 | * c-basic-offset: 8 |
| 194 | * End: |
| 195 | */ |