blob: eab1fba1d6f47a871b956043eb9432a3cf01ca9c [file] [log] [blame]
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001/*
Willy Tarreau4c283dc2009-12-29 14:36:34 +01002 * include/types/stream_interface.h
3 * This file describes the stream_interface struct and associated constants.
4 *
Willy Tarreaua2df3fa2014-11-28 11:53:35 +01005 * Copyright (C) 2000-2014 Willy Tarreau - w@1wt.eu
Willy Tarreau4c283dc2009-12-29 14:36:34 +01006 *
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 Tarreaufa7e1022008-10-19 07:30:41 +020021
22#ifndef _TYPES_STREAM_INTERFACE_H
23#define _TYPES_STREAM_INTERFACE_H
24
Willy Tarreau3fdb3662012-11-12 00:42:33 +010025#include <types/obj_type.h>
Willy Tarreaufa7e1022008-10-19 07:30:41 +020026#include <common/config.h>
27
Jamie Gloudon801a0a32012-08-25 00:18:33 -040028/* A stream interface must have its own errors independently of the buffer's,
Willy Tarreaufa7e1022008-10-19 07:30:41 +020029 * so that applications can rely on what the buffer reports while the stream
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010030 * interface is performing some retries (eg: connection error). Some states are
31 * transient and do not last beyond process_session().
Willy Tarreaufa7e1022008-10-19 07:30:41 +020032 */
Willy Tarreau721854f2013-12-06 23:31:58 +010033enum si_state {
Willy Tarreauefb453c2008-10-26 20:49:47 +010034 SI_ST_INI = 0, /* interface not sollicitated yet */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010035 SI_ST_REQ, /* [transient] connection initiation desired and not started yet */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020036 SI_ST_QUE, /* interface waiting in queue */
37 SI_ST_TAR, /* interface in turn-around state after failed connect attempt */
38 SI_ST_ASS, /* server just assigned to this interface */
39 SI_ST_CON, /* initiated connection request (resource exists) */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010040 SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020041 SI_ST_EST, /* connection established (resource exists) */
Willy Tarreau74ab2ac2008-11-23 17:23:07 +010042 SI_ST_DIS, /* [transient] disconnected from other side, but cleanup not done yet */
Willy Tarreaucff64112008-11-03 06:26:53 +010043 SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */
Willy Tarreau721854f2013-12-06 23:31:58 +010044} __attribute__((packed));
Willy Tarreaufa7e1022008-10-19 07:30:41 +020045
46/* error types reported on the streams interface for more accurate reporting */
47enum {
Willy Tarreaue5ed4062008-08-30 03:17:31 +020048 SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */
49 SI_ET_QUEUE_TO = 0x0001, /* queue timeout */
50 SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */
51 SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */
52 SI_ET_CONN_TO = 0x0008, /* connection timeout */
53 SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */
54 SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */
Willy Tarreau2d400bb2012-05-14 12:11:47 +020055 SI_ET_CONN_RES = 0x0040, /* connection aborted due to lack of resources */
56 SI_ET_CONN_OTHER = 0x0080, /* connection aborted for other reason (eg: 500) */
57 SI_ET_DATA_TO = 0x0100, /* timeout during data phase */
58 SI_ET_DATA_ERR = 0x0200, /* error during data phase */
59 SI_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020060};
61
Willy Tarreaua44e5762018-11-14 10:53:42 +010062/* flags set after I/O (32 bit) */
Willy Tarreaud7704b52008-09-04 11:51:16 +020063enum {
Willy Tarreaua44e5762018-11-14 10:53:42 +010064 SI_FL_NONE = 0x00000000, /* nothing */
65 SI_FL_EXP = 0x00000001, /* timeout has expired */
66 SI_FL_ERR = 0x00000002, /* a non-recoverable error has occurred */
Willy Tarreau94f79072018-11-14 11:24:08 +010067 /* unused: 0x00000004 */
Willy Tarreaua44e5762018-11-14 10:53:42 +010068 SI_FL_WAIT_DATA = 0x00000008, /* stream-int waits for more outgoing data to send */
69 SI_FL_ISBACK = 0x00000010, /* 0 for front-side SI, 1 for back-side */
70 SI_FL_DONT_WAKE = 0x00000020, /* resync in progress, don't wake up */
71 SI_FL_INDEP_STR = 0x00000040, /* independent streams = don't update rex on write */
72 SI_FL_NOLINGER = 0x00000080, /* may close without lingering. One-shot. */
73 SI_FL_NOHALF = 0x00000100, /* no half close, close both sides at once */
74 SI_FL_SRC_ADDR = 0x00001000, /* get the source ip/port with getsockname */
Willy Tarreau05b9b642018-11-14 13:43:35 +010075 /* unused: 0x00002000 */
Willy Tarreaua44e5762018-11-14 10:53:42 +010076 SI_FL_WANT_GET = 0x00004000, /* a stream-int would like to get some data from the buffer */
77 SI_FL_CLEAN_ABRT = 0x00008000, /* SI_FL_ERR is used to report aborts, and not SHUTR */
Willy Tarreau94f79072018-11-14 11:24:08 +010078
79 SI_FL_RXBLK_CHAN = 0x00010000, /* the channel doesn't want the stream-int to introduce data */
80 SI_FL_RXBLK_BUFF = 0x00020000, /* stream-int waits for a buffer allocation to complete */
81 SI_FL_RXBLK_ROOM = 0x00040000, /* stream-int waits for more buffer room to store incoming data */
82 SI_FL_RXBLK_SHUT = 0x00080000, /* input is now closed, nothing new will ever come */
Willy Tarreaua3b62d32018-12-06 15:24:01 +010083 SI_FL_RXBLK_CONN = 0x00100000, /* other side is not connected */
84 SI_FL_RXBLK_ANY = 0x001F0000, /* any of the RXBLK flags above */
85 SI_FL_RX_WAIT_EP = 0x00200000, /* stream-int waits for more data from the end point */
Willy Tarreaud7704b52008-09-04 11:51:16 +020086};
87
Willy Tarreaud414f8e2015-04-06 11:43:45 +020088/* A stream interface has 3 parts :
89 * - the buffer side, which interfaces to the buffers.
90 * - the remote side, which describes the state and address of the other side.
91 * - the functions, which are used by the buffer side to communicate with the
92 * remote side from the buffer side.
93 */
94
95/* Note that if an applet is registered, the update function will not be called
96 * by the session handler, so it may be used to resync flags at the end of the
Willy Tarreau14bfe9a2018-12-19 15:19:27 +010097 * applet handler. See si_update() for reference.
Willy Tarreaud414f8e2015-04-06 11:43:45 +020098 */
99struct stream_interface {
100 /* struct members used by the "buffer" side */
101 enum si_state state; /* SI_ST* */
102 enum si_state prev_state;/* SI_ST*, copy of previous state */
Willy Tarreaua44e5762018-11-14 10:53:42 +0100103 /* 16-bit hole here */
104 unsigned int flags; /* SI_FL_* */
Willy Tarreaud414f8e2015-04-06 11:43:45 +0200105 enum obj_type *end; /* points to the end point (connection or appctx) */
106 struct si_ops *ops; /* general operations at the stream interface layer */
Willy Tarreaua44e5762018-11-14 10:53:42 +0100107 unsigned int exp; /* wake up time for connect, queue, turn-around, ... */
Willy Tarreaud414f8e2015-04-06 11:43:45 +0200108
109 /* struct members below are the "remote" part, as seen from the buffer side */
110 unsigned int err_type; /* first error detected, one of SI_ET_* */
111 int conn_retries; /* number of connect retries left */
Hongbo Longe39683c2017-03-10 18:41:51 +0100112 unsigned int hcto; /* half-closed timeout (0 = unset) */
Olivier Houchardfa8aa862018-10-10 18:25:41 +0200113 struct wait_event wait_event; /* We're in a wait list */
Willy Tarreaud414f8e2015-04-06 11:43:45 +0200114};
115
Willy Tarreauc5788912012-08-24 18:12:41 +0200116/* operations available on a stream-interface */
117struct si_ops {
Willy Tarreau57f08bb2018-11-07 11:28:12 +0100118 void (*chk_rcv)(struct stream_interface *); /* chk_rcv function, may not be null */
119 void (*chk_snd)(struct stream_interface *); /* chk_snd function, may not be null */
120 void (*shutr)(struct stream_interface *); /* shut read function, may not be null */
121 void (*shutw)(struct stream_interface *); /* shut write function, may not be null */
Willy Tarreau060781f2012-05-07 16:50:03 +0200122};
123
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200124#endif /* _TYPES_STREAM_INTERFACE_H */
125
126/*
127 * Local variables:
128 * c-indent-level: 8
129 * c-basic-offset: 8
130 * End:
131 */