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 | a2df3fa | 2014-11-28 11:53:35 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2014 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 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 25 | #include <types/obj_type.h> |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 26 | #include <common/config.h> |
| 27 | |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 28 | /* 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] | 29 | * 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] | 30 | * interface is performing some retries (eg: connection error). Some states are |
| 31 | * transient and do not last beyond process_session(). |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 32 | */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 33 | enum si_state { |
Willy Tarreau | efb453c | 2008-10-26 20:49:47 +0100 | [diff] [blame] | 34 | SI_ST_INI = 0, /* interface not sollicitated yet */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 35 | SI_ST_REQ, /* [transient] connection initiation desired and not started yet */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 36 | 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 Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 40 | SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */ |
Willy Tarreau | 4f283fa | 2019-06-05 14:34:03 +0200 | [diff] [blame] | 41 | SI_ST_RDY, /* [transient] ready proven after I/O success during SI_ST_CON */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 42 | SI_ST_EST, /* connection established (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 43 | 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] | 44 | SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */ |
Willy Tarreau | 721854f | 2013-12-06 23:31:58 +0100 | [diff] [blame] | 45 | } __attribute__((packed)); |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 46 | |
Willy Tarreau | bedcd69 | 2019-06-05 14:45:06 +0200 | [diff] [blame] | 47 | /* state bits for use with lists of states */ |
| 48 | enum si_state_bit { |
| 49 | SI_SB_NONE = 0, |
| 50 | SI_SB_INI = 1U << SI_ST_INI, |
| 51 | SI_SB_REQ = 1U << SI_ST_REQ, |
| 52 | SI_SB_QUE = 1U << SI_ST_QUE, |
| 53 | SI_SB_TAR = 1U << SI_ST_TAR, |
| 54 | SI_SB_ASS = 1U << SI_ST_ASS, |
| 55 | SI_SB_CON = 1U << SI_ST_CON, |
| 56 | SI_SB_CER = 1U << SI_ST_CER, |
Willy Tarreau | 4f283fa | 2019-06-05 14:34:03 +0200 | [diff] [blame] | 57 | SI_SB_RDY = 1U << SI_ST_RDY, |
Willy Tarreau | bedcd69 | 2019-06-05 14:45:06 +0200 | [diff] [blame] | 58 | SI_SB_EST = 1U << SI_ST_EST, |
| 59 | SI_SB_DIS = 1U << SI_ST_DIS, |
| 60 | SI_SB_CLO = 1U << SI_ST_CLO, |
Willy Tarreau | 4f283fa | 2019-06-05 14:34:03 +0200 | [diff] [blame] | 61 | SI_SB_ALL = SI_SB_INI|SI_SB_REQ|SI_SB_QUE|SI_SB_TAR|SI_SB_ASS|SI_SB_CON|SI_SB_CER|SI_SB_RDY|SI_SB_EST|SI_SB_DIS|SI_SB_CLO, |
Willy Tarreau | bedcd69 | 2019-06-05 14:45:06 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 64 | /* error types reported on the streams interface for more accurate reporting */ |
| 65 | enum { |
Willy Tarreau | e5ed406 | 2008-08-30 03:17:31 +0200 | [diff] [blame] | 66 | SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */ |
| 67 | SI_ET_QUEUE_TO = 0x0001, /* queue timeout */ |
| 68 | SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */ |
| 69 | SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */ |
| 70 | SI_ET_CONN_TO = 0x0008, /* connection timeout */ |
| 71 | SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */ |
| 72 | SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */ |
Willy Tarreau | 2d400bb | 2012-05-14 12:11:47 +0200 | [diff] [blame] | 73 | SI_ET_CONN_RES = 0x0040, /* connection aborted due to lack of resources */ |
| 74 | SI_ET_CONN_OTHER = 0x0080, /* connection aborted for other reason (eg: 500) */ |
| 75 | SI_ET_DATA_TO = 0x0100, /* timeout during data phase */ |
| 76 | SI_ET_DATA_ERR = 0x0200, /* error during data phase */ |
| 77 | SI_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
Willy Tarreau | a44e576 | 2018-11-14 10:53:42 +0100 | [diff] [blame] | 80 | /* flags set after I/O (32 bit) */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 81 | enum { |
Willy Tarreau | a44e576 | 2018-11-14 10:53:42 +0100 | [diff] [blame] | 82 | SI_FL_NONE = 0x00000000, /* nothing */ |
| 83 | SI_FL_EXP = 0x00000001, /* timeout has expired */ |
| 84 | SI_FL_ERR = 0x00000002, /* a non-recoverable error has occurred */ |
Willy Tarreau | 0f9cd7b | 2019-01-31 19:02:43 +0100 | [diff] [blame] | 85 | SI_FL_KILL_CONN = 0x00000004, /* next shutw must kill the whole conn, not just the stream */ |
Willy Tarreau | a44e576 | 2018-11-14 10:53:42 +0100 | [diff] [blame] | 86 | SI_FL_WAIT_DATA = 0x00000008, /* stream-int waits for more outgoing data to send */ |
| 87 | SI_FL_ISBACK = 0x00000010, /* 0 for front-side SI, 1 for back-side */ |
| 88 | SI_FL_DONT_WAKE = 0x00000020, /* resync in progress, don't wake up */ |
| 89 | SI_FL_INDEP_STR = 0x00000040, /* independent streams = don't update rex on write */ |
| 90 | SI_FL_NOLINGER = 0x00000080, /* may close without lingering. One-shot. */ |
| 91 | SI_FL_NOHALF = 0x00000100, /* no half close, close both sides at once */ |
| 92 | SI_FL_SRC_ADDR = 0x00001000, /* get the source ip/port with getsockname */ |
Christopher Faulet | 87a8f35 | 2019-03-22 14:51:36 +0100 | [diff] [blame] | 93 | /* unused: 0x00000200 */ |
Willy Tarreau | a44e576 | 2018-11-14 10:53:42 +0100 | [diff] [blame] | 94 | SI_FL_WANT_GET = 0x00004000, /* a stream-int would like to get some data from the buffer */ |
| 95 | SI_FL_CLEAN_ABRT = 0x00008000, /* SI_FL_ERR is used to report aborts, and not SHUTR */ |
Willy Tarreau | 94f7907 | 2018-11-14 11:24:08 +0100 | [diff] [blame] | 96 | |
| 97 | SI_FL_RXBLK_CHAN = 0x00010000, /* the channel doesn't want the stream-int to introduce data */ |
| 98 | SI_FL_RXBLK_BUFF = 0x00020000, /* stream-int waits for a buffer allocation to complete */ |
| 99 | SI_FL_RXBLK_ROOM = 0x00040000, /* stream-int waits for more buffer room to store incoming data */ |
| 100 | SI_FL_RXBLK_SHUT = 0x00080000, /* input is now closed, nothing new will ever come */ |
Willy Tarreau | a3b62d3 | 2018-12-06 15:24:01 +0100 | [diff] [blame] | 101 | SI_FL_RXBLK_CONN = 0x00100000, /* other side is not connected */ |
| 102 | SI_FL_RXBLK_ANY = 0x001F0000, /* any of the RXBLK flags above */ |
| 103 | SI_FL_RX_WAIT_EP = 0x00200000, /* stream-int waits for more data from the end point */ |
Olivier Houchard | a254a37 | 2019-04-05 15:30:12 +0200 | [diff] [blame] | 104 | SI_FL_L7_RETRY = 0x01000000, /* The stream interface may attempt L7 retries */ |
Olivier Houchard | 602bf7d | 2019-05-10 13:59:15 +0200 | [diff] [blame] | 105 | SI_FL_D_L7_RETRY = 0x02000000, /* Disable L7 retries on this stream interface, even if configured to do it */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Willy Tarreau | d414f8e | 2015-04-06 11:43:45 +0200 | [diff] [blame] | 108 | /* A stream interface has 3 parts : |
| 109 | * - the buffer side, which interfaces to the buffers. |
| 110 | * - the remote side, which describes the state and address of the other side. |
| 111 | * - the functions, which are used by the buffer side to communicate with the |
| 112 | * remote side from the buffer side. |
| 113 | */ |
| 114 | |
| 115 | /* Note that if an applet is registered, the update function will not be called |
| 116 | * by the session handler, so it may be used to resync flags at the end of the |
Willy Tarreau | 14bfe9a | 2018-12-19 15:19:27 +0100 | [diff] [blame] | 117 | * applet handler. See si_update() for reference. |
Willy Tarreau | d414f8e | 2015-04-06 11:43:45 +0200 | [diff] [blame] | 118 | */ |
| 119 | struct stream_interface { |
| 120 | /* struct members used by the "buffer" side */ |
| 121 | enum si_state state; /* SI_ST* */ |
| 122 | enum si_state prev_state;/* SI_ST*, copy of previous state */ |
Willy Tarreau | a44e576 | 2018-11-14 10:53:42 +0100 | [diff] [blame] | 123 | /* 16-bit hole here */ |
| 124 | unsigned int flags; /* SI_FL_* */ |
Willy Tarreau | d414f8e | 2015-04-06 11:43:45 +0200 | [diff] [blame] | 125 | enum obj_type *end; /* points to the end point (connection or appctx) */ |
| 126 | struct si_ops *ops; /* general operations at the stream interface layer */ |
Willy Tarreau | a44e576 | 2018-11-14 10:53:42 +0100 | [diff] [blame] | 127 | unsigned int exp; /* wake up time for connect, queue, turn-around, ... */ |
Willy Tarreau | d414f8e | 2015-04-06 11:43:45 +0200 | [diff] [blame] | 128 | |
| 129 | /* struct members below are the "remote" part, as seen from the buffer side */ |
| 130 | unsigned int err_type; /* first error detected, one of SI_ET_* */ |
| 131 | int conn_retries; /* number of connect retries left */ |
Hongbo Long | e39683c | 2017-03-10 18:41:51 +0100 | [diff] [blame] | 132 | unsigned int hcto; /* half-closed timeout (0 = unset) */ |
Olivier Houchard | fa8aa86 | 2018-10-10 18:25:41 +0200 | [diff] [blame] | 133 | struct wait_event wait_event; /* We're in a wait list */ |
Olivier Houchard | a254a37 | 2019-04-05 15:30:12 +0200 | [diff] [blame] | 134 | struct buffer l7_buffer; /* To store the data, in case we have to retry */ |
Willy Tarreau | d414f8e | 2015-04-06 11:43:45 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 137 | /* operations available on a stream-interface */ |
| 138 | struct si_ops { |
Willy Tarreau | 57f08bb | 2018-11-07 11:28:12 +0100 | [diff] [blame] | 139 | void (*chk_rcv)(struct stream_interface *); /* chk_rcv function, may not be null */ |
| 140 | void (*chk_snd)(struct stream_interface *); /* chk_snd function, may not be null */ |
| 141 | void (*shutr)(struct stream_interface *); /* shut read function, may not be null */ |
| 142 | void (*shutw)(struct stream_interface *); /* shut write function, may not be null */ |
Willy Tarreau | 060781f | 2012-05-07 16:50:03 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 145 | #endif /* _TYPES_STREAM_INTERFACE_H */ |
| 146 | |
| 147 | /* |
| 148 | * Local variables: |
| 149 | * c-indent-level: 8 |
| 150 | * c-basic-offset: 8 |
| 151 | * End: |
| 152 | */ |