2
include/types/buffers.h
3
Buffer management definitions, macros and inline functions.
5
Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
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
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.
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
2
* include/types/buffers.h
3
* Buffer management definitions, macros and inline functions.
5
* Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
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
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.
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
22
22
#ifndef _TYPES_BUFFERS_H
23
23
#define _TYPES_BUFFERS_H
46
46
* BF_SHUT*_NOW, BF_*_ENA, BF_HIJACK
48
48
* The flags have been arranged for readability, so that the read and write
49
* bits have se same position in a byte (read being the lower byte and write
49
* bits have the same position in a byte (read being the lower byte and write
50
* the second one). All flag names are relative to the buffer. For instance,
51
* 'write' indicates the direction from the buffer to the stream interface.
53
54
#define BF_READ_NULL 0x000001 /* last read detected on producer side */
56
57
#define BF_READ_ERROR 0x000008 /* unrecoverable error on producer side */
57
58
#define BF_READ_ACTIVITY (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR)
59
#define BF_FULL 0x000010 /* buffer cannot accept any more data (l >= max_len) */
60
#define BF_FULL 0x000010 /* buffer cannot accept any more data (l >= max len) */
60
61
#define BF_SHUTR 0x000020 /* producer has already shut down */
61
#define BF_SHUTR_NOW 0x000040 /* the producer must shut down for reads immediately */
62
#define BF_SHUTR_NOW 0x000040 /* the producer must shut down for reads ASAP */
62
63
#define BF_READ_NOEXP 0x000080 /* producer should not expire */
64
65
#define BF_WRITE_NULL 0x000100 /* write(0) or connect() succeeded on consumer side */
67
68
#define BF_WRITE_ERROR 0x000800 /* unrecoverable error on consumer side */
68
69
#define BF_WRITE_ACTIVITY (BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR)
70
#define BF_EMPTY 0x001000 /* buffer is empty */
71
#define BF_OUT_EMPTY 0x001000 /* send_max and pipe are empty. Set by last change. */
71
72
#define BF_SHUTW 0x002000 /* consumer has already shut down */
72
#define BF_SHUTW_NOW 0x004000 /* the consumer must shut down for writes immediately */
73
#define BF_WRITE_ENA 0x008000 /* consumer is allowed to forward all buffer contents */
73
#define BF_SHUTW_NOW 0x004000 /* the consumer must shut down for writes ASAP */
74
#define BF_AUTO_CLOSE 0x008000 /* producer can forward shutdown to other side */
76
/* When either BF_SHUTR_NOW or BF_HIJACK is set, it is strictly forbidden for
77
* the producer to alter the buffer contents. When BF_SHUTW_NOW is set, the
78
* consumer is free to perform a shutw() when it has consumed the last contents,
79
* otherwise the session processor will do it anyway.
81
* The SHUT* flags work like this :
83
* SHUTR SHUTR_NOW meaning
84
* 0 0 normal case, connection still open and data is being read
85
* 0 1 closing : the producer cannot feed data anymore but can close
86
* 1 0 closed: the producer has closed its input channel.
89
* SHUTW SHUTW_NOW meaning
90
* 0 0 normal case, connection still open and data is being written
91
* 0 1 closing: the consumer can send last data and may then close
92
* 1 0 closed: the consumer has closed its output channel.
95
* The SHUTW_NOW flag should be set by the session processor when SHUTR and AUTO_CLOSE
96
* are both set. It may also be set by a hijacker at the end of data. And it may also
97
* be set by the producer when it detects SHUTR while directly forwarding data to the
100
* The SHUTR_NOW flag is mostly used to force the producer to abort when an error is
101
* detected on the consumer side.
75
104
#define BF_STREAMER 0x010000 /* the producer is identified as streaming data */
76
105
#define BF_STREAMER_FAST 0x020000 /* the consumer seems to eat the stream very fast */
78
/* When either BF_SHUTR_NOW or BF_HIJACK is set, it is strictly forbidden for
79
* the stream interface to alter the buffer contents. When BF_SHUTW_NOW is set,
80
* it is strictly forbidden for the stream interface to send anything from the
83
107
#define BF_HIJACK 0x040000 /* the producer is temporarily replaced by ->hijacker */
84
108
#define BF_ANA_TIMEOUT 0x080000 /* the analyser timeout has expired */
85
109
#define BF_READ_ATTACHED 0x100000 /* the read side is attached for the first time */
86
110
#define BF_KERN_SPLICING 0x200000 /* kernel splicing desired for this buffer */
87
111
#define BF_READ_DONTWAIT 0x400000 /* wake the task up after every read (eg: HTTP request) */
112
#define BF_AUTO_CONNECT 0x800000 /* consumer may attempt to establish a new connection */
114
#define BF_DONT_READ 0x1000000 /* disable reading for now */
115
#define BF_EXPECT_MORE 0x2000000 /* more data expected to be sent very soon (one-shoot) */
116
#define BF_SEND_DONTWAIT 0x4000000 /* don't wait for sending data (one-shoot) */
89
118
/* Use these masks to clear the flags before going back to lower layers */
90
119
#define BF_CLEAR_READ (~(BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_ATTACHED))
108
137
#define AN_REQ_INSPECT 0x00000001 /* inspect request contents */
109
#define AN_REQ_HTTP_HDR 0x00000002 /* inspect HTTP request headers */
110
#define AN_REQ_HTTP_BODY 0x00000004 /* inspect HTTP request body */
111
#define AN_REQ_HTTP_TARPIT 0x00000008 /* wait for end of HTTP tarpit */
112
#define AN_RTR_HTTP_HDR 0x00000010 /* inspect HTTP response headers */
113
#define AN_REQ_UNIX_STATS 0x00000020 /* process unix stats socket request */
138
#define AN_REQ_WAIT_HTTP 0x00000002 /* wait for an HTTP request */
139
#define AN_REQ_HTTP_PROCESS_FE 0x00000004 /* process the frontend's HTTP part */
140
#define AN_REQ_SWITCHING_RULES 0x00000008 /* apply the switching rules */
141
#define AN_REQ_HTTP_PROCESS_BE 0x00000010 /* process the backend's HTTP part */
142
#define AN_REQ_HTTP_INNER 0x00000020 /* inner processing of HTTP request */
143
#define AN_REQ_HTTP_TARPIT 0x00000040 /* wait for end of HTTP tarpit */
144
#define AN_REQ_HTTP_BODY 0x00000080 /* inspect HTTP request body */
145
#define AN_REQ_STICKING_RULES 0x00000100 /* table persistence matching */
147
#define AN_REQ_PRST_RDP_COOKIE 0x00000400 /* persistence on rdp cookie */
148
#define AN_REQ_HTTP_XFER_BODY 0x00000800 /* forward request body */
150
/* response analysers */
151
#define AN_RES_INSPECT 0x00010000 /* content inspection */
152
#define AN_RES_WAIT_HTTP 0x00020000 /* wait for HTTP response */
153
#define AN_RES_HTTP_PROCESS_BE 0x00040000 /* process backend's HTTP part */
154
#define AN_RES_HTTP_PROCESS_FE 0x00040000 /* process frontend's HTTP part (same for now) */
155
#define AN_RES_STORE_RULES 0x00080000 /* table persistence matching */
156
#define AN_RES_HTTP_XFER_BODY 0x00100000 /* forward response body */
159
/* Magic value to forward infinite size (TCP, ...), used with ->to_forward */
160
#define BUF_INFINITE_FORWARD (~0UL)
115
162
/* describes a chunk of string */
117
164
char *str; /* beginning of the string itself. Might not be 0-terminated */
118
int len; /* size of the string from first to last char. <0 = uninit. */
165
size_t size; /* total size of the buffer, 0 if the *str is read-only */
166
int len; /* current size of the string from first to last char. <0 = uninit. */
121
169
/* needed for a declaration below */
130
178
int cto; /* connect timeout, in ticks */
131
179
unsigned int l; /* data length */
132
180
char *r, *w, *lr; /* read ptr, write ptr, last read */
133
unsigned int max_len; /* read limit, used to keep room for header rewriting */
181
unsigned int size; /* buffer size in bytes */
134
182
unsigned int send_max; /* number of bytes the sender can consume om this buffer, <= l */
135
unsigned int to_forward; /* number of bytes to forward after send_max without a wake-up */
183
unsigned long to_forward; /* number of bytes to forward after send_max without a wake-up */
136
184
unsigned int analysers; /* bit field indicating what to do on the buffer */
137
185
int analyse_exp; /* expiration date for current analysers (if set) */
138
186
void (*hijacker)(struct session *, struct buffer *); /* alternative content producer */
174
222
The producer is responsible for decreasing ->to_forward and increasing
175
223
->send_max. The ->to_forward parameter indicates how many bytes may be fed
176
into either data buffer without waking the parent up. The ->send_max
224
into either data buffer without waking the parent up. The special value
225
BUF_INFINITE_FORWARD is never decreased nor increased. The ->send_max
177
226
parameter says how many bytes may be read from the visible buffer. Thus it
178
227
may never exceed ->l. This parameter is updated by any buffer_write() as
179
228
well as any data forwarded through the visible buffer.
194
243
whole buffer, and reduce ->to_forward to 8000. After that, the producer may
195
244
try to feed the additional data through the invisible buffer using a
196
245
platform-specific method such as splice().
247
The ->to_forward entry is also used to detect whether we can fill the buffer
248
or not. The idea is that we need to save some space for data manipulation
249
(mainly header rewriting in HTTP) so we don't want to have a full buffer on
250
input before processing a request or response. Thus, we ensure that there is
251
always global.maxrewrite bytes of free space. Since we don't want to forward
252
chunks without filling the buffer, we rely on ->to_forward. When ->to_forward
253
is null, we may have some processing to do so we don't want to fill the
254
buffer. When ->to_forward is non-null, we know we don't care for at least as
255
many bytes. In the end, we know that each of the ->to_forward bytes will
256
eventually leave the buffer. So as long as ->to_forward is larger than
257
global.maxrewrite, we can fill the buffer. If ->to_forward is smaller than
258
global.maxrewrite, then we don't want to fill the buffer with more than
259
->size - global.maxrewrite + ->to_forward.
261
Note that this also means that anyone touching ->to_forward must also take
262
care of updating the BF_FULL flag. For this reason, it's really advised to
263
use buffer_forward() only.
199
266
#endif /* _TYPES_BUFFERS_H */