2021-11-12 15:09:54 +00:00
|
|
|
#include <haproxy/hq_interop.h>
|
|
|
|
|
|
|
|
#include <import/ist.h>
|
|
|
|
#include <haproxy/buf.h>
|
|
|
|
#include <haproxy/connection.h>
|
|
|
|
#include <haproxy/dynbuf.h>
|
|
|
|
#include <haproxy/htx.h>
|
|
|
|
#include <haproxy/http.h>
|
2022-04-04 14:13:44 +00:00
|
|
|
#include <haproxy/mux_quic.h>
|
2021-11-12 15:09:54 +00:00
|
|
|
|
2022-06-07 15:30:55 +00:00
|
|
|
static ssize_t hq_interop_decode_qcs(struct qcs *qcs, struct buffer *b, int fin)
|
2021-11-12 15:09:54 +00:00
|
|
|
{
|
|
|
|
struct htx *htx;
|
|
|
|
struct htx_sl *sl;
|
|
|
|
struct buffer htx_buf = BUF_NULL;
|
|
|
|
struct ist path;
|
2022-06-03 14:40:34 +00:00
|
|
|
char *ptr = b_head(b);
|
|
|
|
char *end = b_wrap(b);
|
|
|
|
size_t size = b_size(b);
|
|
|
|
size_t data = b_data(b);
|
2021-11-12 15:09:54 +00:00
|
|
|
|
|
|
|
b_alloc(&htx_buf);
|
|
|
|
htx = htx_from_buf(&htx_buf);
|
|
|
|
|
|
|
|
/* skip method */
|
2021-12-15 21:38:48 +00:00
|
|
|
while (data && HTTP_IS_TOKEN(*ptr)) {
|
|
|
|
if (++ptr == end)
|
|
|
|
ptr -= size;
|
|
|
|
data--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data || !HTTP_IS_SPHT(*ptr)) {
|
|
|
|
fprintf(stderr, "truncated stream\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++ptr == end)
|
|
|
|
ptr -= size;
|
|
|
|
|
|
|
|
if (!--data) {
|
|
|
|
fprintf(stderr, "truncated stream\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2021-11-12 15:09:54 +00:00
|
|
|
|
|
|
|
/* extract path */
|
|
|
|
BUG_ON(HTTP_IS_LWS(*ptr));
|
|
|
|
path.ptr = ptr;
|
2021-12-15 21:38:48 +00:00
|
|
|
while (data && !HTTP_IS_LWS(*ptr)) {
|
|
|
|
if (++ptr == end)
|
|
|
|
ptr -= size;
|
|
|
|
data--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
fprintf(stderr, "truncated stream\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-12 15:09:54 +00:00
|
|
|
BUG_ON(!HTTP_IS_LWS(*ptr));
|
|
|
|
path.len = ptr - path.ptr;
|
|
|
|
|
|
|
|
sl = htx_add_stline(htx, HTX_BLK_REQ_SL, 0, ist("GET"), path, ist("HTTP/1.0"));
|
2021-11-18 13:40:26 +00:00
|
|
|
if (!sl)
|
2022-06-07 15:30:55 +00:00
|
|
|
return -1;
|
2021-11-18 13:40:26 +00:00
|
|
|
|
2021-11-12 15:09:54 +00:00
|
|
|
sl->flags |= HTX_SL_F_BODYLESS;
|
|
|
|
sl->info.req.meth = find_http_meth("GET", 3);
|
|
|
|
|
|
|
|
htx_add_endof(htx, HTX_BLK_EOH);
|
|
|
|
htx_to_buf(htx, &htx_buf);
|
|
|
|
|
2022-09-15 09:22:32 +00:00
|
|
|
if (!qc_attach_sc(qcs, &htx_buf))
|
2022-06-07 15:30:55 +00:00
|
|
|
return -1;
|
2021-11-12 15:09:54 +00:00
|
|
|
|
|
|
|
b_free(&htx_buf);
|
|
|
|
|
2021-11-30 10:23:29 +00:00
|
|
|
if (fin)
|
|
|
|
htx->flags |= HTX_FL_EOM;
|
|
|
|
|
2022-06-07 15:30:55 +00:00
|
|
|
return b_data(b);
|
2021-11-12 15:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct buffer *mux_get_buf(struct qcs *qcs)
|
|
|
|
{
|
|
|
|
if (!b_size(&qcs->tx.buf))
|
|
|
|
b_alloc(&qcs->tx.buf);
|
|
|
|
|
|
|
|
return &qcs->tx.buf;
|
|
|
|
}
|
|
|
|
|
2022-09-15 09:22:32 +00:00
|
|
|
static size_t hq_interop_snd_buf(struct qcs *qcs, struct buffer *buf,
|
2021-11-12 15:09:54 +00:00
|
|
|
size_t count, int flags)
|
|
|
|
{
|
|
|
|
struct htx *htx;
|
|
|
|
enum htx_blk_type btype;
|
|
|
|
struct htx_blk *blk;
|
|
|
|
int32_t idx;
|
|
|
|
uint32_t bsize, fsize;
|
|
|
|
struct buffer *res, outbuf;
|
|
|
|
size_t total = 0;
|
|
|
|
|
|
|
|
htx = htx_from_buf(buf);
|
|
|
|
res = mux_get_buf(qcs);
|
|
|
|
outbuf = b_make(b_tail(res), b_contig_space(res), 0, 0);
|
|
|
|
|
2021-12-03 13:40:01 +00:00
|
|
|
while (count && !htx_is_empty(htx) && !(qcs->flags & QC_SF_BLK_MROOM)) {
|
2021-11-12 15:09:54 +00:00
|
|
|
/* Not implemented : QUIC on backend side */
|
|
|
|
idx = htx_get_head(htx);
|
|
|
|
blk = htx_get_blk(htx, idx);
|
|
|
|
btype = htx_get_blk_type(blk);
|
|
|
|
fsize = bsize = htx_get_blksz(blk);
|
|
|
|
|
|
|
|
BUG_ON(btype == HTX_BLK_REQ_SL);
|
|
|
|
|
|
|
|
switch (btype) {
|
|
|
|
case HTX_BLK_DATA:
|
|
|
|
if (fsize > count)
|
|
|
|
fsize = count;
|
2021-12-07 15:19:03 +00:00
|
|
|
|
2021-12-09 09:07:23 +00:00
|
|
|
if (b_room(&outbuf) < fsize)
|
|
|
|
fsize = b_room(&outbuf);
|
2021-12-07 15:19:03 +00:00
|
|
|
|
|
|
|
if (!fsize) {
|
|
|
|
qcs->flags |= QC_SF_BLK_MROOM;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2021-11-12 15:09:54 +00:00
|
|
|
b_putblk(&outbuf, htx_get_blk_ptr(htx, blk), fsize);
|
|
|
|
total += fsize;
|
|
|
|
count -= fsize;
|
|
|
|
|
|
|
|
if (fsize == bsize)
|
|
|
|
htx_remove_blk(htx, blk);
|
|
|
|
else
|
|
|
|
htx_cut_data_blk(htx, blk, fsize);
|
|
|
|
break;
|
|
|
|
|
2021-12-25 06:45:52 +00:00
|
|
|
/* only body is transferred on HTTP/0.9 */
|
2021-11-12 15:09:54 +00:00
|
|
|
case HTX_BLK_RES_SL:
|
|
|
|
case HTX_BLK_TLR:
|
|
|
|
case HTX_BLK_EOT:
|
|
|
|
default:
|
|
|
|
htx_remove_blk(htx, blk);
|
|
|
|
total += bsize;
|
|
|
|
count -= bsize;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:19:03 +00:00
|
|
|
end:
|
2021-12-03 14:03:36 +00:00
|
|
|
if ((htx->flags & HTX_FL_EOM) && htx_is_empty(htx))
|
|
|
|
qcs->flags |= QC_SF_FIN_STREAM;
|
|
|
|
|
2021-11-12 15:09:54 +00:00
|
|
|
b_add(res, b_data(&outbuf));
|
|
|
|
|
|
|
|
if (total) {
|
|
|
|
if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
|
|
|
|
tasklet_wakeup(qcs->qcc->wait_event.tasklet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2022-08-03 09:17:57 +00:00
|
|
|
static int hq_interop_attach(struct qcs *qcs, void *conn_ctx)
|
|
|
|
{
|
|
|
|
qcs_wait_http_req(qcs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-12 15:09:54 +00:00
|
|
|
const struct qcc_app_ops hq_interop_ops = {
|
|
|
|
.decode_qcs = hq_interop_decode_qcs,
|
|
|
|
.snd_buf = hq_interop_snd_buf,
|
2022-08-03 09:17:57 +00:00
|
|
|
.attach = hq_interop_attach,
|
2021-11-12 15:09:54 +00:00
|
|
|
};
|