CLEANUP: h3: rename struct h3 -> h3c

struct h3 represents the whole HTTP/3 connection. A new type h3s was
recently introduced to represent a single HTTP/3 stream. To facilitate
the analogy with other haproxy code, most notable in MUX, rename h3 type
to h3c.
This commit is contained in:
Amaury Denoyelle 2022-05-24 14:55:43 +02:00
parent 0ffd6e7e64
commit 8d1ecac5d9

144
src/h3.c
View File

@ -48,7 +48,7 @@ static uint64_t h3_settings_qpack_max_table_capacity = 0;
static uint64_t h3_settings_qpack_blocked_streams = 4096;
static uint64_t h3_settings_max_field_section_size = QUIC_VARINT_8_BYTE_MAX; /* Unlimited */
struct h3 {
struct h3c {
struct qcc *qcc;
enum h3_err err;
uint32_t flags;
@ -67,7 +67,7 @@ struct h3 {
struct buffer_wait buf_wait; /* wait list for buffer allocations */
};
DECLARE_STATIC_POOL(pool_head_h3, "h3", sizeof(struct h3));
DECLARE_STATIC_POOL(pool_head_h3c, "h3c", sizeof(struct h3c));
struct h3s {
int demux_frame_len;
@ -344,7 +344,7 @@ static int h3_decode_qcs(struct qcs *qcs, int fin, void *ctx)
* <rxbuf> buffer. This function does not update this buffer.
* Returns 0 if something wrong happened, 1 if not.
*/
static int h3_parse_settings_frm(struct h3 *h3, const struct ncbuf *rxbuf, size_t flen)
static int h3_parse_settings_frm(struct h3c *h3c, const struct ncbuf *rxbuf, size_t flen)
{
uint64_t id, value;
const unsigned char *buf, *end;
@ -360,16 +360,16 @@ static int h3_parse_settings_frm(struct h3 *h3, const struct ncbuf *rxbuf, size_
__func__, (unsigned long long)id, (unsigned long long)value);
switch (id) {
case H3_SETTINGS_QPACK_MAX_TABLE_CAPACITY:
h3->qpack_max_table_capacity = value;
h3c->qpack_max_table_capacity = value;
break;
case H3_SETTINGS_MAX_FIELD_SECTION_SIZE:
h3->max_field_section_size = value;
h3c->max_field_section_size = value;
break;
case H3_SETTINGS_QPACK_BLOCKED_STREAMS:
h3->qpack_blocked_streams = value;
h3c->qpack_blocked_streams = value;
break;
case H3_SETTINGS_RESERVED_2 ... H3_SETTINGS_RESERVED_5:
h3->err = H3_SETTINGS_ERROR;
h3c->err = H3_SETTINGS_ERROR;
return 0;
default:
/* MUST be ignored */
@ -387,7 +387,7 @@ static int h3_parse_settings_frm(struct h3 *h3, const struct ncbuf *rxbuf, size_
static int h3_control_recv(struct h3_uqs *h3_uqs, void *ctx)
{
struct ncbuf *rxbuf = &h3_uqs->qcs->rx.ncbuf;
struct h3 *h3 = ctx;
struct h3c *h3c = ctx;
h3_debug_printf(stderr, "%s STREAM ID: %lu\n", __func__, h3_uqs->qcs->id);
if (!ncb_data(rxbuf, 0))
@ -417,7 +417,7 @@ static int h3_control_recv(struct h3_uqs *h3_uqs, void *ctx)
ABORT_NOW();
break;
case H3_FT_SETTINGS:
if (!h3_parse_settings_frm(h3, rxbuf, flen))
if (!h3_parse_settings_frm(h3c, rxbuf, flen))
return 0;
break;
case H3_FT_GOAWAY:
@ -430,7 +430,7 @@ static int h3_control_recv(struct h3_uqs *h3_uqs, void *ctx)
break;
default:
/* Error */
h3->err = H3_FRAME_UNEXPECTED;
h3c->err = H3_FRAME_UNEXPECTED;
return 0;
}
qcs_consume(h3_uqs->qcs, flen);
@ -461,13 +461,13 @@ static struct buffer *mux_get_buf(struct qcs *qcs)
static int h3_control_send(struct h3_uqs *h3_uqs, void *ctx)
{
int ret;
struct h3 *h3 = ctx;
struct h3c *h3c = ctx;
unsigned char data[(2 + 3) * 2 * QUIC_VARINT_MAX_SIZE]; /* enough for 3 settings */
struct buffer pos, *res;
ret = 0;
pos = b_make((char *)data, sizeof(data), 0, 0);
if (!(h3->flags & H3_CF_SETTINGS_SENT)) {
if (!(h3c->flags & H3_CF_SETTINGS_SENT)) {
struct qcs *qcs = h3_uqs->qcs;
size_t frm_len;
@ -502,7 +502,7 @@ static int h3_control_send(struct h3_uqs *h3_uqs, void *ctx)
ret = b_force_xfer(res, &pos, b_data(&pos));
if (ret > 0) {
h3->flags |= H3_CF_SETTINGS_SENT;
h3c->flags |= H3_CF_SETTINGS_SENT;
if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
tasklet_wakeup(qcs->qcc->wait_event.tasklet);
}
@ -782,7 +782,7 @@ static int h3_attach(struct qcs *qcs)
static int h3_attach_ruqs(struct qcs *qcs, void *ctx)
{
uint64_t strm_type;
struct h3 *h3 = ctx;
struct h3c *h3c = ctx;
struct ncbuf *rxbuf = &qcs->rx.ncbuf;
struct buffer b;
size_t len = 0;
@ -800,41 +800,41 @@ static int h3_attach_ruqs(struct qcs *qcs, void *ctx)
*/
switch (strm_type) {
case H3_UNI_STRM_TP_CONTROL_STREAM:
if (h3->rctrl.qcs) {
h3->err = H3_STREAM_CREATION_ERROR;
if (h3c->rctrl.qcs) {
h3c->err = H3_STREAM_CREATION_ERROR;
return 0;
}
h3->rctrl.qcs = qcs;
h3->rctrl.cb = h3_control_recv;
qcs_subscribe(qcs, SUB_RETRY_RECV, &h3->rctrl.wait_event);
h3c->rctrl.qcs = qcs;
h3c->rctrl.cb = h3_control_recv;
qcs_subscribe(qcs, SUB_RETRY_RECV, &h3c->rctrl.wait_event);
break;
case H3_UNI_STRM_TP_PUSH_STREAM:
/* NOT SUPPORTED */
break;
case H3_UNI_STRM_TP_QPACK_ENCODER:
if (h3->rqpack_enc.qcs) {
h3->err = H3_STREAM_CREATION_ERROR;
if (h3c->rqpack_enc.qcs) {
h3c->err = H3_STREAM_CREATION_ERROR;
return 0;
}
h3->rqpack_enc.qcs = qcs;
h3->rqpack_enc.cb = qpack_decode_enc;
qcs_subscribe(qcs, SUB_RETRY_RECV, &h3->rqpack_enc.wait_event);
h3c->rqpack_enc.qcs = qcs;
h3c->rqpack_enc.cb = qpack_decode_enc;
qcs_subscribe(qcs, SUB_RETRY_RECV, &h3c->rqpack_enc.wait_event);
break;
case H3_UNI_STRM_TP_QPACK_DECODER:
if (h3->rqpack_dec.qcs) {
h3->err = H3_STREAM_CREATION_ERROR;
if (h3c->rqpack_dec.qcs) {
h3c->err = H3_STREAM_CREATION_ERROR;
return 0;
}
h3->rqpack_dec.qcs = qcs;
h3->rqpack_dec.cb = qpack_decode_dec;
qcs_subscribe(qcs, SUB_RETRY_RECV, &h3->rqpack_dec.wait_event);
h3c->rqpack_dec.qcs = qcs;
h3c->rqpack_dec.cb = qpack_decode_dec;
qcs_subscribe(qcs, SUB_RETRY_RECV, &h3c->rqpack_dec.wait_event);
break;
default:
/* Error */
h3->err = H3_STREAM_CREATION_ERROR;
h3c->err = H3_STREAM_CREATION_ERROR;
return 0;
}
@ -850,14 +850,14 @@ static void h3_detach(struct qcs *qcs)
static int h3_finalize(void *ctx)
{
struct h3 *h3 = ctx;
struct h3c *h3c = ctx;
h3->lctrl.qcs = qcs_new(h3->qcc, 0x3, QCS_SRV_UNI);
if (!h3->lctrl.qcs)
h3c->lctrl.qcs = qcs_new(h3c->qcc, 0x3, QCS_SRV_UNI);
if (!h3c->lctrl.qcs)
return 0;
/* Wakeup ->lctrl uni-stream */
h3_control_send(&h3->lctrl, h3);
h3_control_send(&h3c->lctrl, h3c);
return 1;
}
@ -866,9 +866,9 @@ static int h3_finalize(void *ctx)
static struct task *h3_uqs_task(struct task *t, void *ctx, unsigned int state)
{
struct h3_uqs *h3_uqs = ctx;
struct h3 *h3 = h3_uqs->qcs->qcc->ctx;
struct h3c *h3c = h3_uqs->qcs->qcc->ctx;
h3_uqs->cb(h3_uqs, h3);
h3_uqs->cb(h3_uqs, h3c);
return NULL;
}
@ -881,12 +881,12 @@ static inline void h3_uqs_tasklet_release(struct h3_uqs *h3_uqs)
tasklet_free(t);
}
/* Release all the tasklet attached to <h3> uni-streams */
static void h3_uqs_tasklets_release(struct h3 *h3)
/* Release all the tasklet attached to <h3c> uni-streams */
static void h3_uqs_tasklets_release(struct h3c *h3c)
{
h3_uqs_tasklet_release(&h3->rqpack_enc);
h3_uqs_tasklet_release(&h3->rqpack_dec);
h3_uqs_tasklet_release(&h3->rctrl);
h3_uqs_tasklet_release(&h3c->rqpack_enc);
h3_uqs_tasklet_release(&h3c->rqpack_dec);
h3_uqs_tasklet_release(&h3c->rctrl);
}
/* Tasklet dedicated to h3 outgoing uni-streams */
@ -894,14 +894,14 @@ __maybe_unused
static struct task *h3_uqs_send_task(struct task *t, void *ctx, unsigned int state)
{
struct h3_uqs *h3_uqs = ctx;
struct h3 *h3 = h3_uqs->qcs->qcc->ctx;
struct h3c *h3c = h3_uqs->qcs->qcc->ctx;
h3_uqs->cb(h3_uqs, h3);
h3_uqs->cb(h3_uqs, h3c);
return NULL;
}
/* Initialize <h3_uqs> uni-stream with <t> as tasklet */
static int h3_uqs_init(struct h3_uqs *h3_uqs, struct h3 *h3,
static int h3_uqs_init(struct h3_uqs *h3_uqs, struct h3c *h3c,
int (*cb)(struct h3_uqs *h3_uqs, void *ctx),
struct task *(*t)(struct task *, void *, unsigned int))
{
@ -923,14 +923,14 @@ static inline void h3_uqs_release(struct h3_uqs *h3_uqs)
qcs_free(h3_uqs->qcs);
}
static inline void h3_uqs_release_all(struct h3 *h3)
static inline void h3_uqs_release_all(struct h3c *h3c)
{
h3_uqs_tasklet_release(&h3->lctrl);
h3_uqs_release(&h3->lctrl);
h3_uqs_tasklet_release(&h3->lqpack_enc);
h3_uqs_release(&h3->lqpack_enc);
h3_uqs_tasklet_release(&h3->lqpack_dec);
h3_uqs_release(&h3->lqpack_dec);
h3_uqs_tasklet_release(&h3c->lctrl);
h3_uqs_release(&h3c->lctrl);
h3_uqs_tasklet_release(&h3c->lqpack_enc);
h3_uqs_release(&h3c->lqpack_enc);
h3_uqs_tasklet_release(&h3c->lqpack_dec);
h3_uqs_release(&h3c->lqpack_dec);
}
/* Initialize the HTTP/3 context for <qcc> mux.
@ -938,47 +938,47 @@ static inline void h3_uqs_release_all(struct h3 *h3)
*/
static int h3_init(struct qcc *qcc)
{
struct h3 *h3;
struct h3c *h3c;
h3 = pool_alloc(pool_head_h3);
if (!h3)
h3c = pool_alloc(pool_head_h3c);
if (!h3c)
goto fail_no_h3;
h3->qcc = qcc;
h3->err = H3_NO_ERROR;
h3->flags = 0;
h3c->qcc = qcc;
h3c->err = H3_NO_ERROR;
h3c->flags = 0;
if (!h3_uqs_init(&h3->rqpack_enc, h3, NULL, h3_uqs_task) ||
!h3_uqs_init(&h3->rqpack_dec, h3, NULL, h3_uqs_task) ||
!h3_uqs_init(&h3->rctrl, h3, h3_control_recv, h3_uqs_task))
if (!h3_uqs_init(&h3c->rqpack_enc, h3c, NULL, h3_uqs_task) ||
!h3_uqs_init(&h3c->rqpack_dec, h3c, NULL, h3_uqs_task) ||
!h3_uqs_init(&h3c->rctrl, h3c, h3_control_recv, h3_uqs_task))
goto fail_no_h3_ruqs;
if (!h3_uqs_init(&h3->lctrl, h3, h3_control_send, h3_uqs_task) ||
!h3_uqs_init(&h3->lqpack_enc, h3, NULL, h3_uqs_task) ||
!h3_uqs_init(&h3->lqpack_dec, h3, NULL, h3_uqs_task))
if (!h3_uqs_init(&h3c->lctrl, h3c, h3_control_send, h3_uqs_task) ||
!h3_uqs_init(&h3c->lqpack_enc, h3c, NULL, h3_uqs_task) ||
!h3_uqs_init(&h3c->lqpack_dec, h3c, NULL, h3_uqs_task))
goto fail_no_h3_luqs;
qcc->ctx = h3;
LIST_INIT(&h3->buf_wait.list);
qcc->ctx = h3c;
LIST_INIT(&h3c->buf_wait.list);
return 1;
fail_no_h3_ruqs:
h3_uqs_release_all(h3);
h3_uqs_release_all(h3c);
fail_no_h3_luqs:
h3_uqs_tasklets_release(h3);
pool_free(pool_head_h3, h3);
h3_uqs_tasklets_release(h3c);
pool_free(pool_head_h3c, h3c);
fail_no_h3:
return 0;
}
static void h3_release(void *ctx)
{
struct h3 *h3 = ctx;
struct h3c *h3c = ctx;
h3_uqs_release_all(h3);
h3_uqs_tasklets_release(h3);
pool_free(pool_head_h3, h3);
h3_uqs_release_all(h3c);
h3_uqs_tasklets_release(h3c);
pool_free(pool_head_h3c, h3c);
}
/* Check if the H3 connection can still be considered as active.