]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-quic: add a app-layer context in qcs
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 27 Apr 2022 13:17:11 +0000 (15:17 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 28 Apr 2022 13:44:19 +0000 (15:44 +0200)
Define 2 new callback for qcc_app_ops : attach and detach. They are
called when a qcs instance is respectively allocated and freed. If
implemented, they can allocate a custom context stored in the new
abstract field ctx of qcs.

For now, h3 and hq-interop does not use these new callbacks. They will
be soon implemented by the h3 layer to allocate a context used for
stateful demuxing.

This change is required to support the demuxing of H3 frames bigger than
a buffer.

include/haproxy/mux_quic-t.h
src/mux_quic.c

index 1b6a4c8cbd088d27365e65a2a3eafbf53a2c5df7..eafa62d15df78d25dc54684efec2a0d231212e59 100644 (file)
@@ -98,6 +98,7 @@ struct qcs {
        struct conn_stream *cs;
        struct cs_endpoint *endp;
        uint32_t flags;      /* QC_SF_* */
+       void *ctx;           /* app-ops context */
 
        struct {
                struct eb_root frms; /* received frames ordered by their offsets */
@@ -126,9 +127,11 @@ struct qcs {
 /* QUIC application layer operations */
 struct qcc_app_ops {
        int (*init)(struct qcc *qcc);
+       int (*attach)(struct qcs *qcs);
        int (*attach_ruqs)(struct qcs *qcs, void *ctx);
        int (*decode_qcs)(struct qcs *qcs, int fin, void *ctx);
        size_t (*snd_buf)(struct conn_stream *cs, struct buffer *buf, size_t count, int flags);
+       void (*detach)(struct qcs *qcs);
        int (*finalize)(void *ctx);
        int (*is_active)(const struct qcc *qcc, void *ctx);
        void (*release)(void *ctx);
index 17adf46611745f8a000a7a59db8bf1160644f99c..5c5ba2cb9f8621f4afa1becdf2133858324523a2 100644 (file)
@@ -116,6 +116,7 @@ struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type)
        qcs->qcc = qcc;
        qcs->cs = NULL;
        qcs->flags = QC_SF_NONE;
+       qcs->ctx = NULL;
 
        /* allocate transport layer stream descriptor
         *
@@ -126,6 +127,10 @@ struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type)
        if (!qcs->stream)
                goto err;
 
+       if (qcc->app_ops->attach) {
+               if (qcc->app_ops->attach(qcs))
+                       goto err;
+       }
 
        qcs->endp = cs_endpoint_new();
        if (!qcs->endp) {
@@ -169,6 +174,9 @@ struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type)
        return qcs;
 
  err:
+       if (qcs->ctx && qcc->app_ops->detach)
+               qcc->app_ops->detach(qcs);
+
        if (qcs->stream)
                qc_stream_desc_release(qcs->stream);
 
@@ -188,6 +196,9 @@ void qcs_free(struct qcs *qcs)
        BUG_ON(!qcs->qcc->strms[qcs_id_type(qcs->id)].nb_streams);
        --qcs->qcc->strms[qcs_id_type(qcs->id)].nb_streams;
 
+       if (qcs->ctx && qcs->qcc->app_ops->detach)
+               qcs->qcc->app_ops->detach(qcs);
+
        qc_stream_desc_release(qcs->stream);
 
        BUG_ON(qcs->endp && !(qcs->endp->flags & CS_EP_ORPHAN));