Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 2 | * include/types/stream_interface.h |
| 3 | * This file describes the stream_interface struct and associated constants. |
| 4 | * |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 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 | */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _TYPES_STREAM_INTERFACE_H |
| 23 | #define _TYPES_STREAM_INTERFACE_H |
| 24 | |
| 25 | #include <stdlib.h> |
Emeric Brun | 129c590 | 2010-01-04 14:47:58 +0100 | [diff] [blame] | 26 | #include <sys/socket.h> |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 27 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 28 | #include <types/channel.h> |
Willy Tarreau | 56e9c5e | 2012-07-06 09:47:57 +0200 | [diff] [blame] | 29 | #include <types/connection.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 30 | #include <types/obj_type.h> |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 31 | #include <common/config.h> |
| 32 | |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 33 | /* A stream interface must have its own errors independently of the buffer's, |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 34 | * so that applications can rely on what the buffer reports while the stream |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 35 | * interface is performing some retries (eg: connection error). Some states are |
| 36 | * transient and do not last beyond process_session(). |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 37 | */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 38 | enum si_state { |
Willy Tarreau | efb453c | 2008-10-26 20:49:47 +0100 | [diff] [blame] | 39 | SI_ST_INI = 0, /* interface not sollicitated yet */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 40 | SI_ST_REQ, /* [transient] connection initiation desired and not started yet */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 41 | SI_ST_QUE, /* interface waiting in queue */ |
| 42 | SI_ST_TAR, /* interface in turn-around state after failed connect attempt */ |
| 43 | SI_ST_ASS, /* server just assigned to this interface */ |
| 44 | SI_ST_CON, /* initiated connection request (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 45 | SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 46 | SI_ST_EST, /* connection established (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 47 | SI_ST_DIS, /* [transient] disconnected from other side, but cleanup not done yet */ |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 48 | SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 49 | } __attribute__((packed)); |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 50 | |
| 51 | /* error types reported on the streams interface for more accurate reporting */ |
| 52 | enum { |
Willy Tarreau | e5ed406 | 2008-08-30 03:17:31 +0200 | [diff] [blame] | 53 | SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */ |
| 54 | SI_ET_QUEUE_TO = 0x0001, /* queue timeout */ |
| 55 | SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */ |
| 56 | SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */ |
| 57 | SI_ET_CONN_TO = 0x0008, /* connection timeout */ |
| 58 | SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */ |
| 59 | SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */ |
Willy Tarreau | 2d400bb | 2012-05-14 12:11:47 +0200 | [diff] [blame] | 60 | SI_ET_CONN_RES = 0x0040, /* connection aborted due to lack of resources */ |
| 61 | SI_ET_CONN_OTHER = 0x0080, /* connection aborted for other reason (eg: 500) */ |
| 62 | SI_ET_DATA_TO = 0x0100, /* timeout during data phase */ |
| 63 | SI_ET_DATA_ERR = 0x0200, /* error during data phase */ |
| 64 | SI_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 67 | /* flags set after I/O (16 bit) */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 68 | enum { |
| 69 | SI_FL_NONE = 0x0000, /* nothing */ |
| 70 | SI_FL_EXP = 0x0001, /* timeout has expired */ |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 71 | SI_FL_ERR = 0x0002, /* a non-recoverable error has occurred */ |
Willy Tarreau | b0ef735 | 2008-12-14 13:26:20 +0100 | [diff] [blame] | 72 | SI_FL_WAIT_ROOM = 0x0004, /* waiting for space to store incoming data */ |
| 73 | SI_FL_WAIT_DATA = 0x0008, /* waiting for more data to send */ |
Willy Tarreau | 93b0f4f | 2012-08-30 21:23:53 +0200 | [diff] [blame] | 74 | /* unused 0x0010 */ |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 75 | SI_FL_DONT_WAKE = 0x0020, /* resync in progress, don't wake up */ |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 76 | SI_FL_INDEP_STR = 0x0040, /* independent streams = don't update rex on write */ |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 77 | SI_FL_NOLINGER = 0x0080, /* may close without lingering. One-shot. */ |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 78 | SI_FL_NOHALF = 0x0100, /* no half close, close both sides at once */ |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 79 | SI_FL_SRC_ADDR = 0x1000, /* get the source ip/port with getsockname */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 82 | struct stream_interface; |
Willy Tarreau | 48099c7 | 2013-10-24 20:03:27 +0200 | [diff] [blame] | 83 | struct si_applet; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 84 | |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 85 | /* operations available on a stream-interface */ |
| 86 | struct si_ops { |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 87 | void (*update)(struct stream_interface *); /* I/O update function */ |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 88 | void (*chk_rcv)(struct stream_interface *); /* chk_rcv function */ |
| 89 | void (*chk_snd)(struct stream_interface *); /* chk_snd function */ |
Willy Tarreau | 6fe1541 | 2013-09-29 15:16:03 +0200 | [diff] [blame] | 90 | void (*shutr)(struct stream_interface *); /* shut read function */ |
| 91 | void (*shutw)(struct stream_interface *); /* shut write function */ |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Willy Tarreau | 452d3bb | 2013-11-24 02:28:49 +0100 | [diff] [blame] | 94 | /* Context of a running applet. */ |
| 95 | struct appctx { |
Willy Tarreau | 0788f47 | 2013-10-24 22:45:25 +0200 | [diff] [blame] | 96 | enum obj_type obj_type; /* OBJ_TYPE_APPCTX */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 97 | /* 3 unused bytes here */ |
Willy Tarreau | 452d3bb | 2013-11-24 02:28:49 +0100 | [diff] [blame] | 98 | unsigned int st0; /* CLI state for stats, session state for peers */ |
| 99 | unsigned int st1; /* prompt for stats, session error for peers */ |
| 100 | unsigned int st2; /* output state for stats, unused by peers */ |
Willy Tarreau | 48099c7 | 2013-10-24 20:03:27 +0200 | [diff] [blame] | 101 | struct si_applet *applet; /* applet this context refers to */ |
Willy Tarreau | 452d3bb | 2013-11-24 02:28:49 +0100 | [diff] [blame] | 102 | |
| 103 | union { |
| 104 | struct { |
| 105 | struct proxy *px; |
| 106 | struct server *sv; |
| 107 | void *l; |
| 108 | int scope_str; /* limit scope to a frontend/backend substring */ |
| 109 | int scope_len; /* length of the string above in the buffer */ |
| 110 | int px_st; /* STAT_PX_ST* */ |
| 111 | unsigned int flags; /* STAT_* */ |
| 112 | int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */ |
| 113 | int st_code; /* the status code returned by an action */ |
| 114 | } stats; |
| 115 | struct { |
| 116 | struct bref bref; /* back-reference from the session being dumped */ |
| 117 | void *target; /* session we want to dump, or NULL for all */ |
| 118 | unsigned int uid; /* if non-null, the uniq_id of the session being dumped */ |
| 119 | int section; /* section of the session being dumped */ |
| 120 | int pos; /* last position of the current session's buffer */ |
| 121 | } sess; |
| 122 | struct { |
| 123 | int iid; /* if >= 0, ID of the proxy to filter on */ |
| 124 | struct proxy *px; /* current proxy being dumped, NULL = not started yet. */ |
| 125 | unsigned int buf; /* buffer being dumped, 0 = req, 1 = rep */ |
| 126 | unsigned int sid; /* session ID of error being dumped */ |
| 127 | int ptr; /* <0: headers, >=0 : text pointer to restart from */ |
| 128 | int bol; /* pointer to beginning of current line */ |
| 129 | } errors; |
| 130 | struct { |
| 131 | void *target; /* table we want to dump, or NULL for all */ |
| 132 | struct proxy *proxy; /* table being currently dumped (first if NULL) */ |
| 133 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 134 | long long value; /* value to compare against */ |
| 135 | signed char data_type; /* type of data to compare, or -1 if none */ |
| 136 | signed char data_op; /* operator (STD_OP_*) when data_type set */ |
| 137 | } table; |
| 138 | struct { |
| 139 | const char *msg; /* pointer to a persistent message to be returned in PRINT state */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 140 | char *err; /* pointer to a 'must free' message to be returned in PRINT_FREE state */ |
Willy Tarreau | 452d3bb | 2013-11-24 02:28:49 +0100 | [diff] [blame] | 141 | } cli; |
| 142 | struct { |
| 143 | void *ptr; /* multi-purpose pointer for peers */ |
| 144 | } peers; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 145 | struct { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 146 | unsigned int display_flags; |
| 147 | struct pat_ref *ref; |
| 148 | struct pat_ref_elt *elt; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 149 | struct map_descriptor *desc; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 150 | struct pattern_expr *expr; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 151 | struct chunk chunk; |
| 152 | } map; |
Willy Tarreau | 452d3bb | 2013-11-24 02:28:49 +0100 | [diff] [blame] | 153 | } ctx; /* used by stats I/O handlers to dump the stats */ |
| 154 | }; |
| 155 | |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 156 | /* A stream interface has 3 parts : |
| 157 | * - the buffer side, which interfaces to the buffers. |
| 158 | * - the remote side, which describes the state and address of the other side. |
| 159 | * - the functions, which are used by the buffer side to communicate with the |
| 160 | * remote side from the buffer side. |
| 161 | */ |
| 162 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 163 | /* Note that if an applet is registered, the update function will not be called |
| 164 | * by the session handler, so it may be used to resync flags at the end of the |
| 165 | * applet handler. See stream_int_update_embedded() for reference. |
Willy Tarreau | fb90d94 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 166 | */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 167 | struct stream_interface { |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 168 | /* struct members used by the "buffer" side */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 169 | enum si_state state; /* SI_ST* */ |
| 170 | enum si_state prev_state;/* SI_ST*, copy of previous state */ |
| 171 | unsigned short flags; /* SI_FL_* */ |
Willy Tarreau | 3537467 | 2008-09-03 18:11:02 +0200 | [diff] [blame] | 172 | unsigned int exp; /* wake up time for connect, queue, turn-around, ... */ |
Willy Tarreau | b8020ce | 2013-10-24 21:10:08 +0200 | [diff] [blame] | 173 | struct channel *ib, *ob; /* input and output buffers */ |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 174 | void *owner; /* generally a (struct task*) */ |
Willy Tarreau | 7d67d7b | 2013-09-29 16:05:22 +0200 | [diff] [blame] | 175 | enum obj_type *end; /* points to the end point (connection or appctx) */ |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 176 | struct si_ops *ops; /* general operations at the stream interface layer */ |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 177 | |
| 178 | /* struct members below are the "remote" part, as seen from the buffer side */ |
Willy Tarreau | b8020ce | 2013-10-24 21:10:08 +0200 | [diff] [blame] | 179 | unsigned int err_type; /* first error detected, one of SI_ET_* */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 180 | int conn_retries; /* number of connect retries left */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 181 | }; |
| 182 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 183 | /* An applet designed to run in a stream interface */ |
| 184 | struct si_applet { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 185 | enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 186 | /* 3 unused bytes here */ |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 187 | char *name; /* applet's name to report in logs */ |
| 188 | void (*fct)(struct stream_interface *); /* internal I/O handler, may never be NULL */ |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 189 | void (*release)(struct stream_interface *); /* callback to release resources, may be NULL */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 190 | }; |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 191 | |
| 192 | #endif /* _TYPES_STREAM_INTERFACE_H */ |
| 193 | |
| 194 | /* |
| 195 | * Local variables: |
| 196 | * c-indent-level: 8 |
| 197 | * c-basic-offset: 8 |
| 198 | * End: |
| 199 | */ |