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 | 48adac5 | 2008-08-30 04:58:38 +0200 | [diff] [blame] | 28 | #include <types/buffers.h> |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 29 | #include <common/config.h> |
| 30 | |
| 31 | /* A stream interface must have its own errors independantly of the buffer's, |
| 32 | * 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] | 33 | * interface is performing some retries (eg: connection error). Some states are |
| 34 | * transient and do not last beyond process_session(). |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 35 | */ |
| 36 | enum { |
Willy Tarreau | efb453c | 2008-10-26 20:49:47 +0100 | [diff] [blame] | 37 | SI_ST_INI = 0, /* interface not sollicitated yet */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 38 | SI_ST_REQ, /* [transient] connection initiation desired and not started yet */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 39 | SI_ST_QUE, /* interface waiting in queue */ |
| 40 | SI_ST_TAR, /* interface in turn-around state after failed connect attempt */ |
| 41 | SI_ST_ASS, /* server just assigned to this interface */ |
| 42 | SI_ST_CON, /* initiated connection request (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 43 | SI_ST_CER, /* [transient] previous connection attempt failed (resource released) */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 44 | SI_ST_EST, /* connection established (resource exists) */ |
Willy Tarreau | 74ab2ac | 2008-11-23 17:23:07 +0100 | [diff] [blame] | 45 | 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] | 46 | SI_ST_CLO, /* stream intf closed, might not existing anymore. Buffers shut. */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /* error types reported on the streams interface for more accurate reporting */ |
| 50 | enum { |
Willy Tarreau | e5ed406 | 2008-08-30 03:17:31 +0200 | [diff] [blame] | 51 | SI_ET_NONE = 0x0000, /* no error yet, leave it to zero */ |
| 52 | SI_ET_QUEUE_TO = 0x0001, /* queue timeout */ |
| 53 | SI_ET_QUEUE_ERR = 0x0002, /* queue error (eg: full) */ |
| 54 | SI_ET_QUEUE_ABRT = 0x0004, /* aborted in queue by external cause */ |
| 55 | SI_ET_CONN_TO = 0x0008, /* connection timeout */ |
| 56 | SI_ET_CONN_ERR = 0x0010, /* connection error (eg: no server available) */ |
| 57 | SI_ET_CONN_ABRT = 0x0020, /* connection aborted by external cause (eg: abort) */ |
| 58 | SI_ET_CONN_OTHER = 0x0040, /* connection aborted for other reason (eg: 500) */ |
| 59 | SI_ET_DATA_TO = 0x0080, /* timeout during data phase */ |
| 60 | SI_ET_DATA_ERR = 0x0100, /* error during data phase */ |
| 61 | SI_ET_DATA_ABRT = 0x0200, /* data phase aborted by external cause */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 64 | /* flags set after I/O */ |
| 65 | enum { |
| 66 | SI_FL_NONE = 0x0000, /* nothing */ |
| 67 | SI_FL_EXP = 0x0001, /* timeout has expired */ |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 68 | SI_FL_ERR = 0x0002, /* a non-recoverable error has occurred */ |
Willy Tarreau | b0ef735 | 2008-12-14 13:26:20 +0100 | [diff] [blame] | 69 | SI_FL_WAIT_ROOM = 0x0004, /* waiting for space to store incoming data */ |
| 70 | SI_FL_WAIT_DATA = 0x0008, /* waiting for more data to send */ |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 71 | SI_FL_CAP_SPLTCP = 0x0010, /* splicing possible from/to TCP */ |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 72 | SI_FL_DONT_WAKE = 0x0020, /* resync in progress, don't wake up */ |
Willy Tarreau | f27b5ea | 2009-10-03 22:01:18 +0200 | [diff] [blame] | 73 | SI_FL_INDEP_STR = 0x0040, /* independant streams = don't update rex on write */ |
Willy Tarreau | 4c283dc | 2009-12-29 14:36:34 +0100 | [diff] [blame] | 74 | SI_FL_NOLINGER = 0x0080, /* may close without lingering. One-shot. */ |
Willy Tarreau | d7704b5 | 2008-09-04 11:51:16 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 77 | /* target types */ |
| 78 | enum { |
| 79 | TARG_TYPE_NONE = 0, /* no target set, pointer is NULL by definition */ |
| 80 | TARG_TYPE_PROXY, /* target is a proxy ; use address with the proxy's settings */ |
| 81 | TARG_TYPE_SERVER, /* target is a server ; use address with server's and its proxy's settings */ |
| 82 | TARG_TYPE_APPLET, /* target is an applet ; use only the applet */ |
Willy Tarreau | 7c0a151 | 2011-03-10 11:17:02 +0100 | [diff] [blame] | 83 | TARG_TYPE_TASK, /* target is a task running an external applet */ |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 86 | #define SI_FL_CAP_SPLICE (SI_FL_CAP_SPLTCP) |
| 87 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 88 | struct server; |
| 89 | struct proxy; |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 90 | struct si_applet; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 91 | |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 92 | struct target { |
| 93 | int type; |
| 94 | union { |
| 95 | void *v; /* pointer value, for any type */ |
| 96 | struct proxy *p; /* when type is TARG_TYPE_PROXY */ |
| 97 | struct server *s; /* when type is TARG_TYPE_SERVER */ |
| 98 | struct si_applet *a; /* when type is TARG_TYPE_APPLET */ |
Willy Tarreau | 7c0a151 | 2011-03-10 11:17:02 +0100 | [diff] [blame] | 99 | struct task *t; /* when type is TARG_TYPE_TASK */ |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 100 | } ptr; |
| 101 | }; |
| 102 | |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 103 | /* A stream interface has 3 parts : |
| 104 | * - the buffer side, which interfaces to the buffers. |
| 105 | * - the remote side, which describes the state and address of the other side. |
| 106 | * - the functions, which are used by the buffer side to communicate with the |
| 107 | * remote side from the buffer side. |
| 108 | */ |
| 109 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 110 | /* Note that if an applet is registered, the update function will not be called |
| 111 | * by the session handler, so it may be used to resync flags at the end of the |
| 112 | * applet handler. See stream_int_update_embedded() for reference. |
Willy Tarreau | fb90d94 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 113 | */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 114 | struct stream_interface { |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 115 | /* struct members used by the "buffer" side */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 116 | unsigned int state; /* SI_ST* */ |
Willy Tarreau | e5ed406 | 2008-08-30 03:17:31 +0200 | [diff] [blame] | 117 | unsigned int prev_state;/* SI_ST*, copy of previous state */ |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 118 | unsigned int flags; /* SI_FL_* */ |
| 119 | struct buffer *ib, *ob; /* input and output buffers */ |
Willy Tarreau | 3537467 | 2008-09-03 18:11:02 +0200 | [diff] [blame] | 120 | unsigned int exp; /* wake up time for connect, queue, turn-around, ... */ |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 121 | void *owner; /* generally a (struct task*) */ |
| 122 | unsigned int err_type; /* first error detected, one of SI_ET_* */ |
| 123 | void *err_loc; /* commonly the server, NULL when SI_ET_NONE */ |
| 124 | |
| 125 | /* these struct members are used by the buffer side to act on the remote side */ |
Willy Tarreau | b029f8c | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 126 | void (*update)(struct stream_interface *); /* I/O update function */ |
Willy Tarreau | 0a5d5dd | 2008-11-23 19:31:35 +0100 | [diff] [blame] | 127 | void (*shutr)(struct stream_interface *); /* shutr function */ |
| 128 | void (*shutw)(struct stream_interface *); /* shutw function */ |
Willy Tarreau | 3ffeba1 | 2008-12-14 14:42:35 +0100 | [diff] [blame] | 129 | void (*chk_rcv)(struct stream_interface *);/* chk_rcv function */ |
| 130 | void (*chk_snd)(struct stream_interface *);/* chk_snd function */ |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 131 | int (*connect)(struct stream_interface *); /* connect function if any */ |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 132 | void (*release)(struct stream_interface *); /* handler to call after the last close() */ |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 133 | |
| 134 | /* struct members below are the "remote" part, as seen from the buffer side */ |
Willy Tarreau | ac82540 | 2011-03-04 22:04:29 +0100 | [diff] [blame] | 135 | struct target target; /* the target to connect to (server, proxy, applet, ...) */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 136 | int conn_retries; /* number of connect retries left */ |
Willy Tarreau | be5ea19 | 2011-03-03 17:08:11 +0100 | [diff] [blame] | 137 | int fd; /* file descriptor for a stream driver when known */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 138 | struct { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 139 | int state; /* applet state, initialized to zero */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 140 | void *private; /* may be used by any function above */ |
| 141 | unsigned int st0, st1; /* may be used by any function above */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 142 | union { |
| 143 | struct { |
| 144 | struct proxy *px; |
| 145 | struct server *sv; |
| 146 | struct listener *l; |
| 147 | int px_st; /* STAT_PX_ST* */ |
| 148 | unsigned int flags; /* STAT_* */ |
| 149 | int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */ |
| 150 | const char *st_code; /* pointer to the status code returned by an action */ |
| 151 | } stats; |
| 152 | struct { |
| 153 | struct bref bref; /* back-reference from the session being dumped */ |
| 154 | void *target; /* session we want to dump, or NULL for all */ |
| 155 | unsigned int uid; /* if non-null, the uniq_id of the session being dumped */ |
| 156 | int section; /* section of the session being dumped */ |
| 157 | int pos; /* last position of the current session's buffer */ |
| 158 | } sess; |
| 159 | struct { |
| 160 | int iid; /* if >= 0, ID of the proxy to filter on */ |
| 161 | struct proxy *px; /* current proxy being dumped, NULL = not started yet. */ |
| 162 | unsigned int buf; /* buffer being dumped, 0 = req, 1 = rep */ |
| 163 | unsigned int sid; /* session ID of error being dumped */ |
| 164 | int ptr; /* <0: headers, >=0 : text pointer to restart from */ |
| 165 | int bol; /* pointer to beginning of current line */ |
| 166 | } errors; |
| 167 | struct { |
| 168 | void *target; /* table we want to dump, or NULL for all */ |
| 169 | struct proxy *proxy; /* table being currently dumped (first if NULL) */ |
| 170 | struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ |
| 171 | long long value; /* value to compare against */ |
| 172 | signed char data_type; /* type of data to compare, or -1 if none */ |
| 173 | signed char data_op; /* operator (STD_OP_*) when data_type set */ |
| 174 | } table; |
| 175 | struct { |
| 176 | const char *msg; /* pointer to a persistent message to be returned in PRINT state */ |
| 177 | } cli; |
| 178 | } ctx; /* used by stats I/O handlers to dump the stats */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 179 | } applet; |
Willy Tarreau | 957c0a5 | 2011-03-03 17:42:23 +0100 | [diff] [blame] | 180 | union { |
| 181 | struct { |
| 182 | struct sockaddr_storage from; /* the client address */ |
| 183 | struct sockaddr_storage to; /* the address reached by the client if SN_FRT_ADDR_SET is set */ |
| 184 | } c; /* client side */ |
| 185 | struct { |
| 186 | struct sockaddr_in from; /* the address to spoof when connecting to the server (transparent mode) */ |
| 187 | struct sockaddr_in to; /* the address to connect to */ |
| 188 | } s; /* server side */ |
| 189 | } addr; /* addresses of the remote side */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 190 | }; |
| 191 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 192 | /* An applet designed to run in a stream interface */ |
| 193 | struct si_applet { |
| 194 | char *name; /* applet's name to report in logs */ |
| 195 | void (*fct)(struct stream_interface *); /* internal I/O handler, may never be NULL */ |
| 196 | }; |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 197 | |
| 198 | #endif /* _TYPES_STREAM_INTERFACE_H */ |
| 199 | |
| 200 | /* |
| 201 | * Local variables: |
| 202 | * c-indent-level: 8 |
| 203 | * c-basic-offset: 8 |
| 204 | * End: |
| 205 | */ |