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 | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame^] | 8 | #include <haproxy/htx.h> |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 9 | #include <haproxy/pool.h> |
Amaury Denoyelle | eb01f59 | 2021-10-07 16:44:05 +0200 | [diff] [blame] | 10 | #include <haproxy/ssl_sock-t.h> |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 11 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 12 | DECLARE_POOL(pool_head_qcc, "qcc", sizeof(struct qcc)); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 13 | DECLARE_POOL(pool_head_qcs, "qcs", sizeof(struct qcs)); |
| 14 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 15 | void quic_mux_transport_params_update(struct qcc *qcc) |
| 16 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 17 | struct quic_transport_params *clt_params; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 18 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 19 | /* Client parameters, params used to TX. */ |
| 20 | clt_params = &qcc->conn->qc->tx.params; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 21 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 22 | qcc->tx.max_data = clt_params->initial_max_data; |
| 23 | /* Client initiated streams must respect the server flow control. */ |
| 24 | qcc->strms[QCS_CLT_BIDI].rx.max_data = clt_params->initial_max_stream_data_bidi_local; |
| 25 | qcc->strms[QCS_CLT_UNI].rx.max_data = clt_params->initial_max_stream_data_uni; |
| 26 | |
| 27 | /* Server initiated streams must respect the server flow control. */ |
| 28 | qcc->strms[QCS_SRV_BIDI].max_streams = clt_params->initial_max_streams_bidi; |
| 29 | qcc->strms[QCS_SRV_BIDI].tx.max_data = clt_params->initial_max_stream_data_bidi_remote; |
| 30 | |
| 31 | qcc->strms[QCS_SRV_UNI].max_streams = clt_params->initial_max_streams_uni; |
| 32 | qcc->strms[QCS_SRV_UNI].tx.max_data = clt_params->initial_max_stream_data_uni; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 33 | } |
| 34 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 35 | /* Allocate a new QUIC streams with id <id> and type <type>. */ |
| 36 | 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] | 37 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 38 | struct qcs *qcs; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 39 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 40 | qcs = pool_alloc(pool_head_qcs); |
| 41 | if (!qcs) |
| 42 | goto out; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 43 | |
Amaury Denoyelle | fdbf63e | 2021-12-16 15:22:30 +0100 | [diff] [blame] | 44 | fprintf(stderr, "%s: stream ID %lu\n", __func__, id); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 45 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 46 | qcs->qcc = qcc; |
| 47 | qcs->cs = NULL; |
| 48 | qcs->flags = QC_SF_NONE; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 49 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 50 | qcs->by_id.key = id; |
| 51 | eb64_insert(&qcc->streams_by_id, &qcs->by_id); |
| 52 | qcc->strms[type].nb_streams++; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 53 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 54 | qcs->rx.buf = BUF_NULL; |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame^] | 55 | qcs->rx.app_buf = BUF_NULL; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 56 | qcs->rx.offset = 0; |
| 57 | qcs->rx.frms = EB_ROOT_UNIQUE; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 58 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 59 | qcs->tx.buf = BUF_NULL; |
| 60 | qcs->tx.xprt_buf = BUF_NULL; |
| 61 | qcs->tx.offset = 0; |
| 62 | qcs->tx.ack_offset = 0; |
| 63 | qcs->tx.acked_frms = EB_ROOT_UNIQUE; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 64 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 65 | qcs->wait_event.tasklet = NULL; |
| 66 | qcs->wait_event.events = 0; |
| 67 | qcs->subs = NULL; |
| 68 | |
| 69 | out: |
| 70 | return qcs; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 73 | /* Free a qcs. This function must only be used for unidirectional streams. |
| 74 | * Bidirectional streams are released by the upper layer through qc_detach(). |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 75 | */ |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 76 | void uni_qcs_free(struct qcs *qcs) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 77 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 78 | eb64_delete(&qcs->by_id); |
| 79 | pool_free(pool_head_qcs, qcs); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 82 | 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] | 83 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 84 | struct buffer *buf = b_alloc(bptr); |
| 85 | BUG_ON(!buf); |
| 86 | return buf; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Amaury Denoyelle | a3f222d | 2021-12-06 11:24:00 +0100 | [diff] [blame] | 89 | int qcs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es) |
| 90 | { |
| 91 | fprintf(stderr, "%s\n", __func__); |
| 92 | |
| 93 | BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV)); |
| 94 | BUG_ON(qcs->subs && qcs->subs != es); |
| 95 | |
| 96 | es->events |= event_type; |
| 97 | qcs->subs = es; |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | void qcs_notify_recv(struct qcs *qcs) |
| 103 | { |
| 104 | if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) { |
| 105 | tasklet_wakeup(qcs->subs->tasklet); |
| 106 | qcs->subs->events &= ~SUB_RETRY_RECV; |
| 107 | if (!qcs->subs->events) |
| 108 | qcs->subs = NULL; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | void qcs_notify_send(struct qcs *qcs) |
| 113 | { |
| 114 | if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) { |
| 115 | tasklet_wakeup(qcs->subs->tasklet); |
| 116 | qcs->subs->events &= ~SUB_RETRY_SEND; |
| 117 | if (!qcs->subs->events) |
| 118 | qcs->subs = NULL; |
| 119 | } |
| 120 | } |
| 121 | |
Amaury Denoyelle | 8a5b27a | 2021-12-21 11:53:10 +0100 | [diff] [blame] | 122 | /* Retrieve as an ebtree node the stream with <id> as ID, possibly allocates |
| 123 | * several streams, depending on the already open ones. |
| 124 | * Return this node if succeeded, NULL if not. |
| 125 | */ |
| 126 | struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id) |
| 127 | { |
| 128 | unsigned int strm_type; |
| 129 | int64_t sub_id; |
| 130 | struct eb64_node *strm_node; |
| 131 | |
| 132 | strm_type = id & QCS_ID_TYPE_MASK; |
| 133 | sub_id = id >> QCS_ID_TYPE_SHIFT; |
| 134 | strm_node = NULL; |
| 135 | if (qc_local_stream_id(qcc, id)) { |
| 136 | /* Local streams: this stream must be already opened. */ |
| 137 | strm_node = eb64_lookup(&qcc->streams_by_id, id); |
| 138 | if (!strm_node) { |
| 139 | /* unknown stream id */ |
| 140 | goto out; |
| 141 | } |
| 142 | } |
| 143 | else { |
| 144 | /* Remote streams. */ |
| 145 | struct eb_root *strms; |
| 146 | uint64_t largest_id; |
| 147 | enum qcs_type qcs_type; |
| 148 | |
| 149 | strms = &qcc->streams_by_id; |
| 150 | qcs_type = qcs_id_type(id); |
| 151 | if (sub_id + 1 > qcc->strms[qcs_type].max_streams) { |
| 152 | /* streams limit reached */ |
| 153 | goto out; |
| 154 | } |
| 155 | |
| 156 | /* Note: ->largest_id was initialized with (uint64_t)-1 as value, 0 being a |
| 157 | * correct value. |
| 158 | */ |
| 159 | largest_id = qcc->strms[qcs_type].largest_id; |
| 160 | if (sub_id > (int64_t)largest_id) { |
| 161 | /* RFC: "A stream ID that is used out of order results in all streams |
| 162 | * of that type with lower-numbered stream IDs also being opened". |
| 163 | * So, let's "open" these streams. |
| 164 | */ |
| 165 | int64_t i; |
| 166 | struct qcs *qcs; |
| 167 | |
| 168 | qcs = NULL; |
| 169 | for (i = largest_id + 1; i <= sub_id; i++) { |
| 170 | uint64_t id = (i << QCS_ID_TYPE_SHIFT) | strm_type; |
| 171 | enum qcs_type type = id & QCS_ID_DIR_BIT ? QCS_CLT_UNI : QCS_CLT_BIDI; |
| 172 | qcs = qcs_new(qcc, id, type); |
| 173 | if (!qcs) { |
| 174 | /* allocation failure */ |
| 175 | goto out; |
| 176 | } |
| 177 | |
| 178 | qcc->strms[qcs_type].largest_id = i; |
| 179 | } |
| 180 | if (qcs) |
| 181 | strm_node = &qcs->by_id; |
| 182 | } |
| 183 | else { |
| 184 | strm_node = eb64_lookup(strms, id); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return strm_node; |
| 189 | |
| 190 | out: |
| 191 | return NULL; |
| 192 | } |
| 193 | |
Ilya Shipitsin | 5e87bcf | 2021-12-25 11:45:52 +0500 | [diff] [blame] | 194 | /* 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] | 195 | static void qcs_destroy(struct qcs *qcs) |
| 196 | { |
| 197 | fprintf(stderr, "%s: release stream %llu\n", __func__, qcs->by_id.key); |
| 198 | |
| 199 | eb64_delete(&qcs->by_id); |
| 200 | |
| 201 | b_free(&qcs->rx.buf); |
| 202 | b_free(&qcs->tx.buf); |
| 203 | b_free(&qcs->tx.xprt_buf); |
| 204 | |
| 205 | --qcs->qcc->strms[qcs_id_type(qcs->by_id.key)].nb_streams; |
| 206 | |
| 207 | pool_free(pool_head_qcs, qcs); |
| 208 | } |
| 209 | |
| 210 | static inline int qcc_is_dead(const struct qcc *qcc) |
| 211 | { |
| 212 | fprintf(stderr, "%s: %lu\n", __func__, qcc->strms[QCS_CLT_BIDI].nb_streams); |
| 213 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 214 | if (!qcc->strms[QCS_CLT_BIDI].nb_streams && !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 | |
| 224 | /* Consider that the timeout must be set if no bidirectional streams |
| 225 | * are opened. |
| 226 | */ |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 227 | if (!qcc->strms[QCS_CLT_BIDI].nb_streams) |
| 228 | return 1; |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* release function. This one should be called to free all resources allocated |
| 234 | * to the mux. |
| 235 | */ |
| 236 | static void qc_release(struct qcc *qcc) |
| 237 | { |
| 238 | struct connection *conn = NULL; |
| 239 | |
| 240 | if (qcc) { |
| 241 | /* The connection must be aattached to this mux to be released */ |
| 242 | if (qcc->conn && qcc->conn->ctx == qcc) |
| 243 | conn = qcc->conn; |
| 244 | |
| 245 | if (qcc->wait_event.tasklet) |
| 246 | tasklet_free(qcc->wait_event.tasklet); |
| 247 | |
| 248 | pool_free(pool_head_qcc, qcc); |
| 249 | } |
| 250 | |
| 251 | if (conn) { |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 252 | LIST_DEL_INIT(&conn->stopping_list); |
| 253 | |
Frédéric Lécaille | 19cd46e | 2022-01-10 11:40:33 +0100 | [diff] [blame] | 254 | conn->qc->conn = NULL; |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 255 | conn->mux = NULL; |
| 256 | conn->ctx = NULL; |
| 257 | |
| 258 | conn_stop_tracking(conn); |
| 259 | conn_full_close(conn); |
| 260 | if (conn->destroy_cb) |
| 261 | conn->destroy_cb(conn); |
| 262 | conn_free(conn); |
Frédéric Lécaille | 19cd46e | 2022-01-10 11:40:33 +0100 | [diff] [blame] | 263 | fprintf(stderr, "conn@%p released\n", conn); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 267 | static int qcs_push_frame(struct qcs *qcs, struct buffer *payload, int fin, uint64_t offset) |
| 268 | { |
| 269 | struct quic_frame *frm; |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 270 | struct buffer *buf = &qcs->tx.xprt_buf; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 271 | struct quic_enc_level *qel = &qcs->qcc->conn->qc->els[QUIC_TLS_ENC_LEVEL_APP]; |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 272 | int total = 0, to_xfer; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 273 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 274 | fprintf(stderr, "%s\n", __func__); |
| 275 | |
Amaury Denoyelle | 1e308ff | 2021-10-12 18:14:12 +0200 | [diff] [blame] | 276 | qc_get_buf(qcs, buf); |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 277 | to_xfer = QUIC_MIN(b_data(payload), b_room(buf)); |
| 278 | if (!to_xfer) |
| 279 | goto out; |
| 280 | |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 281 | frm = pool_zalloc(pool_head_quic_frame); |
| 282 | if (!frm) |
| 283 | goto err; |
| 284 | |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 285 | total = b_force_xfer(buf, payload, to_xfer); |
Amaury Denoyelle | fecfa0d | 2021-12-07 16:50:14 +0100 | [diff] [blame] | 286 | /* FIN is positioned only when the buffer has been totally emptied. */ |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 287 | fin = fin && !b_data(payload); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 288 | frm->type = QUIC_FT_STREAM_8; |
| 289 | if (fin) |
| 290 | frm->type |= QUIC_STREAM_FRAME_TYPE_FIN_BIT; |
| 291 | if (offset) { |
| 292 | frm->type |= QUIC_STREAM_FRAME_TYPE_OFF_BIT; |
| 293 | frm->stream.offset.key = offset; |
| 294 | } |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 295 | frm->stream.qcs = (struct qcs *)qcs; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 296 | frm->stream.buf = buf; |
| 297 | frm->stream.id = qcs->by_id.key; |
| 298 | if (total) { |
| 299 | frm->type |= QUIC_STREAM_FRAME_TYPE_LEN_BIT; |
| 300 | frm->stream.len = total; |
| 301 | } |
| 302 | |
Frédéric Lécaille | 82468ea | 2022-01-14 20:23:22 +0100 | [diff] [blame] | 303 | LIST_APPEND(&qel->pktns->tx.frms, &frm->list); |
Frédéric Lécaille | d2ba096 | 2021-09-20 17:50:03 +0200 | [diff] [blame] | 304 | out: |
Frédéric Lécaille | 677b99d | 2021-12-21 11:53:33 +0100 | [diff] [blame] | 305 | fprintf(stderr, "%s: total=%d fin=%d id=%llu offset=%lu\n", |
| 306 | __func__, total, fin, (ull)qcs->by_id.key, offset); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 307 | return total; |
| 308 | |
| 309 | err: |
| 310 | return -1; |
| 311 | } |
| 312 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 313 | static int qc_send(struct qcc *qcc) |
| 314 | { |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 315 | struct eb64_node *node; |
Amaury Denoyelle | e257d9e | 2021-12-03 14:39:29 +0100 | [diff] [blame] | 316 | int xprt_wake = 0; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 317 | int ret; |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 318 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 319 | fprintf(stderr, "%s\n", __func__); |
Frédéric Lécaille | 8526f14 | 2021-09-20 17:58:22 +0200 | [diff] [blame] | 320 | |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 321 | /* TODO simple loop through all streams and check if there is frames to |
| 322 | * send |
| 323 | */ |
| 324 | node = eb64_first(&qcc->streams_by_id); |
| 325 | while (node) { |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 326 | struct qcs *qcs = container_of(node, struct qcs, by_id); |
| 327 | struct buffer *buf = &qcs->tx.buf; |
| 328 | if (b_data(buf)) { |
Amaury Denoyelle | fecfa0d | 2021-12-07 16:50:14 +0100 | [diff] [blame] | 329 | char fin = qcs->flags & QC_SF_FIN_STREAM; |
Amaury Denoyelle | c2025c1 | 2021-12-03 15:03:36 +0100 | [diff] [blame] | 330 | ret = qcs_push_frame(qcs, buf, fin, qcs->tx.offset); |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 331 | if (ret < 0) |
| 332 | ABORT_NOW(); |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 333 | |
Amaury Denoyelle | e257d9e | 2021-12-03 14:39:29 +0100 | [diff] [blame] | 334 | if (ret > 0) { |
Amaury Denoyelle | a3f222d | 2021-12-06 11:24:00 +0100 | [diff] [blame] | 335 | qcs_notify_send(qcs); |
Amaury Denoyelle | 84ea8dc | 2021-12-03 14:40:01 +0100 | [diff] [blame] | 336 | if (qcs->flags & QC_SF_BLK_MROOM) |
| 337 | qcs->flags &= ~QC_SF_BLK_MROOM; |
| 338 | |
Amaury Denoyelle | e257d9e | 2021-12-03 14:39:29 +0100 | [diff] [blame] | 339 | xprt_wake = 1; |
| 340 | } |
Amaury Denoyelle | a543eb1 | 2021-10-06 14:53:13 +0200 | [diff] [blame] | 341 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 342 | fprintf(stderr, "%s ret=%d\n", __func__, ret); |
Amaury Denoyelle | d3d97c6 | 2021-10-05 11:45:58 +0200 | [diff] [blame] | 343 | qcs->tx.offset += ret; |
Amaury Denoyelle | a2c58a7 | 2021-12-03 14:38:31 +0100 | [diff] [blame] | 344 | |
| 345 | if (b_data(buf)) { |
| 346 | qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx, |
| 347 | SUB_RETRY_SEND, &qcc->wait_event); |
| 348 | } |
Frédéric Lécaille | 578a789 | 2021-09-13 16:13:00 +0200 | [diff] [blame] | 349 | } |
| 350 | node = eb64_next(node); |
| 351 | } |
Frédéric Lécaille | 8526f14 | 2021-09-20 17:58:22 +0200 | [diff] [blame] | 352 | |
Amaury Denoyelle | e257d9e | 2021-12-03 14:39:29 +0100 | [diff] [blame] | 353 | if (xprt_wake) |
| 354 | tasklet_wakeup(((struct ssl_sock_ctx *)(qcc->conn->xprt_ctx))->wait_event.tasklet); |
| 355 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 356 | return ret; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Amaury Denoyelle | 6a4aebf | 2022-02-01 10:16:05 +0100 | [diff] [blame] | 359 | /* Release all streams that are already marked as detached. This is only done |
| 360 | * if their TX buffers are empty or if a CONNECTION_CLOSE has been received. |
| 361 | * |
| 362 | * Return the number of released stream. |
| 363 | */ |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 364 | static int qc_release_detached_streams(struct qcc *qcc) |
| 365 | { |
| 366 | struct eb64_node *node; |
| 367 | int release = 0; |
| 368 | |
| 369 | node = eb64_first(&qcc->streams_by_id); |
| 370 | while (node) { |
| 371 | struct qcs *qcs = container_of(node, struct qcs, by_id); |
| 372 | node = eb64_next(node); |
| 373 | |
| 374 | if (qcs->flags & QC_SF_DETACH) { |
Amaury Denoyelle | d975148 | 2022-02-01 15:15:11 +0100 | [diff] [blame] | 375 | if ((!b_data(&qcs->tx.buf) && !b_data(&qcs->tx.xprt_buf))) { |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 376 | qcs_destroy(qcs); |
| 377 | release = 1; |
| 378 | } |
| 379 | else { |
| 380 | qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx, |
| 381 | SUB_RETRY_SEND, &qcc->wait_event); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | return release; |
| 387 | } |
| 388 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 389 | static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int status) |
| 390 | { |
Amaury Denoyelle | 769e9ff | 2021-10-05 11:43:50 +0200 | [diff] [blame] | 391 | struct qcc *qcc = ctx; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 392 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 393 | fprintf(stderr, "%s\n", __func__); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 394 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 395 | qc_send(qcc); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 396 | |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 397 | if (qc_release_detached_streams(qcc)) { |
Amaury Denoyelle | 1136e92 | 2022-02-01 10:33:09 +0100 | [diff] [blame] | 398 | /* Schedule the mux timeout if no bidirectional streams left. */ |
| 399 | if (qcc_may_expire(qcc)) { |
| 400 | qcc->task->expire = tick_add(now_ms, qcc->timeout); |
| 401 | task_queue(qcc->task); |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 405 | return NULL; |
| 406 | } |
| 407 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 408 | static struct task *qc_timeout_task(struct task *t, void *ctx, unsigned int state) |
| 409 | { |
| 410 | struct qcc *qcc = ctx; |
| 411 | int expired = tick_is_expired(t->expire, now_ms); |
| 412 | |
| 413 | fprintf(stderr, "%s\n", __func__); |
| 414 | |
| 415 | if (qcc) { |
| 416 | if (!expired) { |
| 417 | fprintf(stderr, "%s: not expired\n", __func__); |
| 418 | return t; |
| 419 | } |
| 420 | |
| 421 | if (!qcc_may_expire(qcc)) { |
| 422 | fprintf(stderr, "%s: cannot expire\n", __func__); |
| 423 | t->expire = TICK_ETERNITY; |
| 424 | return t; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | fprintf(stderr, "%s: timeout\n", __func__); |
| 429 | task_destroy(t); |
| 430 | qcc->task = NULL; |
| 431 | |
| 432 | if (qcc_is_dead(qcc)) |
| 433 | qc_release(qcc); |
| 434 | |
| 435 | return NULL; |
| 436 | } |
| 437 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 438 | static int qc_init(struct connection *conn, struct proxy *prx, |
| 439 | struct session *sess, struct buffer *input) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 440 | { |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 441 | struct qcc *qcc; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 442 | struct quic_transport_params *srv_params; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 443 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 444 | qcc = pool_alloc(pool_head_qcc); |
| 445 | if (!qcc) |
| 446 | goto fail_no_qcc; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 447 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 448 | qcc->conn = conn; |
| 449 | conn->ctx = qcc; |
Amaury Denoyelle | ce1f30d | 2022-02-01 15:14:24 +0100 | [diff] [blame] | 450 | qcc->flags = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 451 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 452 | qcc->app_ops = NULL; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 453 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 454 | qcc->streams_by_id = EB_ROOT_UNIQUE; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 455 | |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 456 | /* Server parameters, params used for RX flow control. */ |
| 457 | srv_params = &conn->qc->rx.params; |
| 458 | |
| 459 | qcc->rx.max_data = srv_params->initial_max_data; |
| 460 | qcc->tx.max_data = 0; |
| 461 | |
| 462 | /* Client initiated streams must respect the server flow control. */ |
| 463 | qcc->strms[QCS_CLT_BIDI].max_streams = srv_params->initial_max_streams_bidi; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 464 | qcc->strms[QCS_CLT_BIDI].nb_streams = 0; |
| 465 | qcc->strms[QCS_CLT_BIDI].largest_id = -1; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 466 | qcc->strms[QCS_CLT_BIDI].rx.max_data = 0; |
| 467 | qcc->strms[QCS_CLT_BIDI].tx.max_data = srv_params->initial_max_stream_data_bidi_remote; |
| 468 | |
| 469 | qcc->strms[QCS_CLT_UNI].max_streams = srv_params->initial_max_streams_uni; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 470 | qcc->strms[QCS_CLT_UNI].nb_streams = 0; |
| 471 | qcc->strms[QCS_CLT_UNI].largest_id = -1; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 472 | qcc->strms[QCS_CLT_UNI].rx.max_data = 0; |
| 473 | qcc->strms[QCS_CLT_UNI].tx.max_data = srv_params->initial_max_stream_data_uni; |
| 474 | |
| 475 | /* Server initiated streams must respect the server flow control. */ |
| 476 | qcc->strms[QCS_SRV_BIDI].max_streams = 0; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 477 | qcc->strms[QCS_SRV_BIDI].nb_streams = 0; |
| 478 | qcc->strms[QCS_SRV_BIDI].largest_id = -1; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 479 | qcc->strms[QCS_SRV_BIDI].rx.max_data = srv_params->initial_max_stream_data_bidi_local; |
| 480 | qcc->strms[QCS_SRV_BIDI].tx.max_data = 0; |
| 481 | |
| 482 | qcc->strms[QCS_SRV_UNI].max_streams = 0; |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 483 | qcc->strms[QCS_SRV_UNI].nb_streams = 0; |
| 484 | qcc->strms[QCS_SRV_UNI].largest_id = -1; |
Amaury Denoyelle | f3b0ba7 | 2021-12-08 15:12:01 +0100 | [diff] [blame] | 485 | qcc->strms[QCS_SRV_UNI].rx.max_data = srv_params->initial_max_stream_data_uni; |
| 486 | qcc->strms[QCS_SRV_UNI].tx.max_data = 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 487 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 488 | qcc->wait_event.tasklet = tasklet_new(); |
| 489 | if (!qcc->wait_event.tasklet) |
| 490 | goto fail_no_tasklet; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 491 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 492 | qcc->subs = NULL; |
| 493 | qcc->wait_event.tasklet->process = qc_io_cb; |
| 494 | qcc->wait_event.tasklet->context = qcc; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 495 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 496 | /* haproxy timeouts */ |
| 497 | qcc->timeout = prx->timeout.client; |
| 498 | qcc->task = task_new_here(); |
| 499 | if (!qcc->task) |
| 500 | goto fail_no_timeout_task; |
| 501 | qcc->task->process = qc_timeout_task; |
| 502 | qcc->task->context = qcc; |
| 503 | qcc->task->expire = tick_add(now_ms, qcc->timeout); |
| 504 | |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 505 | if (!conn_is_back(conn)) { |
| 506 | if (!LIST_INLIST(&conn->stopping_list)) { |
| 507 | LIST_APPEND(&mux_stopping_data[tid].list, |
| 508 | &conn->stopping_list); |
| 509 | } |
| 510 | } |
| 511 | |
Frédéric Lécaille | b80b20c | 2022-01-12 17:46:56 +0100 | [diff] [blame] | 512 | HA_ATOMIC_STORE(&conn->qc->qcc, qcc); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 513 | /* init read cycle */ |
| 514 | tasklet_wakeup(qcc->wait_event.tasklet); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 515 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 516 | return 0; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 517 | |
Amaury Denoyelle | aebe26f | 2022-01-13 16:28:06 +0100 | [diff] [blame] | 518 | fail_no_timeout_task: |
| 519 | tasklet_free(qcc->wait_event.tasklet); |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 520 | fail_no_tasklet: |
| 521 | pool_free(pool_head_qcc, qcc); |
| 522 | fail_no_qcc: |
| 523 | return -1; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 526 | static void qc_detach(struct conn_stream *cs) |
| 527 | { |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 528 | struct qcs *qcs = cs->ctx; |
| 529 | struct qcc *qcc = qcs->qcc; |
| 530 | |
| 531 | fprintf(stderr, "%s: leaving with tx.buf.data=%lu, tx.xprt_buf.data=%lu\n", |
| 532 | __func__, b_data(&qcs->tx.buf), b_data(&qcs->tx.xprt_buf)); |
| 533 | |
Amaury Denoyelle | d975148 | 2022-02-01 15:15:11 +0100 | [diff] [blame] | 534 | /* TODO on CONNECTION_CLOSE reception, it should be possible to free |
| 535 | * qcs instances. This should be done once the buffering and ACK |
| 536 | * managment between xprt and mux is reorganized. |
| 537 | */ |
| 538 | |
| 539 | if ((b_data(&qcs->tx.buf) || b_data(&qcs->tx.xprt_buf))) { |
Amaury Denoyelle | 2873a31 | 2021-12-08 14:42:55 +0100 | [diff] [blame] | 540 | qcs->flags |= QC_SF_DETACH; |
| 541 | return; |
| 542 | } |
| 543 | |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 544 | qcs_destroy(qcs); |
Amaury Denoyelle | 1136e92 | 2022-02-01 10:33:09 +0100 | [diff] [blame] | 545 | |
| 546 | /* Schedule the mux timeout if no bidirectional streams left. */ |
| 547 | if (qcc_may_expire(qcc)) { |
| 548 | qcc->task->expire = tick_add(now_ms, qcc->timeout); |
| 549 | task_queue(qcc->task); |
Amaury Denoyelle | 916f0ac | 2021-12-06 16:03:47 +0100 | [diff] [blame] | 550 | } |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 551 | } |
| 552 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 553 | /* Called from the upper layer, to receive data */ |
| 554 | static size_t qc_rcv_buf(struct conn_stream *cs, struct buffer *buf, |
| 555 | size_t count, int flags) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 556 | { |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame^] | 557 | struct qcs *qcs = cs->ctx; |
| 558 | struct htx *qcs_htx = NULL; |
| 559 | struct htx *cs_htx = NULL; |
| 560 | size_t ret = 0; |
| 561 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 562 | fprintf(stderr, "%s\n", __func__); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 563 | |
Amaury Denoyelle | 9a327a7 | 2022-02-14 17:11:09 +0100 | [diff] [blame^] | 564 | qcs_htx = htx_from_buf(&qcs->rx.app_buf); |
| 565 | if (htx_is_empty(qcs_htx)) { |
| 566 | /* Set buffer data to 0 as HTX is empty. */ |
| 567 | htx_to_buf(qcs_htx, &qcs->rx.app_buf); |
| 568 | goto end; |
| 569 | } |
| 570 | |
| 571 | ret = qcs_htx->data; |
| 572 | |
| 573 | cs_htx = htx_from_buf(buf); |
| 574 | if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) { |
| 575 | htx_to_buf(cs_htx, buf); |
| 576 | htx_to_buf(qcs_htx, &qcs->rx.app_buf); |
| 577 | b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf)); |
| 578 | goto end; |
| 579 | } |
| 580 | |
| 581 | htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED); |
| 582 | BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR); |
| 583 | |
| 584 | /* Copy EOM from src to dst buffer if all data copied. */ |
| 585 | if (htx_is_empty(qcs_htx)) |
| 586 | cs_htx->flags |= (qcs_htx->flags & HTX_FL_EOM); |
| 587 | |
| 588 | cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0; |
| 589 | htx_to_buf(cs_htx, buf); |
| 590 | htx_to_buf(qcs_htx, &qcs->rx.app_buf); |
| 591 | ret -= qcs_htx->data; |
| 592 | |
| 593 | end: |
| 594 | if (b_data(&qcs->rx.app_buf)) { |
| 595 | cs->flags |= (CS_FL_RCV_MORE | CS_FL_WANT_ROOM); |
| 596 | } |
| 597 | else { |
| 598 | cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM); |
| 599 | if (cs->flags & CS_FL_ERR_PENDING) |
| 600 | cs->flags |= CS_FL_ERROR; |
| 601 | |
| 602 | /* TODO put CS_FL_EOI/EOS on fin */ |
| 603 | |
| 604 | if (b_size(&qcs->rx.app_buf)) { |
| 605 | b_free(&qcs->rx.app_buf); |
| 606 | offer_buffers(NULL, 1); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (ret) |
| 611 | tasklet_wakeup(qcs->qcc->wait_event.tasklet); |
| 612 | |
| 613 | return ret; |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 616 | static size_t qc_snd_buf(struct conn_stream *cs, struct buffer *buf, |
| 617 | size_t count, int flags) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 618 | { |
| 619 | struct qcs *qcs = cs->ctx; |
| 620 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 621 | fprintf(stderr, "%s\n", __func__); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 622 | |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 623 | return qcs->qcc->app_ops->snd_buf(cs, buf, count, flags); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* Called from the upper layer, to subscribe <es> to events <event_type>. The |
| 627 | * event subscriber <es> is not allowed to change from a previous call as long |
| 628 | * as at least one event is still subscribed. The <event_type> must only be a |
| 629 | * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0. |
| 630 | */ |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 631 | static int qc_subscribe(struct conn_stream *cs, int event_type, |
| 632 | struct wait_event *es) |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 633 | { |
Amaury Denoyelle | a3f222d | 2021-12-06 11:24:00 +0100 | [diff] [blame] | 634 | return qcs_subscribe(cs->ctx, event_type, es); |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /* Called from the upper layer, to unsubscribe <es> from events <event_type>. |
| 638 | * The <es> pointer is not allowed to differ from the one passed to the |
| 639 | * subscribe() call. It always returns zero. |
| 640 | */ |
| 641 | static int qc_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es) |
| 642 | { |
| 643 | struct qcs *qcs = cs->ctx; |
| 644 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 645 | BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV)); |
| 646 | BUG_ON(qcs->subs && qcs->subs != es); |
| 647 | |
| 648 | es->events &= ~event_type; |
| 649 | if (!es->events) |
| 650 | qcs->subs = NULL; |
| 651 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 655 | static int qc_wake(struct connection *conn) |
| 656 | { |
| 657 | struct qcc *qcc = conn->ctx; |
| 658 | |
| 659 | /* Check if a soft-stop is in progress. |
| 660 | * Release idling front connection if this is the case. |
| 661 | */ |
| 662 | if (unlikely(conn->qc->li->bind_conf->frontend->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { |
| 663 | qc_release(qcc); |
| 664 | } |
| 665 | |
| 666 | return 1; |
| 667 | } |
| 668 | |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 669 | static const struct mux_ops qc_ops = { |
| 670 | .init = qc_init, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 671 | .detach = qc_detach, |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 672 | .rcv_buf = qc_rcv_buf, |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 673 | .snd_buf = qc_snd_buf, |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 674 | .subscribe = qc_subscribe, |
| 675 | .unsubscribe = qc_unsubscribe, |
Amaury Denoyelle | 0e0969d | 2022-01-31 15:41:14 +0100 | [diff] [blame] | 676 | .wake = qc_wake, |
Frédéric Lécaille | dfbae76 | 2021-02-18 09:59:01 +0100 | [diff] [blame] | 677 | }; |
| 678 | |
| 679 | static struct mux_proto_list mux_proto_quic = |
Amaury Denoyelle | deed777 | 2021-12-03 11:36:46 +0100 | [diff] [blame] | 680 | { .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] | 681 | |
| 682 | INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_quic); |