blob: fa3ffa8d06c77cbaaad1be68ed6b3fd669da487d [file] [log] [blame]
Christopher Faulet51dbc942018-09-13 09:05:15 +02001/*
2 * HTT/1 mux-demux for connections
3 *
4 * Copyright 2018 Christopher Faulet <cfaulet@haproxy.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12#include <common/cfgparse.h>
13#include <common/config.h>
Willy Tarreau0108d902018-11-25 19:14:37 +010014#include <common/initcall.h>
Christopher Faulet51dbc942018-09-13 09:05:15 +020015
Christopher Faulet1be55f92018-10-02 15:59:23 +020016#include <types/pipe.h>
Christopher Fauletf2824e62018-10-01 12:12:37 +020017#include <types/proxy.h>
18#include <types/session.h>
19
Christopher Faulet51dbc942018-09-13 09:05:15 +020020#include <proto/connection.h>
Christopher Faulet129817b2018-09-20 16:14:40 +020021#include <proto/h1.h>
Christopher Faulet9768c262018-10-22 09:34:31 +020022#include <proto/http_htx.h>
23#include <proto/htx.h>
Christopher Faulet129817b2018-09-20 16:14:40 +020024#include <proto/log.h>
Christopher Faulet51dbc942018-09-13 09:05:15 +020025#include <proto/stream.h>
26#include <proto/stream_interface.h>
27
28/*
29 * H1 Connection flags (32 bits)
30 */
31#define H1C_F_NONE 0x00000000
32
33/* Flags indicating why writing output data are blocked */
34#define H1C_F_OUT_ALLOC 0x00000001 /* mux is blocked on lack of output buffer */
35#define H1C_F_OUT_FULL 0x00000002 /* mux is blocked on output buffer full */
36/* 0x00000004 - 0x00000008 unused */
37
38/* Flags indicating why reading input data are blocked. */
39#define H1C_F_IN_ALLOC 0x00000010 /* mux is blocked on lack of input buffer */
40#define H1C_F_IN_FULL 0x00000020 /* mux is blocked on input buffer full */
Christopher Fauletcb55f482018-12-10 11:56:47 +010041#define H1C_F_IN_BUSY 0x00000040
Christopher Faulet539e0292018-11-19 10:40:09 +010042/* 0x00000040 - 0x00000800 unused */
Christopher Faulet51dbc942018-09-13 09:05:15 +020043
44#define H1C_F_CS_ERROR 0x00001000 /* connection must be closed ASAP because an error occurred */
45#define H1C_F_CS_SHUTW_NOW 0x00002000 /* connection must be shut down for writes ASAP */
46#define H1C_F_CS_SHUTW 0x00004000 /* connection is already shut down */
Christopher Faulet3b88b8d2018-10-26 17:36:03 +020047#define H1C_F_CS_WAIT_CONN 0x00008000 /* waiting for the connection establishment */
Christopher Faulet51dbc942018-09-13 09:05:15 +020048
Christopher Fauletf2824e62018-10-01 12:12:37 +020049#define H1C_F_WAIT_NEXT_REQ 0x00010000 /* waiting for the next request to start, use keep-alive timeout */
Christopher Faulet129817b2018-09-20 16:14:40 +020050
Christopher Faulet51dbc942018-09-13 09:05:15 +020051/*
52 * H1 Stream flags (32 bits)
53 */
Christopher Faulet129817b2018-09-20 16:14:40 +020054#define H1S_F_NONE 0x00000000
55#define H1S_F_ERROR 0x00000001 /* An error occurred on the H1 stream */
Christopher Fauletf2824e62018-10-01 12:12:37 +020056#define H1S_F_REQ_ERROR 0x00000002 /* An error occurred during the request parsing/xfer */
57#define H1S_F_RES_ERROR 0x00000004 /* An error occurred during the response parsing/xfer */
Christopher Faulet539e0292018-11-19 10:40:09 +010058/* 0x00000008 unused */
Christopher Fauletf2824e62018-10-01 12:12:37 +020059#define H1S_F_WANT_KAL 0x00000010
60#define H1S_F_WANT_TUN 0x00000020
61#define H1S_F_WANT_CLO 0x00000040
62#define H1S_F_WANT_MSK 0x00000070
63#define H1S_F_NOT_FIRST 0x00000080 /* The H1 stream is not the first one */
Christopher Faulet539e0292018-11-19 10:40:09 +010064#define H1S_F_BUF_FLUSH 0x00000100 /* Flush input buffer and don't read more data */
Christopher Fauletd44ad5b2018-11-19 21:52:12 +010065#define H1S_F_SPLICED_DATA 0x00000200 /* Set when the kernel splicing is in used */
Christopher Faulet32188212018-11-20 18:21:43 +010066#define H1S_F_HAVE_EOD 0x00000400 /* Set during input/output process to know the last empty chunk was processed */
67#define H1S_F_HAVE_TLR 0x00000800 /* Set during input/output process to know the trailers were processed */
Christopher Faulet51dbc942018-09-13 09:05:15 +020068
69/* H1 connection descriptor */
Christopher Faulet51dbc942018-09-13 09:05:15 +020070struct h1c {
71 struct connection *conn;
72 struct proxy *px;
73 uint32_t flags; /* Connection flags: H1C_F_* */
74
75 struct buffer ibuf; /* Input buffer to store data before parsing */
76 struct buffer obuf; /* Output buffer to store data after reformatting */
77
78 struct buffer_wait buf_wait; /* Wait list for buffer allocation */
79 struct wait_event wait_event; /* To be used if we're waiting for I/Os */
80
81 struct h1s *h1s; /* H1 stream descriptor */
Christopher Faulet51dbc942018-09-13 09:05:15 +020082};
83
84/* H1 stream descriptor */
85struct h1s {
86 struct h1c *h1c;
87 struct conn_stream *cs;
Christopher Fauletfeb11742018-11-29 15:12:34 +010088 struct cs_info csinfo; /* CS info, only used for client connections */
89 uint32_t flags; /* Connection flags: H1S_F_* */
Christopher Faulet51dbc942018-09-13 09:05:15 +020090
Christopher Faulet51dbc942018-09-13 09:05:15 +020091 struct wait_event *recv_wait; /* Address of the wait_event the conn_stream associated is waiting on */
92 struct wait_event *send_wait; /* Address of the wait_event the conn_stream associated is waiting on */
Christopher Faulet129817b2018-09-20 16:14:40 +020093
94 struct h1m req;
95 struct h1m res;
96
97 enum http_meth_t meth; /* HTTP resquest method */
98 uint16_t status; /* HTTP response status */
Christopher Faulet51dbc942018-09-13 09:05:15 +020099};
100
101/* the h1c and h1s pools */
Willy Tarreau8ceae722018-11-26 11:58:30 +0100102DECLARE_STATIC_POOL(pool_head_h1c, "h1c", sizeof(struct h1c));
103DECLARE_STATIC_POOL(pool_head_h1s, "h1s", sizeof(struct h1s));
Christopher Faulet51dbc942018-09-13 09:05:15 +0200104
Christopher Faulet51dbc942018-09-13 09:05:15 +0200105static int h1_recv(struct h1c *h1c);
106static int h1_send(struct h1c *h1c);
107static int h1_process(struct h1c *h1c);
108static struct task *h1_io_cb(struct task *t, void *ctx, unsigned short state);
109static void h1_shutw_conn(struct connection *conn);
110
111/*****************************************************/
112/* functions below are for dynamic buffer management */
113/*****************************************************/
114/*
115 * Indicates whether or not the we may call the h1_recv() function to
116 * attempt to receive data into the buffer and/or parse pending data. The
117 * condition is a bit complex due to some API limits for now. The rules are the
118 * following :
119 * - if an error or a shutdown was detected on the connection and the buffer
120 * is empty, we must not attempt to receive
121 * - if the input buffer failed to be allocated, we must not try to receive
122 * and we know there is nothing pending
123 * - if no flag indicates a blocking condition, we may attempt to receive,
124 * regardless of whether the input buffer is full or not, so that only de
125 * receiving part decides whether or not to block. This is needed because
126 * the connection API indeed prevents us from re-enabling receipt that is
127 * already enabled in a polled state, so we must always immediately stop as
128 * soon as the mux can't proceed so as never to hit an end of read with data
129 * pending in the buffers.
130 * - otherwise must may not attempt to receive
131 */
132static inline int h1_recv_allowed(const struct h1c *h1c)
133{
134 if (b_data(&h1c->ibuf) == 0 &&
Christopher Faulet7e346f32018-11-20 17:13:52 +0100135 (h1c->flags & (H1C_F_CS_ERROR|H1C_F_CS_SHUTW) ||
Christopher Faulet51dbc942018-09-13 09:05:15 +0200136 h1c->conn->flags & CO_FL_ERROR ||
137 conn_xprt_read0_pending(h1c->conn)))
138 return 0;
139
Christopher Fauletcb55f482018-12-10 11:56:47 +0100140 if (!(h1c->flags & (H1C_F_IN_ALLOC|H1C_F_IN_FULL|H1C_F_IN_BUSY)))
Christopher Faulet51dbc942018-09-13 09:05:15 +0200141 return 1;
142
143 return 0;
144}
145
146/*
147 * Tries to grab a buffer and to re-enables processing on mux <target>. The h1
148 * flags are used to figure what buffer was requested. It returns 1 if the
149 * allocation succeeds, in which case the connection is woken up, or 0 if it's
150 * impossible to wake up and we prefer to be woken up later.
151 */
152static int h1_buf_available(void *target)
153{
154 struct h1c *h1c = target;
155
156 if ((h1c->flags & H1C_F_IN_ALLOC) && b_alloc_margin(&h1c->ibuf, 0)) {
157 h1c->flags &= ~H1C_F_IN_ALLOC;
158 if (h1_recv_allowed(h1c))
159 tasklet_wakeup(h1c->wait_event.task);
160 return 1;
161 }
162
163 if ((h1c->flags & H1C_F_OUT_ALLOC) && b_alloc_margin(&h1c->obuf, 0)) {
164 h1c->flags &= ~H1C_F_OUT_ALLOC;
165 tasklet_wakeup(h1c->wait_event.task);
166 return 1;
167 }
168
Christopher Faulet51dbc942018-09-13 09:05:15 +0200169 return 0;
170}
171
172/*
173 * Allocate a buffer. If if fails, it adds the mux in buffer wait queue.
174 */
175static inline struct buffer *h1_get_buf(struct h1c *h1c, struct buffer *bptr)
176{
177 struct buffer *buf = NULL;
178
179 if (likely(LIST_ISEMPTY(&h1c->buf_wait.list)) &&
180 unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) {
181 h1c->buf_wait.target = h1c;
182 h1c->buf_wait.wakeup_cb = h1_buf_available;
183 HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock);
184 LIST_ADDQ(&buffer_wq, &h1c->buf_wait.list);
185 HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock);
186 __conn_xprt_stop_recv(h1c->conn);
187 }
188 return buf;
189}
190
191/*
192 * Release a buffer, if any, and try to wake up entities waiting in the buffer
193 * wait queue.
194 */
195static inline void h1_release_buf(struct h1c *h1c, struct buffer *bptr)
196{
197 if (bptr->size) {
198 b_free(bptr);
199 offer_buffers(h1c->buf_wait.target, tasks_run_queue);
200 }
201}
202
203static int h1_avail_streams(struct connection *conn)
204{
205 struct h1c *h1c = conn->mux_ctx;
206
207 return h1c->h1s ? 0 : 1;
208}
209
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100210static int h1_max_streams(struct connection *conn)
211{
212 return 1;
213}
Christopher Faulet51dbc942018-09-13 09:05:15 +0200214
215/*****************************************************************/
216/* functions below are dedicated to the mux setup and management */
217/*****************************************************************/
Christopher Faulet47365272018-10-31 17:40:50 +0100218static struct conn_stream *h1s_new_cs(struct h1s *h1s)
219{
220 struct conn_stream *cs;
221
222 cs = cs_new(h1s->h1c->conn);
223 if (!cs)
224 goto err;
225 h1s->cs = cs;
226 cs->ctx = h1s;
227
228 if (h1s->flags & H1S_F_NOT_FIRST)
229 cs->flags |= CS_FL_NOT_FIRST;
230
231 if (stream_create_from_cs(cs) < 0)
232 goto err;
233 return cs;
234
235 err:
236 cs_free(cs);
237 h1s->cs = NULL;
238 return NULL;
239}
240
Christopher Fauletf2824e62018-10-01 12:12:37 +0200241static struct h1s *h1s_create(struct h1c *h1c, struct conn_stream *cs)
Christopher Faulet51dbc942018-09-13 09:05:15 +0200242{
243 struct h1s *h1s;
244
245 h1s = pool_alloc(pool_head_h1s);
246 if (!h1s)
Christopher Faulet47365272018-10-31 17:40:50 +0100247 goto fail;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200248
249 h1s->h1c = h1c;
250 h1c->h1s = h1s;
251
252 h1s->cs = NULL;
Christopher Faulet129817b2018-09-20 16:14:40 +0200253 h1s->flags = H1S_F_NONE;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200254
255 h1s->recv_wait = NULL;
256 h1s->send_wait = NULL;
Christopher Faulet129817b2018-09-20 16:14:40 +0200257
258 h1m_init_req(&h1s->req);
Christopher Faulet9768c262018-10-22 09:34:31 +0200259 h1s->req.flags |= H1_MF_NO_PHDR;
260
Christopher Faulet129817b2018-09-20 16:14:40 +0200261 h1m_init_res(&h1s->res);
Christopher Faulet9768c262018-10-22 09:34:31 +0200262 h1s->res.flags |= H1_MF_NO_PHDR;
Christopher Faulet129817b2018-09-20 16:14:40 +0200263
264 h1s->status = 0;
265 h1s->meth = HTTP_METH_OTHER;
266
Christopher Faulet47365272018-10-31 17:40:50 +0100267 if (h1c->flags & H1C_F_WAIT_NEXT_REQ)
268 h1s->flags |= H1S_F_NOT_FIRST;
269 h1c->flags &= ~H1C_F_WAIT_NEXT_REQ;
270
Christopher Faulet129817b2018-09-20 16:14:40 +0200271 if (!conn_is_back(h1c->conn)) {
272 if (h1c->px->options2 & PR_O2_REQBUG_OK)
273 h1s->req.err_pos = -1;
274 }
275 else {
276 if (h1c->px->options2 & PR_O2_RSPBUG_OK)
277 h1s->res.err_pos = -1;
278 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200279
Christopher Faulet539e0292018-11-19 10:40:09 +0100280 /* If a conn_stream already exists, attach it to this H1S. Otherwise we
281 * create a new one.
282 */
Christopher Fauletf2824e62018-10-01 12:12:37 +0200283 if (cs) {
Christopher Fauletfeb11742018-11-29 15:12:34 +0100284 h1s->csinfo.create_date = date;
285 h1s->csinfo.tv_create = now;
286 h1s->csinfo.t_handshake = 0;
287 h1s->csinfo.t_idle = -1;
288
Christopher Fauletf2824e62018-10-01 12:12:37 +0200289 cs->ctx = h1s;
290 h1s->cs = cs;
291 }
Christopher Faulet47365272018-10-31 17:40:50 +0100292 else {
Christopher Fauletfeb11742018-11-29 15:12:34 +0100293 struct session *sess = h1c->conn->owner;
294
295 h1s->csinfo.create_date = sess->accept_date;
296 h1s->csinfo.tv_create = sess->tv_accept;
297 h1s->csinfo.t_handshake = sess->t_handshake;
298 h1s->csinfo.t_idle = -1;
299
Christopher Faulet47365272018-10-31 17:40:50 +0100300 cs = h1s_new_cs(h1s);
301 if (!cs)
302 goto fail;
303 }
Christopher Faulet51dbc942018-09-13 09:05:15 +0200304 return h1s;
Christopher Faulet47365272018-10-31 17:40:50 +0100305
306 fail:
307 pool_free(pool_head_h1s, h1s);
308 return NULL;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200309}
310
311static void h1s_destroy(struct h1s *h1s)
312{
Christopher Fauletf2824e62018-10-01 12:12:37 +0200313 if (h1s) {
314 struct h1c *h1c = h1s->h1c;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200315
Christopher Fauletf2824e62018-10-01 12:12:37 +0200316 h1c->h1s = NULL;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200317
Christopher Fauletf2824e62018-10-01 12:12:37 +0200318 if (h1s->recv_wait != NULL)
319 h1s->recv_wait->wait_reason &= ~SUB_CAN_RECV;
320 if (h1s->send_wait != NULL)
321 h1s->send_wait->wait_reason &= ~SUB_CAN_SEND;
322
Christopher Fauletcb55f482018-12-10 11:56:47 +0100323 h1c->flags &= ~H1C_F_IN_BUSY;
Christopher Faulet47365272018-10-31 17:40:50 +0100324 h1c->flags |= H1C_F_WAIT_NEXT_REQ;
325 if (h1s->flags & (H1S_F_REQ_ERROR|H1S_F_RES_ERROR))
326 h1c->flags |= H1C_F_CS_ERROR;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200327
Christopher Fauletf2824e62018-10-01 12:12:37 +0200328 cs_free(h1s->cs);
329 pool_free(pool_head_h1s, h1s);
330 }
Christopher Faulet51dbc942018-09-13 09:05:15 +0200331}
332
Christopher Fauletfeb11742018-11-29 15:12:34 +0100333static const struct cs_info *h1_get_cs_info(struct conn_stream *cs)
334{
335 struct h1s *h1s = cs->ctx;
336
337 if (h1s && !conn_is_back(cs->conn))
338 return &h1s->csinfo;
339 return NULL;
340}
341
Christopher Faulet51dbc942018-09-13 09:05:15 +0200342/*
343 * Initialize the mux once it's attached. It is expected that conn->mux_ctx
344 * points to the existing conn_stream (for outgoing connections) or NULL (for
345 * incoming ones). Returns < 0 on error.
346 */
347static int h1_init(struct connection *conn, struct proxy *proxy)
348{
Christopher Faulet51dbc942018-09-13 09:05:15 +0200349 struct h1c *h1c;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200350
351 h1c = pool_alloc(pool_head_h1c);
352 if (!h1c)
353 goto fail_h1c;
354 h1c->conn = conn;
355 h1c->px = proxy;
356
357 h1c->flags = H1C_F_NONE;
358 h1c->ibuf = BUF_NULL;
359 h1c->obuf = BUF_NULL;
360 h1c->h1s = NULL;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200361
Christopher Faulet51dbc942018-09-13 09:05:15 +0200362 LIST_INIT(&h1c->buf_wait.list);
363 h1c->wait_event.task = tasklet_new();
364 if (!h1c->wait_event.task)
365 goto fail;
366 h1c->wait_event.task->process = h1_io_cb;
367 h1c->wait_event.task->context = h1c;
368 h1c->wait_event.wait_reason = 0;
369
Christopher Faulet3b88b8d2018-10-26 17:36:03 +0200370 if (!(conn->flags & CO_FL_CONNECTED))
371 h1c->flags |= H1C_F_CS_WAIT_CONN;
372
Christopher Fauletf2824e62018-10-01 12:12:37 +0200373 /* Always Create a new H1S */
374 if (!h1s_create(h1c, conn->mux_ctx))
375 goto fail;
Christopher Faulet51dbc942018-09-13 09:05:15 +0200376
Christopher Faulet129817b2018-09-20 16:14:40 +0200377 conn->mux_ctx = h1c;
Christopher Faulet129817b2018-09-20 16:14:40 +0200378
Christopher Faulet51dbc942018-09-13 09:05:15 +0200379 /* Try to read, if nothing is available yet we'll just subscribe */
380 if (h1_recv(h1c))
381 h1_process(h1c);
382
383 /* mux->wake will be called soon to complete the operation */
384 return 0;
385
386 fail:
Christopher Faulet47365272018-10-31 17:40:50 +0100387 if (h1c->wait_event.task)
Christopher Faulet51dbc942018-09-13 09:05:15 +0200388 tasklet_free(h1c->wait_event.task);
389 pool_free(pool_head_h1c, h1c);
390 fail_h1c:
391 return -1;
392}
393
394
395/* release function for a connection. This one should be called to free all
396 * resources allocated to the mux.
397 */
398static void h1_release(struct connection *conn)
399{
400 struct h1c *h1c = conn->mux_ctx;
401
402 LIST_DEL(&conn->list);
403
404 if (h1c) {
405 if (!LIST_ISEMPTY(&h1c->buf_wait.list)) {
406 HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock);
407 LIST_DEL(&h1c->buf_wait.list);
408 LIST_INIT(&h1c->buf_wait.list);
409 HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock);
410 }
411
412 h1_release_buf(h1c, &h1c->ibuf);
413 h1_release_buf(h1c, &h1c->obuf);
414
Christopher Faulet51dbc942018-09-13 09:05:15 +0200415 if (h1c->wait_event.task)
416 tasklet_free(h1c->wait_event.task);
417
Christopher Fauletf2824e62018-10-01 12:12:37 +0200418 h1s_destroy(h1c->h1s);
Christopher Faulet51dbc942018-09-13 09:05:15 +0200419 if (h1c->wait_event.wait_reason != 0)
420 conn->xprt->unsubscribe(conn, h1c->wait_event.wait_reason,
421 &h1c->wait_event);
422 pool_free(pool_head_h1c, h1c);
423 }
424
425 conn->mux = NULL;
426 conn->mux_ctx = NULL;
427
428 conn_stop_tracking(conn);
429 conn_full_close(conn);
430 if (conn->destroy_cb)
431 conn->destroy_cb(conn);
432 conn_free(conn);
433}
434
435/******************************************************/
436/* functions below are for the H1 protocol processing */
437/******************************************************/
Christopher Faulet9768c262018-10-22 09:34:31 +0200438/* Parse the request version and set H1_MF_VER_11 on <h1m> if the version is
439 * greater or equal to 1.1
Christopher Fauletf2824e62018-10-01 12:12:37 +0200440 */
Christopher Faulet570d1612018-11-26 11:13:57 +0100441static void h1_parse_req_vsn(struct h1m *h1m, const struct htx_sl *sl)
Christopher Fauletf2824e62018-10-01 12:12:37 +0200442{
Christopher Faulet570d1612018-11-26 11:13:57 +0100443 const char *p = HTX_SL_REQ_VPTR(sl);
Christopher Faulet9768c262018-10-22 09:34:31 +0200444
Christopher Faulet570d1612018-11-26 11:13:57 +0100445 if ((HTX_SL_REQ_VLEN(sl) == 8) &&
Christopher Faulet9768c262018-10-22 09:34:31 +0200446 (*(p + 5) > '1' ||
447 (*(p + 5) == '1' && *(p + 7) >= '1')))
448 h1m->flags |= H1_MF_VER_11;
449}
Christopher Fauletf2824e62018-10-01 12:12:37 +0200450
Christopher Faulet9768c262018-10-22 09:34:31 +0200451/* Parse the response version and set H1_MF_VER_11 on <h1m> if the version is
452 * greater or equal to 1.1
453 */
Christopher Faulet570d1612018-11-26 11:13:57 +0100454static void h1_parse_res_vsn(struct h1m *h1m, const struct htx_sl *sl)
Christopher Faulet9768c262018-10-22 09:34:31 +0200455{
Christopher Faulet570d1612018-11-26 11:13:57 +0100456 const char *p = HTX_SL_RES_VPTR(sl);
Christopher Fauletf2824e62018-10-01 12:12:37 +0200457
Christopher Faulet570d1612018-11-26 11:13:57 +0100458 if ((HTX_SL_RES_VLEN(sl) == 8) &&
Christopher Faulet9768c262018-10-22 09:34:31 +0200459 (*(p + 5) > '1' ||
460 (*(p + 5) == '1' && *(p + 7) >= '1')))
461 h1m->flags |= H1_MF_VER_11;
462}
Christopher Fauletf2824e62018-10-01 12:12:37 +0200463
Christopher Faulet9768c262018-10-22 09:34:31 +0200464/*
465 * Check the validity of the request version. If the version is valid, it
466 * returns 1. Otherwise, it returns 0.
467 */
468static int h1_process_req_vsn(struct h1s *h1s, struct h1m *h1m, union h1_sl sl)
469{
470 struct h1c *h1c = h1s->h1c;
471
472 /* RFC7230#2.6 has enforced the format of the HTTP version string to be
473 * exactly one digit "." one digit. This check may be disabled using
474 * option accept-invalid-http-request.
475 */
476 if (!(h1c->px->options2 & PR_O2_REQBUG_OK)) {
477 if (sl.rq.v.len != 8)
478 return 0;
479
480 if (*(sl.rq.v.ptr + 4) != '/' ||
481 !isdigit((unsigned char)*(sl.rq.v.ptr + 5)) ||
482 *(sl.rq.v.ptr + 6) != '.' ||
483 !isdigit((unsigned char)*(sl.rq.v.ptr + 7)))
484 return 0;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200485 }
Christopher Faulet9768c262018-10-22 09:34:31 +0200486 else if (!sl.rq.v.len) {
487 /* try to convert HTTP/0.9 requests to HTTP/1.0 */
Christopher Fauletf2824e62018-10-01 12:12:37 +0200488
Christopher Faulet9768c262018-10-22 09:34:31 +0200489 /* RFC 1945 allows only GET for HTTP/0.9 requests */
490 if (sl.rq.meth != HTTP_METH_GET)
491 return 0;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200492
Christopher Faulet9768c262018-10-22 09:34:31 +0200493 /* HTTP/0.9 requests *must* have a request URI, per RFC 1945 */
494 if (!sl.rq.u.len)
495 return 0;
496
497 /* Add HTTP version */
498 sl.rq.v = ist("HTTP/1.0");
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100499 return 1;
Christopher Faulet9768c262018-10-22 09:34:31 +0200500 }
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100501
502 if ((sl.rq.v.len == 8) &&
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100503 ((*(sl.rq.v.ptr + 5) > '1') ||
504 ((*(sl.rq.v.ptr + 5) == '1') && (*(sl.rq.v.ptr + 7) >= '1'))))
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100505 h1m->flags |= H1_MF_VER_11;
Christopher Faulet9768c262018-10-22 09:34:31 +0200506 return 1;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200507}
508
Christopher Faulet9768c262018-10-22 09:34:31 +0200509/*
510 * Check the validity of the response version. If the version is valid, it
511 * returns 1. Otherwise, it returns 0.
Christopher Fauletf2824e62018-10-01 12:12:37 +0200512 */
Christopher Faulet9768c262018-10-22 09:34:31 +0200513static int h1_process_res_vsn(struct h1s *h1s, struct h1m *h1m, union h1_sl sl)
Christopher Fauletf2824e62018-10-01 12:12:37 +0200514{
Christopher Faulet9768c262018-10-22 09:34:31 +0200515 struct h1c *h1c = h1s->h1c;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200516
Christopher Faulet9768c262018-10-22 09:34:31 +0200517 /* RFC7230#2.6 has enforced the format of the HTTP version string to be
518 * exactly one digit "." one digit. This check may be disabled using
519 * option accept-invalid-http-request.
520 */
521 if (!(h1c->px->options2 & PR_O2_RSPBUG_OK)) {
522 if (sl.st.v.len != 8)
523 return 0;
524
525 if (*(sl.st.v.ptr + 4) != '/' ||
526 !isdigit((unsigned char)*(sl.st.v.ptr + 5)) ||
527 *(sl.st.v.ptr + 6) != '.' ||
528 !isdigit((unsigned char)*(sl.st.v.ptr + 7)))
529 return 0;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200530 }
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100531
532 if ((sl.st.v.len == 8) &&
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100533 ((*(sl.st.v.ptr + 5) > '1') ||
534 ((*(sl.st.v.ptr + 5) == '1') && (*(sl.st.v.ptr + 7) >= '1'))))
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100535 h1m->flags |= H1_MF_VER_11;
536
Christopher Faulet9768c262018-10-22 09:34:31 +0200537 return 1;
538}
539/* Remove all "Connection:" headers from the HTX message <htx> */
540static void h1_remove_conn_hdrs(struct h1m *h1m, struct htx *htx)
541{
542 struct ist hdr = {.ptr = "Connection", .len = 10};
543 struct http_hdr_ctx ctx;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200544
Christopher Faulet9768c262018-10-22 09:34:31 +0200545 while (http_find_header(htx, hdr, &ctx, 1))
546 http_remove_header(htx, &ctx);
Christopher Fauletf2824e62018-10-01 12:12:37 +0200547
Christopher Faulet9768c262018-10-22 09:34:31 +0200548 h1m->flags &= ~(H1_MF_CONN_KAL|H1_MF_CONN_CLO);
549}
Christopher Fauletf2824e62018-10-01 12:12:37 +0200550
Christopher Faulet9768c262018-10-22 09:34:31 +0200551/* Add a "Connection:" header with the value <value> into the HTX message
552 * <htx>.
553 */
554static void h1_add_conn_hdr(struct h1m *h1m, struct htx *htx, struct ist value)
555{
556 struct ist hdr = {.ptr = "Connection", .len = 10};
Christopher Fauletf2824e62018-10-01 12:12:37 +0200557
Christopher Faulet9768c262018-10-22 09:34:31 +0200558 http_add_header(htx, hdr, value);
Christopher Fauletf2824e62018-10-01 12:12:37 +0200559}
560
561/* Deduce the connection mode of the client connection, depending on the
562 * configuration and the H1 message flags. This function is called twice, the
563 * first time when the request is parsed and the second time when the response
564 * is parsed.
565 */
566static void h1_set_cli_conn_mode(struct h1s *h1s, struct h1m *h1m)
567{
568 struct proxy *fe = h1s->h1c->px;
569 int flag = H1S_F_WANT_KAL; /* For client connection: server-close == keepalive */
570
571 /* Tunnel mode can only by set on the frontend */
572 if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
573 flag = H1S_F_WANT_TUN;
574 else if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
575 flag = H1S_F_WANT_CLO;
576
577 /* flags order: CLO > SCL > TUN > KAL */
578 if ((h1s->flags & H1S_F_WANT_MSK) < flag)
579 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | flag;
580
581 if (h1m->flags & H1_MF_RESP) {
582 /* Either we've established an explicit tunnel, or we're
583 * switching the protocol. In both cases, we're very unlikely to
584 * understand the next protocols. We have to switch to tunnel
585 * mode, so that we transfer the request and responses then let
586 * this protocol pass unmodified. When we later implement
587 * specific parsers for such protocols, we'll want to check the
588 * Upgrade header which contains information about that protocol
589 * for responses with status 101 (eg: see RFC2817 about TLS).
590 */
591 if ((h1s->meth == HTTP_METH_CONNECT && h1s->status == 200) ||
592 h1s->status == 101)
593 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_TUN;
Christopher Fauletbd44ca62018-11-29 09:55:22 +0100594 else if (!(h1m->flags & H1_MF_XFER_LEN) || /* no length known => close */
595 (h1m->flags & H1_MF_CONN_CLO && h1s->req.state != H1_MSG_DONE)) /*explicit close and unfinished request */
Christopher Fauletf2824e62018-10-01 12:12:37 +0200596 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
597 }
598 else {
599 if (h1s->flags & H1S_F_WANT_KAL &&
600 (!(h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL)) || /* no KA in HTTP/1.0 */
601 h1m->flags & H1_MF_CONN_CLO)) /* explicit close */
602 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
603 }
604
605 /* If KAL, check if the frontend is stopping. If yes, switch in CLO mode */
606 if (h1s->flags & H1S_F_WANT_KAL && fe->state == PR_STSTOPPED)
607 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
608}
609
610/* Deduce the connection mode of the client connection, depending on the
611 * configuration and the H1 message flags. This function is called twice, the
612 * first time when the request is parsed and the second time when the response
613 * is parsed.
614 */
615static void h1_set_srv_conn_mode(struct h1s *h1s, struct h1m *h1m)
616{
Christopher Fauleta1692f52018-11-22 10:19:50 +0100617 struct h1c *h1c = h1s->h1c;
618 struct session *sess = h1c->conn->owner;
619 struct proxy *fe = sess->fe;
620 struct proxy *be = h1c->px;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200621 int flag = H1S_F_WANT_KAL;
622
623 /* Tunnel mode can only by set on the frontend */
624 if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
625 flag = H1S_F_WANT_TUN;
626
627 /* For the server connection: server-close == httpclose */
628 if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
629 (be->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
630 (fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO ||
631 (be->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO)
632 flag = H1S_F_WANT_CLO;
633
634 /* flags order: CLO > SCL > TUN > KAL */
635 if ((h1s->flags & H1S_F_WANT_MSK) < flag)
636 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | flag;
637
638 if (h1m->flags & H1_MF_RESP) {
639 /* Either we've established an explicit tunnel, or we're
640 * switching the protocol. In both cases, we're very unlikely to
641 * understand the next protocols. We have to switch to tunnel
642 * mode, so that we transfer the request and responses then let
643 * this protocol pass unmodified. When we later implement
644 * specific parsers for such protocols, we'll want to check the
645 * Upgrade header which contains information about that protocol
646 * for responses with status 101 (eg: see RFC2817 about TLS).
647 */
648 if ((h1s->meth == HTTP_METH_CONNECT && h1s->status == 200) ||
649 h1s->status == 101)
650 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_TUN;
651 else if (!(h1m->flags & H1_MF_XFER_LEN)) /* no length known => close */
652 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
653 else if (h1s->flags & H1S_F_WANT_KAL &&
654 (!(h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL)) || /* no KA in HTTP/1.0 */
655 h1m->flags & H1_MF_CONN_CLO)) /* explicit close */
656 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
657 }
Christopher Faulet70033782018-12-05 13:50:11 +0100658 else {
659 if (h1s->flags & H1S_F_WANT_KAL &&
660 (!(h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL)) || /* no KA in HTTP/1.0 */
661 h1m->flags & H1_MF_CONN_CLO)) /* explicit close */
662 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
663 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200664
665 /* If KAL, check if the backend is stopping. If yes, switch in CLO mode */
666 if (h1s->flags & H1S_F_WANT_KAL && be->state == PR_STSTOPPED)
667 h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200668}
669
Christopher Faulet9768c262018-10-22 09:34:31 +0200670static void h1_update_req_conn_hdr(struct h1s *h1s, struct h1m *h1m,
671 struct htx *htx, struct ist *conn_val)
Christopher Fauletf2824e62018-10-01 12:12:37 +0200672{
673 struct proxy *px = h1s->h1c->px;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200674
675 /* Don't update "Connection:" header in TUNNEL mode or if "Upgrage"
676 * token is found
677 */
678 if (h1s->flags & H1S_F_WANT_TUN || h1m->flags & H1_MF_CONN_UPG)
Christopher Faulet9768c262018-10-22 09:34:31 +0200679 return;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200680
681 if (h1s->flags & H1S_F_WANT_KAL || px->options2 & PR_O2_FAKE_KA) {
Christopher Faulet9768c262018-10-22 09:34:31 +0200682 if (h1m->flags & H1_MF_CONN_CLO) {
683 if (conn_val)
684 *conn_val = ist("");
685 if (htx)
686 h1_remove_conn_hdrs(h1m, htx);
687 }
688 if (!(h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL))) {
689 if (conn_val)
690 *conn_val = ist("keep-alive");
691 if (htx)
692 h1_add_conn_hdr(h1m, htx, ist("keep-alive"));
693 }
Christopher Fauletce851492018-12-07 18:06:59 +0100694 if ((h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL)) == (H1_MF_VER_11|H1_MF_CONN_KAL)) {
695 if (conn_val)
696 *conn_val = ist("");
697 if (htx)
698 h1_remove_conn_hdrs(h1m, htx);
699 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200700 }
701 else { /* H1S_F_WANT_CLO && !PR_O2_FAKE_KA */
Christopher Faulet9768c262018-10-22 09:34:31 +0200702 if (h1m->flags & H1_MF_CONN_KAL) {
703 if (conn_val)
704 *conn_val = ist("");
705 if (htx)
706 h1_remove_conn_hdrs(h1m, htx);
707 }
708 if ((h1m->flags & (H1_MF_VER_11|H1_MF_CONN_CLO)) == H1_MF_VER_11) {
709 if (conn_val)
710 *conn_val = ist("close");
711 if (htx)
712 h1_add_conn_hdr(h1m, htx, ist("close"));
713 }
Christopher Fauletce851492018-12-07 18:06:59 +0100714 if ((h1m->flags & (H1_MF_VER_11|H1_MF_CONN_CLO)) == H1_MF_CONN_CLO) {
715 if (conn_val)
716 *conn_val = ist("");
717 if (htx)
718 h1_remove_conn_hdrs(h1m, htx);
719 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200720 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200721}
722
Christopher Faulet9768c262018-10-22 09:34:31 +0200723static void h1_update_res_conn_hdr(struct h1s *h1s, struct h1m *h1m,
724 struct htx *htx, struct ist *conn_val)
Christopher Fauletf2824e62018-10-01 12:12:37 +0200725{
Christopher Fauletf2824e62018-10-01 12:12:37 +0200726 /* Don't update "Connection:" header in TUNNEL mode or if "Upgrage"
727 * token is found
728 */
729 if (h1s->flags & H1S_F_WANT_TUN || h1m->flags & H1_MF_CONN_UPG)
Christopher Faulet9768c262018-10-22 09:34:31 +0200730 return;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200731
732 if (h1s->flags & H1S_F_WANT_KAL) {
Christopher Faulet9768c262018-10-22 09:34:31 +0200733 if (h1m->flags & H1_MF_CONN_CLO) {
734 if (conn_val)
735 *conn_val = ist("");
736 if (htx)
737 h1_remove_conn_hdrs(h1m, htx);
738 }
739 if (!(h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL))) {
740 if (conn_val)
741 *conn_val = ist("keep-alive");
742 if (htx)
743 h1_add_conn_hdr(h1m, htx, ist("keep-alive"));
744 }
Christopher Fauletce851492018-12-07 18:06:59 +0100745 if ((h1m->flags & (H1_MF_VER_11|H1_MF_CONN_KAL)) == (H1_MF_VER_11|H1_MF_CONN_KAL)) {
746 if (conn_val)
747 *conn_val = ist("");
748 if (htx)
749 h1_remove_conn_hdrs(h1m, htx);
750 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200751 }
752 else { /* H1S_F_WANT_CLO */
Christopher Faulet9768c262018-10-22 09:34:31 +0200753 if (h1m->flags & H1_MF_CONN_KAL) {
754 if (conn_val)
755 *conn_val = ist("");
756 if (htx)
757 h1_remove_conn_hdrs(h1m, htx);
758 }
759 if ((h1m->flags & (H1_MF_VER_11|H1_MF_CONN_CLO)) == H1_MF_VER_11) {
760 if (conn_val)
761 *conn_val = ist("close");
762 if (htx)
763 h1_add_conn_hdr(h1m, htx, ist("close"));
764 }
Christopher Fauletce851492018-12-07 18:06:59 +0100765 if ((h1m->flags & (H1_MF_VER_11|H1_MF_CONN_CLO)) == H1_MF_CONN_CLO) {
766 if (conn_val)
767 *conn_val = ist("");
768 if (htx)
769 h1_remove_conn_hdrs(h1m, htx);
770 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200771 }
Christopher Faulet9768c262018-10-22 09:34:31 +0200772}
Christopher Fauletf2824e62018-10-01 12:12:37 +0200773
Christopher Faulet9768c262018-10-22 09:34:31 +0200774/* Set the right connection mode and update "Connection:" header if
775 * needed. <htx> and <conn_val> can be NULL. When <htx> is not NULL, the HTX
776 * message is updated accordingly. When <conn_val> is not NULL, it is set with
777 * the new header value.
778 */
779static void h1_process_conn_mode(struct h1s *h1s, struct h1m *h1m,
780 struct htx *htx, struct ist *conn_val)
781{
782 if (!conn_is_back(h1s->h1c->conn)) {
783 h1_set_cli_conn_mode(h1s, h1m);
784 if (h1m->flags & H1_MF_RESP)
785 h1_update_res_conn_hdr(h1s, h1m, htx, conn_val);
786 }
787 else {
788 h1_set_srv_conn_mode(h1s, h1m);
789 if (!(h1m->flags & H1_MF_RESP))
790 h1_update_req_conn_hdr(h1s, h1m, htx, conn_val);
791 }
Christopher Fauletf2824e62018-10-01 12:12:37 +0200792}
793
Christopher Faulete44769b2018-11-29 23:01:45 +0100794
795/* Append the description of what is present in error snapshot <es> into <out>.
796 * The description must be small enough to always fit in a buffer. The output
797 * buffer may be the trash so the trash must not be used inside this function.
798 */
799static void h1_show_error_snapshot(struct buffer *out, const struct error_snapshot *es)
800{
801 chunk_appendf(out,
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100802 " H1 connection flags 0x%08x, H1 stream flags 0x%08x\n"
803 " H1 msg state %s(%d), H1 msg flags 0x%08x\n"
804 " H1 chunk len %lld bytes, H1 body len %lld bytes :\n",
805 es->ctx.h1.c_flags, es->ctx.h1.s_flags,
806 h1m_state_str(es->ctx.h1.state), es->ctx.h1.state,
807 es->ctx.h1.m_flags, es->ctx.h1.m_clen, es->ctx.h1.m_blen);
Christopher Faulete44769b2018-11-29 23:01:45 +0100808}
809/*
810 * Capture a bad request or response and archive it in the proxy's structure.
811 * By default it tries to report the error position as h1m->err_pos. However if
812 * this one is not set, it will then report h1m->next, which is the last known
813 * parsing point. The function is able to deal with wrapping buffers. It always
814 * displays buffers as a contiguous area starting at buf->p. The direction is
815 * determined thanks to the h1m's flags.
816 */
817static void h1_capture_bad_message(struct h1c *h1c, struct h1s *h1s,
818 struct h1m *h1m, struct buffer *buf)
819{
820 struct session *sess = h1c->conn->owner;
821 struct proxy *proxy = h1c->px;
822 struct proxy *other_end = sess->fe;
823 union error_snapshot_ctx ctx;
824
825 if (h1s->cs->data)
826 other_end = si_strm(h1s->cs->data)->be;
827
828 /* http-specific part now */
829 ctx.h1.state = h1m->state;
830 ctx.h1.c_flags = h1c->flags;
831 ctx.h1.s_flags = h1s->flags;
832 ctx.h1.m_flags = h1m->flags;
833 ctx.h1.m_clen = h1m->curr_len;
834 ctx.h1.m_blen = h1m->body_len;
835
836 proxy_capture_error(proxy, !!(h1m->flags & H1_MF_RESP), other_end,
837 h1c->conn->target, sess, buf, 0, 0,
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100838 (h1m->err_pos >= 0) ? h1m->err_pos : h1m->next,
839 &ctx, h1_show_error_snapshot);
Christopher Faulete44769b2018-11-29 23:01:45 +0100840}
841
Christopher Faulet129817b2018-09-20 16:14:40 +0200842/*
843 * Parse HTTP/1 headers. It returns the number of bytes parsed if > 0, or 0 if
Christopher Fauletf2824e62018-10-01 12:12:37 +0200844 * it couldn't proceed. Parsing errors are reported by setting H1S_F_*_ERROR
845 * flag and filling h1s->err_pos and h1s->err_state fields. This functions is
Joseph Herlant30bc5092018-11-25 10:52:20 -0800846 * responsible to update the parser state <h1m>.
Christopher Faulet129817b2018-09-20 16:14:40 +0200847 */
Christopher Faulet9768c262018-10-22 09:34:31 +0200848static size_t h1_process_headers(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
Christopher Fauletf2824e62018-10-01 12:12:37 +0200849 struct buffer *buf, size_t *ofs, size_t max)
Christopher Faulet129817b2018-09-20 16:14:40 +0200850{
851 struct http_hdr hdrs[MAX_HTTP_HDR];
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100852 union h1_sl h1sl;
853 unsigned int flags = HTX_SL_F_NONE;
Christopher Faulet129817b2018-09-20 16:14:40 +0200854 int ret = 0;
855
Christopher Fauletd44ad5b2018-11-19 21:52:12 +0100856 if (!max)
857 goto end;
858
Christopher Faulet129817b2018-09-20 16:14:40 +0200859 /* Realing input buffer if necessary */
860 if (b_head(buf) + b_data(buf) > b_wrap(buf))
861 b_slow_realign(buf, trash.area, 0);
862
Christopher Fauletf2824e62018-10-01 12:12:37 +0200863 ret = h1_headers_to_hdr_list(b_peek(buf, *ofs), b_peek(buf, *ofs) + max,
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100864 hdrs, sizeof(hdrs)/sizeof(hdrs[0]), h1m, &h1sl);
Christopher Faulet129817b2018-09-20 16:14:40 +0200865 if (ret <= 0) {
866 /* Incomplete or invalid message. If the buffer is full, it's an
867 * error because headers are too large to be handled by the
868 * parser. */
Christopher Fauletf2824e62018-10-01 12:12:37 +0200869 if (ret < 0 || (!ret && b_full(buf)))
870 goto error;
Christopher Faulet129817b2018-09-20 16:14:40 +0200871 goto end;
872 }
873
874 /* messages headers fully parsed, do some checks to prepare the body
875 * parsing.
876 */
877
878 /* Be sure to keep some space to do headers rewritting */
Christopher Fauletf2824e62018-10-01 12:12:37 +0200879 if (ret > (b_size(buf) - global.tune.maxrewrite))
880 goto error;
Christopher Faulet129817b2018-09-20 16:14:40 +0200881
Christopher Faulet9768c262018-10-22 09:34:31 +0200882 /* Save the request's method or the response's status, check if the body
883 * length is known and check the VSN validity */
Christopher Faulet129817b2018-09-20 16:14:40 +0200884 if (!(h1m->flags & H1_MF_RESP)) {
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100885 h1s->meth = h1sl.rq.meth;
Christopher Faulet9768c262018-10-22 09:34:31 +0200886
Christopher Faulet129817b2018-09-20 16:14:40 +0200887 /* Request have always a known length */
888 h1m->flags |= H1_MF_XFER_LEN;
889 if (!(h1m->flags & H1_MF_CHNK) && !h1m->body_len)
890 h1m->state = H1_MSG_DONE;
Christopher Faulet9768c262018-10-22 09:34:31 +0200891
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100892 if (!h1_process_req_vsn(h1s, h1m, h1sl)) {
893 h1m->err_pos = h1sl.rq.v.ptr - b_head(buf);
Christopher Faulet9768c262018-10-22 09:34:31 +0200894 h1m->err_state = h1m->state;
895 goto vsn_error;
896 }
Christopher Faulet129817b2018-09-20 16:14:40 +0200897 }
898 else {
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100899 h1s->status = h1sl.st.status;
Christopher Faulet129817b2018-09-20 16:14:40 +0200900
901 if ((h1s->meth == HTTP_METH_HEAD) ||
902 (h1s->status >= 100 && h1s->status < 200) ||
903 (h1s->status == 204) || (h1s->status == 304) ||
904 (h1s->meth == HTTP_METH_CONNECT && h1s->status == 200)) {
905 h1m->flags &= ~(H1_MF_CLEN|H1_MF_CHNK);
906 h1m->flags |= H1_MF_XFER_LEN;
907 h1m->curr_len = h1m->body_len = 0;
908 h1m->state = H1_MSG_DONE;
909 }
910 else if (h1m->flags & (H1_MF_CLEN|H1_MF_CHNK)) {
911 h1m->flags |= H1_MF_XFER_LEN;
912 if ((h1m->flags & H1_MF_CLEN) && !h1m->body_len)
913 h1m->state = H1_MSG_DONE;
914 }
915 else
916 h1m->state = H1_MSG_TUNNEL;
Christopher Faulet9768c262018-10-22 09:34:31 +0200917
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100918 if (!h1_process_res_vsn(h1s, h1m, h1sl)) {
919 h1m->err_pos = h1sl.st.v.ptr - b_head(buf);
Christopher Faulet9768c262018-10-22 09:34:31 +0200920 h1m->err_state = h1m->state;
921 goto vsn_error;
922 }
Christopher Faulet129817b2018-09-20 16:14:40 +0200923 }
924
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100925 /* Set HTX start-line flags */
926 if (h1m->flags & H1_MF_VER_11)
927 flags |= HTX_SL_F_VER_11;
928 if (h1m->flags & H1_MF_XFER_ENC)
929 flags |= HTX_SL_F_XFER_ENC;
930 if (h1m->flags & H1_MF_XFER_LEN) {
931 flags |= HTX_SL_F_XFER_LEN;
932 if (h1m->flags & H1_MF_CHNK)
933 flags |= HTX_SL_F_CHNK;
934 else if (h1m->flags & H1_MF_CLEN)
935 flags |= HTX_SL_F_CLEN;
Christopher Fauletb2db4fa2018-11-27 16:51:09 +0100936 if (h1m->state == H1_MSG_DONE)
937 flags |= HTX_SL_F_BODYLESS;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100938 }
939
Christopher Faulet9768c262018-10-22 09:34:31 +0200940 if (!(h1m->flags & H1_MF_RESP)) {
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100941 struct htx_sl *sl;
942
943 sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, h1sl.rq.m, h1sl.rq.u, h1sl.rq.v);
944 if (!sl || !htx_add_all_headers(htx, hdrs))
Christopher Faulet9768c262018-10-22 09:34:31 +0200945 goto error;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100946 sl->info.req.meth = h1s->meth;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200947 }
948 else {
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100949 struct htx_sl *sl;
950
951 flags |= HTX_SL_F_IS_RESP;
952 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, h1sl.st.v, h1sl.st.c, h1sl.st.r);
953 if (!sl || !htx_add_all_headers(htx, hdrs))
Christopher Faulet9768c262018-10-22 09:34:31 +0200954 goto error;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100955 sl->info.res.status = h1s->status;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200956 }
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100957
Christopher Faulet9768c262018-10-22 09:34:31 +0200958 if (h1m->state == H1_MSG_DONE)
959 if (!htx_add_endof(htx, HTX_BLK_EOM))
960 goto error;
961
962 h1_process_conn_mode(h1s, h1m, htx, NULL);
963
964 /* If body length cannot be determined, set htx->extra to
965 * ULLONG_MAX. This value is impossible in other cases.
966 */
967 htx->extra = ((h1m->flags & H1_MF_XFER_LEN) ? h1m->curr_len : ULLONG_MAX);
968
969 /* Recheck there is enough space to do headers rewritting */
970 if (htx_used_space(htx) > b_size(buf) - global.tune.maxrewrite)
971 goto error;
972
973 *ofs += ret;
Christopher Faulet129817b2018-09-20 16:14:40 +0200974 end:
975 return ret;
Christopher Fauletf2824e62018-10-01 12:12:37 +0200976
977 error:
Christopher Fauletf2824e62018-10-01 12:12:37 +0200978 h1m->err_state = h1m->state;
979 h1m->err_pos = h1m->next;
Christopher Faulet9768c262018-10-22 09:34:31 +0200980 vsn_error:
981 h1s->flags |= (!(h1m->flags & H1_MF_RESP) ? H1S_F_REQ_ERROR : H1S_F_RES_ERROR);
Christopher Faulete44769b2018-11-29 23:01:45 +0100982 h1_capture_bad_message(h1s->h1c, h1s, h1m, buf);
Christopher Fauletf2824e62018-10-01 12:12:37 +0200983 ret = 0;
984 goto end;
Christopher Faulet129817b2018-09-20 16:14:40 +0200985}
986
987/*
Christopher Fauletf2824e62018-10-01 12:12:37 +0200988 * Parse HTTP/1 body. It returns the number of bytes parsed if > 0, or 0 if it
989 * couldn't proceed. Parsing errors are reported by setting H1S_F_*_ERROR flag
Christopher Faulet129817b2018-09-20 16:14:40 +0200990 * and filling h1s->err_pos and h1s->err_state fields. This functions is
Joseph Herlant30bc5092018-11-25 10:52:20 -0800991 * responsible to update the parser state <h1m>.
Christopher Faulet129817b2018-09-20 16:14:40 +0200992 */
Christopher Faulet9768c262018-10-22 09:34:31 +0200993static size_t h1_process_data(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
Christopher Fauletaa75b3d2018-12-05 16:20:40 +0100994 struct buffer *buf, size_t *ofs, size_t max,
995 struct buffer *htxbuf)
Christopher Faulet129817b2018-09-20 16:14:40 +0200996{
Christopher Faulet9768c262018-10-22 09:34:31 +0200997 uint32_t data_space = htx_free_data_space(htx);
Christopher Faulet129817b2018-09-20 16:14:40 +0200998 size_t total = 0;
999 int ret = 0;
1000
1001 if (h1m->flags & H1_MF_XFER_LEN) {
1002 if (h1m->flags & H1_MF_CLEN) {
1003 /* content-length: read only h2m->body_len */
1004 ret = max;
Christopher Faulet9768c262018-10-22 09:34:31 +02001005 if (ret > data_space)
1006 ret = data_space;
Christopher Faulet129817b2018-09-20 16:14:40 +02001007 if ((uint64_t)ret > h1m->curr_len)
1008 ret = h1m->curr_len;
Christopher Faulet9768c262018-10-22 09:34:31 +02001009 if (ret > b_contig_data(buf, *ofs))
1010 ret = b_contig_data(buf, *ofs);
1011 if (ret) {
Willy Tarreau78f548f2018-12-05 10:02:39 +01001012 /* very often with large files we'll face the following
1013 * situation :
1014 * - htx is empty and points to <htxbuf>
1015 * - ret == buf->data
1016 * - buf->head == sizeof(struct htx)
1017 * => we can swap the buffers and place an htx header into
1018 * the target buffer instead
1019 */
1020 if (unlikely(htx_is_empty(htx) && ret == b_data(buf) &&
1021 !*ofs && b_head_ofs(buf) == sizeof(struct htx))) {
1022 void *raw_area = buf->area;
1023 void *htx_area = htxbuf->area;
1024 struct htx_blk *blk;
1025
1026 buf->area = htx_area;
1027 htxbuf->area = raw_area;
1028 htx = (struct htx *)htxbuf->area;
1029 htx->size = htxbuf->size - sizeof(*htx);
1030 htx_reset(htx);
1031 b_set_data(htxbuf, b_size(htxbuf));
1032
1033 blk = htx_add_blk(htx, HTX_BLK_DATA, ret);
1034 blk->info += ret;
1035 /* nothing else to do, the old buffer now contains an
1036 * empty pre-initialized HTX header
1037 */
1038 }
1039 else if (!htx_add_data(htx, ist2(b_peek(buf, *ofs), ret)))
Christopher Faulet9768c262018-10-22 09:34:31 +02001040 goto end;
1041 h1m->curr_len -= ret;
1042 *ofs += ret;
1043 total += ret;
1044 }
1045
1046 if (!h1m->curr_len) {
1047 if (!htx_add_endof(htx, HTX_BLK_EOM))
1048 goto end;
Christopher Faulet129817b2018-09-20 16:14:40 +02001049 h1m->state = H1_MSG_DONE;
Christopher Faulet9768c262018-10-22 09:34:31 +02001050 }
Christopher Faulet129817b2018-09-20 16:14:40 +02001051 }
1052 else if (h1m->flags & H1_MF_CHNK) {
1053 new_chunk:
1054 /* te:chunked : parse chunks */
1055 if (h1m->state == H1_MSG_CHUNK_CRLF) {
Christopher Fauletf2824e62018-10-01 12:12:37 +02001056 ret = h1_skip_chunk_crlf(buf, *ofs, *ofs + max);
Christopher Faulet129817b2018-09-20 16:14:40 +02001057 if (ret <= 0)
1058 goto end;
Christopher Faulet9768c262018-10-22 09:34:31 +02001059 h1m->state = H1_MSG_CHUNK_SIZE;
1060
Christopher Faulet129817b2018-09-20 16:14:40 +02001061 max -= ret;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001062 *ofs += ret;
Christopher Faulet129817b2018-09-20 16:14:40 +02001063 total += ret;
Christopher Faulet129817b2018-09-20 16:14:40 +02001064 }
1065
1066 if (h1m->state == H1_MSG_CHUNK_SIZE) {
1067 unsigned int chksz;
1068
Christopher Fauletf2824e62018-10-01 12:12:37 +02001069 ret = h1_parse_chunk_size(buf, *ofs, *ofs + max, &chksz);
Christopher Faulet129817b2018-09-20 16:14:40 +02001070 if (ret <= 0)
1071 goto end;
Christopher Faulet9768c262018-10-22 09:34:31 +02001072 if (!chksz) {
1073 if (!htx_add_endof(htx, HTX_BLK_EOD))
1074 goto end;
Christopher Faulet17276482018-11-22 11:44:35 +01001075 h1s->flags |= H1S_F_HAVE_EOD;
Christopher Faulet9768c262018-10-22 09:34:31 +02001076 h1m->state = H1_MSG_TRAILERS;
1077 }
1078 else
1079 h1m->state = H1_MSG_DATA;
1080
Christopher Faulet129817b2018-09-20 16:14:40 +02001081 h1m->curr_len = chksz;
1082 h1m->body_len += chksz;
1083 max -= ret;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001084 *ofs += ret;
Christopher Faulet129817b2018-09-20 16:14:40 +02001085 total += ret;
Christopher Faulet129817b2018-09-20 16:14:40 +02001086 }
1087
1088 if (h1m->state == H1_MSG_DATA) {
1089 ret = max;
Christopher Faulet9768c262018-10-22 09:34:31 +02001090 if (ret > data_space)
1091 ret = data_space;
Christopher Faulet129817b2018-09-20 16:14:40 +02001092 if ((uint64_t)ret > h1m->curr_len)
1093 ret = h1m->curr_len;
Christopher Faulet9768c262018-10-22 09:34:31 +02001094 if (ret > b_contig_data(buf, *ofs))
1095 ret = b_contig_data(buf, *ofs);
1096 if (ret) {
1097 if (!htx_add_data(htx, ist2(b_peek(buf, *ofs), ret)))
1098 goto end;
1099 h1m->curr_len -= ret;
1100 max -= ret;
1101 *ofs += ret;
1102 total += ret;
1103 }
1104 if (!h1m->curr_len) {
1105 h1m->state = H1_MSG_CHUNK_CRLF;
1106 goto new_chunk;
1107 }
1108 goto end;
Christopher Faulet129817b2018-09-20 16:14:40 +02001109 }
1110
1111 if (h1m->state == H1_MSG_TRAILERS) {
Christopher Faulet17276482018-11-22 11:44:35 +01001112 /* Trailers were alread parsed, only the EOM
1113 * need to be added */
1114 if (h1s->flags & H1S_F_HAVE_TLR)
1115 goto skip_tlr_parsing;
1116
Christopher Fauletf2824e62018-10-01 12:12:37 +02001117 ret = h1_measure_trailers(buf, *ofs, *ofs + max);
Christopher Faulet9768c262018-10-22 09:34:31 +02001118 if (ret > data_space)
1119 ret = (htx_is_empty(htx) ? -1 : 0);
Christopher Faulet129817b2018-09-20 16:14:40 +02001120 if (ret <= 0)
1121 goto end;
Christopher Faulet9768c262018-10-22 09:34:31 +02001122
1123 /* Realing input buffer if tailers wrap. For now
1124 * this is a workaroung. Because trailers are
1125 * not split on CRLF, like headers, there is no
1126 * way to know where to split it when trailers
1127 * wrap. This is a limitation of
1128 * h1_measure_trailers.
1129 */
1130 if (b_peek(buf, *ofs) > b_peek(buf, *ofs + ret))
1131 b_slow_realign(buf, trash.area, 0);
1132
1133 if (!htx_add_trailer(htx, ist2(b_peek(buf, *ofs), ret)))
1134 goto end;
Christopher Faulet17276482018-11-22 11:44:35 +01001135 h1s->flags |= H1S_F_HAVE_TLR;
Christopher Faulet129817b2018-09-20 16:14:40 +02001136 max -= ret;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001137 *ofs += ret;
Christopher Faulet129817b2018-09-20 16:14:40 +02001138 total += ret;
Christopher Faulet9768c262018-10-22 09:34:31 +02001139
Christopher Faulet17276482018-11-22 11:44:35 +01001140 skip_tlr_parsing:
Christopher Faulet9768c262018-10-22 09:34:31 +02001141 if (!htx_add_endof(htx, HTX_BLK_EOM))
1142 goto end;
Christopher Faulet129817b2018-09-20 16:14:40 +02001143 h1m->state = H1_MSG_DONE;
1144 }
1145 }
1146 else {
1147 /* XFER_LEN is set but not CLEN nor CHNK, it means there
1148 * is no body. Switch the message in DONE state
1149 */
Christopher Faulet9768c262018-10-22 09:34:31 +02001150 if (!htx_add_endof(htx, HTX_BLK_EOM))
1151 goto end;
Christopher Faulet129817b2018-09-20 16:14:40 +02001152 h1m->state = H1_MSG_DONE;
1153 }
1154 }
1155 else {
1156 /* no content length, read till SHUTW */
Christopher Faulet9768c262018-10-22 09:34:31 +02001157 ret = max;
1158 if (ret > data_space)
1159 ret = data_space;
1160 if (ret > b_contig_data(buf, *ofs))
1161 ret = b_contig_data(buf, *ofs);
1162 if (ret) {
1163 if (!htx_add_data(htx, ist2(b_peek(buf, *ofs), ret)))
1164 goto end;
1165
Olivier Houchardcf42d5a2018-12-04 17:41:58 +01001166 *ofs += ret;
1167 total = ret;
Christopher Faulet9768c262018-10-22 09:34:31 +02001168 }
Christopher Faulet129817b2018-09-20 16:14:40 +02001169 }
1170
1171 end:
1172 if (ret < 0) {
Christopher Fauletf2824e62018-10-01 12:12:37 +02001173 h1s->flags |= (!(h1m->flags & H1_MF_RESP) ? H1S_F_REQ_ERROR : H1S_F_RES_ERROR);
Christopher Faulet129817b2018-09-20 16:14:40 +02001174 h1m->err_state = h1m->state;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001175 h1m->err_pos = *ofs + max + ret;
Christopher Faulete44769b2018-11-29 23:01:45 +01001176 h1_capture_bad_message(h1s->h1c, h1s, h1m, buf);
Christopher Faulet129817b2018-09-20 16:14:40 +02001177 return 0;
1178 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001179 /* update htx->extra, only when the body length is known */
1180 if (h1m->flags & H1_MF_XFER_LEN)
1181 htx->extra = h1m->curr_len;
Christopher Faulet129817b2018-09-20 16:14:40 +02001182 return total;
1183}
1184
1185/*
1186 * Synchronize the request and the response before reseting them. Except for 1xx
1187 * responses, we wait that the request and the response are in DONE state and
1188 * that all data are forwarded for both. For 1xx responses, only the response is
1189 * reset, waiting the final one. Many 1xx messages can be sent.
1190 */
1191static void h1_sync_messages(struct h1c *h1c)
1192{
Christopher Fauletf2824e62018-10-01 12:12:37 +02001193 struct h1s *h1s = h1c->h1s;
1194
1195 if (!h1s)
Christopher Faulet129817b2018-09-20 16:14:40 +02001196 return;
1197
Christopher Fauletf2824e62018-10-01 12:12:37 +02001198 if (h1s->res.state == H1_MSG_DONE &&
1199 (h1s->status < 200 && (h1s->status == 100 || h1s->status >= 102)) &&
Christopher Faulet539e0292018-11-19 10:40:09 +01001200 (conn_is_back(h1c->conn) || !b_data(&h1c->obuf))) {
Christopher Faulet129817b2018-09-20 16:14:40 +02001201 /* For 100-Continue response or any other informational 1xx
1202 * response which is non-final, don't reset the request, the
1203 * transaction is not finished. We take care the response was
1204 * transferred before.
1205 */
Christopher Fauletf2824e62018-10-01 12:12:37 +02001206 h1m_init_res(&h1s->res);
Christopher Faulet9768c262018-10-22 09:34:31 +02001207 h1s->res.flags |= H1_MF_NO_PHDR;
Christopher Fauletcb55f482018-12-10 11:56:47 +01001208 h1c->flags &= ~H1C_F_IN_BUSY;
Christopher Faulet129817b2018-09-20 16:14:40 +02001209 }
Christopher Faulet539e0292018-11-19 10:40:09 +01001210 else if (!b_data(&h1c->obuf) &&
Christopher Fauletf2824e62018-10-01 12:12:37 +02001211 h1s->req.state == H1_MSG_DONE && h1s->res.state == H1_MSG_DONE) {
1212 if (h1s->flags & H1S_F_WANT_TUN) {
Christopher Faulet9768c262018-10-22 09:34:31 +02001213 h1m_init_req(&h1s->req);
1214 h1m_init_res(&h1s->res);
Christopher Fauletf2824e62018-10-01 12:12:37 +02001215 h1s->req.state = H1_MSG_TUNNEL;
1216 h1s->res.state = H1_MSG_TUNNEL;
Christopher Fauletcb55f482018-12-10 11:56:47 +01001217 h1c->flags &= ~H1C_F_IN_BUSY;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001218 }
Christopher Faulet129817b2018-09-20 16:14:40 +02001219 }
1220}
1221
1222/*
1223 * Process incoming data. It parses data and transfer them from h1c->ibuf into
Christopher Faulet539e0292018-11-19 10:40:09 +01001224 * <buf>. It returns the number of bytes parsed and transferred if > 0, or 0 if
1225 * it couldn't proceed.
Christopher Faulet129817b2018-09-20 16:14:40 +02001226 */
Christopher Faulet539e0292018-11-19 10:40:09 +01001227static size_t h1_process_input(struct h1c *h1c, struct buffer *buf, int flags)
Christopher Faulet51dbc942018-09-13 09:05:15 +02001228{
Christopher Faulet539e0292018-11-19 10:40:09 +01001229 struct h1s *h1s = h1c->h1s;
Christopher Faulet129817b2018-09-20 16:14:40 +02001230 struct h1m *h1m;
Christopher Faulet9768c262018-10-22 09:34:31 +02001231 struct htx *htx;
Christopher Faulet129817b2018-09-20 16:14:40 +02001232 size_t total = 0;
1233 size_t ret = 0;
Christopher Faulet539e0292018-11-19 10:40:09 +01001234 size_t count, max;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001235 int errflag;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001236
Christopher Faulet539e0292018-11-19 10:40:09 +01001237 htx = htx_from_buf(buf);
1238 count = b_data(&h1c->ibuf);
1239 max = htx_free_space(htx);
1240 if (flags & CO_RFL_KEEP_RSV) {
1241 if (max < global.tune.maxrewrite)
1242 goto end;
1243 max -= global.tune.maxrewrite;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001244 }
Christopher Faulet539e0292018-11-19 10:40:09 +01001245 if (count > max)
1246 count = max;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001247
Christopher Fauletf2824e62018-10-01 12:12:37 +02001248 if (!conn_is_back(h1c->conn)) {
1249 h1m = &h1s->req;
1250 errflag = H1S_F_REQ_ERROR;
1251 }
1252 else {
1253 h1m = &h1s->res;
1254 errflag = H1S_F_RES_ERROR;
1255 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001256
Christopher Fauletd44ad5b2018-11-19 21:52:12 +01001257 do {
Christopher Faulet129817b2018-09-20 16:14:40 +02001258 if (h1m->state <= H1_MSG_LAST_LF) {
Christopher Faulet539e0292018-11-19 10:40:09 +01001259 ret = h1_process_headers(h1s, h1m, htx, &h1c->ibuf, &total, count);
Christopher Faulet129817b2018-09-20 16:14:40 +02001260 if (!ret)
1261 break;
Christopher Faulet129817b2018-09-20 16:14:40 +02001262 }
1263 else if (h1m->state <= H1_MSG_TRAILERS) {
Willy Tarreau78f548f2018-12-05 10:02:39 +01001264 ret = h1_process_data(h1s, h1m, htx, &h1c->ibuf, &total, count, buf);
1265 htx = htx_from_buf(buf);
Christopher Faulet129817b2018-09-20 16:14:40 +02001266 if (!ret)
1267 break;
1268 }
Christopher Fauletcb55f482018-12-10 11:56:47 +01001269 else if (h1m->state == H1_MSG_DONE) {
1270 h1c->flags |= H1C_F_IN_BUSY;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001271 break;
Christopher Fauletcb55f482018-12-10 11:56:47 +01001272 }
Christopher Fauletf2824e62018-10-01 12:12:37 +02001273 else if (h1m->state == H1_MSG_TUNNEL) {
Willy Tarreau78f548f2018-12-05 10:02:39 +01001274 ret = h1_process_data(h1s, h1m, htx, &h1c->ibuf, &total, count, buf);
1275 htx = htx_from_buf(buf);
Christopher Faulet9768c262018-10-22 09:34:31 +02001276 if (!ret)
1277 break;
Christopher Fauletf2824e62018-10-01 12:12:37 +02001278 }
Christopher Faulet129817b2018-09-20 16:14:40 +02001279 else {
Christopher Fauletf2824e62018-10-01 12:12:37 +02001280 h1s->flags |= errflag;
Christopher Faulet129817b2018-09-20 16:14:40 +02001281 break;
1282 }
1283
Christopher Faulet539e0292018-11-19 10:40:09 +01001284 count -= ret;
Christopher Fauletd44ad5b2018-11-19 21:52:12 +01001285 } while (!(h1s->flags & errflag) && count);
Christopher Faulet129817b2018-09-20 16:14:40 +02001286
Christopher Faulet47365272018-10-31 17:40:50 +01001287 if (h1s->flags & errflag)
1288 goto parsing_err;
Christopher Faulet129817b2018-09-20 16:14:40 +02001289
Christopher Faulet539e0292018-11-19 10:40:09 +01001290 b_del(&h1c->ibuf, total);
1291
1292 end:
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01001293 htx_to_buf(htx, buf);
Christopher Faulet9768c262018-10-22 09:34:31 +02001294
Willy Tarreau45f2b892018-12-05 07:59:27 +01001295 if (h1c->flags & H1C_F_IN_FULL && buf_room_for_htx_data(&h1c->ibuf)) {
Christopher Faulet539e0292018-11-19 10:40:09 +01001296 h1c->flags &= ~H1C_F_IN_FULL;
1297 tasklet_wakeup(h1c->wait_event.task);
Christopher Faulet47365272018-10-31 17:40:50 +01001298 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001299
Christopher Faulet9c388402018-11-19 21:54:26 +01001300 if (b_data(&h1c->ibuf)) {
1301 if (!htx_is_empty(htx))
Olivier Houchardd247be02018-12-06 16:22:29 +01001302 h1s->cs->flags |= CS_FL_RCV_MORE | CS_FL_WANT_ROOM;
Christopher Faulet9c388402018-11-19 21:54:26 +01001303 }
Christopher Faulet539e0292018-11-19 10:40:09 +01001304 else {
1305 h1_release_buf(h1c, &h1c->ibuf);
1306 h1_sync_messages(h1c);
Christopher Fauletf6ce9d62018-12-10 15:30:06 +01001307 h1s->cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
1308 }
Christopher Faulet539e0292018-11-19 10:40:09 +01001309
Christopher Fauletf6ce9d62018-12-10 15:30:06 +01001310 if ((h1s->cs->flags & CS_FL_REOS) && (!b_data(&h1c->ibuf) || htx_is_empty(htx))) {
1311 h1s->cs->flags |= CS_FL_EOS;
Olivier Houchardd247be02018-12-06 16:22:29 +01001312 h1s->cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Christopher Faulet539e0292018-11-19 10:40:09 +01001313 }
Christopher Fauletf6ce9d62018-12-10 15:30:06 +01001314
Christopher Faulet539e0292018-11-19 10:40:09 +01001315 return total;
Christopher Faulet47365272018-10-31 17:40:50 +01001316
1317 parsing_err:
Christopher Faulet47365272018-10-31 17:40:50 +01001318 b_reset(&h1c->ibuf);
Christopher Faulet539e0292018-11-19 10:40:09 +01001319 htx->flags |= HTX_FL_PARSING_ERROR;
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01001320 htx_to_buf(htx, buf);
Christopher Faulet539e0292018-11-19 10:40:09 +01001321 h1s->cs->flags |= CS_FL_EOS;
Christopher Faulet9768c262018-10-22 09:34:31 +02001322 return 0;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001323}
1324
Christopher Faulet129817b2018-09-20 16:14:40 +02001325/*
1326 * Process outgoing data. It parses data and transfer them from the channel buffer into
1327 * h1c->obuf. It returns the number of bytes parsed and transferred if > 0, or
1328 * 0 if it couldn't proceed.
1329 */
Christopher Faulet51dbc942018-09-13 09:05:15 +02001330static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t count)
1331{
Christopher Faulet129817b2018-09-20 16:14:40 +02001332 struct h1s *h1s = h1c->h1s;
1333 struct h1m *h1m;
Christopher Faulet9768c262018-10-22 09:34:31 +02001334 struct htx *chn_htx;
1335 struct htx_blk *blk;
1336 struct buffer *tmp;
Christopher Faulet129817b2018-09-20 16:14:40 +02001337 size_t total = 0;
Christopher Fauletd1ebb1e2018-11-28 16:32:50 +01001338 int process_conn_mode = 1; /* If still 1 on EOH, process the connection mode */
Christopher Fauletf2824e62018-10-01 12:12:37 +02001339 int errflag;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001340
Christopher Faulet47365272018-10-31 17:40:50 +01001341 if (!count)
1342 goto end;
Christopher Faulet9768c262018-10-22 09:34:31 +02001343 chn_htx = htx_from_buf(buf);
1344
Christopher Faulet51dbc942018-09-13 09:05:15 +02001345 if (!h1_get_buf(h1c, &h1c->obuf)) {
1346 h1c->flags |= H1C_F_OUT_ALLOC;
1347 goto end;
1348 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001349
Christopher Fauletf2824e62018-10-01 12:12:37 +02001350 if (!conn_is_back(h1c->conn)) {
1351 h1m = &h1s->res;
1352 errflag = H1S_F_RES_ERROR;
1353 }
1354 else {
1355 h1m = &h1s->req;
1356 errflag = H1S_F_REQ_ERROR;
1357 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001358
1359
1360 tmp = get_trash_chunk();
Willy Tarreauc5efa332018-12-05 11:19:27 +01001361
1362 /* pre-align the output buffer like the HTX in case it's empty. In this
1363 * case since it's aligned we don't need to use the temporary trash.
1364 */
1365 if (!b_data(&h1c->obuf)) {
1366 h1c->obuf.head = sizeof(struct htx);
1367 tmp->area = h1c->obuf.area + h1c->obuf.head;
1368 }
1369
Christopher Faulet9768c262018-10-22 09:34:31 +02001370 tmp->size = b_room(&h1c->obuf);
1371
1372 blk = htx_get_head_blk(chn_htx);
Christopher Fauletb2e84162018-12-06 11:39:49 +01001373 while (count && !(h1s->flags & errflag) && blk) {
Christopher Faulet570d1612018-11-26 11:13:57 +01001374 struct htx_sl *sl;
Christopher Faulet9768c262018-10-22 09:34:31 +02001375 struct ist n, v;
Christopher Fauletb2e84162018-12-06 11:39:49 +01001376 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Faulet9768c262018-10-22 09:34:31 +02001377 uint32_t sz = htx_get_blksz(blk);
Christopher Fauletb2e84162018-12-06 11:39:49 +01001378 uint32_t vlen;
Christopher Faulet9768c262018-10-22 09:34:31 +02001379
Christopher Fauletb2e84162018-12-06 11:39:49 +01001380 vlen = sz;
1381 if (vlen > count) {
1382 if (type != HTX_BLK_DATA && type != HTX_BLK_TLR)
1383 goto copy;
1384 vlen = count;
1385 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001386
Christopher Fauletb2e84162018-12-06 11:39:49 +01001387 switch (type) {
Christopher Faulet9768c262018-10-22 09:34:31 +02001388 case HTX_BLK_UNUSED:
Christopher Faulet129817b2018-09-20 16:14:40 +02001389 break;
Christopher Faulet9768c262018-10-22 09:34:31 +02001390
1391 case HTX_BLK_REQ_SL:
Christopher Faulet66229af2018-11-28 16:06:57 +01001392 h1m_init_req(h1m);
1393 h1m->flags |= H1_MF_NO_PHDR;
Christopher Faulet9768c262018-10-22 09:34:31 +02001394 sl = htx_get_blk_ptr(chn_htx, blk);
Christopher Faulet570d1612018-11-26 11:13:57 +01001395 h1s->meth = sl->info.req.meth;
Christopher Faulet9768c262018-10-22 09:34:31 +02001396 h1_parse_req_vsn(h1m, sl);
Christopher Fauletc59ff232018-12-03 13:58:44 +01001397 if (!htx_reqline_to_h1(sl, tmp))
Christopher Faulet9768c262018-10-22 09:34:31 +02001398 goto copy;
1399 h1m->flags |= H1_MF_XFER_LEN;
1400 h1m->state = H1_MSG_HDR_FIRST;
Christopher Faulet129817b2018-09-20 16:14:40 +02001401 break;
Christopher Faulet129817b2018-09-20 16:14:40 +02001402
Christopher Faulet9768c262018-10-22 09:34:31 +02001403 case HTX_BLK_RES_SL:
Christopher Faulet66229af2018-11-28 16:06:57 +01001404 h1m_init_res(h1m);
1405 h1m->flags |= H1_MF_NO_PHDR;
Christopher Faulet9768c262018-10-22 09:34:31 +02001406 sl = htx_get_blk_ptr(chn_htx, blk);
Christopher Faulet570d1612018-11-26 11:13:57 +01001407 h1s->status = sl->info.res.status;
Christopher Faulet9768c262018-10-22 09:34:31 +02001408 h1_parse_res_vsn(h1m, sl);
Christopher Fauletc59ff232018-12-03 13:58:44 +01001409 if (!htx_stline_to_h1(sl, tmp))
Christopher Faulet9768c262018-10-22 09:34:31 +02001410 goto copy;
Christopher Faulet03599112018-11-27 11:21:21 +01001411 if (sl->flags & HTX_SL_F_XFER_LEN)
Christopher Faulet9768c262018-10-22 09:34:31 +02001412 h1m->flags |= H1_MF_XFER_LEN;
Christopher Fauletd1ebb1e2018-11-28 16:32:50 +01001413 if (sl->info.res.status < 200 &&
1414 (sl->info.res.status == 100 || sl->info.res.status >= 102))
1415 process_conn_mode = 0;
Christopher Faulet9768c262018-10-22 09:34:31 +02001416 h1m->state = H1_MSG_HDR_FIRST;
1417 break;
1418
1419 case HTX_BLK_HDR:
Christopher Faulet9768c262018-10-22 09:34:31 +02001420 h1m->state = H1_MSG_HDR_NAME;
1421 n = htx_get_blk_name(chn_htx, blk);
1422 v = htx_get_blk_value(chn_htx, blk);
1423
1424 if (isteqi(n, ist("transfer-encoding")))
1425 h1_parse_xfer_enc_header(h1m, v);
1426 else if (isteqi(n, ist("connection"))) {
1427 h1_parse_connection_header(h1m, v);
1428 h1_process_conn_mode(h1s, h1m, NULL, &v);
Christopher Fauletd1ebb1e2018-11-28 16:32:50 +01001429 process_conn_mode = 0;
Christopher Faulet9768c262018-10-22 09:34:31 +02001430 if (!v.len)
1431 goto skip_hdr;
1432 }
1433
Christopher Fauletc59ff232018-12-03 13:58:44 +01001434 if (!htx_hdr_to_h1(n, v, tmp))
Christopher Faulet9768c262018-10-22 09:34:31 +02001435 goto copy;
1436 skip_hdr:
1437 h1m->state = H1_MSG_HDR_L2_LWS;
1438 break;
1439
1440 case HTX_BLK_PHDR:
1441 /* not implemented yet */
1442 h1m->flags |= errflag;
1443 break;
1444
1445 case HTX_BLK_EOH:
Christopher Fauletde68b132018-12-10 11:21:47 +01001446 if (h1m->state != H1_MSG_LAST_LF && process_conn_mode) {
Christopher Fauletd1ebb1e2018-11-28 16:32:50 +01001447 /* There is no "Connection:" header and
1448 * it the conn_mode must be
1449 * processed. So do it */
1450 n = ist("Connection");
1451 v = ist("");
1452 h1_process_conn_mode(h1s, h1m, NULL, &v);
1453 process_conn_mode = 0;
1454 if (v.len) {
Christopher Fauletc59ff232018-12-03 13:58:44 +01001455 if (!htx_hdr_to_h1(n, v, tmp))
Christopher Fauletd1ebb1e2018-11-28 16:32:50 +01001456 goto copy;
1457 }
1458 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001459 h1m->state = H1_MSG_LAST_LF;
1460 if (!chunk_memcat(tmp, "\r\n", 2))
1461 goto copy;
1462
1463 h1m->state = H1_MSG_DATA;
1464 break;
1465
1466 case HTX_BLK_DATA:
1467 v = htx_get_blk_value(chn_htx, blk);
Christopher Fauletb2e84162018-12-06 11:39:49 +01001468 v.len = vlen;
Christopher Fauletc59ff232018-12-03 13:58:44 +01001469 if (!htx_data_to_h1(v, tmp, !!(h1m->flags & H1_MF_CHNK)))
Christopher Faulet9768c262018-10-22 09:34:31 +02001470 goto copy;
1471 break;
1472
1473 case HTX_BLK_EOD:
1474 if (!chunk_memcat(tmp, "0\r\n", 3))
1475 goto copy;
Christopher Faulet32188212018-11-20 18:21:43 +01001476 h1s->flags |= H1S_F_HAVE_EOD;
Christopher Faulet9768c262018-10-22 09:34:31 +02001477 h1m->state = H1_MSG_TRAILERS;
1478 break;
1479
1480 case HTX_BLK_TLR:
Christopher Faulet32188212018-11-20 18:21:43 +01001481 if (!(h1s->flags & H1S_F_HAVE_EOD)) {
1482 if (!chunk_memcat(tmp, "0\r\n", 3))
1483 goto copy;
1484 h1s->flags |= H1S_F_HAVE_EOD;
1485 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001486 v = htx_get_blk_value(chn_htx, blk);
Christopher Fauletb2e84162018-12-06 11:39:49 +01001487 v.len = vlen;
Christopher Fauletc59ff232018-12-03 13:58:44 +01001488 if (!htx_trailer_to_h1(v, tmp))
Christopher Faulet9768c262018-10-22 09:34:31 +02001489 goto copy;
Christopher Faulet32188212018-11-20 18:21:43 +01001490 h1s->flags |= H1S_F_HAVE_TLR;
Christopher Faulet9768c262018-10-22 09:34:31 +02001491 break;
1492
1493 case HTX_BLK_EOM:
Christopher Faulet32188212018-11-20 18:21:43 +01001494 if ((h1m->flags & H1_MF_CHNK)) {
1495 if (!(h1s->flags & H1S_F_HAVE_EOD)) {
1496 if (!chunk_memcat(tmp, "0\r\n", 3))
1497 goto copy;
1498 h1s->flags |= H1S_F_HAVE_EOD;
1499 }
1500 if (!(h1s->flags & H1S_F_HAVE_TLR)) {
1501 if (!chunk_memcat(tmp, "\r\n", 2))
1502 goto copy;
1503 h1s->flags |= H1S_F_HAVE_TLR;
1504 }
1505 }
Christopher Faulet9768c262018-10-22 09:34:31 +02001506 h1m->state = H1_MSG_DONE;
1507 break;
1508
1509 case HTX_BLK_OOB:
1510 v = htx_get_blk_value(chn_htx, blk);
1511 if (!chunk_memcat(tmp, v.ptr, v.len))
1512 goto copy;
1513 break;
1514
1515 default:
1516 h1m->flags |= errflag;
1517 break;
1518 }
Christopher Fauletb2e84162018-12-06 11:39:49 +01001519 total += vlen;
1520 count -= vlen;
1521 if (sz == vlen)
1522 blk = htx_remove_blk(chn_htx, blk);
1523 else {
1524 htx_cut_data_blk(chn_htx, blk, vlen);
1525 break;
1526 }
Christopher Faulet129817b2018-09-20 16:14:40 +02001527 }
1528
Christopher Faulet9768c262018-10-22 09:34:31 +02001529 copy:
Willy Tarreauc5efa332018-12-05 11:19:27 +01001530 /* when the output buffer is empty, tmp shares the same area so that we
1531 * only have to update pointers and lengths.
1532 */
1533 if (tmp->area == h1c->obuf.area)
1534 h1c->obuf.data = tmp->data;
1535 else
1536 b_putblk(&h1c->obuf, tmp->area, tmp->data);
Christopher Faulet51dbc942018-09-13 09:05:15 +02001537
Willy Tarreau45f2b892018-12-05 07:59:27 +01001538 if (!buf_room_for_htx_data(&h1c->obuf))
Christopher Faulet51dbc942018-09-13 09:05:15 +02001539 h1c->flags |= H1C_F_OUT_FULL;
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01001540 htx_to_buf(chn_htx, buf);
Christopher Faulet9768c262018-10-22 09:34:31 +02001541 end:
1542 return total;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001543}
1544
Christopher Faulet51dbc942018-09-13 09:05:15 +02001545/*********************************************************/
1546/* functions below are I/O callbacks from the connection */
1547/*********************************************************/
1548/*
1549 * Attempt to read data, and subscribe if none available
1550 */
1551static int h1_recv(struct h1c *h1c)
1552{
1553 struct connection *conn = h1c->conn;
Christopher Fauletfeb11742018-11-29 15:12:34 +01001554 struct h1s *h1s = h1c->h1s;
Olivier Houchard75159a92018-12-03 18:46:09 +01001555 size_t ret = 0, max;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001556 int rcvd = 0;
1557
1558 if (h1c->wait_event.wait_reason & SUB_CAN_RECV)
Christopher Fauletc386a882018-12-04 16:06:28 +01001559 return (b_data(&h1c->ibuf));
Christopher Faulet51dbc942018-09-13 09:05:15 +02001560
Olivier Houchard75159a92018-12-03 18:46:09 +01001561 if (!h1_recv_allowed(h1c)) {
1562 rcvd = 1;
Christopher Faulet9768c262018-10-22 09:34:31 +02001563 goto end;
Olivier Houchard75159a92018-12-03 18:46:09 +01001564 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001565
Christopher Fauletfeb11742018-11-29 15:12:34 +01001566 if (h1s && (h1s->flags & (H1S_F_BUF_FLUSH|H1S_F_SPLICED_DATA))) {
Christopher Faulet9768c262018-10-22 09:34:31 +02001567 rcvd = 1;
1568 goto end;
1569 }
Christopher Faulet1be55f92018-10-02 15:59:23 +02001570
Christopher Faulet51dbc942018-09-13 09:05:15 +02001571 if (!h1_get_buf(h1c, &h1c->ibuf)) {
1572 h1c->flags |= H1C_F_IN_ALLOC;
Christopher Faulet9768c262018-10-22 09:34:31 +02001573 goto end;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001574 }
1575
Olivier Houchard29a22bc2018-12-04 18:16:45 +01001576 /*
1577 * If we only have a small amount of data, realign it,
1578 * it's probably cheaper than doing 2 recv() calls.
1579 */
1580 if (b_data(&h1c->ibuf) > 0 && b_data(&h1c->ibuf) < 128)
1581 b_slow_realign(&h1c->ibuf, trash.area, 0);
1582
Willy Tarreau45f2b892018-12-05 07:59:27 +01001583 max = buf_room_for_htx_data(&h1c->ibuf);
Christopher Faulet51dbc942018-09-13 09:05:15 +02001584 if (max) {
Willy Tarreau78f548f2018-12-05 10:02:39 +01001585 int aligned = 0;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001586 h1c->flags &= ~H1C_F_IN_FULL;
Willy Tarreau78f548f2018-12-05 10:02:39 +01001587
1588 if (!b_data(&h1c->ibuf)) {
1589 /* try to pre-align the buffer like the rxbufs will be
1590 * to optimize memory copies.
1591 */
1592 h1c->ibuf.data = sizeof(struct htx);
1593 aligned = 1;
1594 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001595 ret = conn->xprt->rcv_buf(conn, &h1c->ibuf, max, 0);
Willy Tarreau78f548f2018-12-05 10:02:39 +01001596 if (aligned) {
1597 h1c->ibuf.data -= sizeof(struct htx);
1598 h1c->ibuf.head = sizeof(struct htx);
1599 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001600 }
Christopher Faulet47365272018-10-31 17:40:50 +01001601 if (ret > 0) {
Christopher Faulet51dbc942018-09-13 09:05:15 +02001602 rcvd = 1;
Christopher Fauletfeb11742018-11-29 15:12:34 +01001603 if (h1s && h1s->cs) {
Christopher Faulet37e36072018-12-04 15:54:12 +01001604 h1s->cs->flags |= (CS_FL_READ_PARTIAL|CS_FL_RCV_MORE);
Christopher Fauletfeb11742018-11-29 15:12:34 +01001605 if (h1s->csinfo.t_idle == -1)
1606 h1s->csinfo.t_idle = tv_ms_elapsed(&h1s->csinfo.tv_create, &now) - h1s->csinfo.t_handshake;
1607 }
Christopher Faulet47365272018-10-31 17:40:50 +01001608 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001609
Willy Tarreau45f2b892018-12-05 07:59:27 +01001610 if (h1_recv_allowed(h1c) && buf_room_for_htx_data(&h1c->ibuf))
Christopher Faulet51dbc942018-09-13 09:05:15 +02001611 conn->xprt->subscribe(conn, SUB_CAN_RECV, &h1c->wait_event);
Christopher Faulet81d48432018-11-19 21:22:43 +01001612 else
1613 rcvd = 1;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001614
Christopher Faulet9768c262018-10-22 09:34:31 +02001615 end:
Olivier Houchard75159a92018-12-03 18:46:09 +01001616 if ((ret > 0 || (conn->flags & CO_FL_ERROR) ||
1617 conn_xprt_read0_pending(conn)) && h1s && h1s->recv_wait) {
1618 h1s->recv_wait->wait_reason &= ~SUB_CAN_RECV;
1619 tasklet_wakeup(h1s->recv_wait->task);
1620 h1s->recv_wait = NULL;
1621
1622 }
Christopher Faulete6b39942018-12-07 09:42:49 +01001623 if (conn_xprt_read0_pending(conn) && h1s && h1s->cs)
Olivier Houchard6a2d3342018-12-06 17:41:26 +01001624 h1s->cs->flags |= CS_FL_REOS;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001625 if (!b_data(&h1c->ibuf))
1626 h1_release_buf(h1c, &h1c->ibuf);
Willy Tarreau45f2b892018-12-05 07:59:27 +01001627 else if (!buf_room_for_htx_data(&h1c->ibuf))
Christopher Faulet51dbc942018-09-13 09:05:15 +02001628 h1c->flags |= H1C_F_IN_FULL;
1629 return rcvd;
1630}
1631
1632
1633/*
1634 * Try to send data if possible
1635 */
1636static int h1_send(struct h1c *h1c)
1637{
1638 struct connection *conn = h1c->conn;
1639 unsigned int flags = 0;
1640 size_t ret;
1641 int sent = 0;
1642
1643 if (conn->flags & CO_FL_ERROR)
1644 return 0;
1645
Christopher Faulet3b88b8d2018-10-26 17:36:03 +02001646 if (h1c->flags & H1C_F_CS_WAIT_CONN) {
1647 if (!(h1c->wait_event.wait_reason & SUB_CAN_SEND))
1648 conn->xprt->subscribe(conn, SUB_CAN_SEND, &h1c->wait_event);
1649 return 0;
1650 }
1651
Christopher Faulet51dbc942018-09-13 09:05:15 +02001652 if (!b_data(&h1c->obuf))
1653 goto end;
1654
1655 if (h1c->flags & H1C_F_OUT_FULL)
1656 flags |= CO_SFL_MSG_MORE;
1657
1658 ret = conn->xprt->snd_buf(conn, &h1c->obuf, b_data(&h1c->obuf), flags);
1659 if (ret > 0) {
1660 h1c->flags &= ~H1C_F_OUT_FULL;
1661 b_del(&h1c->obuf, ret);
1662 sent = 1;
1663 }
1664
Christopher Faulet145aa472018-12-06 10:56:20 +01001665 if (conn->flags & (CO_FL_ERROR|CO_FL_SOCK_WR_SH)) {
1666 /* error or output closed, nothing to send, clear the buffer to release it */
1667 b_reset(&h1c->obuf);
1668 }
1669
Christopher Faulet51dbc942018-09-13 09:05:15 +02001670 end:
Olivier Houchard75159a92018-12-03 18:46:09 +01001671 if (!(h1c->flags & H1C_F_OUT_FULL) && h1c->h1s && h1c->h1s->send_wait) {
1672 struct h1s *h1s = h1c->h1s;
1673
1674 h1s->send_wait->wait_reason &= ~SUB_CAN_SEND;
1675 tasklet_wakeup(h1s->send_wait->task);
1676 h1s->send_wait = NULL;
1677 }
Christopher Faulet51dbc942018-09-13 09:05:15 +02001678 /* We're done, no more to send */
1679 if (!b_data(&h1c->obuf)) {
1680 h1_release_buf(h1c, &h1c->obuf);
Christopher Fauletf2824e62018-10-01 12:12:37 +02001681 h1_sync_messages(h1c);
Christopher Faulet51dbc942018-09-13 09:05:15 +02001682 if (h1c->flags & H1C_F_CS_SHUTW_NOW)
1683 h1_shutw_conn(conn);
1684 }
1685 else if (!(h1c->wait_event.wait_reason & SUB_CAN_SEND))
1686 conn->xprt->subscribe(conn, SUB_CAN_SEND, &h1c->wait_event);
1687
1688 return sent;
1689}
1690
Christopher Faulet51dbc942018-09-13 09:05:15 +02001691
1692/* callback called on any event by the connection handler.
1693 * It applies changes and returns zero, or < 0 if it wants immediate
1694 * destruction of the connection.
1695 */
1696static int h1_process(struct h1c * h1c)
1697{
1698 struct connection *conn = h1c->conn;
Christopher Fauletfeb11742018-11-29 15:12:34 +01001699 struct h1s *h1s = h1c->h1s;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001700
Christopher Faulet51dbc942018-09-13 09:05:15 +02001701 if (!conn->mux_ctx)
1702 return -1;
1703
Christopher Faulet3b88b8d2018-10-26 17:36:03 +02001704 if (h1c->flags & H1C_F_CS_WAIT_CONN) {
Christopher Faulet539e0292018-11-19 10:40:09 +01001705 if (!(conn->flags & (CO_FL_CONNECTED|CO_FL_ERROR)))
1706 goto end;
1707 h1c->flags &= ~H1C_F_CS_WAIT_CONN;
Christopher Faulet3b88b8d2018-10-26 17:36:03 +02001708 }
1709
Christopher Fauletfeb11742018-11-29 15:12:34 +01001710 if (!h1s) {
Christopher Faulet539e0292018-11-19 10:40:09 +01001711 if (h1c->flags & H1C_F_CS_ERROR ||
1712 conn->flags & CO_FL_ERROR ||
1713 conn_xprt_read0_pending(conn))
1714 goto release;
Christopher Faulet81d48432018-11-19 21:22:43 +01001715 if (!conn_is_back(conn) && !(h1c->flags & (H1C_F_CS_SHUTW_NOW|H1C_F_CS_SHUTW))) {
Christopher Faulet539e0292018-11-19 10:40:09 +01001716 if (!h1s_create(h1c, NULL))
1717 goto release;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001718 }
Christopher Faulet1a7ad7a2018-12-04 16:10:44 +01001719 else
Olivier Houcharde7284782018-12-06 18:54:54 +01001720 goto end;
Christopher Fauletfeb11742018-11-29 15:12:34 +01001721 h1s = h1c->h1s;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001722 }
1723
Christopher Fauletfeb11742018-11-29 15:12:34 +01001724 if (b_data(&h1c->ibuf) && h1s->csinfo.t_idle == -1)
1725 h1s->csinfo.t_idle = tv_ms_elapsed(&h1s->csinfo.tv_create, &now) - h1s->csinfo.t_handshake;
1726
Olivier Houchard75159a92018-12-03 18:46:09 +01001727 if (!b_data(&h1c->ibuf) && h1s && h1s->cs && h1s->cs->data_cb->wake &&
1728 (conn_xprt_read0_pending(conn) || h1c->flags & H1C_F_CS_ERROR ||
1729 conn->flags & CO_FL_ERROR)) {
1730 int flags = 0;
1731
1732 if (h1c->flags & H1C_F_CS_ERROR || conn->flags & CO_FL_ERROR)
1733 flags |= CS_FL_ERROR;
1734 if (conn_xprt_read0_pending(conn))
Christopher Faulet5f50f5e2018-12-07 11:39:55 +01001735 flags |= CS_FL_EOS;
Olivier Houchard75159a92018-12-03 18:46:09 +01001736 h1s->cs->flags |= flags;
1737 h1s->cs->data_cb->wake(h1s->cs);
1738 }
Christopher Faulet47365272018-10-31 17:40:50 +01001739 end:
Christopher Faulet51dbc942018-09-13 09:05:15 +02001740 return 0;
Christopher Faulet539e0292018-11-19 10:40:09 +01001741
1742 release:
1743 h1_release(conn);
1744 return -1;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001745}
1746
1747static struct task *h1_io_cb(struct task *t, void *ctx, unsigned short status)
1748{
1749 struct h1c *h1c = ctx;
1750 int ret = 0;
1751
1752 if (!(h1c->wait_event.wait_reason & SUB_CAN_SEND))
1753 ret = h1_send(h1c);
1754 if (!(h1c->wait_event.wait_reason & SUB_CAN_RECV))
1755 ret |= h1_recv(h1c);
Christopher Faulet81d48432018-11-19 21:22:43 +01001756 if (ret || !h1c->h1s)
Christopher Faulet51dbc942018-09-13 09:05:15 +02001757 h1_process(h1c);
1758 return NULL;
1759}
1760
1761
1762static int h1_wake(struct connection *conn)
1763{
1764 struct h1c *h1c = conn->mux_ctx;
Olivier Houchard75159a92018-12-03 18:46:09 +01001765 int ret;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001766
Christopher Faulet539e0292018-11-19 10:40:09 +01001767 h1_send(h1c);
Olivier Houchard75159a92018-12-03 18:46:09 +01001768 ret = h1_process(h1c);
1769 if (ret == 0) {
1770 struct h1s *h1s = h1c->h1s;
1771
1772 if (h1s && h1s->cs && h1s->cs->data_cb->wake)
1773 ret = h1s->cs->data_cb->wake(h1s->cs);
1774 }
1775 return ret;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001776}
1777
Christopher Faulet51dbc942018-09-13 09:05:15 +02001778/*******************************************/
1779/* functions below are used by the streams */
1780/*******************************************/
1781/*
1782 * Attach a new stream to a connection
1783 * (Used for outgoing connections)
1784 */
1785static struct conn_stream *h1_attach(struct connection *conn)
1786{
1787 struct h1c *h1c = conn->mux_ctx;
1788 struct conn_stream *cs = NULL;
1789 struct h1s *h1s;
1790
1791 if (h1c->flags & H1C_F_CS_ERROR)
1792 goto end;
1793
1794 cs = cs_new(h1c->conn);
1795 if (!cs)
1796 goto end;
1797
Christopher Fauletf2824e62018-10-01 12:12:37 +02001798 h1s = h1s_create(h1c, cs);
Christopher Faulet51dbc942018-09-13 09:05:15 +02001799 if (h1s == NULL)
1800 goto end;
1801
1802 return cs;
1803 end:
1804 cs_free(cs);
1805 return NULL;
1806}
1807
1808/* Retrieves a valid conn_stream from this connection, or returns NULL. For
1809 * this mux, it's easy as we can only store a single conn_stream.
1810 */
1811static const struct conn_stream *h1_get_first_cs(const struct connection *conn)
1812{
1813 struct h1c *h1c = conn->mux_ctx;
1814 struct h1s *h1s = h1c->h1s;
1815
1816 if (h1s)
1817 return h1s->cs;
1818
1819 return NULL;
1820}
1821
1822static void h1_destroy(struct connection *conn)
1823{
1824 struct h1c *h1c = conn->mux_ctx;
1825
1826 if (!h1c->h1s)
1827 h1_release(conn);
1828}
1829
1830/*
1831 * Detach the stream from the connection and possibly release the connection.
1832 */
1833static void h1_detach(struct conn_stream *cs)
1834{
1835 struct h1s *h1s = cs->ctx;
1836 struct h1c *h1c;
1837
1838 cs->ctx = NULL;
1839 if (!h1s)
1840 return;
1841
1842 h1c = h1s->h1c;
1843 h1s->cs = NULL;
1844
Olivier Houchard7ccff1a2018-12-03 16:33:19 +01001845 if (conn_is_back(h1c->conn) && (h1s->flags & H1S_F_WANT_KAL) && h1c->conn->owner) {
Christopher Faulet9400a392018-11-23 23:10:39 +01001846 /* Never ever allow to reuse a connection from a non-reuse backend */
1847 if (h1c->conn && (h1c->px->options & PR_O_REUSE_MASK) == PR_O_REUSE_NEVR)
1848 h1c->conn->flags |= CO_FL_PRIVATE;
1849
1850 /* we're in keep-alive with an idle connection, monitor it if not already done */
1851 if (h1c->conn && LIST_ISEMPTY(&h1c->conn->list)) {
1852 struct server *srv = objt_server(h1c->conn->target);
1853
1854 if (srv) {
1855 if (h1c->conn->flags & CO_FL_PRIVATE)
1856 LIST_ADD(&srv->priv_conns[tid], &h1c->conn->list);
1857 else if (h1s->flags & H1S_F_NOT_FIRST)
1858 LIST_ADD(&srv->safe_conns[tid], &h1c->conn->list);
1859 else
1860 LIST_ADD(&srv->idle_conns[tid], &h1c->conn->list);
1861 }
1862 }
1863 }
1864
Christopher Faulet51dbc942018-09-13 09:05:15 +02001865 h1s_destroy(h1s);
1866
1867 /* We don't want to close right now unless the connection is in error */
1868 if ((h1c->flags & (H1C_F_CS_ERROR|H1C_F_CS_SHUTW)) ||
Olivier Houchard7ccff1a2018-12-03 16:33:19 +01001869 (h1c->conn->flags & CO_FL_ERROR) || !h1c->conn->owner)
Christopher Faulet51dbc942018-09-13 09:05:15 +02001870 h1_release(h1c->conn);
1871 else
1872 tasklet_wakeup(h1c->wait_event.task);
1873}
1874
1875
1876static void h1_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
1877{
1878 struct h1s *h1s = cs->ctx;
1879
1880 if (!h1s)
1881 return;
1882
Christopher Fauletf2824e62018-10-01 12:12:37 +02001883 if ((h1s->flags & H1S_F_WANT_KAL) && !(cs->flags & (CS_FL_REOS|CS_FL_EOS)))
1884 return;
1885
Christopher Faulet51dbc942018-09-13 09:05:15 +02001886 /* NOTE: Be sure to handle abort (cf. h2_shutr) */
1887 if (cs->flags & CS_FL_SHR)
1888 return;
1889 if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutr)
1890 cs->conn->xprt->shutr(cs->conn, (mode == CS_SHR_DRAIN));
1891 if (cs->flags & CS_FL_SHW) {
1892 h1s->h1c->flags = (h1s->h1c->flags & ~H1C_F_CS_SHUTW_NOW) | H1C_F_CS_SHUTW;
1893 conn_full_close(cs->conn);
1894 }
1895}
1896
1897static void h1_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
1898{
1899 struct h1s *h1s = cs->ctx;
1900 struct h1c *h1c;
1901
1902 if (!h1s)
1903 return;
1904 h1c = h1s->h1c;
1905
Christopher Fauletf2824e62018-10-01 12:12:37 +02001906 if ((h1s->flags & H1S_F_WANT_KAL) &&
1907 !(cs->flags & (CS_FL_REOS|CS_FL_EOS)) &&
1908 h1s->req.state == H1_MSG_DONE && h1s->res.state == H1_MSG_DONE)
1909 return;
1910
Christopher Faulet51dbc942018-09-13 09:05:15 +02001911 h1c->flags |= H1C_F_CS_SHUTW_NOW;
1912 if ((cs->flags & CS_FL_SHW) || b_data(&h1c->obuf))
1913 return;
1914
1915 h1_shutw_conn(cs->conn);
1916}
1917
1918static void h1_shutw_conn(struct connection *conn)
1919{
1920 struct h1c *h1c = conn->mux_ctx;
1921
1922 if (conn_xprt_ready(conn) && conn->xprt->shutw)
1923 conn->xprt->shutw(conn, 1);
1924 if (!(conn->flags & CO_FL_SOCK_RD_SH))
1925 conn_sock_shutw(conn, 1);
1926 else {
1927 h1c->flags = (h1c->flags & ~H1C_F_CS_SHUTW_NOW) | H1C_F_CS_SHUTW;
1928 conn_full_close(conn);
1929 }
1930}
1931
1932/* Called from the upper layer, to unsubscribe to events */
1933static int h1_unsubscribe(struct conn_stream *cs, int event_type, void *param)
1934{
1935 struct wait_event *sw;
1936 struct h1s *h1s = cs->ctx;
1937
1938 if (!h1s)
1939 return 0;
1940
1941 if (event_type & SUB_CAN_RECV) {
1942 sw = param;
1943 if (h1s->recv_wait == sw) {
1944 sw->wait_reason &= ~SUB_CAN_RECV;
1945 h1s->recv_wait = NULL;
1946 }
1947 }
1948 if (event_type & SUB_CAN_SEND) {
1949 sw = param;
1950 if (h1s->send_wait == sw) {
1951 sw->wait_reason &= ~SUB_CAN_SEND;
1952 h1s->send_wait = NULL;
1953 }
1954 }
1955 return 0;
1956}
1957
1958/* Called from the upper layer, to subscribe to events, such as being able to send */
1959static int h1_subscribe(struct conn_stream *cs, int event_type, void *param)
1960{
1961 struct wait_event *sw;
1962 struct h1s *h1s = cs->ctx;
1963
1964 if (!h1s)
1965 return -1;
1966
1967 switch (event_type) {
1968 case SUB_CAN_RECV:
1969 sw = param;
1970 if (!(sw->wait_reason & SUB_CAN_RECV)) {
1971 sw->wait_reason |= SUB_CAN_RECV;
1972 sw->handle = h1s;
1973 h1s->recv_wait = sw;
1974 }
1975 return 0;
1976 case SUB_CAN_SEND:
1977 sw = param;
1978 if (!(sw->wait_reason & SUB_CAN_SEND)) {
1979 sw->wait_reason |= SUB_CAN_SEND;
1980 sw->handle = h1s;
1981 h1s->send_wait = sw;
1982 }
1983 return 0;
1984 default:
1985 break;
1986 }
1987 return -1;
1988}
1989
1990/* Called from the upper layer, to receive data */
1991static size_t h1_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
1992{
1993 struct h1s *h1s = cs->ctx;
Christopher Faulet539e0292018-11-19 10:40:09 +01001994 struct h1c *h1c = h1s->h1c;
Christopher Faulet51dbc942018-09-13 09:05:15 +02001995 size_t ret = 0;
1996
Christopher Faulet539e0292018-11-19 10:40:09 +01001997 if (!(h1c->flags & H1C_F_IN_ALLOC))
1998 ret = h1_process_input(h1c, buf, flags);
Christopher Faulet1be55f92018-10-02 15:59:23 +02001999
2000 if (flags & CO_RFL_BUF_FLUSH)
2001 h1s->flags |= H1S_F_BUF_FLUSH;
Christopher Fauletd44ad5b2018-11-19 21:52:12 +01002002 else if (ret > 0 || (h1s->flags & H1S_F_SPLICED_DATA)) {
2003 h1s->flags &= ~H1S_F_SPLICED_DATA;
Christopher Faulet539e0292018-11-19 10:40:09 +01002004 if (!(h1c->wait_event.wait_reason & SUB_CAN_RECV))
2005 tasklet_wakeup(h1c->wait_event.task);
Christopher Faulet51dbc942018-09-13 09:05:15 +02002006 }
2007 return ret;
2008}
2009
2010
2011/* Called from the upper layer, to send data */
2012static size_t h1_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
2013{
2014 struct h1s *h1s = cs->ctx;
2015 struct h1c *h1c;
Christopher Faulet5d37dac2018-11-22 10:58:42 +01002016 size_t total = 0;
Christopher Faulet51dbc942018-09-13 09:05:15 +02002017
2018 if (!h1s)
Christopher Faulet5d37dac2018-11-22 10:58:42 +01002019 return 0;
Christopher Faulet51dbc942018-09-13 09:05:15 +02002020
2021 h1c = h1s->h1c;
Christopher Faulet3b88b8d2018-10-26 17:36:03 +02002022 if (h1c->flags & H1C_F_CS_WAIT_CONN)
2023 return 0;
Christopher Faulet51dbc942018-09-13 09:05:15 +02002024
Christopher Faulet5d37dac2018-11-22 10:58:42 +01002025 while (total != count) {
2026 size_t ret = 0;
Christopher Faulet51dbc942018-09-13 09:05:15 +02002027
Christopher Faulet5d37dac2018-11-22 10:58:42 +01002028 if (!(h1c->flags & (H1C_F_OUT_FULL|H1C_F_OUT_ALLOC)))
2029 ret = h1_process_output(h1c, buf, count);
2030 if (!ret)
2031 break;
2032 total += ret;
2033 if (!h1_send(h1c))
2034 break;
Christopher Faulet51dbc942018-09-13 09:05:15 +02002035 }
Christopher Fauletf96c3222018-11-20 18:38:01 +01002036
Christopher Faulet5d37dac2018-11-22 10:58:42 +01002037 return total;
Christopher Faulet51dbc942018-09-13 09:05:15 +02002038}
2039
Christopher Faulet1be55f92018-10-02 15:59:23 +02002040#if defined(CONFIG_HAP_LINUX_SPLICE)
2041/* Send and get, using splicing */
2042static int h1_rcv_pipe(struct conn_stream *cs, struct pipe *pipe, unsigned int count)
2043{
2044 struct h1s *h1s = cs->ctx;
2045 struct h1m *h1m = (!conn_is_back(cs->conn) ? &h1s->req : &h1s->res);
2046 int ret = 0;
2047
Christopher Fauletd44ad5b2018-11-19 21:52:12 +01002048 if (b_data(&h1s->h1c->ibuf)) {
2049 h1s->flags |= H1S_F_BUF_FLUSH;
Christopher Faulet1be55f92018-10-02 15:59:23 +02002050 goto end;
Christopher Fauletd44ad5b2018-11-19 21:52:12 +01002051 }
2052
2053 h1s->flags &= ~H1S_F_BUF_FLUSH;
2054 h1s->flags |= H1S_F_SPLICED_DATA;
Christopher Faulet1be55f92018-10-02 15:59:23 +02002055 if (h1m->state == H1_MSG_DATA && count > h1m->curr_len)
2056 count = h1m->curr_len;
2057 ret = cs->conn->xprt->rcv_pipe(cs->conn, pipe, count);
2058 if (h1m->state == H1_MSG_DATA && ret > 0)
2059 h1m->curr_len -= ret;
2060 end:
2061 return ret;
2062
2063}
2064
2065static int h1_snd_pipe(struct conn_stream *cs, struct pipe *pipe)
2066{
2067 struct h1s *h1s = cs->ctx;
Christopher Faulet1be55f92018-10-02 15:59:23 +02002068 int ret = 0;
2069
2070 if (b_data(&h1s->h1c->obuf))
2071 goto end;
2072
2073 ret = cs->conn->xprt->snd_pipe(cs->conn, pipe);
Christopher Faulet1be55f92018-10-02 15:59:23 +02002074 end:
Christopher Fauletd44ad5b2018-11-19 21:52:12 +01002075 if (pipe->data) {
2076 if (!(h1s->h1c->wait_event.wait_reason & SUB_CAN_SEND))
2077 cs->conn->xprt->subscribe(cs->conn, SUB_CAN_SEND, &h1s->h1c->wait_event);
2078 }
Christopher Faulet1be55f92018-10-02 15:59:23 +02002079 return ret;
2080}
2081#endif
2082
Christopher Faulet51dbc942018-09-13 09:05:15 +02002083/****************************************/
2084/* MUX initialization and instanciation */
2085/****************************************/
2086
2087/* The mux operations */
2088const struct mux_ops mux_h1_ops = {
2089 .init = h1_init,
2090 .wake = h1_wake,
2091 .attach = h1_attach,
2092 .get_first_cs = h1_get_first_cs,
Christopher Fauletfeb11742018-11-29 15:12:34 +01002093 .get_cs_info = h1_get_cs_info,
Christopher Faulet51dbc942018-09-13 09:05:15 +02002094 .detach = h1_detach,
2095 .destroy = h1_destroy,
2096 .avail_streams = h1_avail_streams,
Olivier Houchard8defe4b2018-12-02 01:31:17 +01002097 .max_streams = h1_max_streams,
Christopher Faulet51dbc942018-09-13 09:05:15 +02002098 .rcv_buf = h1_rcv_buf,
2099 .snd_buf = h1_snd_buf,
Christopher Faulet1be55f92018-10-02 15:59:23 +02002100#if defined(CONFIG_HAP_LINUX_SPLICE)
2101 .rcv_pipe = h1_rcv_pipe,
2102 .snd_pipe = h1_snd_pipe,
2103#endif
Christopher Faulet51dbc942018-09-13 09:05:15 +02002104 .subscribe = h1_subscribe,
2105 .unsubscribe = h1_unsubscribe,
2106 .shutr = h1_shutr,
2107 .shutw = h1_shutw,
2108 .flags = MX_FL_NONE,
2109 .name = "h1",
2110};
2111
2112
2113/* this mux registers default HTX proto */
2114static struct mux_proto_list mux_proto_htx =
2115{ .token = IST(""), .mode = PROTO_MODE_HTX, .side = PROTO_SIDE_BOTH, .mux = &mux_h1_ops };
2116
Willy Tarreau0108d902018-11-25 19:14:37 +01002117INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_htx);
2118
Christopher Faulet51dbc942018-09-13 09:05:15 +02002119/*
2120 * Local variables:
2121 * c-indent-level: 8
2122 * c-basic-offset: 8
2123 * End:
2124 */