haproxy/include/types/applet.h

195 lines
8.4 KiB
C
Raw Normal View History

/*
* include/types/applet.h
* This file describes the applet struct and associated constants.
*
* Copyright (C) 2000-2015 Willy Tarreau - w@1wt.eu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _TYPES_APPLET_H
#define _TYPES_APPLET_H
#include <types/freq_ctr.h>
#include <types/hlua.h>
#include <types/obj_type.h>
#include <types/proxy.h>
#include <types/stream.h>
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled When an entity tries to get a buffer, if it cannot be allocted, for example because the number of buffers which may be allocated per process is limited, this entity is added in a list (called <buffer_wq>) and wait for an available buffer. Historically, the <buffer_wq> list was logically attached to streams because it were the only entities likely to be added in it. Now, applets can also be waiting for a free buffer. And with filters, we could imagine to have more other entities waiting for a buffer. So it make sense to have a generic list. Anyway, with the current design there is a bug. When an applet failed to get a buffer, it will wait. But we add the stream attached to the applet in <buffer_wq>, instead of the applet itself. So when a buffer is available, we wake up the stream and not the waiting applet. So, it is possible to have waiting applets and never awakened. So, now, <buffer_wq> is independant from streams. And we really add the waiting entity in <buffer_wq>. To be generic, the entity is responsible to define the callback used to awaken it. In addition, applets will still request an input buffer when they become active. But they will not be sleeped anymore if no buffer are available. So this is the responsibility to the applet I/O handler to check if this buffer is allocated or not. This way, an applet can decide if this buffer is required or not and can do additional processing if not. [wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
#include <common/buffer.h>
#include <common/chunk.h>
#include <common/config.h>
#include <common/xref.h>
struct appctx;
/* Applet descriptor */
struct applet {
enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */
/* 3 unused bytes here */
char *name; /* applet's name to report in logs */
int (*init)(struct appctx *, struct proxy *px, struct stream *strm); /* callback to init ressources, may be NULL.
expect 1 if ok, 0 if an error occurs, -1 if miss data. */
void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */
void (*release)(struct appctx *); /* callback to release resources, may be NULL */
unsigned int timeout; /* execution timeout. */
};
#define APPLET_WANT_DIE 0x01 /* applet was running and requested to die */
#define APPCTX_CLI_ST1_PROMPT (1 << 0)
#define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
#define APPCTX_CLI_ST1_NOLF (1 << 2)
/* Context of a running applet. */
struct appctx {
enum obj_type obj_type; /* OBJ_TYPE_APPCTX */
/* 3 unused bytes here */
unsigned short state; /* Internal appctx state */
unsigned int st0; /* CLI state for stats, session state for peers */
unsigned int st1; /* prompt/payload (bitwise OR of APPCTX_CLI_ST1_*) for stats, session error for peers */
struct buffer *chunk; /* used to store unfinished commands */
unsigned int st2; /* output state for stats, unused by peers */
struct applet *applet; /* applet this context refers to */
void *owner; /* pointer to upper layer's entity (eg: stream interface) */
struct act_rule *rule; /* rule associated with the applet. */
int (*io_handler)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK */
void (*io_release)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK,
if the command is terminated or the session released */
int cli_severity_output; /* used within the cli_io_handler to format severity output of informational feedback */
int cli_level; /* the level of CLI which can be lowered dynamically */
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled When an entity tries to get a buffer, if it cannot be allocted, for example because the number of buffers which may be allocated per process is limited, this entity is added in a list (called <buffer_wq>) and wait for an available buffer. Historically, the <buffer_wq> list was logically attached to streams because it were the only entities likely to be added in it. Now, applets can also be waiting for a free buffer. And with filters, we could imagine to have more other entities waiting for a buffer. So it make sense to have a generic list. Anyway, with the current design there is a bug. When an applet failed to get a buffer, it will wait. But we add the stream attached to the applet in <buffer_wq>, instead of the applet itself. So when a buffer is available, we wake up the stream and not the waiting applet. So, it is possible to have waiting applets and never awakened. So, now, <buffer_wq> is independant from streams. And we really add the waiting entity in <buffer_wq>. To be generic, the entity is responsible to define the callback used to awaken it. In addition, applets will still request an input buffer when they become active. But they will not be sleeped anymore if no buffer are available. So this is the responsibility to the applet I/O handler to check if this buffer is allocated or not. This way, an applet can decide if this buffer is required or not and can do additional processing if not. [wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
unsigned long thread_mask; /* mask of thread IDs authorized to process the applet */
struct task *t; /* task associated to the applet */
struct freq_ctr call_rate; /* appctx call rate */
union {
struct {
void *ptr; /* current peer or NULL, do not use for something else */
} peers; /* used by the peers applet */
struct {
int connected;
struct xref xref; /* cross reference with the Lua object owner. */
struct list wake_on_read;
struct list wake_on_write;
int die;
} hlua_cosocket; /* used by the Lua cosockets */
struct {
struct hlua *hlua;
int flags;
struct task *task;
} hlua_apptcp; /* used by the Lua TCP services */
struct {
struct hlua *hlua;
int left_bytes; /* The max amount of bytes that we can read. */
int flags;
int status;
const char *reason;
struct task *task;
} hlua_apphttp; /* used by the Lua HTTP services */
struct {
void *ptr; /* private pointer for SPOE filter */
} spoe; /* used by SPOE filter */
struct {
const char *msg; /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
int severity; /* severity of the message to be returned according to (syslog) rfc5424 */
char *err; /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
struct list l0; /* General purpose list element, pointers, offsets and integers for... */
void *p0, *p1; /* ...registered commands, initialized to 0 by the CLI before first... */
size_t o0, o1; /* ...invocation of the keyword parser, except for the list element which... */
int i0, i1; /* ...is initialized with LIST_INIT(). */
} cli; /* context used by the CLI */
struct {
struct cache_entry *entry; /* Entry to be sent from cache. */
unsigned int sent; /* The number of bytes already sent for this cache entry. */
unsigned int offset; /* start offset of remaining data relative to beginning of the next block */
unsigned int rem_data; /* Remaing bytes for the last data block (HTX only, 0 means process next block) */
struct shared_block *next; /* The next block of data to be sent for this cache entry. */
} cache;
/* all entries below are used by various CLI commands, please
* keep the grouped together and avoid adding new ones.
*/
struct {
struct proxy *px;
struct server *sv;
void *l;
int scope_str; /* limit scope to a frontend/backend substring */
int scope_len; /* length of the string above in the buffer */
int px_st; /* STAT_PX_ST* */
unsigned int flags; /* STAT_* */
int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */
int st_code; /* the status code returned by an action */
} stats;
struct {
struct bref bref; /* back-reference from the session being dumped */
void *target; /* session we want to dump, or NULL for all */
unsigned int uid; /* if non-null, the uniq_id of the session being dumped */
int section; /* section of the session being dumped */
int pos; /* last position of the current session's buffer */
} sess;
struct {
int iid; /* if >= 0, ID of the proxy to filter on */
struct proxy *px; /* current proxy being dumped, NULL = not started yet. */
unsigned int flag; /* bit0: buffer being dumped, 0 = req, 1 = resp ; bit1=skip req ; bit2=skip resp. */
unsigned int ev_id; /* event ID of error being dumped */
int ptr; /* <0: headers, >=0 : text pointer to restart from */
int bol; /* pointer to beginning of current line */
} errors;
struct {
void *target; /* table we want to dump, or NULL for all */
MEDIUM: stick-table: Stop handling stick-tables as proxies. This patch adds the support for the "table" line parsing in "peers" sections to declare stick-table in such sections. This also prevents the user from having to declare dummy backends sections with a unique stick-table inside. Even if still supported, this usage will become deprecated. To do so, the ->table member of proxy struct which is a stktable struct is replaced by a pointer to a stktable struct allocated at parsing time in src/cfgparse-listen.c for the dummy stick-table backends and in src/cfgparse.c for "peers" sections. This has an impact on the code for stick-table sample converters and on the stickiness rules parsers which first store the name of the dummy before resolving the rules. This patch replaces proxy_tbl_by_name() calls by stktable_find_by_name() calls to lookup for stick-tables stored in "stktable_by_name" ebtree at parsing time. There is only one remaining place where proxy_tbl_by_name() is used: src/hlua.c. At several places in the code we relied on the fact that ->size member of stick-table was equal to zero to consider the stick-table was present by not configured, this do not make sense anymore as ->table member of struct proxyis fow now on a pointer. These tests are replaced by a test on ->table value itself. In "peers" section we do not have to temporary store the name of the section the stick-table are attached to because this name is obviously already known just after having entered this "peers" section. About the CLI stick-table I/O handler, the pointer to proxy struct is replaced by a pointer to a stktable struct.
2019-03-14 02:07:41 -04:00
struct stktable *t; /* table being currently dumped (first if NULL) */
struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */
long long value; /* value to compare against */
signed char data_type; /* type of data to compare, or -1 if none */
signed char data_op; /* operator (STD_OP_*) when data_type set */
char action; /* action on the table : one of STK_CLI_ACT_* */
} table;
struct {
unsigned int display_flags;
struct pat_ref *ref;
struct bref bref; /* back-reference from the pat_ref_elt being dumped */
struct pattern_expr *expr;
struct buffer chunk;
} map;
struct {
struct hlua *hlua;
struct task *task;
struct hlua_function *fcn;
} hlua_cli;
struct {
void *target;
struct peers *peers; /* "peers" section being currently dumped. */
struct peer *peer; /* "peer" being currently dumped. */
} cfgpeers;
struct {
char *path;
MINOR: ssl/cli: rework 'set ssl cert' as 'set/commit' This patch splits the 'set ssl cert' CLI command into 2 commands. The previous way of updating the certificate on the CLI was limited with the bundles. It was only able to apply one of the tree part of the certificate during an update, which mean that we needed 3 updates to update a full 3 certs bundle. It was also not possible to apply atomically several part of a certificate with the ability to rollback on error. (For example applying a .pem, then a .ocsp, then a .sctl) The command 'set ssl cert' will now duplicate the certificate (or bundle) and update it in a temporary transaction.. The second command 'commit ssl cert' will commit all the changes made during the transaction for the certificate. This commit breaks the ability to update a certificate which was used as a unique file and as a bundle in the HAProxy configuration. This way of using the certificates wasn't making any sense. Example: // For a bundle: $ echo -e "set ssl cert localhost.pem.rsa <<\n$(cat kikyo.pem.rsa)\n" | socat /tmp/sock1 - Transaction created for certificate localhost.pem! $ echo -e "set ssl cert localhost.pem.dsa <<\n$(cat kikyo.pem.dsa)\n" | socat /tmp/sock1 - Transaction updated for certificate localhost.pem! $ echo -e "set ssl cert localhost.pem.ecdsa <<\n$(cat kikyo.pem.ecdsa)\n" | socat /tmp/sock1 - Transaction updated for certificate localhost.pem! $ echo "commit ssl cert localhost.pem" | socat /tmp/sock1 - Committing localhost.pem. Success!
2019-10-29 18:48:19 -04:00
struct ckch_store *old_ckchs;
struct ckch_store *new_ckchs;
struct ckch_inst *next_ckchi;
} ssl;
/* NOTE: please add regular applet contexts (ie: not
* CLI-specific ones) above, before "cli".
*/
} ctx; /* context-specific variables used by any applet */
};
#endif /* _TYPES_APPLET_H */
/*
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* End:
*/