Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/buffers.h |
| 3 | Buffer management definitions, macros and inline functions. |
| 4 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5 | Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 0a5d5dd | 2008-11-23 19:31:35 +0100 | [diff] [blame] | 6 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | */ |
| 21 | |
| 22 | #ifndef _TYPES_BUFFERS_H |
| 23 | #define _TYPES_BUFFERS_H |
| 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/memory.h> |
Willy Tarreau | 0a5d5dd | 2008-11-23 19:31:35 +0100 | [diff] [blame] | 27 | #include <types/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 28 | |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 29 | /* The BF_* macros designate Buffer Flags, which may be ORed in the bit field |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 30 | * member 'flags' in struct buffer. Here we have several types of flags : |
| 31 | * |
| 32 | * - pure status flags, reported by the lower layer, which must be cleared |
| 33 | * before doing further I/O : |
| 34 | * BF_*_NULL, BF_*_PARTIAL |
| 35 | * |
| 36 | * - pure status flags, reported by mid-layer, which must also be cleared |
| 37 | * before doing further I/O : |
| 38 | * BF_*_TIMEOUT, BF_*_ERROR |
| 39 | * |
| 40 | * - read-only indicators reported by lower levels : |
| 41 | * BF_STREAMER, BF_STREAMER_FAST |
| 42 | * |
| 43 | * - write-once status flags reported by the mid-level : BF_SHUTR, BF_SHUTW |
| 44 | * |
| 45 | * - persistent control flags managed only by higher level : |
| 46 | * BF_SHUT*_NOW, BF_*_ENA, BF_HIJACK |
| 47 | * |
| 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 |
| 50 | * the second one). |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 51 | */ |
Willy Tarreau | e393fe2 | 2008-08-16 22:18:07 +0200 | [diff] [blame] | 52 | |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 53 | #define BF_READ_NULL 0x000001 /* last read detected on producer side */ |
| 54 | #define BF_READ_PARTIAL 0x000002 /* some data were read from producer */ |
| 55 | #define BF_READ_TIMEOUT 0x000004 /* timeout while waiting for producer */ |
| 56 | #define BF_READ_ERROR 0x000008 /* unrecoverable error on producer side */ |
| 57 | #define BF_READ_ACTIVITY (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR) |
Willy Tarreau | 0f9f505 | 2006-07-29 17:39:25 +0200 | [diff] [blame] | 58 | |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 59 | #define BF_FULL 0x000010 /* buffer cannot accept any more data (l >= rlim-data) */ |
| 60 | #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_READ_ENA 0x000080 /* producer is allowed to feed data into the buffer */ |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 63 | |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 64 | #define BF_WRITE_NULL 0x000100 /* write(0) or connect() succeeded on consumer side */ |
| 65 | #define BF_WRITE_PARTIAL 0x000200 /* some data were written to the consumer */ |
| 66 | #define BF_WRITE_TIMEOUT 0x000400 /* timeout while waiting for consumer */ |
| 67 | #define BF_WRITE_ERROR 0x000800 /* unrecoverable error on consumer side */ |
| 68 | #define BF_WRITE_ACTIVITY (BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR) |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 69 | |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 70 | #define BF_EMPTY 0x001000 /* buffer is empty */ |
| 71 | #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 */ |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 74 | |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 75 | #define BF_STREAMER 0x010000 /* the producer is identified as streaming data */ |
| 76 | #define BF_STREAMER_FAST 0x020000 /* the consumer seems to eat the stream very fast */ |
Willy Tarreau | 0f9f505 | 2006-07-29 17:39:25 +0200 | [diff] [blame] | 77 | |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 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 |
| 81 | * buffer. |
| 82 | */ |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 83 | #define BF_HIJACK 0x040000 /* the producer is temporarily replaced by ->hijacker */ |
Willy Tarreau | 9a2d154 | 2008-08-30 12:31:07 +0200 | [diff] [blame] | 84 | #define BF_ANA_TIMEOUT 0x080000 /* the analyser timeout has expired */ |
| 85 | #define BF_READ_ATTACHED 0x100000 /* the read side is attached for the first time */ |
| 86 | |
| 87 | /* Use these masks to clear the flags before going back to lower layers */ |
| 88 | #define BF_CLEAR_READ (~(BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_ATTACHED)) |
| 89 | #define BF_CLEAR_WRITE (~(BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR)) |
| 90 | #define BF_CLEAR_TIMEOUT (~(BF_READ_TIMEOUT|BF_WRITE_TIMEOUT|BF_ANA_TIMEOUT)) |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 91 | |
Willy Tarreau | fe3718a | 2008-11-30 18:14:12 +0100 | [diff] [blame] | 92 | /* Masks which define input events for stream analysers */ |
Willy Tarreau | 4ffd51a | 2008-08-30 13:36:43 +0200 | [diff] [blame] | 93 | #define BF_MASK_ANALYSER (BF_READ_ATTACHED|BF_READ_ACTIVITY|BF_READ_TIMEOUT|BF_ANA_TIMEOUT|BF_WRITE_ACTIVITY) |
Willy Tarreau | fe3718a | 2008-11-30 18:14:12 +0100 | [diff] [blame] | 94 | |
| 95 | /* Mask for static flags which are not events, but might change during processing */ |
| 96 | #define BF_MASK_STATIC (BF_EMPTY|BF_FULL|BF_HIJACK|BF_WRITE_ENA|BF_READ_ENA|BF_SHUTR|BF_SHUTW|BF_SHUTR_NOW|BF_SHUTW_NOW) |
Willy Tarreau | 3da77c5 | 2008-08-29 09:58:42 +0200 | [diff] [blame] | 97 | |
Willy Tarreau | 2df28e8 | 2008-08-17 15:20:19 +0200 | [diff] [blame] | 98 | |
| 99 | /* Analysers (buffer->analysers). |
| 100 | * Those bits indicate that there are some processing to do on the buffer |
Willy Tarreau | 70cb633 | 2008-12-07 11:28:08 +0100 | [diff] [blame] | 101 | * contents. It will probably evolve into a linked list later. Those |
Willy Tarreau | 2df28e8 | 2008-08-17 15:20:19 +0200 | [diff] [blame] | 102 | * analysers could be compared to higher level processors. |
| 103 | * The field is blanked by buffer_init() and only by analysers themselves |
| 104 | * afterwards. |
| 105 | */ |
| 106 | #define AN_REQ_INSPECT 0x00000001 /* inspect request contents */ |
| 107 | #define AN_REQ_HTTP_HDR 0x00000002 /* inspect HTTP request headers */ |
| 108 | #define AN_REQ_HTTP_BODY 0x00000004 /* inspect HTTP request body */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 109 | #define AN_REQ_HTTP_TARPIT 0x00000008 /* wait for end of HTTP tarpit */ |
| 110 | #define AN_RTR_HTTP_HDR 0x00000010 /* inspect HTTP response headers */ |
Willy Tarreau | 70cb633 | 2008-12-07 11:28:08 +0100 | [diff] [blame] | 111 | #define AN_REQ_UNIX_STATS 0x00000020 /* process unix stats socket request */ |
Willy Tarreau | 2df28e8 | 2008-08-17 15:20:19 +0200 | [diff] [blame] | 112 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 113 | /* describes a chunk of string */ |
| 114 | struct chunk { |
| 115 | char *str; /* beginning of the string itself. Might not be 0-terminated */ |
| 116 | int len; /* size of the string from first to last char. <0 = uninit. */ |
| 117 | }; |
| 118 | |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 119 | /* needed for a declaration below */ |
| 120 | struct session; |
| 121 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 122 | struct buffer { |
Willy Tarreau | aad2e49 | 2006-10-15 23:32:18 +0200 | [diff] [blame] | 123 | unsigned int flags; /* BF_* */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 124 | int rex; /* expiration date for a read, in ticks */ |
Willy Tarreau | 26ed74d | 2008-08-17 12:11:14 +0200 | [diff] [blame] | 125 | int wex; /* expiration date for a write or connect, in ticks */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 126 | int rto; /* read timeout, in ticks */ |
| 127 | int wto; /* write timeout, in ticks */ |
| 128 | int cto; /* connect timeout, in ticks */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 129 | unsigned int l; /* data length */ |
Willy Tarreau | e09e0ce | 2007-03-18 16:31:29 +0100 | [diff] [blame] | 130 | char *r, *w, *lr; /* read ptr, write ptr, last read */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 131 | char *rlim; /* read limit, used for header rewriting */ |
Willy Tarreau | 2df28e8 | 2008-08-17 15:20:19 +0200 | [diff] [blame] | 132 | unsigned int analysers; /* bit field indicating what to do on the buffer */ |
Willy Tarreau | ffab5b4 | 2008-08-17 18:03:28 +0200 | [diff] [blame] | 133 | int analyse_exp; /* expiration date for current analysers (if set) */ |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 134 | void (*hijacker)(struct session *, struct buffer *); /* alternative content producer */ |
Willy Tarreau | 8a7af60 | 2008-05-03 23:07:14 +0200 | [diff] [blame] | 135 | unsigned char xfer_large; /* number of consecutive large xfers */ |
| 136 | unsigned char xfer_small; /* number of consecutive small xfers */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 137 | unsigned long long total; /* total data read */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 138 | struct stream_interface *prod; /* producer attached to this buffer */ |
| 139 | struct stream_interface *cons; /* consumer attached to this buffer */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 140 | char data[BUFSIZE]; |
| 141 | }; |
| 142 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 143 | |
| 144 | #endif /* _TYPES_BUFFERS_H */ |
| 145 | |
| 146 | /* |
| 147 | * Local variables: |
| 148 | * c-indent-level: 8 |
| 149 | * c-basic-offset: 8 |
| 150 | * End: |
| 151 | */ |