From 7e98c057ff76f399be5de17d8bca98c954eb2bbb Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 10 Oct 2017 15:56:59 +0200 Subject: [PATCH] MINOR: h2: create a stream parser for the demuxer The function h2_process_demux() now tries to parse the incoming bytes to process as many streams as possible. For now it does nothing but dropping all incoming frames. --- src/mux_h2.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/mux_h2.c b/src/mux_h2.c index 71111eb53..f7319d054 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -807,7 +807,58 @@ static void h2_process_demux(struct h2c *h2c) h2c->st0 = H2_CS_FRAME_P; } } - return; + + /* process as many incoming frames as possible below */ + while (h2c->dbuf->i) { + int ret = 0; + + if (h2c->st0 >= H2_CS_ERROR) + break; + + if (h2c->st0 == H2_CS_FRAME_H) { + struct h2_fh hdr; + + if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) + break; + + if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); + h2c->st0 = H2_CS_ERROR; + break; + } + + h2c->dfl = hdr.len; + h2c->dsi = hdr.sid; + h2c->dft = hdr.ft; + h2c->dff = hdr.ff; + h2c->st0 = H2_CS_FRAME_P; + h2_skip_frame_hdr(h2c->dbuf); + } + + /* Only H2_CS_FRAME_P and H2_CS_FRAME_A here */ + + switch (h2c->dft) { + /* FIXME: implement all supported frame types here */ + default: + /* drop frames that we ignore. They may be larger than + * the buffer so we drain all of their contents until + * we reach the end. + */ + ret = MIN(h2c->dbuf->i, h2c->dfl); + bi_del(h2c->dbuf, ret); + h2c->dfl -= ret; + ret = h2c->dfl == 0; + } + + /* error or missing data condition met above ? */ + if (ret <= 0) + break; + + if (h2c->st0 != H2_CS_FRAME_H) { + bi_del(h2c->dbuf, h2c->dfl); + h2c->st0 = H2_CS_FRAME_H; + } + } fail: /* we can go here on missing data, blocked response or error */