Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1 | #include <haproxy/mux_quic.h> |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2 | |
Amaury Denoyelle | eb01f59 | 2021-10-07 16:44:05 +0200 | [diff] [blame] | 3 | #include <import/eb64tree.h> |
| 4 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 5 | #include <haproxy/api.h> |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 6 | #include <haproxy/connection.h> |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 7 | #include <haproxy/dynbuf.h> |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 8 | #include <haproxy/list.h> |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 9 | #include <haproxy/ncbuf.h> |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 10 | #include <haproxy/pool.h> |
Amaury Denoyelle | d80fbca | 2022-09-19 17:02:28 +0200 | [diff] [blame] | 11 | #include <haproxy/qmux_http.h> |
Amaury Denoyelle | 36d50bf | 2022-09-19 16:12:38 +0200 | [diff] [blame] | 12 | #include <haproxy/qmux_trace.h> |
Amaury Denoyelle | 92fa63f | 2022-09-30 18:11:13 +0200 | [diff] [blame] | 13 | #include <haproxy/quic_conn.h> |
Amaury Denoyelle | 0cc02a3 | 2022-04-19 17:21:11 +0200 | [diff] [blame] | 14 | #include <haproxy/quic_stream.h> |
Frédéric Lécaille | 748ece6 | 2022-05-21 23:58:40 +0200 | [diff] [blame] | 15 | #include <haproxy/quic_tp-t.h> |
Amaury Denoyelle | eb01f59 | 2021-10-07 16:44:05 +0200 | [diff] [blame] | 16 | #include <haproxy/ssl_sock-t.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 17 | #include <haproxy/stconn.h> |
Amaury Denoyelle | dd4fbfb | 2022-03-24 16:09:16 +0100 | [diff] [blame] | 18 | #include <haproxy/trace.h> |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 19 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 20 | DECLARE_POOL(pool_head_qcc, "qcc", sizeof(struct qcc)); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 21 | DECLARE_POOL(pool_head_qcs, "qcs", sizeof(struct qcs)); |
| 22 | |
Amaury Denoyelle | 9fab9fd | 2022-05-20 15:04:38 +0200 | [diff] [blame] | 23 | /* Emit a CONNECTION_CLOSE with error <err>. This will interrupt all future |
Amaury Denoyelle | 5c4373a | 2022-05-24 14:47:48 +0200 | [diff] [blame] | 24 | * send/receive operations. |
Amaury Denoyelle | 9fab9fd | 2022-05-20 15:04:38 +0200 | [diff] [blame] | 25 | */ |
| 26 | static void qcc_emit_cc(struct qcc *qcc, int err) |
| 27 | { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 28 | TRACE_ENTER(QMUX_EV_QCC_END, qcc->conn); |
| 29 | |
| 30 | TRACE_STATE("set CONNECTION_CLOSE on quic-conn", QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | 57e6db7 | 2022-07-13 15:07:56 +0200 | [diff] [blame] | 31 | quic_set_connection_close(qcc->conn->handle.qc, quic_err_transport(err)); |
Amaury Denoyelle | 9fab9fd | 2022-05-20 15:04:38 +0200 | [diff] [blame] | 32 | qcc->flags |= QC_CF_CC_EMIT; |
| 33 | tasklet_wakeup(qcc->wait_event.tasklet); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 34 | |
| 35 | TRACE_LEAVE(QMUX_EV_QCC_END, qcc->conn); |
Amaury Denoyelle | 9fab9fd | 2022-05-20 15:04:38 +0200 | [diff] [blame] | 36 | } |
| 37 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 38 | /* Allocate a new QUIC streams with id <id> and type <type>. */ |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 39 | static struct qcs *qcs_new(struct qcc *qcc, uint64_t id, enum qcs_type type) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 40 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 41 | struct qcs *qcs; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 42 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 43 | TRACE_ENTER(QMUX_EV_QCS_NEW, qcc->conn); |
| 44 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 45 | qcs = pool_alloc(pool_head_qcs); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 46 | if (!qcs) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 47 | TRACE_ERROR("alloc failure", QMUX_EV_QCS_NEW, qcc->conn); |
Amaury Denoyelle | 17014a6 | 2022-04-27 15:09:27 +0200 | [diff] [blame] | 48 | return NULL; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 49 | } |
Amaury Denoyelle | 17014a6 | 2022-04-27 15:09:27 +0200 | [diff] [blame] | 50 | |
| 51 | qcs->stream = NULL; |
| 52 | qcs->qcc = qcc; |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 53 | qcs->sd = NULL; |
Amaury Denoyelle | 17014a6 | 2022-04-27 15:09:27 +0200 | [diff] [blame] | 54 | qcs->flags = QC_SF_NONE; |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 55 | qcs->st = QC_SS_IDLE; |
Amaury Denoyelle | 47447af | 2022-04-27 15:17:11 +0200 | [diff] [blame] | 56 | qcs->ctx = NULL; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 57 | |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 58 | /* App callback attach may register the stream for http-request wait. |
| 59 | * These fields must be initialed before. |
| 60 | */ |
| 61 | LIST_INIT(&qcs->el_opening); |
| 62 | qcs->start = TICK_ETERNITY; |
| 63 | |
Amaury Denoyelle | 93fba32 | 2022-05-24 16:53:14 +0200 | [diff] [blame] | 64 | /* Allocate transport layer stream descriptor. Only needed for TX. */ |
| 65 | if (!quic_stream_is_uni(id) || !quic_stream_is_remote(qcc, id)) { |
| 66 | struct quic_conn *qc = qcc->conn->handle.qc; |
| 67 | qcs->stream = qc_stream_desc_new(id, type, qcs, qc); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 68 | if (!qcs->stream) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 69 | TRACE_ERROR("qc_stream_desc alloc failure", QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | 93fba32 | 2022-05-24 16:53:14 +0200 | [diff] [blame] | 70 | goto err; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 71 | } |
Amaury Denoyelle | 93fba32 | 2022-05-24 16:53:14 +0200 | [diff] [blame] | 72 | } |
Amaury Denoyelle | 7272cd7 | 2022-03-29 15:15:54 +0200 | [diff] [blame] | 73 | |
Amaury Denoyelle | 3236a8e | 2022-05-24 15:24:03 +0200 | [diff] [blame] | 74 | qcs->id = qcs->by_id.key = id; |
Amaury Denoyelle | 47447af | 2022-04-27 15:17:11 +0200 | [diff] [blame] | 75 | if (qcc->app_ops->attach) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 76 | if (qcc->app_ops->attach(qcs, qcc->ctx)) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 77 | TRACE_ERROR("app proto failure", QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | 47447af | 2022-04-27 15:17:11 +0200 | [diff] [blame] | 78 | goto err; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 79 | } |
Amaury Denoyelle | 47447af | 2022-04-27 15:17:11 +0200 | [diff] [blame] | 80 | } |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 81 | |
Amaury Denoyelle | d8e680c | 2022-03-29 15:18:44 +0200 | [diff] [blame] | 82 | /* store transport layer stream descriptor in qcc tree */ |
Amaury Denoyelle | e4301da | 2022-04-19 17:59:50 +0200 | [diff] [blame] | 83 | eb64_insert(&qcc->streams_by_id, &qcs->by_id); |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 84 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 85 | qcc->strms[type].nb_streams++; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 86 | |
Amaury Denoyelle | 6ea7819 | 2022-03-07 15:47:02 +0100 | [diff] [blame] | 87 | /* If stream is local, use peer remote-limit, or else the opposite. */ |
| 88 | /* TODO use uni limit for unidirectional streams */ |
| 89 | qcs->tx.msd = quic_stream_is_local(qcc, id) ? qcc->rfctl.msd_bidi_r : |
| 90 | qcc->rfctl.msd_bidi_l; |
| 91 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 92 | qcs->rx.ncbuf = NCBUF_NULL; |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 93 | qcs->rx.app_buf = BUF_NULL; |
Amaury Denoyelle | d46b0f5 | 2022-05-20 15:05:07 +0200 | [diff] [blame] | 94 | qcs->rx.offset = qcs->rx.offset_max = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 95 | |
Amaury Denoyelle | 44d0912 | 2022-04-26 11:21:10 +0200 | [diff] [blame] | 96 | /* TODO use uni limit for unidirectional streams */ |
| 97 | qcs->rx.msd = quic_stream_is_local(qcc, id) ? qcc->lfctl.msd_bidi_l : |
| 98 | qcc->lfctl.msd_bidi_r; |
Amaury Denoyelle | a977355 | 2022-05-16 14:38:25 +0200 | [diff] [blame] | 99 | qcs->rx.msd_init = qcs->rx.msd; |
Amaury Denoyelle | 44d0912 | 2022-04-26 11:21:10 +0200 | [diff] [blame] | 100 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 101 | qcs->tx.buf = BUF_NULL; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 102 | qcs->tx.offset = 0; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 103 | qcs->tx.sent_offset = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 104 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 105 | qcs->wait_event.tasklet = NULL; |
| 106 | qcs->wait_event.events = 0; |
| 107 | qcs->subs = NULL; |
| 108 | |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 109 | qcs->err = 0; |
| 110 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 111 | out: |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 112 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 113 | return qcs; |
Amaury Denoyelle | 17014a6 | 2022-04-27 15:09:27 +0200 | [diff] [blame] | 114 | |
| 115 | err: |
Amaury Denoyelle | 47447af | 2022-04-27 15:17:11 +0200 | [diff] [blame] | 116 | if (qcs->ctx && qcc->app_ops->detach) |
| 117 | qcc->app_ops->detach(qcs); |
| 118 | |
Amaury Denoyelle | 93fba32 | 2022-05-24 16:53:14 +0200 | [diff] [blame] | 119 | qc_stream_desc_release(qcs->stream); |
Amaury Denoyelle | 17014a6 | 2022-04-27 15:09:27 +0200 | [diff] [blame] | 120 | pool_free(pool_head_qcs, qcs); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 121 | |
| 122 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | 17014a6 | 2022-04-27 15:09:27 +0200 | [diff] [blame] | 123 | return NULL; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 126 | static void qc_free_ncbuf(struct qcs *qcs, struct ncbuf *ncbuf) |
| 127 | { |
| 128 | struct buffer buf; |
| 129 | |
Amaury Denoyelle | 7313f5e | 2022-05-17 18:53:21 +0200 | [diff] [blame] | 130 | if (ncb_is_null(ncbuf)) |
| 131 | return; |
| 132 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 133 | buf = b_make(ncbuf->area, ncbuf->size, 0, 0); |
| 134 | b_free(&buf); |
Amaury Denoyelle | 7313f5e | 2022-05-17 18:53:21 +0200 | [diff] [blame] | 135 | offer_buffers(NULL, 1); |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 136 | |
| 137 | *ncbuf = NCBUF_NULL; |
| 138 | } |
| 139 | |
Amaury Denoyelle | dccbd73 | 2022-03-29 18:36:59 +0200 | [diff] [blame] | 140 | /* Free a qcs. This function must only be done to remove a stream on allocation |
| 141 | * error or connection shutdown. Else use qcs_destroy which handle all the |
| 142 | * QUIC connection mechanism. |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 143 | */ |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 144 | static void qcs_free(struct qcs *qcs) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 145 | { |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 146 | struct qcc *qcc = qcs->qcc; |
| 147 | |
| 148 | TRACE_ENTER(QMUX_EV_QCS_END, qcc->conn, qcs); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 149 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 150 | qc_free_ncbuf(qcs, &qcs->rx.ncbuf); |
Amaury Denoyelle | dccbd73 | 2022-03-29 18:36:59 +0200 | [diff] [blame] | 151 | b_free(&qcs->tx.buf); |
Amaury Denoyelle | dccbd73 | 2022-03-29 18:36:59 +0200 | [diff] [blame] | 152 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 153 | BUG_ON(!qcc->strms[qcs_id_type(qcs->id)].nb_streams); |
| 154 | --qcc->strms[qcs_id_type(qcs->id)].nb_streams; |
Amaury Denoyelle | dccbd73 | 2022-03-29 18:36:59 +0200 | [diff] [blame] | 155 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 156 | if (qcs->ctx && qcc->app_ops->detach) |
| 157 | qcc->app_ops->detach(qcs); |
Amaury Denoyelle | 47447af | 2022-04-27 15:17:11 +0200 | [diff] [blame] | 158 | |
Amaury Denoyelle | e4301da | 2022-04-19 17:59:50 +0200 | [diff] [blame] | 159 | qc_stream_desc_release(qcs->stream); |
| 160 | |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 161 | BUG_ON(qcs->sd && !se_fl_test(qcs->sd, SE_FL_ORPHAN)); |
| 162 | sedesc_free(qcs->sd); |
Amaury Denoyelle | e4301da | 2022-04-19 17:59:50 +0200 | [diff] [blame] | 163 | |
| 164 | eb64_delete(&qcs->by_id); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 165 | pool_free(pool_head_qcs, qcs); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 166 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 167 | TRACE_LEAVE(QMUX_EV_QCS_END, qcc->conn); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Amaury Denoyelle | 3abeb57 | 2022-07-04 11:42:27 +0200 | [diff] [blame] | 170 | static forceinline struct stconn *qcs_sc(const struct qcs *qcs) |
| 171 | { |
| 172 | return qcs->sd ? qcs->sd->sc : NULL; |
| 173 | } |
| 174 | |
Amaury Denoyelle | bd6ec1b | 2022-07-25 11:53:18 +0200 | [diff] [blame] | 175 | /* Reset the <qcc> inactivity timeout for http-keep-alive timeout. */ |
| 176 | static forceinline void qcc_reset_idle_start(struct qcc *qcc) |
| 177 | { |
| 178 | qcc->idle_start = now_ms; |
| 179 | } |
| 180 | |
Amaury Denoyelle | c603de4 | 2022-07-25 11:21:46 +0200 | [diff] [blame] | 181 | /* Decrement <qcc> sc. */ |
| 182 | static forceinline void qcc_rm_sc(struct qcc *qcc) |
| 183 | { |
| 184 | BUG_ON_HOT(!qcc->nb_sc); |
| 185 | --qcc->nb_sc; |
Amaury Denoyelle | bd6ec1b | 2022-07-25 11:53:18 +0200 | [diff] [blame] | 186 | |
| 187 | /* Reset qcc idle start for http-keep-alive timeout. Timeout will be |
| 188 | * refreshed after this on stream detach. |
| 189 | */ |
| 190 | if (!qcc->nb_sc && !qcc->nb_hreq) |
| 191 | qcc_reset_idle_start(qcc); |
Amaury Denoyelle | c603de4 | 2022-07-25 11:21:46 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* Decrement <qcc> hreq. */ |
| 195 | static forceinline void qcc_rm_hreq(struct qcc *qcc) |
| 196 | { |
| 197 | BUG_ON_HOT(!qcc->nb_hreq); |
| 198 | --qcc->nb_hreq; |
Amaury Denoyelle | bd6ec1b | 2022-07-25 11:53:18 +0200 | [diff] [blame] | 199 | |
| 200 | /* Reset qcc idle start for http-keep-alive timeout. Timeout will be |
| 201 | * refreshed after this on I/O handler. |
| 202 | */ |
| 203 | if (!qcc->nb_sc && !qcc->nb_hreq) |
| 204 | qcc_reset_idle_start(qcc); |
Amaury Denoyelle | c603de4 | 2022-07-25 11:21:46 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 207 | static inline int qcc_is_dead(const struct qcc *qcc) |
| 208 | { |
| 209 | /* Mux connection is considered dead if : |
| 210 | * - all stream-desc are detached AND |
| 211 | * = connection is on error OR |
| 212 | * = mux timeout has already fired or is unset |
| 213 | */ |
| 214 | if (!qcc->nb_sc && ((qcc->conn->flags & CO_FL_ERROR) || !qcc->task)) |
| 215 | return 1; |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /* Return true if the mux timeout should be armed. */ |
| 221 | static inline int qcc_may_expire(struct qcc *qcc) |
| 222 | { |
| 223 | return !qcc->nb_sc; |
| 224 | } |
| 225 | |
| 226 | /* Refresh the timeout on <qcc> if needed depending on its state. */ |
| 227 | static void qcc_refresh_timeout(struct qcc *qcc) |
| 228 | { |
| 229 | const struct proxy *px = qcc->proxy; |
| 230 | |
| 231 | TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc->conn); |
| 232 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 233 | if (!qcc->task) { |
| 234 | TRACE_DEVEL("already expired", QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 235 | goto leave; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 236 | } |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 237 | |
Amaury Denoyelle | 6ec9837 | 2022-08-01 17:59:38 +0200 | [diff] [blame] | 238 | /* Check if upper layer is responsible of timeout management. */ |
| 239 | if (!qcc_may_expire(qcc)) { |
| 240 | TRACE_DEVEL("not eligible for timeout", QMUX_EV_QCC_WAKE, qcc->conn); |
| 241 | qcc->task->expire = TICK_ETERNITY; |
| 242 | task_queue(qcc->task); |
| 243 | goto leave; |
| 244 | } |
| 245 | |
| 246 | /* TODO if connection is idle on frontend and proxy is disabled, remove |
| 247 | * it with global close_spread delay applied. |
| 248 | */ |
| 249 | |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 250 | /* TODO implement client/server-fin timeout for graceful shutdown */ |
Amaury Denoyelle | 6ec9837 | 2022-08-01 17:59:38 +0200 | [diff] [blame] | 251 | |
| 252 | /* Frontend timeout management |
| 253 | * - detached streams with data left to send -> default timeout |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 254 | * - stream waiting on incomplete request or no stream yet activated -> timeout http-request |
Amaury Denoyelle | 6ec9837 | 2022-08-01 17:59:38 +0200 | [diff] [blame] | 255 | * - idle after stream processing -> timeout http-keep-alive |
| 256 | */ |
| 257 | if (!conn_is_back(qcc->conn)) { |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 258 | if (qcc->nb_hreq) { |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 259 | TRACE_DEVEL("one or more requests still in progress", QMUX_EV_QCC_WAKE, qcc->conn); |
| 260 | qcc->task->expire = tick_add_ifset(now_ms, qcc->timeout); |
Amaury Denoyelle | 6ec9837 | 2022-08-01 17:59:38 +0200 | [diff] [blame] | 261 | task_queue(qcc->task); |
| 262 | goto leave; |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 263 | } |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 264 | |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 265 | if (!LIST_ISEMPTY(&qcc->opening_list) || unlikely(!qcc->largest_bidi_r)) { |
| 266 | int timeout = px->timeout.httpreq; |
| 267 | struct qcs *qcs = NULL; |
| 268 | int base_time; |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 269 | |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 270 | /* Use start time of first stream waiting on HTTP or |
| 271 | * qcc idle if no stream not yet used. |
| 272 | */ |
| 273 | if (likely(!LIST_ISEMPTY(&qcc->opening_list))) |
| 274 | qcs = LIST_ELEM(qcc->opening_list.n, struct qcs *, el_opening); |
| 275 | base_time = qcs ? qcs->start : qcc->idle_start; |
| 276 | |
| 277 | TRACE_DEVEL("waiting on http request", QMUX_EV_QCC_WAKE, qcc->conn, qcs); |
| 278 | qcc->task->expire = tick_add_ifset(base_time, timeout); |
| 279 | } |
| 280 | else { |
| 281 | /* Use http-request timeout if keep-alive timeout not set */ |
| 282 | int timeout = tick_isset(px->timeout.httpka) ? |
| 283 | px->timeout.httpka : px->timeout.httpreq; |
| 284 | |
| 285 | TRACE_DEVEL("at least one request achieved but none currently in progress", QMUX_EV_QCC_WAKE, qcc->conn); |
| 286 | qcc->task->expire = tick_add_ifset(qcc->idle_start, timeout); |
| 287 | } |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 288 | } |
Amaury Denoyelle | 6ec9837 | 2022-08-01 17:59:38 +0200 | [diff] [blame] | 289 | |
| 290 | /* fallback to default timeout if frontend specific undefined or for |
| 291 | * backend connections. |
| 292 | */ |
| 293 | if (!tick_isset(qcc->task->expire)) { |
| 294 | TRACE_DEVEL("fallback to default timeout", QMUX_EV_QCC_WAKE, qcc->conn); |
| 295 | qcc->task->expire = tick_add_ifset(now_ms, qcc->timeout); |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 298 | task_queue(qcc->task); |
| 299 | |
| 300 | leave: |
| 301 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn); |
| 302 | } |
| 303 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 304 | /* Mark a stream as open if it was idle. This can be used on every |
| 305 | * successful emission/reception operation to update the stream state. |
| 306 | */ |
| 307 | static void qcs_idle_open(struct qcs *qcs) |
| 308 | { |
| 309 | /* This operation must not be used if the stream is already closed. */ |
| 310 | BUG_ON_HOT(qcs->st == QC_SS_CLO); |
| 311 | |
| 312 | if (qcs->st == QC_SS_IDLE) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 313 | TRACE_STATE("opening stream", QMUX_EV_QCS_NEW, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 314 | qcs->st = QC_SS_OPEN; |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | /* Close the local channel of <qcs> instance. */ |
| 319 | static void qcs_close_local(struct qcs *qcs) |
| 320 | { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 321 | TRACE_STATE("closing stream locally", QMUX_EV_QCS_SEND, qcs->qcc->conn, qcs); |
| 322 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 323 | /* The stream must have already been opened. */ |
| 324 | BUG_ON_HOT(qcs->st == QC_SS_IDLE); |
| 325 | |
| 326 | /* This operation cannot be used multiple times. */ |
| 327 | BUG_ON_HOT(qcs->st == QC_SS_HLOC || qcs->st == QC_SS_CLO); |
| 328 | |
| 329 | if (quic_stream_is_bidi(qcs->id)) { |
| 330 | qcs->st = (qcs->st == QC_SS_HREM) ? QC_SS_CLO : QC_SS_HLOC; |
Amaury Denoyelle | afb7b9d | 2022-09-19 11:58:24 +0200 | [diff] [blame] | 331 | |
| 332 | if (qcs->flags & QC_SF_HREQ_RECV) |
| 333 | qcc_rm_hreq(qcs->qcc); |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 334 | } |
| 335 | else { |
| 336 | /* Only local uni streams are valid for this operation. */ |
| 337 | BUG_ON_HOT(quic_stream_is_remote(qcs->qcc, qcs->id)); |
| 338 | qcs->st = QC_SS_CLO; |
| 339 | } |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* Close the remote channel of <qcs> instance. */ |
| 343 | static void qcs_close_remote(struct qcs *qcs) |
| 344 | { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 345 | TRACE_STATE("closing stream remotely", QMUX_EV_QCS_RECV, qcs->qcc->conn, qcs); |
| 346 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 347 | /* The stream must have already been opened. */ |
| 348 | BUG_ON_HOT(qcs->st == QC_SS_IDLE); |
| 349 | |
| 350 | /* This operation cannot be used multiple times. */ |
| 351 | BUG_ON_HOT(qcs->st == QC_SS_HREM || qcs->st == QC_SS_CLO); |
| 352 | |
| 353 | if (quic_stream_is_bidi(qcs->id)) { |
| 354 | qcs->st = (qcs->st == QC_SS_HLOC) ? QC_SS_CLO : QC_SS_HREM; |
| 355 | } |
| 356 | else { |
| 357 | /* Only remote uni streams are valid for this operation. */ |
| 358 | BUG_ON_HOT(quic_stream_is_local(qcs->qcc, qcs->id)); |
| 359 | qcs->st = QC_SS_CLO; |
| 360 | } |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static int qcs_is_close_local(struct qcs *qcs) |
| 364 | { |
| 365 | return qcs->st == QC_SS_HLOC || qcs->st == QC_SS_CLO; |
| 366 | } |
| 367 | |
| 368 | static __maybe_unused int qcs_is_close_remote(struct qcs *qcs) |
| 369 | { |
| 370 | return qcs->st == QC_SS_HREM || qcs->st == QC_SS_CLO; |
| 371 | } |
| 372 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 373 | struct buffer *qc_get_buf(struct qcs *qcs, struct buffer *bptr) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 374 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 375 | struct buffer *buf = b_alloc(bptr); |
| 376 | BUG_ON(!buf); |
| 377 | return buf; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Amaury Denoyelle | a441ec9 | 2022-07-04 15:48:57 +0200 | [diff] [blame] | 380 | static struct ncbuf *qc_get_ncbuf(struct qcs *qcs, struct ncbuf *ncbuf) |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 381 | { |
| 382 | struct buffer buf = BUF_NULL; |
| 383 | |
| 384 | if (ncb_is_null(ncbuf)) { |
| 385 | b_alloc(&buf); |
| 386 | BUG_ON(b_is_null(&buf)); |
| 387 | |
| 388 | *ncbuf = ncb_make(buf.area, buf.size, 0); |
| 389 | ncb_init(ncbuf, 0); |
| 390 | } |
| 391 | |
| 392 | return ncbuf; |
| 393 | } |
| 394 | |
Ilya Shipitsin | 3b64a28 | 2022-07-29 22:26:53 +0500 | [diff] [blame] | 395 | /* Notify an eventual subscriber on <qcs> or else wakeup up the stconn layer if |
Amaury Denoyelle | 4561f84 | 2022-07-06 14:54:34 +0200 | [diff] [blame] | 396 | * initialized. |
| 397 | */ |
| 398 | static void qcs_alert(struct qcs *qcs) |
| 399 | { |
| 400 | if (qcs->subs) { |
| 401 | qcs_notify_recv(qcs); |
| 402 | qcs_notify_send(qcs); |
| 403 | } |
| 404 | else if (qcs_sc(qcs) && qcs->sd->sc->app_ops->wake) { |
| 405 | qcs->sd->sc->app_ops->wake(qcs->sd->sc); |
| 406 | } |
| 407 | } |
| 408 | |
Amaury Denoyelle | a3f222d | 2021-12-06 11:24:00 +0100 | [diff] [blame] | 409 | int qcs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es) |
| 410 | { |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 411 | struct qcc *qcc = qcs->qcc; |
| 412 | |
| 413 | TRACE_ENTER(QMUX_EV_STRM_SEND|QMUX_EV_STRM_RECV, qcc->conn, qcs); |
Amaury Denoyelle | a3f222d | 2021-12-06 11:24:00 +0100 | [diff] [blame] | 414 | |
| 415 | BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV)); |
| 416 | BUG_ON(qcs->subs && qcs->subs != es); |
| 417 | |
| 418 | es->events |= event_type; |
| 419 | qcs->subs = es; |
| 420 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 421 | if (event_type & SUB_RETRY_RECV) |
| 422 | TRACE_DEVEL("subscribe(recv)", QMUX_EV_STRM_RECV, qcc->conn, qcs); |
| 423 | |
| 424 | if (event_type & SUB_RETRY_SEND) |
| 425 | TRACE_DEVEL("subscribe(send)", QMUX_EV_STRM_SEND, qcc->conn, qcs); |
| 426 | |
| 427 | TRACE_LEAVE(QMUX_EV_STRM_SEND|QMUX_EV_STRM_RECV, qcc->conn, qcs); |
| 428 | |
Amaury Denoyelle | a3f222d | 2021-12-06 11:24:00 +0100 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | void qcs_notify_recv(struct qcs *qcs) |
| 433 | { |
| 434 | if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) { |
| 435 | tasklet_wakeup(qcs->subs->tasklet); |
| 436 | qcs->subs->events &= ~SUB_RETRY_RECV; |
| 437 | if (!qcs->subs->events) |
| 438 | qcs->subs = NULL; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | void qcs_notify_send(struct qcs *qcs) |
| 443 | { |
| 444 | if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) { |
| 445 | tasklet_wakeup(qcs->subs->tasklet); |
| 446 | qcs->subs->events &= ~SUB_RETRY_SEND; |
| 447 | if (!qcs->subs->events) |
| 448 | qcs->subs = NULL; |
| 449 | } |
| 450 | } |
| 451 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 452 | /* Open a locally initiated stream for the connection <qcc>. Set <bidi> for a |
| 453 | * bidirectional stream, else an unidirectional stream is opened. The next |
| 454 | * available ID on the connection will be used according to the stream type. |
| 455 | * |
| 456 | * Returns the allocated stream instance or NULL on error. |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 457 | */ |
Amaury Denoyelle | b143723 | 2022-07-08 11:53:22 +0200 | [diff] [blame] | 458 | struct qcs *qcc_init_stream_local(struct qcc *qcc, int bidi) |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 459 | { |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 460 | struct qcs *qcs; |
| 461 | enum qcs_type type; |
| 462 | uint64_t *next; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 463 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 464 | TRACE_ENTER(QMUX_EV_QCS_NEW, qcc->conn); |
| 465 | |
| 466 | if (bidi) { |
| 467 | next = &qcc->next_bidi_l; |
| 468 | type = conn_is_back(qcc->conn) ? QCS_CLT_BIDI : QCS_SRV_BIDI; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 469 | } |
| 470 | else { |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 471 | next = &qcc->next_uni_l; |
| 472 | type = conn_is_back(qcc->conn) ? QCS_CLT_UNI : QCS_SRV_UNI; |
| 473 | } |
| 474 | |
| 475 | /* TODO ensure that we won't overflow remote peer flow control limit on |
| 476 | * streams. Else, we should emit a STREAMS_BLOCKED frame. |
| 477 | */ |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 478 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 479 | qcs = qcs_new(qcc, *next, type); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 480 | if (!qcs) { |
| 481 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn); |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 482 | return NULL; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 483 | } |
Amaury Denoyelle | c055e30 | 2022-02-07 16:09:06 +0100 | [diff] [blame] | 484 | |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 485 | TRACE_PROTO("opening local stream", QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 486 | *next += 4; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 487 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 488 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 489 | return qcs; |
| 490 | } |
| 491 | |
| 492 | /* Open a remote initiated stream for the connection <qcc> with ID <id>. The |
| 493 | * caller is responsible to ensure that a stream with the same ID was not |
| 494 | * already opened. This function will also create all intermediaries streams |
| 495 | * with ID smaller than <id> not already opened before. |
| 496 | * |
| 497 | * Returns the allocated stream instance or NULL on error. |
| 498 | */ |
Amaury Denoyelle | b143723 | 2022-07-08 11:53:22 +0200 | [diff] [blame] | 499 | static struct qcs *qcc_init_stream_remote(struct qcc *qcc, uint64_t id) |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 500 | { |
| 501 | struct qcs *qcs = NULL; |
| 502 | enum qcs_type type; |
Amaury Denoyelle | bf3c208 | 2022-08-16 11:29:08 +0200 | [diff] [blame] | 503 | uint64_t *largest, max_id; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 504 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 505 | TRACE_ENTER(QMUX_EV_QCS_NEW, qcc->conn); |
Amaury Denoyelle | 7272cd7 | 2022-03-29 15:15:54 +0200 | [diff] [blame] | 506 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 507 | BUG_ON_HOT(quic_stream_is_local(qcc, id)); |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 508 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 509 | if (quic_stream_is_bidi(id)) { |
| 510 | largest = &qcc->largest_bidi_r; |
| 511 | type = conn_is_back(qcc->conn) ? QCS_SRV_BIDI : QCS_CLT_BIDI; |
| 512 | } |
| 513 | else { |
| 514 | largest = &qcc->largest_uni_r; |
| 515 | type = conn_is_back(qcc->conn) ? QCS_SRV_UNI : QCS_CLT_UNI; |
| 516 | } |
| 517 | |
Amaury Denoyelle | bf3c208 | 2022-08-16 11:29:08 +0200 | [diff] [blame] | 518 | /* RFC 9000 4.6. Controlling Concurrency |
| 519 | * |
| 520 | * An endpoint that receives a frame with a stream ID exceeding the |
| 521 | * limit it has sent MUST treat this as a connection error of type |
| 522 | * STREAM_LIMIT_ERROR |
| 523 | */ |
| 524 | max_id = quic_stream_is_bidi(id) ? qcc->lfctl.ms_bidi * 4 : |
| 525 | qcc->lfctl.ms_uni * 4; |
| 526 | if (id >= max_id) { |
| 527 | TRACE_ERROR("flow control error", QMUX_EV_QCS_NEW|QMUX_EV_PROTO_ERR, qcc->conn); |
| 528 | qcc_emit_cc(qcc, QC_ERR_STREAM_LIMIT_ERROR); |
| 529 | goto err; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* Only stream ID not already opened can be used. */ |
| 533 | BUG_ON(id < *largest); |
| 534 | |
| 535 | while (id >= *largest) { |
Amaury Denoyelle | fd79ddb | 2022-08-16 11:13:45 +0200 | [diff] [blame] | 536 | const char *str = *largest < id ? "initializing intermediary remote stream" : |
| 537 | "initializing remote stream"; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 538 | |
| 539 | qcs = qcs_new(qcc, *largest, type); |
| 540 | if (!qcs) { |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 541 | /* TODO emit RESET_STREAM */ |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 542 | TRACE_ERROR("stream fallocation failure", QMUX_EV_QCS_NEW, qcc->conn); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 543 | goto err; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 544 | } |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 545 | |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 546 | TRACE_PROTO(str, QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 547 | *largest += 4; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 548 | } |
| 549 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 550 | out: |
| 551 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn, qcs); |
Amaury Denoyelle | 5074229 | 2022-03-29 14:57:19 +0200 | [diff] [blame] | 552 | return qcs; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 553 | |
| 554 | err: |
| 555 | TRACE_LEAVE(QMUX_EV_QCS_NEW, qcc->conn); |
| 556 | return NULL; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* Use this function for a stream <id> which is not in <qcc> stream tree. It |
| 560 | * returns true if the associated stream is closed. |
| 561 | */ |
| 562 | static int qcc_stream_id_is_closed(struct qcc *qcc, uint64_t id) |
| 563 | { |
| 564 | uint64_t *largest; |
| 565 | |
| 566 | /* This function must only be used for stream not present in the stream tree. */ |
| 567 | BUG_ON_HOT(eb64_lookup(&qcc->streams_by_id, id)); |
| 568 | |
| 569 | if (quic_stream_is_local(qcc, id)) { |
| 570 | largest = quic_stream_is_uni(id) ? &qcc->next_uni_l : |
| 571 | &qcc->next_bidi_l; |
| 572 | } |
| 573 | else { |
| 574 | largest = quic_stream_is_uni(id) ? &qcc->largest_uni_r : |
| 575 | &qcc->largest_bidi_r; |
| 576 | } |
| 577 | |
| 578 | return id < *largest; |
| 579 | } |
| 580 | |
| 581 | /* Retrieve the stream instance from <id> ID. This can be used when receiving |
| 582 | * STREAM, STREAM_DATA_BLOCKED, RESET_STREAM, MAX_STREAM_DATA or STOP_SENDING |
Amaury Denoyelle | 5fbb869 | 2022-07-06 15:43:21 +0200 | [diff] [blame] | 583 | * frames. Set to false <receive_only> or <send_only> if these particular types |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 584 | * of streams are not allowed. If the stream instance is found, it is stored in |
| 585 | * <out>. |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 586 | * |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 587 | * Returns 0 on success else non-zero. On error, a RESET_STREAM or a |
| 588 | * CONNECTION_CLOSE is automatically emitted. Beware that <out> may be NULL |
| 589 | * on success if the stream has already been closed. |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 590 | */ |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 591 | int qcc_get_qcs(struct qcc *qcc, uint64_t id, int receive_only, int send_only, |
| 592 | struct qcs **out) |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 593 | { |
| 594 | struct eb64_node *node; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 595 | |
| 596 | TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 597 | *out = NULL; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 598 | |
Amaury Denoyelle | 5fbb869 | 2022-07-06 15:43:21 +0200 | [diff] [blame] | 599 | if (!receive_only && quic_stream_is_uni(id) && quic_stream_is_remote(qcc, id)) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 600 | TRACE_ERROR("receive-only stream not allowed", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS|QMUX_EV_PROTO_ERR, qcc->conn, NULL, &id); |
Amaury Denoyelle | 5fbb869 | 2022-07-06 15:43:21 +0200 | [diff] [blame] | 601 | qcc_emit_cc(qcc, QC_ERR_STREAM_STATE_ERROR); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 602 | goto err; |
Amaury Denoyelle | 5fbb869 | 2022-07-06 15:43:21 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | if (!send_only && quic_stream_is_uni(id) && quic_stream_is_local(qcc, id)) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 606 | TRACE_ERROR("send-only stream not allowed", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS|QMUX_EV_PROTO_ERR, qcc->conn, NULL, &id); |
Amaury Denoyelle | 5fbb869 | 2022-07-06 15:43:21 +0200 | [diff] [blame] | 607 | qcc_emit_cc(qcc, QC_ERR_STREAM_STATE_ERROR); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 608 | goto err; |
Amaury Denoyelle | 5fbb869 | 2022-07-06 15:43:21 +0200 | [diff] [blame] | 609 | } |
| 610 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 611 | /* Search the stream in the connection tree. */ |
| 612 | node = eb64_lookup(&qcc->streams_by_id, id); |
| 613 | if (node) { |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 614 | *out = eb64_entry(node, struct qcs, by_id); |
| 615 | TRACE_DEVEL("using stream from connection tree", QMUX_EV_QCC_RECV, qcc->conn, *out); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 616 | goto out; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /* Check if stream is already closed. */ |
| 620 | if (qcc_stream_id_is_closed(qcc, id)) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 621 | TRACE_DATA("already closed stream", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS, qcc->conn, NULL, &id); |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 622 | /* Consider this as a success even if <out> is left NULL. */ |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 623 | goto out; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* Create the stream. This is valid only for remote initiated one. A |
Ilya Shipitsin | 3b64a28 | 2022-07-29 22:26:53 +0500 | [diff] [blame] | 627 | * local stream must have already been explicitly created by the |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 628 | * application protocol layer. |
| 629 | */ |
| 630 | if (quic_stream_is_local(qcc, id)) { |
| 631 | /* RFC 9000 19.8. STREAM Frames |
| 632 | * |
| 633 | * An endpoint MUST terminate the connection with error |
| 634 | * STREAM_STATE_ERROR if it receives a STREAM frame for a locally |
| 635 | * initiated stream that has not yet been created, or for a send-only |
| 636 | * stream. |
| 637 | */ |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 638 | TRACE_ERROR("locally initiated stream not yet created", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS|QMUX_EV_PROTO_ERR, qcc->conn, NULL, &id); |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 639 | qcc_emit_cc(qcc, QC_ERR_STREAM_STATE_ERROR); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 640 | goto err; |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 641 | } |
| 642 | else { |
| 643 | /* Remote stream not found - try to open it. */ |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 644 | *out = qcc_init_stream_remote(qcc, id); |
| 645 | if (!*out) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 646 | TRACE_ERROR("stream creation error", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS, qcc->conn, NULL, &id); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 647 | goto err; |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 648 | } |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 649 | } |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 650 | |
| 651 | out: |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 652 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn, *out); |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 653 | return 0; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 654 | |
| 655 | err: |
| 656 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
| 657 | return 1; |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 658 | } |
| 659 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 660 | /* Simple function to duplicate a buffer */ |
| 661 | static inline struct buffer qcs_b_dup(const struct ncbuf *b) |
| 662 | { |
| 663 | return b_make(ncb_orig(b), b->size, b->head, ncb_data(b, 0)); |
| 664 | } |
| 665 | |
Amaury Denoyelle | 36d4b5e | 2022-07-01 11:25:40 +0200 | [diff] [blame] | 666 | /* Remove <bytes> from <qcs> Rx buffer. Flow-control for received offsets may |
| 667 | * be allocated for the peer if needed. |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 668 | */ |
| 669 | static void qcs_consume(struct qcs *qcs, uint64_t bytes) |
| 670 | { |
| 671 | struct qcc *qcc = qcs->qcc; |
| 672 | struct quic_frame *frm; |
| 673 | struct ncbuf *buf = &qcs->rx.ncbuf; |
| 674 | enum ncb_ret ret; |
| 675 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 676 | TRACE_ENTER(QMUX_EV_QCS_RECV, qcc->conn, qcs); |
| 677 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 678 | ret = ncb_advance(buf, bytes); |
| 679 | if (ret) { |
| 680 | ABORT_NOW(); /* should not happens because removal only in data */ |
| 681 | } |
| 682 | |
| 683 | if (ncb_is_empty(buf)) |
| 684 | qc_free_ncbuf(qcs, buf); |
| 685 | |
| 686 | qcs->rx.offset += bytes; |
| 687 | if (qcs->rx.msd - qcs->rx.offset < qcs->rx.msd_init / 2) { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 688 | TRACE_DATA("increase stream credit via MAX_STREAM_DATA", QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 689 | frm = pool_zalloc(pool_head_quic_frame); |
| 690 | BUG_ON(!frm); /* TODO handle this properly */ |
| 691 | |
| 692 | qcs->rx.msd = qcs->rx.offset + qcs->rx.msd_init; |
| 693 | |
| 694 | LIST_INIT(&frm->reflist); |
| 695 | frm->type = QUIC_FT_MAX_STREAM_DATA; |
| 696 | frm->max_stream_data.id = qcs->id; |
| 697 | frm->max_stream_data.max_stream_data = qcs->rx.msd; |
| 698 | |
| 699 | LIST_APPEND(&qcc->lfctl.frms, &frm->list); |
| 700 | tasklet_wakeup(qcc->wait_event.tasklet); |
| 701 | } |
| 702 | |
| 703 | qcc->lfctl.offsets_consume += bytes; |
| 704 | if (qcc->lfctl.md - qcc->lfctl.offsets_consume < qcc->lfctl.md_init / 2) { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 705 | TRACE_DATA("increase conn credit via MAX_DATA", QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 706 | frm = pool_zalloc(pool_head_quic_frame); |
| 707 | BUG_ON(!frm); /* TODO handle this properly */ |
| 708 | |
| 709 | qcc->lfctl.md = qcc->lfctl.offsets_consume + qcc->lfctl.md_init; |
| 710 | |
| 711 | LIST_INIT(&frm->reflist); |
| 712 | frm->type = QUIC_FT_MAX_DATA; |
| 713 | frm->max_data.max_data = qcc->lfctl.md; |
| 714 | |
| 715 | LIST_APPEND(&qcs->qcc->lfctl.frms, &frm->list); |
| 716 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
| 717 | } |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 718 | |
| 719 | TRACE_LEAVE(QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 722 | /* Decode the content of STREAM frames already received on the stream instance |
| 723 | * <qcs>. |
| 724 | * |
| 725 | * Returns 0 on success else non-zero. |
| 726 | */ |
| 727 | static int qcc_decode_qcs(struct qcc *qcc, struct qcs *qcs) |
| 728 | { |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 729 | struct buffer b; |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 730 | ssize_t ret; |
Amaury Denoyelle | 6befccd | 2022-07-01 11:26:04 +0200 | [diff] [blame] | 731 | int fin = 0; |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 732 | |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 733 | TRACE_ENTER(QMUX_EV_QCS_RECV, qcc->conn, qcs); |
| 734 | |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 735 | b = qcs_b_dup(&qcs->rx.ncbuf); |
Amaury Denoyelle | 6befccd | 2022-07-01 11:26:04 +0200 | [diff] [blame] | 736 | |
Amaury Denoyelle | d1310f8 | 2022-09-16 13:30:59 +0200 | [diff] [blame] | 737 | /* Signal FIN to application if STREAM FIN received with all data. */ |
| 738 | if (qcs_is_close_remote(qcs)) |
Amaury Denoyelle | 6befccd | 2022-07-01 11:26:04 +0200 | [diff] [blame] | 739 | fin = 1; |
| 740 | |
| 741 | ret = qcc->app_ops->decode_qcs(qcs, &b, fin); |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 742 | if (ret < 0) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 743 | TRACE_ERROR("decoding error", QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 744 | goto err; |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 745 | } |
| 746 | |
Amaury Denoyelle | 1f21ebd | 2022-06-07 17:30:55 +0200 | [diff] [blame] | 747 | if (ret) { |
| 748 | qcs_consume(qcs, ret); |
Amaury Denoyelle | 62eef85 | 2022-06-03 16:40:34 +0200 | [diff] [blame] | 749 | qcs_notify_recv(qcs); |
| 750 | } |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 751 | |
| 752 | TRACE_LEAVE(QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 753 | return 0; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 754 | |
| 755 | err: |
| 756 | TRACE_LEAVE(QMUX_EV_QCS_RECV, qcc->conn, qcs); |
| 757 | return 1; |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 758 | } |
| 759 | |
Amaury Denoyelle | f9e190e | 2022-05-23 16:12:15 +0200 | [diff] [blame] | 760 | /* Emit a CONNECTION_CLOSE_APP with error <err>. Reserved for application error |
Amaury Denoyelle | d666d74 | 2022-07-13 15:15:58 +0200 | [diff] [blame] | 761 | * code. To close the connection right away, set <immediate> : this is useful |
| 762 | * when dealing with a connection fatal error. Else a graceful shutdown will be |
| 763 | * conducted : the error-code is only registered. The lower layer is |
| 764 | * responsible to close the connection when deemed suitable. Note that in this |
| 765 | * case the error code might be overwritten if an immediate close is requested |
| 766 | * in the interval. |
Amaury Denoyelle | f9e190e | 2022-05-23 16:12:15 +0200 | [diff] [blame] | 767 | */ |
Amaury Denoyelle | d666d74 | 2022-07-13 15:15:58 +0200 | [diff] [blame] | 768 | void qcc_emit_cc_app(struct qcc *qcc, int err, int immediate) |
Amaury Denoyelle | f9e190e | 2022-05-23 16:12:15 +0200 | [diff] [blame] | 769 | { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 770 | TRACE_ENTER(QMUX_EV_QCC_END, qcc->conn); |
| 771 | |
Amaury Denoyelle | d666d74 | 2022-07-13 15:15:58 +0200 | [diff] [blame] | 772 | if (immediate) { |
| 773 | quic_set_connection_close(qcc->conn->handle.qc, quic_err_app(err)); |
| 774 | qcc->flags |= QC_CF_CC_EMIT; |
| 775 | tasklet_wakeup(qcc->wait_event.tasklet); |
| 776 | } |
| 777 | else { |
| 778 | /* Only register the error code for graceful shutdown. */ |
| 779 | qcc->conn->handle.qc->err = quic_err_app(err); |
| 780 | } |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 781 | |
| 782 | TRACE_LEAVE(QMUX_EV_QCC_END, qcc->conn); |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /* Prepare for the emission of RESET_STREAM on <qcs> with error code <err>. */ |
| 786 | void qcc_reset_stream(struct qcs *qcs, int err) |
| 787 | { |
| 788 | struct qcc *qcc = qcs->qcc; |
| 789 | |
| 790 | if ((qcs->flags & QC_SF_TO_RESET) || qcs_is_close_local(qcs)) |
| 791 | return; |
| 792 | |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 793 | TRACE_STATE("reset stream", QMUX_EV_QCS_END, qcc->conn, qcs); |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 794 | qcs->flags |= QC_SF_TO_RESET; |
| 795 | qcs->err = err; |
| 796 | tasklet_wakeup(qcc->wait_event.tasklet); |
Amaury Denoyelle | f9e190e | 2022-05-23 16:12:15 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 799 | /* Install the <app_ops> applicative layer of a QUIC connection on mux <qcc>. |
| 800 | * Returns 0 on success else non-zero. |
| 801 | */ |
| 802 | int qcc_install_app_ops(struct qcc *qcc, const struct qcc_app_ops *app_ops) |
| 803 | { |
| 804 | TRACE_ENTER(QMUX_EV_QCC_NEW, qcc->conn); |
| 805 | |
| 806 | qcc->app_ops = app_ops; |
| 807 | if (qcc->app_ops->init && !qcc->app_ops->init(qcc)) { |
| 808 | TRACE_ERROR("app ops init error", QMUX_EV_QCC_NEW, qcc->conn); |
| 809 | goto err; |
| 810 | } |
| 811 | |
| 812 | TRACE_PROTO("application layer initialized", QMUX_EV_QCC_NEW, qcc->conn); |
| 813 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 814 | TRACE_LEAVE(QMUX_EV_QCC_NEW, qcc->conn); |
| 815 | return 0; |
| 816 | |
| 817 | err: |
| 818 | TRACE_LEAVE(QMUX_EV_QCC_NEW, qcc->conn); |
| 819 | return 1; |
| 820 | } |
| 821 | |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 822 | /* Handle a new STREAM frame for stream with id <id>. Payload is pointed by |
| 823 | * <data> with length <len> and represents the offset <offset>. <fin> is set if |
| 824 | * the QUIC frame FIN bit is set. |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 825 | * |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 826 | * Returns 0 on success else non-zero. On error, the received frame should not |
| 827 | * be acknowledged. |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 828 | */ |
| 829 | int qcc_recv(struct qcc *qcc, uint64_t id, uint64_t len, uint64_t offset, |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 830 | char fin, char *data) |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 831 | { |
| 832 | struct qcs *qcs; |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 833 | enum ncb_ret ret; |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 834 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 835 | TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn); |
| 836 | |
Amaury Denoyelle | 5c4373a | 2022-05-24 14:47:48 +0200 | [diff] [blame] | 837 | if (qcc->flags & QC_CF_CC_EMIT) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 838 | TRACE_DATA("connection closed", QMUX_EV_QCC_RECV, qcc->conn); |
| 839 | goto err; |
Amaury Denoyelle | 5c4373a | 2022-05-24 14:47:48 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Amaury Denoyelle | 6754d7e | 2022-05-23 16:12:49 +0200 | [diff] [blame] | 842 | /* RFC 9000 19.8. STREAM Frames |
| 843 | * |
| 844 | * An endpoint MUST terminate the connection with error |
| 845 | * STREAM_STATE_ERROR if it receives a STREAM frame for a locally |
| 846 | * initiated stream that has not yet been created, or for a send-only |
| 847 | * stream. |
| 848 | */ |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 849 | if (qcc_get_qcs(qcc, id, 1, 0, &qcs)) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 850 | TRACE_DATA("qcs retrieval error", QMUX_EV_QCC_RECV, qcc->conn); |
| 851 | goto err; |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | if (!qcs) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 855 | TRACE_DATA("already closed stream", QMUX_EV_QCC_RECV, qcc->conn); |
| 856 | goto out; |
Amaury Denoyelle | 57161b7 | 2022-07-07 15:02:32 +0200 | [diff] [blame] | 857 | } |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 858 | |
Amaury Denoyelle | bf91e39 | 2022-07-04 10:02:04 +0200 | [diff] [blame] | 859 | /* RFC 9000 4.5. Stream Final Size |
| 860 | * |
| 861 | * Once a final size for a stream is known, it cannot change. If a |
| 862 | * RESET_STREAM or STREAM frame is received indicating a change in the |
| 863 | * final size for the stream, an endpoint SHOULD respond with an error |
| 864 | * of type FINAL_SIZE_ERROR; see Section 11 for details on error |
| 865 | * handling. |
| 866 | */ |
| 867 | if (qcs->flags & QC_SF_SIZE_KNOWN && |
| 868 | (offset + len > qcs->rx.offset_max || (fin && offset + len < qcs->rx.offset_max))) { |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 869 | TRACE_ERROR("final size error", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV|QMUX_EV_PROTO_ERR, qcc->conn, qcs); |
Amaury Denoyelle | bf91e39 | 2022-07-04 10:02:04 +0200 | [diff] [blame] | 870 | qcc_emit_cc(qcc, QC_ERR_FINAL_SIZE_ERROR); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 871 | goto err; |
Amaury Denoyelle | bf91e39 | 2022-07-04 10:02:04 +0200 | [diff] [blame] | 872 | } |
| 873 | |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 874 | if (offset + len <= qcs->rx.offset) { |
Amaury Denoyelle | d1310f8 | 2022-09-16 13:30:59 +0200 | [diff] [blame] | 875 | /* TODO offset may have been received without FIN first and now |
| 876 | * with it. In this case, it must be notified to be able to |
| 877 | * close the stream. |
| 878 | */ |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 879 | TRACE_DATA("already received offset", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
| 880 | goto out; |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 881 | } |
| 882 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 883 | TRACE_PROTO("receiving STREAM", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 884 | qcs_idle_open(qcs); |
| 885 | |
Amaury Denoyelle | d46b0f5 | 2022-05-20 15:05:07 +0200 | [diff] [blame] | 886 | if (offset + len > qcs->rx.offset_max) { |
| 887 | uint64_t diff = offset + len - qcs->rx.offset_max; |
| 888 | qcs->rx.offset_max = offset + len; |
| 889 | qcc->lfctl.offsets_recv += diff; |
| 890 | |
| 891 | if (offset + len > qcs->rx.msd || |
| 892 | qcc->lfctl.offsets_recv > qcc->lfctl.md) { |
| 893 | /* RFC 9000 4.1. Data Flow Control |
| 894 | * |
| 895 | * A receiver MUST close the connection with an error |
| 896 | * of type FLOW_CONTROL_ERROR if the sender violates |
| 897 | * the advertised connection or stream data limits |
| 898 | */ |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 899 | TRACE_ERROR("flow control error", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV|QMUX_EV_PROTO_ERR, |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 900 | qcc->conn, qcs); |
Amaury Denoyelle | d46b0f5 | 2022-05-20 15:05:07 +0200 | [diff] [blame] | 901 | qcc_emit_cc(qcc, QC_ERR_FLOW_CONTROL_ERROR); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 902 | goto err; |
Amaury Denoyelle | d46b0f5 | 2022-05-20 15:05:07 +0200 | [diff] [blame] | 903 | } |
| 904 | } |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 905 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 906 | if (!qc_get_ncbuf(qcs, &qcs->rx.ncbuf) || ncb_is_null(&qcs->rx.ncbuf)) { |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 907 | /* TODO should mark qcs as full */ |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 908 | ABORT_NOW(); |
| 909 | return 1; |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 912 | TRACE_DATA("newly received offset", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 913 | if (offset < qcs->rx.offset) { |
Frédéric Lécaille | a18c333 | 2022-07-04 09:54:58 +0200 | [diff] [blame] | 914 | size_t diff = qcs->rx.offset - offset; |
| 915 | |
| 916 | len -= diff; |
| 917 | data += diff; |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 918 | offset = qcs->rx.offset; |
| 919 | } |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 920 | |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 921 | ret = ncb_add(&qcs->rx.ncbuf, offset - qcs->rx.offset, data, len, NCB_ADD_COMPARE); |
| 922 | if (ret != NCB_RET_OK) { |
| 923 | if (ret == NCB_RET_DATA_REJ) { |
Amaury Denoyelle | cc3d716 | 2022-05-20 15:14:57 +0200 | [diff] [blame] | 924 | /* RFC 9000 2.2. Sending and Receiving Data |
| 925 | * |
| 926 | * An endpoint could receive data for a stream at the |
| 927 | * same stream offset multiple times. Data that has |
| 928 | * already been received can be discarded. The data at |
| 929 | * a given offset MUST NOT change if it is sent |
| 930 | * multiple times; an endpoint MAY treat receipt of |
| 931 | * different data at the same offset within a stream as |
| 932 | * a connection error of type PROTOCOL_VIOLATION. |
| 933 | */ |
Amaury Denoyelle | c7fb0d2 | 2022-08-10 16:39:54 +0200 | [diff] [blame] | 934 | TRACE_ERROR("overlapping data rejected", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV|QMUX_EV_PROTO_ERR, |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 935 | qcc->conn, qcs); |
Amaury Denoyelle | cc3d716 | 2022-05-20 15:14:57 +0200 | [diff] [blame] | 936 | qcc_emit_cc(qcc, QC_ERR_PROTOCOL_VIOLATION); |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 937 | } |
| 938 | else if (ret == NCB_RET_GAP_SIZE) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 939 | TRACE_DATA("cannot bufferize frame due to gap size limit", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, |
| 940 | qcc->conn, qcs); |
Amaury Denoyelle | 1290f1e | 2022-05-13 14:49:05 +0200 | [diff] [blame] | 941 | } |
| 942 | return 1; |
| 943 | } |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 944 | |
| 945 | if (fin) |
Amaury Denoyelle | 3f39b40 | 2022-07-01 16:11:03 +0200 | [diff] [blame] | 946 | qcs->flags |= QC_SF_SIZE_KNOWN; |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 947 | |
Amaury Denoyelle | d1310f8 | 2022-09-16 13:30:59 +0200 | [diff] [blame] | 948 | if (qcs->flags & QC_SF_SIZE_KNOWN && |
| 949 | qcs->rx.offset_max == qcs->rx.offset + ncb_data(&qcs->rx.ncbuf, 0)) { |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 950 | qcs_close_remote(qcs); |
Amaury Denoyelle | d1310f8 | 2022-09-16 13:30:59 +0200 | [diff] [blame] | 951 | } |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 952 | |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 953 | if (ncb_data(&qcs->rx.ncbuf, 0) && !(qcs->flags & QC_SF_DEM_FULL)) { |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 954 | qcc_decode_qcs(qcc, qcs); |
Amaury Denoyelle | 418ba21 | 2022-08-02 15:57:16 +0200 | [diff] [blame] | 955 | qcc_refresh_timeout(qcc); |
| 956 | } |
Amaury Denoyelle | 3a08640 | 2022-05-18 11:38:22 +0200 | [diff] [blame] | 957 | |
Amaury Denoyelle | 849b24f | 2022-05-24 17:22:07 +0200 | [diff] [blame] | 958 | if (qcs->flags & QC_SF_READ_ABORTED) { |
| 959 | /* TODO should send a STOP_SENDING */ |
| 960 | qcs_free(qcs); |
| 961 | } |
| 962 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 963 | out: |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 964 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 965 | return 0; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 966 | |
| 967 | err: |
| 968 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
| 969 | return 1; |
Amaury Denoyelle | 0e3010b | 2022-02-28 11:37:48 +0100 | [diff] [blame] | 970 | } |
| 971 | |
Amaury Denoyelle | 1e5e513 | 2022-03-08 16:23:03 +0100 | [diff] [blame] | 972 | /* Handle a new MAX_DATA frame. <max> must contains the maximum data field of |
| 973 | * the frame. |
| 974 | * |
| 975 | * Returns 0 on success else non-zero. |
| 976 | */ |
| 977 | int qcc_recv_max_data(struct qcc *qcc, uint64_t max) |
| 978 | { |
Amaury Denoyelle | 392e94e | 2022-07-06 15:44:16 +0200 | [diff] [blame] | 979 | TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn); |
| 980 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 981 | TRACE_PROTO("receiving MAX_DATA", QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 1e5e513 | 2022-03-08 16:23:03 +0100 | [diff] [blame] | 982 | if (qcc->rfctl.md < max) { |
| 983 | qcc->rfctl.md = max; |
Amaury Denoyelle | 392e94e | 2022-07-06 15:44:16 +0200 | [diff] [blame] | 984 | TRACE_DEVEL("increase remote max-data", QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 1e5e513 | 2022-03-08 16:23:03 +0100 | [diff] [blame] | 985 | |
| 986 | if (qcc->flags & QC_CF_BLK_MFCTL) { |
| 987 | qcc->flags &= ~QC_CF_BLK_MFCTL; |
| 988 | tasklet_wakeup(qcc->wait_event.tasklet); |
| 989 | } |
| 990 | } |
Amaury Denoyelle | 392e94e | 2022-07-06 15:44:16 +0200 | [diff] [blame] | 991 | |
| 992 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 1e5e513 | 2022-03-08 16:23:03 +0100 | [diff] [blame] | 993 | return 0; |
| 994 | } |
| 995 | |
Amaury Denoyelle | 8727ff4 | 2022-03-08 10:39:55 +0100 | [diff] [blame] | 996 | /* Handle a new MAX_STREAM_DATA frame. <max> must contains the maximum data |
| 997 | * field of the frame and <id> is the identifier of the QUIC stream. |
| 998 | * |
Amaury Denoyelle | b68559a | 2022-07-06 15:45:20 +0200 | [diff] [blame] | 999 | * Returns 0 on success else non-zero. On error, the received frame should not |
| 1000 | * be acknowledged. |
Amaury Denoyelle | 8727ff4 | 2022-03-08 10:39:55 +0100 | [diff] [blame] | 1001 | */ |
| 1002 | int qcc_recv_max_stream_data(struct qcc *qcc, uint64_t id, uint64_t max) |
| 1003 | { |
| 1004 | struct qcs *qcs; |
Amaury Denoyelle | 8727ff4 | 2022-03-08 10:39:55 +0100 | [diff] [blame] | 1005 | |
Amaury Denoyelle | 392e94e | 2022-07-06 15:44:16 +0200 | [diff] [blame] | 1006 | TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn); |
| 1007 | |
Amaury Denoyelle | b68559a | 2022-07-06 15:45:20 +0200 | [diff] [blame] | 1008 | /* RFC 9000 19.10. MAX_STREAM_DATA Frames |
| 1009 | * |
| 1010 | * Receiving a MAX_STREAM_DATA frame for a locally |
| 1011 | * initiated stream that has not yet been created MUST be treated as a |
| 1012 | * connection error of type STREAM_STATE_ERROR. An endpoint that |
| 1013 | * receives a MAX_STREAM_DATA frame for a receive-only stream MUST |
| 1014 | * terminate the connection with error STREAM_STATE_ERROR. |
| 1015 | */ |
| 1016 | if (qcc_get_qcs(qcc, id, 0, 1, &qcs)) { |
| 1017 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
| 1018 | return 1; |
| 1019 | } |
| 1020 | |
| 1021 | if (qcs) { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1022 | TRACE_PROTO("receiving MAX_STREAM_DATA", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 8727ff4 | 2022-03-08 10:39:55 +0100 | [diff] [blame] | 1023 | if (max > qcs->tx.msd) { |
| 1024 | qcs->tx.msd = max; |
Amaury Denoyelle | 392e94e | 2022-07-06 15:44:16 +0200 | [diff] [blame] | 1025 | TRACE_DEVEL("increase remote max-stream-data", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | 8727ff4 | 2022-03-08 10:39:55 +0100 | [diff] [blame] | 1026 | |
| 1027 | if (qcs->flags & QC_SF_BLK_SFCTL) { |
| 1028 | qcs->flags &= ~QC_SF_BLK_SFCTL; |
| 1029 | tasklet_wakeup(qcc->wait_event.tasklet); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 1034 | if (qcc_may_expire(qcc) && !qcc->nb_hreq) |
| 1035 | qcc_refresh_timeout(qcc); |
| 1036 | |
Amaury Denoyelle | 392e94e | 2022-07-06 15:44:16 +0200 | [diff] [blame] | 1037 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 8727ff4 | 2022-03-08 10:39:55 +0100 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
Amaury Denoyelle | a5b5075 | 2022-07-04 11:44:53 +0200 | [diff] [blame] | 1041 | /* Handle a new STOP_SENDING frame for stream ID <id>. The error code should be |
| 1042 | * specified in <err>. |
| 1043 | * |
| 1044 | * Returns 0 on success else non-zero. On error, the received frame should not |
| 1045 | * be acknowledged. |
| 1046 | */ |
| 1047 | int qcc_recv_stop_sending(struct qcc *qcc, uint64_t id, uint64_t err) |
| 1048 | { |
| 1049 | struct qcs *qcs; |
| 1050 | |
| 1051 | TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn); |
| 1052 | |
| 1053 | /* RFC 9000 19.5. STOP_SENDING Frames |
| 1054 | * |
| 1055 | * Receiving a STOP_SENDING frame for a |
| 1056 | * locally initiated stream that has not yet been created MUST be |
| 1057 | * treated as a connection error of type STREAM_STATE_ERROR. An |
| 1058 | * endpoint that receives a STOP_SENDING frame for a receive-only stream |
| 1059 | * MUST terminate the connection with error STREAM_STATE_ERROR. |
| 1060 | */ |
| 1061 | if (qcc_get_qcs(qcc, id, 0, 1, &qcs)) { |
| 1062 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
| 1063 | return 1; |
| 1064 | } |
| 1065 | |
| 1066 | if (!qcs) |
| 1067 | goto out; |
| 1068 | |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 1069 | TRACE_PROTO("receiving STOP_SENDING", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
Amaury Denoyelle | d775537 | 2022-10-03 17:20:31 +0200 | [diff] [blame] | 1070 | |
| 1071 | /* RFC 9000 3.5. Solicited State Transitions |
| 1072 | * |
| 1073 | * An endpoint is expected to send another STOP_SENDING frame if a |
| 1074 | * packet containing a previous STOP_SENDING is lost. However, once |
| 1075 | * either all stream data or a RESET_STREAM frame has been received for |
| 1076 | * the stream -- that is, the stream is in any state other than "Recv" |
| 1077 | * or "Size Known" -- sending a STOP_SENDING frame is unnecessary. |
| 1078 | */ |
| 1079 | |
| 1080 | /* TODO thanks to previous RFC clause, STOP_SENDING is ignored if current stream |
| 1081 | * has already been closed locally. This is useful to not emit multiple |
| 1082 | * RESET_STREAM for a single stream. This is functional if stream is |
| 1083 | * locally closed due to all data transmitted, but in this case the RFC |
| 1084 | * advices to use an explicit RESET_STREAM. |
| 1085 | */ |
| 1086 | if (qcs_is_close_local(qcs)) { |
| 1087 | TRACE_STATE("ignoring STOP_SENDING", QMUX_EV_QCC_RECV|QMUX_EV_QCS_RECV, qcc->conn, qcs); |
| 1088 | goto out; |
| 1089 | } |
| 1090 | |
Amaury Denoyelle | 96ca1b7 | 2022-08-09 17:36:38 +0200 | [diff] [blame] | 1091 | qcs_idle_open(qcs); |
| 1092 | |
Amaury Denoyelle | a5b5075 | 2022-07-04 11:44:53 +0200 | [diff] [blame] | 1093 | /* RFC 9000 3.5. Solicited State Transitions |
| 1094 | * |
| 1095 | * An endpoint that receives a STOP_SENDING frame |
| 1096 | * MUST send a RESET_STREAM frame if the stream is in the "Ready" or |
| 1097 | * "Send" state. If the stream is in the "Data Sent" state, the |
| 1098 | * endpoint MAY defer sending the RESET_STREAM frame until the packets |
| 1099 | * containing outstanding data are acknowledged or declared lost. If |
| 1100 | * any outstanding data is declared lost, the endpoint SHOULD send a |
| 1101 | * RESET_STREAM frame instead of retransmitting the data. |
| 1102 | * |
| 1103 | * An endpoint SHOULD copy the error code from the STOP_SENDING frame to |
| 1104 | * the RESET_STREAM frame it sends, but it can use any application error |
| 1105 | * code. |
| 1106 | */ |
Amaury Denoyelle | a5b5075 | 2022-07-04 11:44:53 +0200 | [diff] [blame] | 1107 | qcc_reset_stream(qcs, err); |
| 1108 | |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 1109 | if (qcc_may_expire(qcc) && !qcc->nb_hreq) |
| 1110 | qcc_refresh_timeout(qcc); |
| 1111 | |
Amaury Denoyelle | a5b5075 | 2022-07-04 11:44:53 +0200 | [diff] [blame] | 1112 | out: |
| 1113 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1117 | /* Signal the closing of remote stream with id <id>. Flow-control for new |
| 1118 | * streams may be allocated for the peer if needed. |
| 1119 | */ |
| 1120 | static int qcc_release_remote_stream(struct qcc *qcc, uint64_t id) |
Amaury Denoyelle | c055e30 | 2022-02-07 16:09:06 +0100 | [diff] [blame] | 1121 | { |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1122 | struct quic_frame *frm; |
| 1123 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1124 | TRACE_ENTER(QMUX_EV_QCS_END, qcc->conn); |
| 1125 | |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1126 | if (quic_stream_is_bidi(id)) { |
| 1127 | ++qcc->lfctl.cl_bidi_r; |
| 1128 | if (qcc->lfctl.cl_bidi_r > qcc->lfctl.ms_bidi_init / 2) { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1129 | TRACE_DATA("increase max stream limit with MAX_STREAMS_BIDI", QMUX_EV_QCC_SEND, qcc->conn); |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1130 | frm = pool_zalloc(pool_head_quic_frame); |
| 1131 | BUG_ON(!frm); /* TODO handle this properly */ |
| 1132 | |
| 1133 | LIST_INIT(&frm->reflist); |
| 1134 | frm->type = QUIC_FT_MAX_STREAMS_BIDI; |
| 1135 | frm->max_streams_bidi.max_streams = qcc->lfctl.ms_bidi + |
| 1136 | qcc->lfctl.cl_bidi_r; |
| 1137 | LIST_APPEND(&qcc->lfctl.frms, &frm->list); |
| 1138 | tasklet_wakeup(qcc->wait_event.tasklet); |
| 1139 | |
| 1140 | qcc->lfctl.ms_bidi += qcc->lfctl.cl_bidi_r; |
| 1141 | qcc->lfctl.cl_bidi_r = 0; |
| 1142 | } |
| 1143 | } |
| 1144 | else { |
Amaury Denoyelle | bf3c208 | 2022-08-16 11:29:08 +0200 | [diff] [blame] | 1145 | /* TODO in HTTP/3 unidirectional streams cannot be closed or a |
| 1146 | * H3_CLOSED_CRITICAL_STREAM will be triggered before |
| 1147 | * entering here. If a new application protocol is supported it |
| 1148 | * might be necessary to implement MAX_STREAMS_UNI emission. |
| 1149 | */ |
| 1150 | ABORT_NOW(); |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1153 | TRACE_LEAVE(QMUX_EV_QCS_END, qcc->conn); |
| 1154 | |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1155 | return 0; |
Amaury Denoyelle | c055e30 | 2022-02-07 16:09:06 +0100 | [diff] [blame] | 1156 | } |
| 1157 | |
Ilya Shipitsin | 5e87bcf | 2021-12-25 11:45:52 +0500 | [diff] [blame] | 1158 | /* detaches the QUIC stream from its QCC and releases it to the QCS pool. */ |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1159 | static void qcs_destroy(struct qcs *qcs) |
| 1160 | { |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1161 | struct connection *conn = qcs->qcc->conn; |
Amaury Denoyelle | d8e680c | 2022-03-29 15:18:44 +0200 | [diff] [blame] | 1162 | const uint64_t id = qcs->id; |
Amaury Denoyelle | c055e30 | 2022-02-07 16:09:06 +0100 | [diff] [blame] | 1163 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1164 | TRACE_ENTER(QMUX_EV_QCS_END, conn, qcs); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1165 | |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1166 | if (quic_stream_is_remote(qcs->qcc, id)) |
| 1167 | qcc_release_remote_stream(qcs->qcc, id); |
Amaury Denoyelle | c055e30 | 2022-02-07 16:09:06 +0100 | [diff] [blame] | 1168 | |
Amaury Denoyelle | dccbd73 | 2022-03-29 18:36:59 +0200 | [diff] [blame] | 1169 | qcs_free(qcs); |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1170 | |
| 1171 | TRACE_LEAVE(QMUX_EV_QCS_END, conn); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1172 | } |
| 1173 | |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1174 | /* Transfer as much as possible data on <qcs> from <in> to <out>. This is done |
| 1175 | * in respect with available flow-control at stream and connection level. |
Amaury Denoyelle | 75d14ad | 2022-03-22 15:10:29 +0100 | [diff] [blame] | 1176 | * |
Amaury Denoyelle | fe8f555 | 2022-04-27 16:44:49 +0200 | [diff] [blame] | 1177 | * Returns the total bytes of transferred data. |
Amaury Denoyelle | 75d14ad | 2022-03-22 15:10:29 +0100 | [diff] [blame] | 1178 | */ |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1179 | static int qcs_xfer_data(struct qcs *qcs, struct buffer *out, struct buffer *in) |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1180 | { |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1181 | struct qcc *qcc = qcs->qcc; |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1182 | int left, to_xfer; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1183 | int total = 0; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1184 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1185 | TRACE_ENTER(QMUX_EV_QCS_SEND, qcc->conn, qcs); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1186 | |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1187 | qc_get_buf(qcs, out); |
| 1188 | |
| 1189 | /* |
| 1190 | * QCS out buffer diagram |
| 1191 | * head left to_xfer |
| 1192 | * -------------> ----------> -----> |
Amaury Denoyelle | e0320b8 | 2022-03-11 19:12:23 +0100 | [diff] [blame] | 1193 | * -------------------------------------------------- |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1194 | * |...............|xxxxxxxxxxx|<<<<< |
Amaury Denoyelle | e0320b8 | 2022-03-11 19:12:23 +0100 | [diff] [blame] | 1195 | * -------------------------------------------------- |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1196 | * ^ ack-off ^ sent-off ^ off |
| 1197 | * |
| 1198 | * STREAM frame |
| 1199 | * ^ ^ |
| 1200 | * |xxxxxxxxxxxxxxxxx| |
| 1201 | */ |
| 1202 | |
Amaury Denoyelle | 7272cd7 | 2022-03-29 15:15:54 +0200 | [diff] [blame] | 1203 | BUG_ON_HOT(qcs->tx.sent_offset < qcs->stream->ack_offset); |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1204 | BUG_ON_HOT(qcs->tx.offset < qcs->tx.sent_offset); |
Amaury Denoyelle | 78fa559 | 2022-06-10 15:18:12 +0200 | [diff] [blame] | 1205 | BUG_ON_HOT(qcc->tx.offsets < qcc->tx.sent_offsets); |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1206 | |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1207 | left = qcs->tx.offset - qcs->tx.sent_offset; |
Amaury Denoyelle | fe8f555 | 2022-04-27 16:44:49 +0200 | [diff] [blame] | 1208 | to_xfer = QUIC_MIN(b_data(in), b_room(out)); |
Amaury Denoyelle | 6ea7819 | 2022-03-07 15:47:02 +0100 | [diff] [blame] | 1209 | |
| 1210 | BUG_ON_HOT(qcs->tx.offset > qcs->tx.msd); |
| 1211 | /* do not exceed flow control limit */ |
| 1212 | if (qcs->tx.offset + to_xfer > qcs->tx.msd) |
| 1213 | to_xfer = qcs->tx.msd - qcs->tx.offset; |
| 1214 | |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1215 | BUG_ON_HOT(qcc->tx.offsets > qcc->rfctl.md); |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1216 | /* do not overcome flow control limit on connection */ |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1217 | if (qcc->tx.offsets + to_xfer > qcc->rfctl.md) |
| 1218 | to_xfer = qcc->rfctl.md - qcc->tx.offsets; |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1219 | |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1220 | if (!left && !to_xfer) |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 1221 | goto out; |
| 1222 | |
Amaury Denoyelle | fe8f555 | 2022-04-27 16:44:49 +0200 | [diff] [blame] | 1223 | total = b_force_xfer(out, in, to_xfer); |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1224 | |
| 1225 | out: |
| 1226 | { |
| 1227 | struct qcs_xfer_data_trace_arg arg = { |
| 1228 | .prep = b_data(out), .xfer = total, |
| 1229 | }; |
| 1230 | TRACE_LEAVE(QMUX_EV_QCS_SEND|QMUX_EV_QCS_XFER_DATA, |
| 1231 | qcc->conn, qcs, &arg); |
| 1232 | } |
| 1233 | |
| 1234 | return total; |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
Amaury Denoyelle | fe8f555 | 2022-04-27 16:44:49 +0200 | [diff] [blame] | 1237 | /* Prepare a STREAM frame for <qcs> instance using <out> as payload. The frame |
| 1238 | * is appended in <frm_list>. Set <fin> if this is supposed to be the last |
| 1239 | * stream frame. |
| 1240 | * |
| 1241 | * Returns the length of the STREAM frame or a negative error code. |
| 1242 | */ |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1243 | static int qcs_build_stream_frm(struct qcs *qcs, struct buffer *out, char fin, |
| 1244 | struct list *frm_list) |
| 1245 | { |
| 1246 | struct qcc *qcc = qcs->qcc; |
| 1247 | struct quic_frame *frm; |
| 1248 | int head, total; |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1249 | uint64_t base_off; |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1250 | |
| 1251 | TRACE_ENTER(QMUX_EV_QCS_SEND, qcc->conn, qcs); |
| 1252 | |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1253 | /* if ack_offset < buf_offset, it points to an older buffer. */ |
| 1254 | base_off = MAX(qcs->stream->buf_offset, qcs->stream->ack_offset); |
| 1255 | BUG_ON(qcs->tx.sent_offset < base_off); |
| 1256 | |
| 1257 | head = qcs->tx.sent_offset - base_off; |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1258 | total = b_data(out) - head; |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1259 | BUG_ON(total < 0); |
| 1260 | |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1261 | if (!total && !fin) { |
| 1262 | /* No need to send anything if total is NULL and no FIN to signal. */ |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1263 | TRACE_LEAVE(QMUX_EV_QCS_SEND, qcc->conn, qcs); |
| 1264 | return 0; |
| 1265 | } |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1266 | BUG_ON((!total && qcs->tx.sent_offset > qcs->tx.offset) || |
| 1267 | (total && qcs->tx.sent_offset >= qcs->tx.offset)); |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1268 | BUG_ON(qcs->tx.sent_offset + total > qcs->tx.offset); |
Amaury Denoyelle | 78fa559 | 2022-06-10 15:18:12 +0200 | [diff] [blame] | 1269 | BUG_ON(qcc->tx.sent_offsets + total > qcc->rfctl.md); |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1270 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1271 | TRACE_PROTO("sending STREAM frame", QMUX_EV_QCS_SEND, qcc->conn, qcs); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1272 | frm = pool_zalloc(pool_head_quic_frame); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1273 | if (!frm) { |
| 1274 | TRACE_ERROR("frame alloc failure", QMUX_EV_QCS_SEND, qcc->conn, qcs); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1275 | goto err; |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1276 | } |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1277 | |
Frédéric Lécaille | b917191 | 2022-04-21 17:32:10 +0200 | [diff] [blame] | 1278 | LIST_INIT(&frm->reflist); |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1279 | frm->type = QUIC_FT_STREAM_8; |
Amaury Denoyelle | 7272cd7 | 2022-03-29 15:15:54 +0200 | [diff] [blame] | 1280 | frm->stream.stream = qcs->stream; |
Amaury Denoyelle | d8e680c | 2022-03-29 15:18:44 +0200 | [diff] [blame] | 1281 | frm->stream.id = qcs->id; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1282 | frm->stream.buf = out; |
| 1283 | frm->stream.data = (unsigned char *)b_peek(out, head); |
| 1284 | |
Amaury Denoyelle | fecfa0d | 2021-12-07 16:50:14 +0100 | [diff] [blame] | 1285 | /* FIN is positioned only when the buffer has been totally emptied. */ |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1286 | if (fin) |
| 1287 | frm->type |= QUIC_STREAM_FRAME_TYPE_FIN_BIT; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1288 | |
| 1289 | if (qcs->tx.sent_offset) { |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1290 | frm->type |= QUIC_STREAM_FRAME_TYPE_OFF_BIT; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1291 | frm->stream.offset.key = qcs->tx.sent_offset; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1292 | } |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1293 | |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1294 | frm->type |= QUIC_STREAM_FRAME_TYPE_LEN_BIT; |
| 1295 | frm->stream.len = total; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1296 | |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1297 | LIST_APPEND(frm_list, &frm->list); |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1298 | |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 1299 | out: |
Amaury Denoyelle | fdcec36 | 2022-03-25 09:28:10 +0100 | [diff] [blame] | 1300 | { |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1301 | struct qcs_build_stream_trace_arg arg = { |
| 1302 | .len = frm->stream.len, .fin = fin, |
| 1303 | .offset = frm->stream.offset.key, |
Amaury Denoyelle | fdcec36 | 2022-03-25 09:28:10 +0100 | [diff] [blame] | 1304 | }; |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1305 | TRACE_LEAVE(QMUX_EV_QCS_SEND|QMUX_EV_QCS_BUILD_STRM, |
Amaury Denoyelle | fdcec36 | 2022-03-25 09:28:10 +0100 | [diff] [blame] | 1306 | qcc->conn, qcs, &arg); |
| 1307 | } |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1308 | |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1309 | return total; |
| 1310 | |
| 1311 | err: |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1312 | TRACE_LEAVE(QMUX_EV_QCS_SEND, qcc->conn, qcs); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1313 | return -1; |
| 1314 | } |
| 1315 | |
Ilya Shipitsin | 3b64a28 | 2022-07-29 22:26:53 +0500 | [diff] [blame] | 1316 | /* Check after transferring data from qcs.tx.buf if FIN must be set on the next |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1317 | * STREAM frame for <qcs>. |
| 1318 | * |
| 1319 | * Returns true if FIN must be set else false. |
| 1320 | */ |
| 1321 | static int qcs_stream_fin(struct qcs *qcs) |
| 1322 | { |
| 1323 | return qcs->flags & QC_SF_FIN_STREAM && !b_data(&qcs->tx.buf); |
| 1324 | } |
| 1325 | |
Amaury Denoyelle | 54445d0 | 2022-03-10 16:44:14 +0100 | [diff] [blame] | 1326 | /* This function must be called by the upper layer to inform about the sending |
| 1327 | * of a STREAM frame for <qcs> instance. The frame is of <data> length and on |
| 1328 | * <offset>. |
| 1329 | */ |
| 1330 | void qcc_streams_sent_done(struct qcs *qcs, uint64_t data, uint64_t offset) |
| 1331 | { |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1332 | struct qcc *qcc = qcs->qcc; |
| 1333 | uint64_t diff; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1334 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1335 | TRACE_ENTER(QMUX_EV_QCS_SEND, qcc->conn, qcs); |
| 1336 | |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1337 | BUG_ON(offset > qcs->tx.sent_offset); |
Amaury Denoyelle | 78fa559 | 2022-06-10 15:18:12 +0200 | [diff] [blame] | 1338 | BUG_ON(offset + data > qcs->tx.offset); |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1339 | |
Amaury Denoyelle | 54445d0 | 2022-03-10 16:44:14 +0100 | [diff] [blame] | 1340 | /* check if the STREAM frame has already been notified. It can happen |
| 1341 | * for retransmission. |
| 1342 | */ |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1343 | if (offset + data < qcs->tx.sent_offset) { |
| 1344 | TRACE_DEVEL("offset already notified", QMUX_EV_QCS_SEND, qcc->conn, qcs); |
| 1345 | goto out; |
| 1346 | } |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1347 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 1348 | qcs_idle_open(qcs); |
| 1349 | |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1350 | diff = offset + data - qcs->tx.sent_offset; |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1351 | if (diff) { |
| 1352 | /* increase offset sum on connection */ |
| 1353 | qcc->tx.sent_offsets += diff; |
| 1354 | BUG_ON_HOT(qcc->tx.sent_offsets > qcc->rfctl.md); |
| 1355 | if (qcc->tx.sent_offsets == qcc->rfctl.md) |
| 1356 | qcc->flags |= QC_CF_BLK_MFCTL; |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1357 | |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1358 | /* increase offset on stream */ |
| 1359 | qcs->tx.sent_offset += diff; |
| 1360 | BUG_ON_HOT(qcs->tx.sent_offset > qcs->tx.msd); |
| 1361 | BUG_ON_HOT(qcs->tx.sent_offset > qcs->tx.offset); |
| 1362 | if (qcs->tx.sent_offset == qcs->tx.msd) |
| 1363 | qcs->flags |= QC_SF_BLK_SFCTL; |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1364 | |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1365 | if (qcs->tx.offset == qcs->tx.sent_offset && |
| 1366 | b_full(&qcs->stream->buf->buf)) { |
| 1367 | qc_stream_buf_release(qcs->stream); |
| 1368 | /* prepare qcs for immediate send retry if data to send */ |
| 1369 | if (b_data(&qcs->tx.buf)) |
| 1370 | LIST_APPEND(&qcc->send_retry_list, &qcs->el); |
| 1371 | } |
| 1372 | } |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1373 | |
Amaury Denoyelle | 3dc4e5a | 2022-09-13 16:49:21 +0200 | [diff] [blame] | 1374 | if (qcs->tx.offset == qcs->tx.sent_offset && !b_data(&qcs->tx.buf) && |
| 1375 | qcs->flags & (QC_SF_FIN_STREAM|QC_SF_DETACH)) { |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 1376 | /* Close stream locally. */ |
| 1377 | qcs_close_local(qcs); |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1378 | /* Reset flag to not emit multiple FIN STREAM frames. */ |
| 1379 | qcs->flags &= ~QC_SF_FIN_STREAM; |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1380 | } |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1381 | |
| 1382 | out: |
| 1383 | TRACE_LEAVE(QMUX_EV_QCS_SEND, qcc->conn, qcs); |
Amaury Denoyelle | 54445d0 | 2022-03-10 16:44:14 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1386 | /* Wrapper for send on transport layer. Send a list of frames <frms> for the |
| 1387 | * connection <qcc>. |
| 1388 | * |
| 1389 | * Returns 0 if all data sent with success else non-zero. |
| 1390 | */ |
| 1391 | static int qc_send_frames(struct qcc *qcc, struct list *frms) |
| 1392 | { |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1393 | TRACE_ENTER(QMUX_EV_QCC_SEND, qcc->conn); |
| 1394 | |
| 1395 | if (LIST_ISEMPTY(frms)) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1396 | TRACE_DEVEL("no frames to send", QMUX_EV_QCC_SEND, qcc->conn); |
| 1397 | goto err; |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1398 | } |
Frédéric Lécaille | 4e22f28 | 2022-03-18 18:38:19 +0100 | [diff] [blame] | 1399 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1400 | LIST_INIT(&qcc->send_retry_list); |
| 1401 | |
Amaury Denoyelle | 036cc5d | 2022-09-26 15:02:31 +0200 | [diff] [blame] | 1402 | if (!qc_send_mux(qcc->conn->handle.qc, frms)) |
| 1403 | goto err; |
Amaury Denoyelle | e9c4cc1 | 2022-03-04 15:29:53 +0100 | [diff] [blame] | 1404 | |
Amaury Denoyelle | db5d1a1 | 2022-03-10 16:42:23 +0100 | [diff] [blame] | 1405 | /* If there is frames left at this stage, transport layer is blocked. |
| 1406 | * Subscribe on it to retry later. |
| 1407 | */ |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1408 | if (!LIST_ISEMPTY(frms)) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1409 | TRACE_DEVEL("remaining frames to send, subscribing", QMUX_EV_QCC_SEND, qcc->conn); |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1410 | qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx, |
| 1411 | SUB_RETRY_SEND, &qcc->wait_event); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1412 | goto err; |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1415 | TRACE_LEAVE(QMUX_EV_QCC_SEND, qcc->conn); |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 1416 | return 0; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1417 | |
| 1418 | err: |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1419 | TRACE_LEAVE(QMUX_EV_QCC_SEND, qcc->conn); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1420 | return 1; |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | /* Emit a RESET_STREAM on <qcs>. |
| 1424 | * |
| 1425 | * Returns 0 if the frame has been successfully sent else non-zero. |
| 1426 | */ |
| 1427 | static int qcs_send_reset(struct qcs *qcs) |
| 1428 | { |
| 1429 | struct list frms = LIST_HEAD_INIT(frms); |
| 1430 | struct quic_frame *frm; |
| 1431 | |
| 1432 | TRACE_ENTER(QMUX_EV_QCS_SEND, qcs->qcc->conn, qcs); |
| 1433 | |
| 1434 | frm = pool_zalloc(pool_head_quic_frame); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1435 | if (!frm) { |
| 1436 | TRACE_LEAVE(QMUX_EV_QCS_SEND, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 1437 | return 1; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1438 | } |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 1439 | |
| 1440 | LIST_INIT(&frm->reflist); |
| 1441 | frm->type = QUIC_FT_RESET_STREAM; |
| 1442 | frm->reset_stream.id = qcs->id; |
| 1443 | frm->reset_stream.app_error_code = qcs->err; |
| 1444 | frm->reset_stream.final_size = qcs->tx.sent_offset; |
| 1445 | |
| 1446 | LIST_APPEND(&frms, &frm->list); |
| 1447 | if (qc_send_frames(qcs->qcc, &frms)) { |
| 1448 | pool_free(pool_head_quic_frame, frm); |
| 1449 | TRACE_DEVEL("cannot send RESET_STREAM", QMUX_EV_QCS_SEND, qcs->qcc->conn, qcs); |
| 1450 | return 1; |
| 1451 | } |
| 1452 | |
| 1453 | if (qcs_sc(qcs)) { |
| 1454 | se_fl_set_error(qcs->sd); |
| 1455 | qcs_alert(qcs); |
| 1456 | } |
| 1457 | |
| 1458 | qcs_close_local(qcs); |
| 1459 | qcs->flags &= ~QC_SF_TO_RESET; |
| 1460 | |
| 1461 | TRACE_LEAVE(QMUX_EV_QCS_SEND, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1462 | return 0; |
| 1463 | } |
| 1464 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1465 | /* Used internally by qc_send function. Proceed to send for <qcs>. This will |
| 1466 | * transfer data from qcs buffer to its quic_stream counterpart. A STREAM frame |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1467 | * is then generated and inserted in <frms> list. |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1468 | * |
| 1469 | * Returns the total bytes transferred between qcs and quic_stream buffers. Can |
| 1470 | * be null if out buffer cannot be allocated. |
| 1471 | */ |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1472 | static int _qc_send_qcs(struct qcs *qcs, struct list *frms) |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1473 | { |
| 1474 | struct qcc *qcc = qcs->qcc; |
| 1475 | struct buffer *buf = &qcs->tx.buf; |
| 1476 | struct buffer *out = qc_stream_buf_get(qcs->stream); |
| 1477 | int xfer = 0; |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1478 | char fin = 0; |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1479 | |
| 1480 | /* Allocate <out> buffer if necessary. */ |
| 1481 | if (!out) { |
| 1482 | if (qcc->flags & QC_CF_CONN_FULL) |
| 1483 | return 0; |
| 1484 | |
| 1485 | out = qc_stream_buf_alloc(qcs->stream, qcs->tx.offset); |
| 1486 | if (!out) { |
| 1487 | qcc->flags |= QC_CF_CONN_FULL; |
| 1488 | return 0; |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | /* Transfer data from <buf> to <out>. */ |
| 1493 | if (b_data(buf)) { |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1494 | xfer = qcs_xfer_data(qcs, out, buf); |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1495 | if (xfer > 0) { |
| 1496 | qcs_notify_send(qcs); |
| 1497 | qcs->flags &= ~QC_SF_BLK_MROOM; |
| 1498 | } |
| 1499 | |
| 1500 | qcs->tx.offset += xfer; |
Amaury Denoyelle | 78fa559 | 2022-06-10 15:18:12 +0200 | [diff] [blame] | 1501 | BUG_ON_HOT(qcs->tx.offset > qcs->tx.msd); |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1502 | qcc->tx.offsets += xfer; |
Amaury Denoyelle | 78fa559 | 2022-06-10 15:18:12 +0200 | [diff] [blame] | 1503 | BUG_ON_HOT(qcc->tx.offsets > qcc->rfctl.md); |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /* out buffer cannot be emptied if qcs offsets differ. */ |
| 1507 | BUG_ON(!b_data(out) && qcs->tx.sent_offset != qcs->tx.offset); |
| 1508 | |
Ilya Shipitsin | 3b64a28 | 2022-07-29 22:26:53 +0500 | [diff] [blame] | 1509 | /* FIN is set if all incoming data were transferred. */ |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1510 | fin = qcs_stream_fin(qcs); |
| 1511 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1512 | /* Build a new STREAM frame with <out> buffer. */ |
Amaury Denoyelle | e53b489 | 2022-07-08 17:19:40 +0200 | [diff] [blame] | 1513 | if (qcs->tx.sent_offset != qcs->tx.offset || fin) { |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1514 | int ret; |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1515 | ret = qcs_build_stream_frm(qcs, out, fin, frms); |
Amaury Denoyelle | b50f311 | 2022-04-28 14:41:50 +0200 | [diff] [blame] | 1516 | if (ret < 0) { ABORT_NOW(); /* TODO handle this properly */ } |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | return xfer; |
| 1520 | } |
| 1521 | |
Amaury Denoyelle | 75d14ad | 2022-03-22 15:10:29 +0100 | [diff] [blame] | 1522 | /* Proceed to sending. Loop through all available streams for the <qcc> |
| 1523 | * instance and try to send as much as possible. |
| 1524 | * |
| 1525 | * Returns the total of bytes sent to the transport layer. |
| 1526 | */ |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1527 | static int qc_send(struct qcc *qcc) |
| 1528 | { |
Amaury Denoyelle | 6ccfa3c | 2022-03-10 16:45:53 +0100 | [diff] [blame] | 1529 | struct list frms = LIST_HEAD_INIT(frms); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1530 | struct eb64_node *node; |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1531 | struct qcs *qcs, *qcs_tmp; |
| 1532 | int total = 0, tmp_total = 0; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1533 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1534 | TRACE_ENTER(QMUX_EV_QCC_SEND, qcc->conn); |
Frédéric Lécaille | 8526f14 | 2021-09-20 17:58:22 +0200 | [diff] [blame] | 1535 | |
Amaury Denoyelle | 9fab9fd | 2022-05-20 15:04:38 +0200 | [diff] [blame] | 1536 | if (qcc->conn->flags & CO_FL_SOCK_WR_SH || qcc->flags & QC_CF_CC_EMIT) { |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 1537 | qcc->conn->flags |= CO_FL_ERROR; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1538 | TRACE_DEVEL("connection on error", QMUX_EV_QCC_SEND, qcc->conn); |
| 1539 | goto err; |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 1540 | } |
| 1541 | |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1542 | if (!LIST_ISEMPTY(&qcc->lfctl.frms)) { |
| 1543 | if (qc_send_frames(qcc, &qcc->lfctl.frms)) { |
| 1544 | TRACE_DEVEL("flow-control frames rejected by transport, aborting send", QMUX_EV_QCC_SEND, qcc->conn); |
| 1545 | goto out; |
| 1546 | } |
| 1547 | } |
Amaury Denoyelle | c933780 | 2022-04-04 16:36:34 +0200 | [diff] [blame] | 1548 | |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1549 | if (qcc->flags & QC_CF_BLK_MFCTL) |
| 1550 | return 0; |
| 1551 | |
Frédéric Lécaille | 3dd79d3 | 2022-09-08 17:53:36 +0200 | [diff] [blame] | 1552 | if (!(qcc->flags & QC_CF_APP_FINAL) && !eb_is_empty(&qcc->streams_by_id) && |
| 1553 | qcc->app_ops->finalize) { |
| 1554 | /* Finalize the application layer before sending any stream. |
| 1555 | * For h3 this consists in preparing the control stream data (SETTINGS h3). |
| 1556 | */ |
| 1557 | qcc->app_ops->finalize(qcc->ctx); |
| 1558 | qcc->flags |= QC_CF_APP_FINAL; |
| 1559 | } |
| 1560 | |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1561 | /* loop through all streams, construct STREAM frames if data available. |
| 1562 | * TODO optimize the loop to favor streams which are not too heavy. |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1563 | */ |
| 1564 | node = eb64_first(&qcc->streams_by_id); |
| 1565 | while (node) { |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1566 | int ret; |
Amaury Denoyelle | c6195d7 | 2022-05-23 11:39:14 +0200 | [diff] [blame] | 1567 | uint64_t id; |
| 1568 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1569 | qcs = eb64_entry(node, struct qcs, by_id); |
Amaury Denoyelle | c6195d7 | 2022-05-23 11:39:14 +0200 | [diff] [blame] | 1570 | id = qcs->id; |
Amaury Denoyelle | 2c71fe5 | 2022-02-09 18:16:49 +0100 | [diff] [blame] | 1571 | |
Amaury Denoyelle | c6195d7 | 2022-05-23 11:39:14 +0200 | [diff] [blame] | 1572 | if (quic_stream_is_uni(id) && quic_stream_is_remote(qcc, id)) { |
Amaury Denoyelle | e2ec942 | 2022-03-10 16:46:18 +0100 | [diff] [blame] | 1573 | node = eb64_next(node); |
| 1574 | continue; |
| 1575 | } |
| 1576 | |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 1577 | if (qcs->flags & QC_SF_TO_RESET) { |
| 1578 | qcs_send_reset(qcs); |
| 1579 | node = eb64_next(node); |
| 1580 | continue; |
| 1581 | } |
| 1582 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 1583 | if (qcs_is_close_local(qcs)) { |
| 1584 | node = eb64_next(node); |
| 1585 | continue; |
| 1586 | } |
| 1587 | |
Amaury Denoyelle | 6ea7819 | 2022-03-07 15:47:02 +0100 | [diff] [blame] | 1588 | if (qcs->flags & QC_SF_BLK_SFCTL) { |
| 1589 | node = eb64_next(node); |
| 1590 | continue; |
| 1591 | } |
| 1592 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1593 | if (!b_data(&qcs->tx.buf) && !qc_stream_buf_get(qcs->stream)) { |
Amaury Denoyelle | d2f80a2 | 2022-04-15 17:30:49 +0200 | [diff] [blame] | 1594 | node = eb64_next(node); |
| 1595 | continue; |
| 1596 | } |
Amaury Denoyelle | a456920 | 2022-04-15 17:29:25 +0200 | [diff] [blame] | 1597 | |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1598 | ret = _qc_send_qcs(qcs, &frms); |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1599 | total += ret; |
| 1600 | node = eb64_next(node); |
| 1601 | } |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1602 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1603 | if (qc_send_frames(qcc, &frms)) { |
| 1604 | /* data rejected by transport layer, do not retry. */ |
| 1605 | goto out; |
| 1606 | } |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1607 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1608 | retry: |
| 1609 | tmp_total = 0; |
| 1610 | list_for_each_entry_safe(qcs, qcs_tmp, &qcc->send_retry_list, el) { |
| 1611 | int ret; |
| 1612 | BUG_ON(!b_data(&qcs->tx.buf)); |
| 1613 | BUG_ON(qc_stream_buf_get(qcs->stream)); |
Amaury Denoyelle | da6ad20 | 2022-04-12 11:41:04 +0200 | [diff] [blame] | 1614 | |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1615 | ret = _qc_send_qcs(qcs, &frms); |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1616 | tmp_total += ret; |
| 1617 | LIST_DELETE(&qcs->el); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 1618 | } |
Frédéric Lécaille | 8526f14 | 2021-09-20 17:58:22 +0200 | [diff] [blame] | 1619 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1620 | total += tmp_total; |
| 1621 | if (!qc_send_frames(qcc, &frms) && !LIST_ISEMPTY(&qcc->send_retry_list)) |
| 1622 | goto retry; |
Amaury Denoyelle | e257d9e | 2021-12-03 14:39:29 +0100 | [diff] [blame] | 1623 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1624 | out: |
Amaury Denoyelle | 43c090c | 2022-06-10 15:16:40 +0200 | [diff] [blame] | 1625 | /* Deallocate frames that the transport layer has rejected. */ |
| 1626 | if (!LIST_ISEMPTY(&frms)) { |
| 1627 | struct quic_frame *frm, *frm2; |
| 1628 | list_for_each_entry_safe(frm, frm2, &frms, list) { |
| 1629 | LIST_DELETE(&frm->list); |
| 1630 | pool_free(pool_head_quic_frame, frm); |
| 1631 | } |
| 1632 | } |
| 1633 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1634 | TRACE_LEAVE(QMUX_EV_QCC_SEND, qcc->conn); |
Amaury Denoyelle | 75d14ad | 2022-03-22 15:10:29 +0100 | [diff] [blame] | 1635 | return total; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1636 | |
| 1637 | err: |
| 1638 | TRACE_LEAVE(QMUX_EV_QCC_SEND, qcc->conn); |
| 1639 | return 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1642 | /* Proceed on receiving. Loop through all streams from <qcc> and use decode_qcs |
| 1643 | * operation. |
| 1644 | * |
| 1645 | * Returns 0 on success else non-zero. |
| 1646 | */ |
| 1647 | static int qc_recv(struct qcc *qcc) |
| 1648 | { |
| 1649 | struct eb64_node *node; |
| 1650 | struct qcs *qcs; |
| 1651 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1652 | TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | e1cad8b | 2022-05-23 18:52:11 +0200 | [diff] [blame] | 1653 | |
Amaury Denoyelle | 5c4373a | 2022-05-24 14:47:48 +0200 | [diff] [blame] | 1654 | if (qcc->flags & QC_CF_CC_EMIT) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1655 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 5c4373a | 2022-05-24 14:47:48 +0200 | [diff] [blame] | 1656 | return 0; |
| 1657 | } |
| 1658 | |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1659 | node = eb64_first(&qcc->streams_by_id); |
| 1660 | while (node) { |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 1661 | uint64_t id; |
| 1662 | |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1663 | qcs = eb64_entry(node, struct qcs, by_id); |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 1664 | id = qcs->id; |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1665 | |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 1666 | if (!ncb_data(&qcs->rx.ncbuf, 0) || (qcs->flags & QC_SF_DEM_FULL)) { |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1667 | node = eb64_next(node); |
| 1668 | continue; |
| 1669 | } |
| 1670 | |
Amaury Denoyelle | f8db5aa | 2022-05-24 15:26:07 +0200 | [diff] [blame] | 1671 | if (quic_stream_is_uni(id) && quic_stream_is_local(qcc, id)) { |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1672 | node = eb64_next(node); |
| 1673 | continue; |
| 1674 | } |
| 1675 | |
| 1676 | qcc_decode_qcs(qcc, qcs); |
| 1677 | node = eb64_next(node); |
Amaury Denoyelle | 849b24f | 2022-05-24 17:22:07 +0200 | [diff] [blame] | 1678 | |
| 1679 | if (qcs->flags & QC_SF_READ_ABORTED) { |
| 1680 | /* TODO should send a STOP_SENDING */ |
| 1681 | qcs_free(qcs); |
| 1682 | } |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1683 | } |
| 1684 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1685 | TRACE_LEAVE(QMUX_EV_QCC_RECV, qcc->conn); |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1686 | return 0; |
| 1687 | } |
| 1688 | |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1689 | |
| 1690 | /* Release all streams which have their transfer operation achieved. |
Amaury Denoyelle | 6a4aebf | 2022-02-01 10:16:05 +0100 | [diff] [blame] | 1691 | * |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1692 | * Returns true if at least one stream is released. |
Amaury Denoyelle | 6a4aebf | 2022-02-01 10:16:05 +0100 | [diff] [blame] | 1693 | */ |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1694 | static int qc_purge_streams(struct qcc *qcc) |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1695 | { |
| 1696 | struct eb64_node *node; |
| 1697 | int release = 0; |
| 1698 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1699 | TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1700 | |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1701 | node = eb64_first(&qcc->streams_by_id); |
| 1702 | while (node) { |
Amaury Denoyelle | e4301da | 2022-04-19 17:59:50 +0200 | [diff] [blame] | 1703 | struct qcs *qcs = eb64_entry(node, struct qcs, by_id); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1704 | node = eb64_next(node); |
| 1705 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 1706 | /* Release not attached closed streams. */ |
| 1707 | if (qcs->st == QC_SS_CLO && !qcs_sc(qcs)) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 1708 | TRACE_STATE("purging closed stream", QMUX_EV_QCC_WAKE, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 1709 | qcs_destroy(qcs); |
| 1710 | release = 1; |
| 1711 | continue; |
| 1712 | } |
| 1713 | |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1714 | /* Release detached streams with empty buffer. */ |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1715 | if (qcs->flags & QC_SF_DETACH) { |
Amaury Denoyelle | 20d1f84 | 2022-07-11 11:23:17 +0200 | [diff] [blame] | 1716 | if (qcs_is_close_local(qcs)) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 1717 | TRACE_STATE("purging detached stream", QMUX_EV_QCC_WAKE, qcs->qcc->conn, qcs); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1718 | qcs_destroy(qcs); |
| 1719 | release = 1; |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1720 | continue; |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1721 | } |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1722 | |
| 1723 | qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx, |
| 1724 | SUB_RETRY_SEND, &qcc->wait_event); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1725 | } |
| 1726 | } |
| 1727 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1728 | TRACE_LEAVE(QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1729 | return release; |
| 1730 | } |
| 1731 | |
Amaury Denoyelle | c49d5d1 | 2022-07-15 10:32:53 +0200 | [diff] [blame] | 1732 | /* release function. This one should be called to free all resources allocated |
| 1733 | * to the mux. |
| 1734 | */ |
| 1735 | static void qc_release(struct qcc *qcc) |
| 1736 | { |
| 1737 | struct connection *conn = qcc->conn; |
| 1738 | struct eb64_node *node; |
| 1739 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1740 | TRACE_ENTER(QMUX_EV_QCC_END, conn); |
Amaury Denoyelle | c49d5d1 | 2022-07-15 10:32:53 +0200 | [diff] [blame] | 1741 | |
Amaury Denoyelle | f8aaf8b | 2022-09-14 16:23:47 +0200 | [diff] [blame] | 1742 | if (qcc->app_ops && qcc->app_ops->shutdown) { |
Amaury Denoyelle | c49d5d1 | 2022-07-15 10:32:53 +0200 | [diff] [blame] | 1743 | /* Application protocol with dedicated connection closing |
| 1744 | * procedure. |
| 1745 | */ |
Amaury Denoyelle | f8aaf8b | 2022-09-14 16:23:47 +0200 | [diff] [blame] | 1746 | qcc->app_ops->shutdown(qcc->ctx); |
Amaury Denoyelle | a154dc0 | 2022-06-13 17:09:01 +0200 | [diff] [blame] | 1747 | |
| 1748 | /* useful if application protocol should emit some closing |
| 1749 | * frames. For example HTTP/3 GOAWAY frame. |
| 1750 | */ |
| 1751 | qc_send(qcc); |
Amaury Denoyelle | c49d5d1 | 2022-07-15 10:32:53 +0200 | [diff] [blame] | 1752 | } |
| 1753 | else { |
| 1754 | qcc_emit_cc_app(qcc, QC_ERR_NO_ERROR, 0); |
| 1755 | } |
| 1756 | |
| 1757 | if (qcc->task) { |
| 1758 | task_destroy(qcc->task); |
| 1759 | qcc->task = NULL; |
| 1760 | } |
| 1761 | |
| 1762 | if (qcc->wait_event.tasklet) |
| 1763 | tasklet_free(qcc->wait_event.tasklet); |
| 1764 | if (conn && qcc->wait_event.events) { |
| 1765 | conn->xprt->unsubscribe(conn, conn->xprt_ctx, |
| 1766 | qcc->wait_event.events, |
| 1767 | &qcc->wait_event); |
| 1768 | } |
| 1769 | |
| 1770 | /* liberate remaining qcs instances */ |
| 1771 | node = eb64_first(&qcc->streams_by_id); |
| 1772 | while (node) { |
| 1773 | struct qcs *qcs = eb64_entry(node, struct qcs, by_id); |
| 1774 | node = eb64_next(node); |
| 1775 | qcs_free(qcs); |
| 1776 | } |
| 1777 | |
| 1778 | while (!LIST_ISEMPTY(&qcc->lfctl.frms)) { |
| 1779 | struct quic_frame *frm = LIST_ELEM(qcc->lfctl.frms.n, struct quic_frame *, list); |
| 1780 | LIST_DELETE(&frm->list); |
| 1781 | pool_free(pool_head_quic_frame, frm); |
| 1782 | } |
| 1783 | |
Amaury Denoyelle | f8aaf8b | 2022-09-14 16:23:47 +0200 | [diff] [blame] | 1784 | if (qcc->app_ops && qcc->app_ops->release) |
| 1785 | qcc->app_ops->release(qcc->ctx); |
| 1786 | TRACE_PROTO("application layer released", QMUX_EV_QCC_END, conn); |
| 1787 | |
Amaury Denoyelle | c49d5d1 | 2022-07-15 10:32:53 +0200 | [diff] [blame] | 1788 | pool_free(pool_head_qcc, qcc); |
| 1789 | |
| 1790 | if (conn) { |
| 1791 | LIST_DEL_INIT(&conn->stopping_list); |
| 1792 | |
| 1793 | conn->handle.qc->conn = NULL; |
| 1794 | conn->mux = NULL; |
| 1795 | conn->ctx = NULL; |
| 1796 | |
| 1797 | TRACE_DEVEL("freeing conn", QMUX_EV_QCC_END, conn); |
| 1798 | |
| 1799 | conn_stop_tracking(conn); |
| 1800 | conn_full_close(conn); |
| 1801 | if (conn->destroy_cb) |
| 1802 | conn->destroy_cb(conn); |
| 1803 | conn_free(conn); |
| 1804 | } |
| 1805 | |
| 1806 | TRACE_LEAVE(QMUX_EV_QCC_END); |
| 1807 | } |
| 1808 | |
Willy Tarreau | 41e701e | 2022-09-08 15:12:59 +0200 | [diff] [blame] | 1809 | struct task *qc_io_cb(struct task *t, void *ctx, unsigned int status) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1810 | { |
Amaury Denoyelle | 769e9ff | 2021-10-05 11:43:50 +0200 | [diff] [blame] | 1811 | struct qcc *qcc = ctx; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1812 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1813 | TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc->conn); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1814 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1815 | qc_send(qcc); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1816 | |
Amaury Denoyelle | c1a6dfd | 2022-07-08 14:04:21 +0200 | [diff] [blame] | 1817 | if (qc_purge_streams(qcc)) { |
Amaury Denoyelle | 06890aa | 2022-04-04 16:15:06 +0200 | [diff] [blame] | 1818 | if (qcc_is_dead(qcc)) { |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1819 | TRACE_STATE("releasing dead connection", QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1820 | goto release; |
Amaury Denoyelle | 06890aa | 2022-04-04 16:15:06 +0200 | [diff] [blame] | 1821 | } |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 1822 | } |
| 1823 | |
Amaury Denoyelle | 37c2e4a | 2022-05-16 13:54:59 +0200 | [diff] [blame] | 1824 | qc_recv(qcc); |
| 1825 | |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 1826 | /* TODO check if qcc proxy is disabled. If yes, use graceful shutdown |
| 1827 | * to close the connection. |
| 1828 | */ |
| 1829 | |
| 1830 | qcc_refresh_timeout(qcc); |
| 1831 | |
Amaury Denoyelle | d397385 | 2022-07-25 14:56:54 +0200 | [diff] [blame] | 1832 | end: |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1833 | TRACE_LEAVE(QMUX_EV_QCC_WAKE, qcc->conn); |
| 1834 | return NULL; |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1835 | |
Amaury Denoyelle | 3baab74 | 2022-08-11 18:35:55 +0200 | [diff] [blame] | 1836 | release: |
| 1837 | qc_release(qcc); |
| 1838 | TRACE_LEAVE(QMUX_EV_QCC_WAKE); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1839 | return NULL; |
| 1840 | } |
| 1841 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1842 | static struct task *qc_timeout_task(struct task *t, void *ctx, unsigned int state) |
| 1843 | { |
| 1844 | struct qcc *qcc = ctx; |
| 1845 | int expired = tick_is_expired(t->expire, now_ms); |
| 1846 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1847 | TRACE_ENTER(QMUX_EV_QCC_WAKE, qcc ? qcc->conn : NULL); |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1848 | |
| 1849 | if (qcc) { |
| 1850 | if (!expired) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1851 | TRACE_DEVEL("not expired", QMUX_EV_QCC_WAKE, qcc->conn); |
| 1852 | goto requeue; |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | if (!qcc_may_expire(qcc)) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1856 | TRACE_DEVEL("cannot expired", QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1857 | t->expire = TICK_ETERNITY; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1858 | goto requeue; |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1862 | task_destroy(t); |
Amaury Denoyelle | ea3e035 | 2022-02-21 10:05:16 +0100 | [diff] [blame] | 1863 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1864 | if (!qcc) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1865 | TRACE_DEVEL("no more qcc", QMUX_EV_QCC_WAKE); |
| 1866 | goto out; |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1867 | } |
Amaury Denoyelle | ea3e035 | 2022-02-21 10:05:16 +0100 | [diff] [blame] | 1868 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1869 | qcc->task = NULL; |
| 1870 | |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 1871 | /* TODO depending on the timeout condition, different shutdown mode |
| 1872 | * should be used. For http keep-alive or disabled proxy, a graceful |
| 1873 | * shutdown should occurs. For all other cases, an immediate close |
| 1874 | * seems legitimate. |
| 1875 | */ |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1876 | if (qcc_is_dead(qcc)) { |
| 1877 | TRACE_STATE("releasing dead connection", QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1878 | qc_release(qcc); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1879 | } |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1880 | |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1881 | out: |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 1882 | TRACE_LEAVE(QMUX_EV_QCC_WAKE); |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1883 | return NULL; |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 1884 | |
| 1885 | requeue: |
| 1886 | TRACE_LEAVE(QMUX_EV_QCC_WAKE); |
| 1887 | return t; |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1890 | static int qc_init(struct connection *conn, struct proxy *prx, |
| 1891 | struct session *sess, struct buffer *input) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1892 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1893 | struct qcc *qcc; |
Amaury Denoyelle | 6ea7819 | 2022-03-07 15:47:02 +0100 | [diff] [blame] | 1894 | struct quic_transport_params *lparams, *rparams; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1895 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1896 | TRACE_ENTER(QMUX_EV_QCC_NEW); |
| 1897 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1898 | qcc = pool_alloc(pool_head_qcc); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1899 | if (!qcc) { |
| 1900 | TRACE_ERROR("alloc failure", QMUX_EV_QCC_NEW); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1901 | goto fail_no_qcc; |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1902 | } |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1903 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1904 | qcc->conn = conn; |
| 1905 | conn->ctx = qcc; |
Amaury Denoyelle | c603de4 | 2022-07-25 11:21:46 +0200 | [diff] [blame] | 1906 | qcc->nb_hreq = qcc->nb_sc = 0; |
Amaury Denoyelle | ce1f30d | 2022-02-01 15:14:24 +0100 | [diff] [blame] | 1907 | qcc->flags = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1908 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1909 | qcc->app_ops = NULL; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1910 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1911 | qcc->streams_by_id = EB_ROOT_UNIQUE; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1912 | |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1913 | /* Server parameters, params used for RX flow control. */ |
Willy Tarreau | 784b868 | 2022-04-11 14:18:10 +0200 | [diff] [blame] | 1914 | lparams = &conn->handle.qc->rx.params; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1915 | |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1916 | qcc->rx.max_data = lparams->initial_max_data; |
Amaury Denoyelle | b9e0640 | 2022-06-10 15:16:21 +0200 | [diff] [blame] | 1917 | qcc->tx.sent_offsets = qcc->tx.offsets = 0; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1918 | |
| 1919 | /* Client initiated streams must respect the server flow control. */ |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1920 | qcc->strms[QCS_CLT_BIDI].max_streams = lparams->initial_max_streams_bidi; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1921 | qcc->strms[QCS_CLT_BIDI].nb_streams = 0; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1922 | qcc->strms[QCS_CLT_BIDI].rx.max_data = 0; |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1923 | qcc->strms[QCS_CLT_BIDI].tx.max_data = lparams->initial_max_stream_data_bidi_remote; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1924 | |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1925 | qcc->strms[QCS_CLT_UNI].max_streams = lparams->initial_max_streams_uni; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1926 | qcc->strms[QCS_CLT_UNI].nb_streams = 0; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1927 | qcc->strms[QCS_CLT_UNI].rx.max_data = 0; |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1928 | qcc->strms[QCS_CLT_UNI].tx.max_data = lparams->initial_max_stream_data_uni; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1929 | |
| 1930 | /* Server initiated streams must respect the server flow control. */ |
| 1931 | qcc->strms[QCS_SRV_BIDI].max_streams = 0; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1932 | qcc->strms[QCS_SRV_BIDI].nb_streams = 0; |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1933 | qcc->strms[QCS_SRV_BIDI].rx.max_data = lparams->initial_max_stream_data_bidi_local; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1934 | qcc->strms[QCS_SRV_BIDI].tx.max_data = 0; |
| 1935 | |
| 1936 | qcc->strms[QCS_SRV_UNI].max_streams = 0; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1937 | qcc->strms[QCS_SRV_UNI].nb_streams = 0; |
Amaury Denoyelle | 749cb64 | 2022-02-09 10:25:29 +0100 | [diff] [blame] | 1938 | qcc->strms[QCS_SRV_UNI].rx.max_data = lparams->initial_max_stream_data_uni; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 1939 | qcc->strms[QCS_SRV_UNI].tx.max_data = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1940 | |
Amaury Denoyelle | c985cb1 | 2022-05-16 14:29:59 +0200 | [diff] [blame] | 1941 | LIST_INIT(&qcc->lfctl.frms); |
Amaury Denoyelle | 78396e5 | 2022-03-21 17:13:32 +0100 | [diff] [blame] | 1942 | qcc->lfctl.ms_bidi = qcc->lfctl.ms_bidi_init = lparams->initial_max_streams_bidi; |
Amaury Denoyelle | bf3c208 | 2022-08-16 11:29:08 +0200 | [diff] [blame] | 1943 | qcc->lfctl.ms_uni = lparams->initial_max_streams_uni; |
Amaury Denoyelle | 44d0912 | 2022-04-26 11:21:10 +0200 | [diff] [blame] | 1944 | qcc->lfctl.msd_bidi_l = lparams->initial_max_stream_data_bidi_local; |
| 1945 | qcc->lfctl.msd_bidi_r = lparams->initial_max_stream_data_bidi_remote; |
Amaury Denoyelle | 78396e5 | 2022-03-21 17:13:32 +0100 | [diff] [blame] | 1946 | qcc->lfctl.cl_bidi_r = 0; |
Amaury Denoyelle | c055e30 | 2022-02-07 16:09:06 +0100 | [diff] [blame] | 1947 | |
Amaury Denoyelle | c830e1e | 2022-05-16 16:19:59 +0200 | [diff] [blame] | 1948 | qcc->lfctl.md = qcc->lfctl.md_init = lparams->initial_max_data; |
Amaury Denoyelle | d46b0f5 | 2022-05-20 15:05:07 +0200 | [diff] [blame] | 1949 | qcc->lfctl.offsets_recv = qcc->lfctl.offsets_consume = 0; |
Amaury Denoyelle | c830e1e | 2022-05-16 16:19:59 +0200 | [diff] [blame] | 1950 | |
Willy Tarreau | 784b868 | 2022-04-11 14:18:10 +0200 | [diff] [blame] | 1951 | rparams = &conn->handle.qc->tx.params; |
Amaury Denoyelle | 05ce55e | 2022-03-08 10:35:42 +0100 | [diff] [blame] | 1952 | qcc->rfctl.md = rparams->initial_max_data; |
Amaury Denoyelle | 6ea7819 | 2022-03-07 15:47:02 +0100 | [diff] [blame] | 1953 | qcc->rfctl.msd_bidi_l = rparams->initial_max_stream_data_bidi_local; |
| 1954 | qcc->rfctl.msd_bidi_r = rparams->initial_max_stream_data_bidi_remote; |
| 1955 | |
Amaury Denoyelle | a509ffb | 2022-07-04 15:50:33 +0200 | [diff] [blame] | 1956 | if (conn_is_back(conn)) { |
| 1957 | qcc->next_bidi_l = 0x00; |
| 1958 | qcc->largest_bidi_r = 0x01; |
| 1959 | qcc->next_uni_l = 0x02; |
| 1960 | qcc->largest_uni_r = 0x03; |
| 1961 | } |
| 1962 | else { |
| 1963 | qcc->largest_bidi_r = 0x00; |
| 1964 | qcc->next_bidi_l = 0x01; |
| 1965 | qcc->largest_uni_r = 0x02; |
| 1966 | qcc->next_uni_l = 0x03; |
| 1967 | } |
| 1968 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1969 | qcc->wait_event.tasklet = tasklet_new(); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1970 | if (!qcc->wait_event.tasklet) { |
| 1971 | TRACE_ERROR("taslket alloc failure", QMUX_EV_QCC_NEW); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1972 | goto fail_no_tasklet; |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1973 | } |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1974 | |
Amaury Denoyelle | 1b2dba5 | 2022-04-15 17:32:04 +0200 | [diff] [blame] | 1975 | LIST_INIT(&qcc->send_retry_list); |
| 1976 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 1977 | qcc->subs = NULL; |
| 1978 | qcc->wait_event.tasklet->process = qc_io_cb; |
| 1979 | qcc->wait_event.tasklet->context = qcc; |
Frédéric Lécaille | f27b66f | 2022-03-18 22:49:22 +0100 | [diff] [blame] | 1980 | qcc->wait_event.events = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 1981 | |
Amaury Denoyelle | 07bf8f4 | 2022-07-22 16:16:03 +0200 | [diff] [blame] | 1982 | qcc->proxy = prx; |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1983 | /* haproxy timeouts */ |
Amaury Denoyelle | a3daaec | 2022-04-21 16:29:27 +0200 | [diff] [blame] | 1984 | qcc->task = NULL; |
Amaury Denoyelle | b630945 | 2022-07-25 14:51:56 +0200 | [diff] [blame] | 1985 | qcc->timeout = conn_is_back(qcc->conn) ? prx->timeout.server : |
| 1986 | prx->timeout.client; |
Amaury Denoyelle | a3daaec | 2022-04-21 16:29:27 +0200 | [diff] [blame] | 1987 | if (tick_isset(qcc->timeout)) { |
| 1988 | qcc->task = task_new_here(); |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1989 | if (!qcc->task) { |
| 1990 | TRACE_ERROR("timeout task alloc failure", QMUX_EV_QCC_NEW); |
Amaury Denoyelle | a3daaec | 2022-04-21 16:29:27 +0200 | [diff] [blame] | 1991 | goto fail_no_timeout_task; |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 1992 | } |
Amaury Denoyelle | a3daaec | 2022-04-21 16:29:27 +0200 | [diff] [blame] | 1993 | qcc->task->process = qc_timeout_task; |
| 1994 | qcc->task->context = qcc; |
| 1995 | qcc->task->expire = tick_add(now_ms, qcc->timeout); |
| 1996 | } |
Amaury Denoyelle | bd6ec1b | 2022-07-25 11:53:18 +0200 | [diff] [blame] | 1997 | qcc_reset_idle_start(qcc); |
Amaury Denoyelle | 30e260e | 2022-08-03 11:17:57 +0200 | [diff] [blame] | 1998 | LIST_INIT(&qcc->opening_list); |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 1999 | |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2000 | if (!conn_is_back(conn)) { |
| 2001 | if (!LIST_INLIST(&conn->stopping_list)) { |
| 2002 | LIST_APPEND(&mux_stopping_data[tid].list, |
| 2003 | &conn->stopping_list); |
| 2004 | } |
| 2005 | } |
| 2006 | |
Willy Tarreau | 784b868 | 2022-04-11 14:18:10 +0200 | [diff] [blame] | 2007 | HA_ATOMIC_STORE(&conn->handle.qc->qcc, qcc); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2008 | /* init read cycle */ |
| 2009 | tasklet_wakeup(qcc->wait_event.tasklet); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2010 | |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 2011 | TRACE_LEAVE(QMUX_EV_QCC_NEW, qcc->conn); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2012 | return 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2013 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 2014 | fail_no_timeout_task: |
| 2015 | tasklet_free(qcc->wait_event.tasklet); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2016 | fail_no_tasklet: |
| 2017 | pool_free(pool_head_qcc, qcc); |
| 2018 | fail_no_qcc: |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 2019 | TRACE_LEAVE(QMUX_EV_QCC_NEW); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2020 | return -1; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2021 | } |
| 2022 | |
Amaury Denoyelle | 2461bd5 | 2022-04-13 16:54:52 +0200 | [diff] [blame] | 2023 | static void qc_destroy(void *ctx) |
| 2024 | { |
| 2025 | struct qcc *qcc = ctx; |
| 2026 | |
| 2027 | TRACE_ENTER(QMUX_EV_QCC_END, qcc->conn); |
| 2028 | qc_release(qcc); |
| 2029 | TRACE_LEAVE(QMUX_EV_QCC_END); |
| 2030 | } |
| 2031 | |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 2032 | static void qc_detach(struct sedesc *sd) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2033 | { |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 2034 | struct qcs *qcs = sd->se; |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 2035 | struct qcc *qcc = qcs->qcc; |
| 2036 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 2037 | TRACE_ENTER(QMUX_EV_STRM_END, qcc->conn, qcs); |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 2038 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 2039 | /* TODO this BUG_ON_HOT() is not correct as the stconn layer may detach |
| 2040 | * from the stream even if it is not closed remotely at the QUIC layer. |
| 2041 | * This happens for example when a stream must be closed due to a |
| 2042 | * rejected request. To better handle these cases, it will be required |
| 2043 | * to implement shutr/shutw MUX operations. Once this is done, this |
| 2044 | * BUG_ON_HOT() statement can be adjusted. |
| 2045 | */ |
| 2046 | //BUG_ON_HOT(!qcs_is_close_remote(qcs)); |
Amaury Denoyelle | c603de4 | 2022-07-25 11:21:46 +0200 | [diff] [blame] | 2047 | |
| 2048 | qcc_rm_sc(qcc); |
Amaury Denoyelle | 06890aa | 2022-04-04 16:15:06 +0200 | [diff] [blame] | 2049 | |
Amaury Denoyelle | 20d1f84 | 2022-07-11 11:23:17 +0200 | [diff] [blame] | 2050 | if (!qcs_is_close_local(qcs) && !(qcc->conn->flags & CO_FL_ERROR)) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 2051 | TRACE_STATE("remaining data, detaching qcs", QMUX_EV_STRM_END, qcc->conn, qcs); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 2052 | qcs->flags |= QC_SF_DETACH; |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 2053 | qcc_refresh_timeout(qcc); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 2054 | |
| 2055 | TRACE_LEAVE(QMUX_EV_STRM_END, qcc->conn, qcs); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 2056 | return; |
| 2057 | } |
| 2058 | |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 2059 | qcs_destroy(qcs); |
Amaury Denoyelle | 1136e92 | 2022-02-01 10:33:09 +0100 | [diff] [blame] | 2060 | |
Amaury Denoyelle | 06890aa | 2022-04-04 16:15:06 +0200 | [diff] [blame] | 2061 | if (qcc_is_dead(qcc)) { |
Amaury Denoyelle | 047d86a | 2022-08-10 16:42:35 +0200 | [diff] [blame] | 2062 | TRACE_STATE("killing dead connection", QMUX_EV_STRM_END, qcc->conn); |
Amaury Denoyelle | 35a66c0 | 2022-08-12 15:56:21 +0200 | [diff] [blame] | 2063 | goto release; |
Amaury Denoyelle | 06890aa | 2022-04-04 16:15:06 +0200 | [diff] [blame] | 2064 | } |
Amaury Denoyelle | a3daaec | 2022-04-21 16:29:27 +0200 | [diff] [blame] | 2065 | else if (qcc->task) { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 2066 | TRACE_DEVEL("refreshing connection's timeout", QMUX_EV_STRM_END, qcc->conn); |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 2067 | qcc_refresh_timeout(qcc); |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 2068 | } |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 2069 | else { |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 2070 | TRACE_DEVEL("completed", QMUX_EV_STRM_END, qcc->conn); |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 2071 | } |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 2072 | |
| 2073 | TRACE_LEAVE(QMUX_EV_STRM_END, qcc->conn); |
Amaury Denoyelle | 35a66c0 | 2022-08-12 15:56:21 +0200 | [diff] [blame] | 2074 | return; |
| 2075 | |
| 2076 | release: |
| 2077 | qc_release(qcc); |
| 2078 | TRACE_LEAVE(QMUX_EV_STRM_END); |
| 2079 | return; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2080 | } |
| 2081 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2082 | /* Called from the upper layer, to receive data */ |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2083 | static size_t qc_rcv_buf(struct stconn *sc, struct buffer *buf, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2084 | size_t count, int flags) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2085 | { |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2086 | struct qcs *qcs = __sc_mux_strm(sc); |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2087 | size_t ret = 0; |
Amaury Denoyelle | eb53e5b | 2022-02-14 17:11:32 +0100 | [diff] [blame] | 2088 | char fin = 0; |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2089 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 2090 | TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2091 | |
Amaury Denoyelle | d80fbca | 2022-09-19 17:02:28 +0200 | [diff] [blame] | 2092 | ret = qcs_http_rcv_buf(qcs, buf, count, &fin); |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2093 | |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2094 | if (b_data(&qcs->rx.app_buf)) { |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 2095 | se_fl_set(qcs->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2096 | } |
| 2097 | else { |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 2098 | se_fl_clr(qcs->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); |
| 2099 | if (se_fl_test(qcs->sd, SE_FL_ERR_PENDING)) |
| 2100 | se_fl_set(qcs->sd, SE_FL_ERROR); |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2101 | |
Amaury Denoyelle | 72a78e8 | 2022-07-29 15:34:12 +0200 | [diff] [blame] | 2102 | /* Set end-of-input if FIN received and all data extracted. */ |
Amaury Denoyelle | eb53e5b | 2022-02-14 17:11:32 +0100 | [diff] [blame] | 2103 | if (fin) |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 2104 | se_fl_set(qcs->sd, SE_FL_EOI); |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2105 | |
| 2106 | if (b_size(&qcs->rx.app_buf)) { |
| 2107 | b_free(&qcs->rx.app_buf); |
| 2108 | offer_buffers(NULL, 1); |
| 2109 | } |
| 2110 | } |
| 2111 | |
Amaury Denoyelle | f1fc0b3 | 2022-05-02 11:07:06 +0200 | [diff] [blame] | 2112 | if (ret) { |
| 2113 | qcs->flags &= ~QC_SF_DEM_FULL; |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2114 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
Amaury Denoyelle | f1fc0b3 | 2022-05-02 11:07:06 +0200 | [diff] [blame] | 2115 | } |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2116 | |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 2117 | TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs); |
| 2118 | |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame] | 2119 | return ret; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2120 | } |
| 2121 | |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2122 | static size_t qc_snd_buf(struct stconn *sc, struct buffer *buf, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2123 | size_t count, int flags) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2124 | { |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2125 | struct qcs *qcs = __sc_mux_strm(sc); |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 2126 | size_t ret; |
Amaury Denoyelle | 9534e59 | 2022-09-19 17:14:27 +0200 | [diff] [blame] | 2127 | char fin; |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 2128 | |
| 2129 | TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2130 | |
Amaury Denoyelle | 3dc4e5a | 2022-09-13 16:49:21 +0200 | [diff] [blame] | 2131 | /* stream layer has been detached so no transfer must occur after. */ |
| 2132 | BUG_ON_HOT(qcs->flags & QC_SF_DETACH); |
| 2133 | |
Amaury Denoyelle | 843a119 | 2022-07-04 11:44:38 +0200 | [diff] [blame] | 2134 | if (qcs_is_close_local(qcs) || (qcs->flags & QC_SF_TO_RESET)) { |
Amaury Denoyelle | 0ed617a | 2022-09-20 14:46:40 +0200 | [diff] [blame] | 2135 | ret = qcs_http_reset_buf(qcs, buf, count); |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 2136 | goto end; |
| 2137 | } |
| 2138 | |
Amaury Denoyelle | 9534e59 | 2022-09-19 17:14:27 +0200 | [diff] [blame] | 2139 | ret = qcs_http_snd_buf(qcs, buf, count, &fin); |
| 2140 | if (fin) |
| 2141 | qcs->flags |= QC_SF_FIN_STREAM; |
| 2142 | |
| 2143 | if (ret) { |
| 2144 | if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND)) |
| 2145 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
| 2146 | } |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2147 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 2148 | end: |
Amaury Denoyelle | 4f13757 | 2022-03-24 17:10:00 +0100 | [diff] [blame] | 2149 | TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs); |
| 2150 | |
| 2151 | return ret; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /* Called from the upper layer, to subscribe <es> to events <event_type>. The |
| 2155 | * event subscriber <es> is not allowed to change from a previous call as long |
| 2156 | * as at least one event is still subscribed. The <event_type> must only be a |
| 2157 | * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0. |
| 2158 | */ |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2159 | static int qc_subscribe(struct stconn *sc, int event_type, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2160 | struct wait_event *es) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2161 | { |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2162 | return qcs_subscribe(__sc_mux_strm(sc), event_type, es); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | /* Called from the upper layer, to unsubscribe <es> from events <event_type>. |
| 2166 | * The <es> pointer is not allowed to differ from the one passed to the |
| 2167 | * subscribe() call. It always returns zero. |
| 2168 | */ |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2169 | static int qc_unsubscribe(struct stconn *sc, int event_type, struct wait_event *es) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2170 | { |
Willy Tarreau | 3215e73 | 2022-05-27 10:09:11 +0200 | [diff] [blame] | 2171 | struct qcs *qcs = __sc_mux_strm(sc); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2172 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2173 | BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV)); |
| 2174 | BUG_ON(qcs->subs && qcs->subs != es); |
| 2175 | |
| 2176 | es->events &= ~event_type; |
| 2177 | if (!es->events) |
| 2178 | qcs->subs = NULL; |
| 2179 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2180 | return 0; |
| 2181 | } |
| 2182 | |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2183 | /* Loop through all qcs from <qcc>. If CO_FL_ERROR is set on the connection, |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 2184 | * report SE_FL_ERR_PENDING|SE_FL_ERROR on the attached stream connectors and |
| 2185 | * wake them. |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2186 | */ |
| 2187 | static int qc_wake_some_streams(struct qcc *qcc) |
| 2188 | { |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2189 | struct qcs *qcs; |
| 2190 | struct eb64_node *node; |
| 2191 | |
| 2192 | for (node = eb64_first(&qcc->streams_by_id); node; |
| 2193 | node = eb64_next(node)) { |
Amaury Denoyelle | e4301da | 2022-04-19 17:59:50 +0200 | [diff] [blame] | 2194 | qcs = eb64_entry(node, struct qcs, by_id); |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2195 | |
Amaury Denoyelle | 3abeb57 | 2022-07-04 11:42:27 +0200 | [diff] [blame] | 2196 | if (!qcs_sc(qcs)) |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2197 | continue; |
| 2198 | |
| 2199 | if (qcc->conn->flags & CO_FL_ERROR) { |
Willy Tarreau | d7b7e0d | 2022-05-27 16:09:35 +0200 | [diff] [blame] | 2200 | se_fl_set(qcs->sd, SE_FL_ERR_PENDING); |
| 2201 | if (se_fl_test(qcs->sd, SE_FL_EOS)) |
| 2202 | se_fl_set(qcs->sd, SE_FL_ERROR); |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2203 | |
Amaury Denoyelle | 4561f84 | 2022-07-06 14:54:34 +0200 | [diff] [blame] | 2204 | qcs_alert(qcs); |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | return 0; |
| 2209 | } |
| 2210 | |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2211 | static int qc_wake(struct connection *conn) |
| 2212 | { |
| 2213 | struct qcc *qcc = conn->ctx; |
Willy Tarreau | 784b868 | 2022-04-11 14:18:10 +0200 | [diff] [blame] | 2214 | struct proxy *prx = conn->handle.qc->li->bind_conf->frontend; |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2215 | |
| 2216 | TRACE_ENTER(QMUX_EV_QCC_WAKE, conn); |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2217 | |
| 2218 | /* Check if a soft-stop is in progress. |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2219 | * |
cui fliter | a94bedc | 2022-08-29 14:42:57 +0800 | [diff] [blame] | 2220 | * TODO this is relevant for frontend connections only. |
Amaury Denoyelle | d0c6232 | 2022-05-23 08:52:58 +0200 | [diff] [blame] | 2221 | * |
| 2222 | * TODO Client should be notified with a H3 GOAWAY and then a |
| 2223 | * CONNECTION_CLOSE. However, quic-conn uses the listener socket for |
| 2224 | * sending which at this stage is already closed. |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2225 | */ |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2226 | if (unlikely(prx->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) |
Amaury Denoyelle | d0c6232 | 2022-05-23 08:52:58 +0200 | [diff] [blame] | 2227 | qcc->conn->flags |= (CO_FL_SOCK_RD_SH|CO_FL_SOCK_WR_SH); |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2228 | |
Willy Tarreau | 784b868 | 2022-04-11 14:18:10 +0200 | [diff] [blame] | 2229 | if (conn->handle.qc->flags & QUIC_FL_CONN_NOTIFY_CLOSE) |
Amaury Denoyelle | b515b0a | 2022-04-06 10:28:43 +0200 | [diff] [blame] | 2230 | qcc->conn->flags |= (CO_FL_SOCK_RD_SH|CO_FL_SOCK_WR_SH); |
| 2231 | |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2232 | qc_send(qcc); |
| 2233 | |
Amaury Denoyelle | fe035ec | 2022-04-06 15:46:30 +0200 | [diff] [blame] | 2234 | qc_wake_some_streams(qcc); |
| 2235 | |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2236 | if (qcc_is_dead(qcc)) |
| 2237 | goto release; |
| 2238 | |
Amaury Denoyelle | 5fc05d1 | 2022-07-25 14:58:48 +0200 | [diff] [blame] | 2239 | qcc_refresh_timeout(qcc); |
| 2240 | |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2241 | TRACE_LEAVE(QMUX_EV_QCC_WAKE, conn); |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2242 | return 0; |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2243 | |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2244 | release: |
Amaury Denoyelle | 4c9a164 | 2022-08-10 16:58:01 +0200 | [diff] [blame] | 2245 | TRACE_STATE("releasing dead connection", QMUX_EV_QCC_WAKE, qcc->conn); |
Amaury Denoyelle | d97fc80 | 2022-04-06 16:13:09 +0200 | [diff] [blame] | 2246 | qc_release(qcc); |
Amaury Denoyelle | f0b67f9 | 2022-08-10 16:14:32 +0200 | [diff] [blame] | 2247 | TRACE_LEAVE(QMUX_EV_QCC_WAKE); |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2248 | return 1; |
| 2249 | } |
| 2250 | |
Amaury Denoyelle | 38e6006 | 2022-07-01 16:48:42 +0200 | [diff] [blame] | 2251 | |
Willy Tarreau | b4a4fee | 2022-09-02 16:00:40 +0200 | [diff] [blame] | 2252 | /* for debugging with CLI's "show sess" command. May emit multiple lines, each |
| 2253 | * new one being prefixed with <pfx>, if <pfx> is not NULL, otherwise a single |
| 2254 | * line is used. Each field starts with a space so it's safe to print it after |
| 2255 | * existing fields. |
| 2256 | */ |
| 2257 | static int qc_show_sd(struct buffer *msg, struct sedesc *sd, const char *pfx) |
| 2258 | { |
| 2259 | struct qcs *qcs = sd->se; |
| 2260 | struct qcc *qcc; |
| 2261 | int ret = 0; |
| 2262 | |
| 2263 | if (!qcs) |
| 2264 | return ret; |
| 2265 | |
| 2266 | chunk_appendf(msg, " qcs=%p .flg=%#x .id=%llu .st=%s .ctx=%p, .err=%#llx", |
| 2267 | qcs, qcs->flags, (ull)qcs->id, qcs_st_to_str(qcs->st), qcs->ctx, (ull)qcs->err); |
| 2268 | |
| 2269 | if (pfx) |
| 2270 | chunk_appendf(msg, "\n%s", pfx); |
| 2271 | |
| 2272 | qcc = qcs->qcc; |
| 2273 | chunk_appendf(msg, " qcc=%p .flg=%#x .nbsc=%llu .nbhreq=%llu, .task=%p", |
| 2274 | qcc, qcc->flags, (ull)qcc->nb_sc, (ull)qcc->nb_hreq, qcc->task); |
| 2275 | return ret; |
| 2276 | } |
| 2277 | |
| 2278 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2279 | static const struct mux_ops qc_ops = { |
| 2280 | .init = qc_init, |
Amaury Denoyelle | 2461bd5 | 2022-04-13 16:54:52 +0200 | [diff] [blame] | 2281 | .destroy = qc_destroy, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2282 | .detach = qc_detach, |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2283 | .rcv_buf = qc_rcv_buf, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2284 | .snd_buf = qc_snd_buf, |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2285 | .subscribe = qc_subscribe, |
| 2286 | .unsubscribe = qc_unsubscribe, |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 2287 | .wake = qc_wake, |
Willy Tarreau | b4a4fee | 2022-09-02 16:00:40 +0200 | [diff] [blame] | 2288 | .show_sd = qc_show_sd, |
Willy Tarreau | b5821e1 | 2022-04-26 11:54:08 +0200 | [diff] [blame] | 2289 | .flags = MX_FL_HTX|MX_FL_NO_UPG|MX_FL_FRAMED, |
Willy Tarreau | 671bd5a | 2022-04-11 09:29:21 +0200 | [diff] [blame] | 2290 | .name = "QUIC", |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2291 | }; |
| 2292 | |
| 2293 | static struct mux_proto_list mux_proto_quic = |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 2294 | { .token = IST("quic"), .mode = PROTO_MODE_HTTP, .side = PROTO_SIDE_FE, .mux = &qc_ops }; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 2295 | |
| 2296 | INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_quic); |