Lines Matching refs:ch

52 DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
54 static void ch_save_err_state(QUIC_CHANNEL *ch);
55 static int ch_rx(QUIC_CHANNEL *ch, int channel_only);
56 static int ch_tx(QUIC_CHANNEL *ch);
57 static int ch_tick_tls(QUIC_CHANNEL *ch, int channel_only);
58 static void ch_rx_handle_packet(QUIC_CHANNEL *ch, int channel_only);
59 static OSSL_TIME ch_determine_next_tick_deadline(QUIC_CHANNEL *ch);
60 static int ch_retry(QUIC_CHANNEL *ch,
64 static void ch_cleanup(QUIC_CHANNEL *ch);
65 static int ch_generate_transport_params(QUIC_CHANNEL *ch);
86 static int ch_retry(QUIC_CHANNEL *ch,
90 static void ch_update_idle(QUIC_CHANNEL *ch);
91 static int ch_discard_el(QUIC_CHANNEL *ch,
93 static void ch_on_idle_timeout(QUIC_CHANNEL *ch);
94 static void ch_update_idle(QUIC_CHANNEL *ch);
95 static void ch_update_ping_deadline(QUIC_CHANNEL *ch);
96 static void ch_on_terminating_timeout(QUIC_CHANNEL *ch);
97 static void ch_start_terminating(QUIC_CHANNEL *ch,
102 static void ch_rx_handle_version_neg(QUIC_CHANNEL *ch, OSSL_QRX_PKT *pkt);
103 static void ch_raise_version_neg_failure(QUIC_CHANNEL *ch);
104 static void ch_record_state_transition(QUIC_CHANNEL *ch, uint32_t new_state);
109 static QLOG *ch_get_qlog(QUIC_CHANNEL *ch) in ch_get_qlog() argument
114 if (ch->qlog != NULL) in ch_get_qlog()
115 return ch->qlog; in ch_get_qlog()
117 if (!ch->use_qlog) in ch_get_qlog()
120 if (ch->is_server && ch->init_dcid.id_len == 0) in ch_get_qlog()
123 qti.odcid = ch->init_dcid; in ch_get_qlog()
124 qti.title = ch->qlog_title; in ch_get_qlog()
127 qti.is_server = ch->is_server; in ch_get_qlog()
129 qti.now_cb_arg = ch; in ch_get_qlog()
130 if ((ch->qlog = ossl_qlog_new_from_env(&qti)) == NULL) { in ch_get_qlog()
131 ch->use_qlog = 0; /* don't try again */ in ch_get_qlog()
135 return ch->qlog; in ch_get_qlog()
144 QUIC_CHANNEL *ch = arg; in ch_get_qlog_cb() local
146 return ch_get_qlog(ch); in ch_get_qlog_cb()
161 static int ch_init(QUIC_CHANNEL *ch) in ch_init() argument
171 if (ch->port == NULL || ch->lcidm == NULL || ch->srtm == NULL) in ch_init()
174 rx_short_dcid_len = ossl_quic_port_get_rx_short_dcid_len(ch->port); in ch_init()
175 tx_init_dcid_len = ossl_quic_port_get_tx_init_dcid_len(ch->port); in ch_init()
178 if (!ch->is_server in ch_init()
179 && !ossl_quic_gen_rand_conn_id(ch->port->engine->libctx, tx_init_dcid_len, in ch_init()
180 &ch->init_dcid)) in ch_init()
184 qtx_args.libctx = ch->port->engine->libctx; in ch_init()
186 qtx_args.get_qlog_cb_arg = ch; in ch_init()
188 ch->rx_max_udp_payload_size = qtx_args.mdpl; in ch_init()
190 ch->ping_deadline = ossl_time_infinite(); in ch_init()
192 ch->qtx = ossl_qtx_new(&qtx_args); in ch_init()
193 if (ch->qtx == NULL) in ch_init()
196 ch->txpim = ossl_quic_txpim_new(); in ch_init()
197 if (ch->txpim == NULL) in ch_init()
200 ch->cfq = ossl_quic_cfq_new(); in ch_init()
201 if (ch->cfq == NULL) in ch_init()
204 if (!ossl_quic_txfc_init(&ch->conn_txfc, NULL)) in ch_init()
211 ch->tx_init_max_stream_data_bidi_local = DEFAULT_INIT_STREAM_RXFC_WND; in ch_init()
212 ch->tx_init_max_stream_data_bidi_remote = DEFAULT_INIT_STREAM_RXFC_WND; in ch_init()
213 ch->tx_init_max_stream_data_uni = DEFAULT_INIT_STREAM_RXFC_WND; in ch_init()
215 if (!ossl_quic_rxfc_init(&ch->conn_rxfc, NULL, in ch_init()
219 get_time, ch)) in ch_init()
223 if (!ossl_quic_rxfc_init_standalone(&ch->crypto_rxfc[pn_space], in ch_init()
225 get_time, ch)) in ch_init()
228 if (!ossl_quic_rxfc_init_standalone(&ch->max_streams_bidi_rxfc, in ch_init()
230 get_time, ch)) in ch_init()
233 if (!ossl_quic_rxfc_init_standalone(&ch->max_streams_uni_rxfc, in ch_init()
235 get_time, ch)) in ch_init()
238 if (!ossl_statm_init(&ch->statm)) in ch_init()
241 ch->have_statm = 1; in ch_init()
242 ch->cc_method = &ossl_cc_newreno_method; in ch_init()
243 if ((ch->cc_data = ch->cc_method->new(get_time, ch)) == NULL) in ch_init()
246 if ((ch->ackm = ossl_ackm_new(get_time, ch, &ch->statm, in ch_init()
247 ch->cc_method, ch->cc_data)) == NULL) in ch_init()
250 if (!ossl_quic_stream_map_init(&ch->qsm, get_stream_limit, ch, in ch_init()
251 &ch->max_streams_bidi_rxfc, in ch_init()
252 &ch->max_streams_uni_rxfc, in ch_init()
253 ch->is_server)) in ch_init()
256 ch->have_qsm = 1; in ch_init()
258 if (!ch->is_server in ch_init()
259 && !ossl_quic_lcidm_generate_initial(ch->lcidm, ch, &txp_args.cur_scid)) in ch_init()
263 txp_args.cur_dcid = ch->init_dcid; in ch_init()
265 txp_args.qtx = ch->qtx; in ch_init()
266 txp_args.txpim = ch->txpim; in ch_init()
267 txp_args.cfq = ch->cfq; in ch_init()
268 txp_args.ackm = ch->ackm; in ch_init()
269 txp_args.qsm = &ch->qsm; in ch_init()
270 txp_args.conn_txfc = &ch->conn_txfc; in ch_init()
271 txp_args.conn_rxfc = &ch->conn_rxfc; in ch_init()
272 txp_args.max_streams_bidi_rxfc = &ch->max_streams_bidi_rxfc; in ch_init()
273 txp_args.max_streams_uni_rxfc = &ch->max_streams_uni_rxfc; in ch_init()
274 txp_args.cc_method = ch->cc_method; in ch_init()
275 txp_args.cc_data = ch->cc_data; in ch_init()
277 txp_args.now_arg = ch; in ch_init()
279 txp_args.get_qlog_cb_arg = ch; in ch_init()
282 ch->crypto_send[pn_space] = ossl_quic_sstream_new(INIT_CRYPTO_SEND_BUF_LEN); in ch_init()
283 if (ch->crypto_send[pn_space] == NULL) in ch_init()
286 txp_args.crypto[pn_space] = ch->crypto_send[pn_space]; in ch_init()
289 ch->txp = ossl_quic_tx_packetiser_new(&txp_args); in ch_init()
290 if (ch->txp == NULL) in ch_init()
293 ossl_quic_tx_packetiser_set_ack_tx_cb(ch->txp, ch_on_txp_ack_tx, ch); in ch_init()
295 qrx_args.libctx = ch->port->engine->libctx; in ch_init()
296 qrx_args.demux = ch->port->demux; in ch_init()
300 if ((ch->qrx = ossl_qrx_new(&qrx_args)) == NULL) in ch_init()
303 if (!ossl_qrx_set_late_validation_cb(ch->qrx, in ch_init()
305 ch)) in ch_init()
308 if (!ossl_qrx_set_key_update_cb(ch->qrx, in ch_init()
310 ch)) in ch_init()
314 ch->crypto_recv[pn_space] = ossl_quic_rstream_new(NULL, NULL, 0); in ch_init()
315 if (ch->crypto_recv[pn_space] == NULL) in ch_init()
320 tls_args.s = ch->tls; in ch_init()
322 tls_args.crypto_send_cb_arg = ch; in ch_init()
324 tls_args.crypto_recv_rcd_cb_arg = ch; in ch_init()
326 tls_args.crypto_release_rcd_cb_arg = ch; in ch_init()
328 tls_args.yield_secret_cb_arg = ch; in ch_init()
330 tls_args.got_transport_params_cb_arg= ch; in ch_init()
332 tls_args.handshake_complete_cb_arg = ch; in ch_init()
334 tls_args.alert_cb_arg = ch; in ch_init()
335 tls_args.is_server = ch->is_server; in ch_init()
337 if ((ch->qtls = ossl_quic_tls_new(&tls_args)) == NULL) in ch_init()
340 ch->tx_max_ack_delay = DEFAULT_MAX_ACK_DELAY; in ch_init()
341 ch->rx_max_ack_delay = QUIC_DEFAULT_MAX_ACK_DELAY; in ch_init()
342 ch->rx_ack_delay_exp = QUIC_DEFAULT_ACK_DELAY_EXP; in ch_init()
343 ch->rx_active_conn_id_limit = QUIC_MIN_ACTIVE_CONN_ID_LIMIT; in ch_init()
344 ch->tx_enc_level = QUIC_ENC_LEVEL_INITIAL; in ch_init()
345 ch->rx_enc_level = QUIC_ENC_LEVEL_INITIAL; in ch_init()
346 ch->txku_threshold_override = UINT64_MAX; in ch_init()
348 ch->max_idle_timeout_local_req = QUIC_DEFAULT_IDLE_TIMEOUT; in ch_init()
349 ch->max_idle_timeout_remote_req = 0; in ch_init()
350 ch->max_idle_timeout = ch->max_idle_timeout_local_req; in ch_init()
352 ossl_ackm_set_tx_max_ack_delay(ch->ackm, ossl_ms2time(ch->tx_max_ack_delay)); in ch_init()
353 ossl_ackm_set_rx_max_ack_delay(ch->ackm, ossl_ms2time(ch->rx_max_ack_delay)); in ch_init()
355 ch_update_idle(ch); in ch_init()
356 ossl_list_ch_insert_tail(&ch->port->channel_list, ch); in ch_init()
357 ch->on_port_list = 1; in ch_init()
361 ch_cleanup(ch); in ch_init()
365 static void ch_cleanup(QUIC_CHANNEL *ch) in ch_cleanup() argument
369 if (ch->ackm != NULL) in ch_cleanup()
373 ossl_ackm_on_pkt_space_discarded(ch->ackm, pn_space); in ch_cleanup()
375 ossl_quic_lcidm_cull(ch->lcidm, ch); in ch_cleanup()
376 ossl_quic_srtm_cull(ch->srtm, ch); in ch_cleanup()
377 ossl_quic_tx_packetiser_free(ch->txp); in ch_cleanup()
378 ossl_quic_txpim_free(ch->txpim); in ch_cleanup()
379 ossl_quic_cfq_free(ch->cfq); in ch_cleanup()
380 ossl_qtx_free(ch->qtx); in ch_cleanup()
381 if (ch->cc_data != NULL) in ch_cleanup()
382 ch->cc_method->free(ch->cc_data); in ch_cleanup()
383 if (ch->have_statm) in ch_cleanup()
384 ossl_statm_destroy(&ch->statm); in ch_cleanup()
385 ossl_ackm_free(ch->ackm); in ch_cleanup()
387 if (ch->have_qsm) in ch_cleanup()
388 ossl_quic_stream_map_cleanup(&ch->qsm); in ch_cleanup()
391 ossl_quic_sstream_free(ch->crypto_send[pn_space]); in ch_cleanup()
392 ossl_quic_rstream_free(ch->crypto_recv[pn_space]); in ch_cleanup()
395 ossl_qrx_pkt_release(ch->qrx_pkt); in ch_cleanup()
396 ch->qrx_pkt = NULL; in ch_cleanup()
398 ossl_quic_tls_free(ch->qtls); in ch_cleanup()
399 ossl_qrx_free(ch->qrx); in ch_cleanup()
400 OPENSSL_free(ch->local_transport_params); in ch_cleanup()
401 OPENSSL_free((char *)ch->terminate_cause.reason); in ch_cleanup()
402 OSSL_ERR_STATE_free(ch->err_state); in ch_cleanup()
403 OPENSSL_free(ch->ack_range_scratch); in ch_cleanup()
405 if (ch->on_port_list) { in ch_cleanup()
406 ossl_list_ch_remove(&ch->port->channel_list, ch); in ch_cleanup()
407 ch->on_port_list = 0; in ch_cleanup()
411 if (ch->qlog != NULL) in ch_cleanup()
412 ossl_qlog_flush(ch->qlog); /* best effort */ in ch_cleanup()
414 OPENSSL_free(ch->qlog_title); in ch_cleanup()
415 ossl_qlog_free(ch->qlog); in ch_cleanup()
421 QUIC_CHANNEL *ch = NULL; in ossl_quic_channel_new() local
423 if ((ch = OPENSSL_zalloc(sizeof(*ch))) == NULL) in ossl_quic_channel_new()
426 ch->port = args->port; in ossl_quic_channel_new()
427 ch->is_server = args->is_server; in ossl_quic_channel_new()
428 ch->tls = args->tls; in ossl_quic_channel_new()
429 ch->lcidm = args->lcidm; in ossl_quic_channel_new()
430 ch->srtm = args->srtm; in ossl_quic_channel_new()
432 ch->use_qlog = args->use_qlog; in ossl_quic_channel_new()
434 if (ch->use_qlog && args->qlog_title != NULL) { in ossl_quic_channel_new()
435 if ((ch->qlog_title = OPENSSL_strdup(args->qlog_title)) == NULL) { in ossl_quic_channel_new()
436 OPENSSL_free(ch); in ossl_quic_channel_new()
442 if (!ch_init(ch)) { in ossl_quic_channel_new()
443 OPENSSL_free(ch); in ossl_quic_channel_new()
447 return ch; in ossl_quic_channel_new()
450 void ossl_quic_channel_free(QUIC_CHANNEL *ch) in ossl_quic_channel_free() argument
452 if (ch == NULL) in ossl_quic_channel_free()
455 ch_cleanup(ch); in ossl_quic_channel_free()
456 OPENSSL_free(ch); in ossl_quic_channel_free()
460 int ossl_quic_channel_set_mutator(QUIC_CHANNEL *ch, in ossl_quic_channel_set_mutator() argument
465 if (ch->qtx == NULL) in ossl_quic_channel_set_mutator()
468 ossl_qtx_set_mutator(ch->qtx, mutatecb, finishmutatecb, mutatearg); in ossl_quic_channel_set_mutator()
472 int ossl_quic_channel_get_peer_addr(QUIC_CHANNEL *ch, BIO_ADDR *peer_addr) in ossl_quic_channel_get_peer_addr() argument
474 if (!ch->addressed_mode) in ossl_quic_channel_get_peer_addr()
477 *peer_addr = ch->cur_peer_addr; in ossl_quic_channel_get_peer_addr()
481 int ossl_quic_channel_set_peer_addr(QUIC_CHANNEL *ch, const BIO_ADDR *peer_addr) in ossl_quic_channel_set_peer_addr() argument
483 if (ch->state != QUIC_CHANNEL_STATE_IDLE) in ossl_quic_channel_set_peer_addr()
487 BIO_ADDR_clear(&ch->cur_peer_addr); in ossl_quic_channel_set_peer_addr()
488 ch->addressed_mode = 0; in ossl_quic_channel_set_peer_addr()
492 ch->cur_peer_addr = *peer_addr; in ossl_quic_channel_set_peer_addr()
493 ch->addressed_mode = 1; in ossl_quic_channel_set_peer_addr()
497 QUIC_REACTOR *ossl_quic_channel_get_reactor(QUIC_CHANNEL *ch) in ossl_quic_channel_get_reactor() argument
499 return ossl_quic_port_get0_reactor(ch->port); in ossl_quic_channel_get_reactor()
502 QUIC_STREAM_MAP *ossl_quic_channel_get_qsm(QUIC_CHANNEL *ch) in ossl_quic_channel_get_qsm() argument
504 return &ch->qsm; in ossl_quic_channel_get_qsm()
507 OSSL_STATM *ossl_quic_channel_get_statm(QUIC_CHANNEL *ch) in ossl_quic_channel_get_statm() argument
509 return &ch->statm; in ossl_quic_channel_get_statm()
512 QUIC_STREAM *ossl_quic_channel_get_stream_by_id(QUIC_CHANNEL *ch, in ossl_quic_channel_get_stream_by_id() argument
515 return ossl_quic_stream_map_get_by_id(&ch->qsm, stream_id); in ossl_quic_channel_get_stream_by_id()
518 int ossl_quic_channel_is_active(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_active() argument
520 return ch != NULL && ch->state == QUIC_CHANNEL_STATE_ACTIVE; in ossl_quic_channel_is_active()
523 int ossl_quic_channel_is_closing(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_closing() argument
525 return ch->state == QUIC_CHANNEL_STATE_TERMINATING_CLOSING; in ossl_quic_channel_is_closing()
528 static int ossl_quic_channel_is_draining(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_draining() argument
530 return ch->state == QUIC_CHANNEL_STATE_TERMINATING_DRAINING; in ossl_quic_channel_is_draining()
533 static int ossl_quic_channel_is_terminating(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_terminating() argument
535 return ossl_quic_channel_is_closing(ch) in ossl_quic_channel_is_terminating()
536 || ossl_quic_channel_is_draining(ch); in ossl_quic_channel_is_terminating()
539 int ossl_quic_channel_is_terminated(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_terminated() argument
541 return ch->state == QUIC_CHANNEL_STATE_TERMINATED; in ossl_quic_channel_is_terminated()
544 int ossl_quic_channel_is_term_any(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_term_any() argument
546 return ossl_quic_channel_is_terminating(ch) in ossl_quic_channel_is_term_any()
547 || ossl_quic_channel_is_terminated(ch); in ossl_quic_channel_is_term_any()
551 ossl_quic_channel_get_terminate_cause(const QUIC_CHANNEL *ch) in ossl_quic_channel_get_terminate_cause() argument
553 return ossl_quic_channel_is_term_any(ch) ? &ch->terminate_cause : NULL; in ossl_quic_channel_get_terminate_cause()
556 int ossl_quic_channel_is_handshake_complete(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_handshake_complete() argument
558 return ch->handshake_complete; in ossl_quic_channel_is_handshake_complete()
561 int ossl_quic_channel_is_handshake_confirmed(const QUIC_CHANNEL *ch) in ossl_quic_channel_is_handshake_confirmed() argument
563 return ch->handshake_confirmed; in ossl_quic_channel_is_handshake_confirmed()
566 QUIC_DEMUX *ossl_quic_channel_get0_demux(QUIC_CHANNEL *ch) in ossl_quic_channel_get0_demux() argument
568 return ch->port->demux; in ossl_quic_channel_get0_demux()
571 QUIC_PORT *ossl_quic_channel_get0_port(QUIC_CHANNEL *ch) in ossl_quic_channel_get0_port() argument
573 return ch->port; in ossl_quic_channel_get0_port()
576 QUIC_ENGINE *ossl_quic_channel_get0_engine(QUIC_CHANNEL *ch) in ossl_quic_channel_get0_engine() argument
578 return ossl_quic_port_get0_engine(ch->port); in ossl_quic_channel_get0_engine()
581 CRYPTO_MUTEX *ossl_quic_channel_get_mutex(QUIC_CHANNEL *ch) in ossl_quic_channel_get_mutex() argument
583 return ossl_quic_port_get0_mutex(ch->port); in ossl_quic_channel_get_mutex()
586 int ossl_quic_channel_has_pending(const QUIC_CHANNEL *ch) in ossl_quic_channel_has_pending() argument
588 return ossl_quic_demux_has_pending(ch->port->demux) in ossl_quic_channel_has_pending()
589 || ossl_qrx_processed_read_pending(ch->qrx); in ossl_quic_channel_has_pending()
600 QUIC_CHANNEL *ch = arg; in get_time() local
602 return ossl_quic_port_get_time(ch->port); in get_time()
608 QUIC_CHANNEL *ch = arg; in get_stream_limit() local
610 return uni ? ch->max_local_streams_uni : ch->max_local_streams_bidi; in get_stream_limit()
619 QUIC_CHANNEL *ch = arg; in rx_late_validate() local
622 if (!ossl_ackm_is_rx_pn_processable(ch->ackm, pn, pn_space)) in rx_late_validate()
633 static void ch_trigger_txku(QUIC_CHANNEL *ch) in ch_trigger_txku() argument
636 = ossl_quic_tx_packetiser_get_next_pn(ch->txp, QUIC_PN_SPACE_APP); in ch_trigger_txku()
639 || !ossl_qtx_trigger_key_update(ch->qtx)) { in ch_trigger_txku()
640 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INTERNAL_ERROR, 0, in ch_trigger_txku()
645 ch->txku_in_progress = 1; in ch_trigger_txku()
646 ch->txku_pn = next_pn; in ch_trigger_txku()
647 ch->rxku_expected = ch->ku_locally_initiated; in ch_trigger_txku()
651 static int txku_in_progress(QUIC_CHANNEL *ch) in txku_in_progress() argument
653 if (ch->txku_in_progress in txku_in_progress()
654 && ossl_ackm_get_largest_acked(ch->ackm, QUIC_PN_SPACE_APP) >= ch->txku_pn) { in txku_in_progress()
655 OSSL_TIME pto = ossl_ackm_get_pto_duration(ch->ackm); in txku_in_progress()
666 ch->txku_in_progress = 0; in txku_in_progress()
667 ch->txku_cooldown_deadline = ossl_time_add(get_time(ch), in txku_in_progress()
671 return ch->txku_in_progress; in txku_in_progress()
675 static int txku_allowed(QUIC_CHANNEL *ch) in txku_allowed() argument
677 return ch->tx_enc_level == QUIC_ENC_LEVEL_1RTT /* Sanity check. */ in txku_allowed()
679 && ch->handshake_confirmed in txku_allowed()
680 && !txku_in_progress(ch); in txku_allowed()
684 static int txku_recommendable(QUIC_CHANNEL *ch) in txku_recommendable() argument
686 if (!txku_allowed(ch)) in txku_recommendable()
691 ossl_time_compare(get_time(ch), ch->txku_cooldown_deadline) >= 0 in txku_recommendable()
693 && !ch->rxku_in_progress in txku_recommendable()
694 && !ch->rxku_pending_confirm; in txku_recommendable()
698 static int txku_desirable(QUIC_CHANNEL *ch) in txku_desirable() argument
704 cur_pkt_count = ossl_qtx_get_cur_epoch_pkt_count(ch->qtx, enc_level); in txku_desirable()
705 max_pkt_count = ossl_qtx_get_max_epoch_pkt_count(ch->qtx, enc_level); in txku_desirable()
708 if (ch->txku_threshold_override != UINT64_MAX) in txku_desirable()
709 thresh_pkt_count = ch->txku_threshold_override; in txku_desirable()
715 static void ch_maybe_trigger_spontaneous_txku(QUIC_CHANNEL *ch) in ch_maybe_trigger_spontaneous_txku() argument
717 if (!txku_recommendable(ch) || !txku_desirable(ch)) in ch_maybe_trigger_spontaneous_txku()
720 ch->ku_locally_initiated = 1; in ch_maybe_trigger_spontaneous_txku()
721 ch_trigger_txku(ch); in ch_maybe_trigger_spontaneous_txku()
725 static int rxku_allowed(QUIC_CHANNEL *ch) in rxku_allowed() argument
742 return ch->handshake_confirmed && !ch->rxku_pending_confirm; in rxku_allowed()
758 QUIC_CHANNEL *ch = arg; in rxku_detected() local
766 assert(!ch->rxku_in_progress); in rxku_detected()
768 if (!rxku_allowed(ch)) in rxku_detected()
772 else if (ch->ku_locally_initiated) in rxku_detected()
788 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_KEY_UPDATE_ERROR, in rxku_detected()
793 pto = ossl_ackm_get_pto_duration(ch->ackm); in rxku_detected()
795 ch->ku_locally_initiated = 0; in rxku_detected()
796 ch->rxku_in_progress = 1; in rxku_detected()
797 ch->rxku_pending_confirm = 1; in rxku_detected()
798 ch->rxku_trigger_pn = pn; in rxku_detected()
799 ch->rxku_update_end_deadline = ossl_time_add(get_time(ch), pto); in rxku_detected()
800 ch->rxku_expected = 0; in rxku_detected()
804 ch_trigger_txku(ch); in rxku_detected()
821 ossl_quic_tx_packetiser_schedule_ack(ch->txp, QUIC_PN_SPACE_APP); in rxku_detected()
826 static void ch_rxku_tick(QUIC_CHANNEL *ch) in ch_rxku_tick() argument
828 if (!ch->rxku_in_progress in ch_rxku_tick()
829 || ossl_time_compare(get_time(ch), ch->rxku_update_end_deadline) < 0) in ch_rxku_tick()
832 ch->rxku_update_end_deadline = ossl_time_infinite(); in ch_rxku_tick()
833 ch->rxku_in_progress = 0; in ch_rxku_tick()
835 if (!ossl_qrx_key_update_timeout(ch->qrx, /*normal=*/1)) in ch_rxku_tick()
836 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INTERNAL_ERROR, 0, in ch_rxku_tick()
844 QUIC_CHANNEL *ch = arg; in ch_on_txp_ack_tx() local
846 if (pn_space != QUIC_PN_SPACE_APP || !ch->rxku_pending_confirm in ch_on_txp_ack_tx()
847 || !ossl_quic_frame_ack_contains_pn(ack, ch->rxku_trigger_pn)) in ch_on_txp_ack_tx()
854 ch->rxku_pending_confirm_done = 1; in ch_on_txp_ack_tx()
865 QUIC_CHANNEL *ch = arg; in ch_on_crypto_send() local
866 uint32_t enc_level = ch->tx_enc_level; in ch_on_crypto_send()
868 QUIC_SSTREAM *sstream = ch->crypto_send[pn_space]; in ch_on_crypto_send()
894 QUIC_CHANNEL *ch = arg; in ch_on_crypto_recv_record() local
912 for (i = QUIC_ENC_LEVEL_INITIAL; i < ch->rx_enc_level; ++i) in ch_on_crypto_recv_record()
914 !crypto_ensure_empty(ch->crypto_recv[ossl_quic_enc_level_to_pn_space(i)])) { in ch_on_crypto_recv_record()
916 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_PROTOCOL_VIOLATION, in ch_on_crypto_recv_record()
922 rstream = ch->crypto_recv[ossl_quic_enc_level_to_pn_space(ch->rx_enc_level)]; in ch_on_crypto_recv_record()
932 QUIC_CHANNEL *ch = arg; in ch_on_crypto_release_record() local
935 uint32_t rx_pn_space = ossl_quic_enc_level_to_pn_space(ch->rx_enc_level); in ch_on_crypto_release_record()
937 rstream = ch->crypto_recv[rx_pn_space]; in ch_on_crypto_release_record()
941 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(ch), &rtt_info); in ch_on_crypto_release_record()
942 if (!ossl_quic_rxfc_on_retire(&ch->crypto_rxfc[rx_pn_space], bytes_read, in ch_on_crypto_release_record()
955 QUIC_CHANNEL *ch = arg; in ch_on_handshake_yield_secret() local
965 if (enc_level <= ch->tx_enc_level) in ch_on_handshake_yield_secret()
972 if (!ossl_qtx_provide_secret(ch->qtx, enc_level, in ch_on_handshake_yield_secret()
977 ch->tx_enc_level = enc_level; in ch_on_handshake_yield_secret()
980 if (enc_level <= ch->rx_enc_level) in ch_on_handshake_yield_secret()
992 if (!crypto_ensure_empty(ch->crypto_recv[ossl_quic_enc_level_to_pn_space(i)])) { in ch_on_handshake_yield_secret()
994 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_PROTOCOL_VIOLATION, in ch_on_handshake_yield_secret()
1000 if (!ossl_qrx_provide_secret(ch->qrx, enc_level, in ch_on_handshake_yield_secret()
1005 ch->have_new_rx_secret = 1; in ch_on_handshake_yield_secret()
1006 ch->rx_enc_level = enc_level; in ch_on_handshake_yield_secret()
1014 QUIC_CHANNEL *ch = arg; in ch_on_handshake_complete() local
1016 if (!ossl_assert(!ch->handshake_complete)) in ch_on_handshake_complete()
1019 if (!ossl_assert(ch->tx_enc_level == QUIC_ENC_LEVEL_1RTT)) in ch_on_handshake_complete()
1022 if (!ch->got_remote_transport_params) { in ch_on_handshake_complete()
1027 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_CRYPTO_MISSING_EXT, in ch_on_handshake_complete()
1034 OPENSSL_free(ch->local_transport_params); in ch_on_handshake_complete()
1035 ch->local_transport_params = NULL; in ch_on_handshake_complete()
1038 ossl_qrx_allow_1rtt_processing(ch->qrx); in ch_on_handshake_complete()
1041 ossl_quic_tx_packetiser_notify_handshake_complete(ch->txp); in ch_on_handshake_complete()
1043 ch->handshake_complete = 1; in ch_on_handshake_complete()
1045 if (ch->is_server) { in ch_on_handshake_complete()
1049 ossl_quic_channel_on_handshake_confirmed(ch); in ch_on_handshake_complete()
1051 ossl_quic_tx_packetiser_schedule_handshake_done(ch->txp); in ch_on_handshake_complete()
1054 ch_record_state_transition(ch, ch->state); in ch_on_handshake_complete()
1060 QUIC_CHANNEL *ch = arg; in ch_on_handshake_alert() local
1068 && ch->handshake_complete in ch_on_handshake_alert()
1069 && ossl_quic_tls_is_cert_request(ch->qtls)) in ch_on_handshake_alert()
1070 ossl_quic_channel_raise_protocol_error(ch, in ch_on_handshake_alert()
1083 && ch->handshake_complete in ch_on_handshake_alert()
1084 && ossl_quic_tls_has_bad_max_early_data(ch->qtls)) in ch_on_handshake_alert()
1085 ossl_quic_channel_raise_protocol_error(ch, in ch_on_handshake_alert()
1090 ossl_quic_channel_raise_protocol_error(ch, in ch_on_handshake_alert()
1143 QUIC_CHANNEL *ch = arg; in do_update() local
1145 ossl_quic_stream_map_update_state(&ch->qsm, s); in do_update()
1162 QUIC_CHANNEL *ch = arg; in ch_on_transport_params() local
1190 if (ch->got_remote_transport_params) { in ch_on_transport_params()
1196 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INTERNAL_ERROR, 0, in ch_on_transport_params()
1212 if (ch->is_server) { in ch_on_transport_params()
1224 if (!ossl_quic_conn_id_eq(&ch->init_dcid, &cid)) { in ch_on_transport_params()
1234 if (ch->is_server) { in ch_on_transport_params()
1244 if (!ch->doing_retry) { in ch_on_transport_params()
1255 if (!ossl_quic_conn_id_eq(&ch->retry_scid, &cid)) { in ch_on_transport_params()
1276 if (!ossl_quic_conn_id_eq(&ch->init_scid, &cid)) { in ch_on_transport_params()
1296 ossl_quic_txfc_bump_cwm(&ch->conn_txfc, v); in ch_on_transport_params()
1316 ch->rx_init_max_stream_data_bidi_remote = v; in ch_on_transport_params()
1336 ch->rx_init_max_stream_data_bidi_local = v; in ch_on_transport_params()
1339 ossl_quic_stream_map_visit(&ch->qsm, txfc_bump_cwm_bidi, &v); in ch_on_transport_params()
1355 ch->rx_init_max_stream_data_uni = v; in ch_on_transport_params()
1358 ossl_quic_stream_map_visit(&ch->qsm, txfc_bump_cwm_uni, &v); in ch_on_transport_params()
1375 ch->rx_ack_delay_exp = (unsigned char)v; in ch_on_transport_params()
1392 ch->rx_max_ack_delay = v; in ch_on_transport_params()
1393 ossl_ackm_set_rx_max_ack_delay(ch->ackm, in ch_on_transport_params()
1394 ossl_ms2time(ch->rx_max_ack_delay)); in ch_on_transport_params()
1412 assert(ch->max_local_streams_bidi == 0); in ch_on_transport_params()
1413 ch->max_local_streams_bidi = v; in ch_on_transport_params()
1430 assert(ch->max_local_streams_uni == 0); in ch_on_transport_params()
1431 ch->max_local_streams_uni = v; in ch_on_transport_params()
1447 ch->max_idle_timeout_remote_req = v; in ch_on_transport_params()
1449 ch->max_idle_timeout = min_u64_ignore_0(ch->max_idle_timeout_local_req, in ch_on_transport_params()
1450 ch->max_idle_timeout_remote_req); in ch_on_transport_params()
1453 ch_update_idle(ch); in ch_on_transport_params()
1471 ch->rx_max_udp_payload_size = v; in ch_on_transport_params()
1488 ch->rx_active_conn_id_limit = v; in ch_on_transport_params()
1504 if (ch->is_server) { in ch_on_transport_params()
1514 if (!ossl_quic_srtm_add(ch->srtm, ch, ch->cur_remote_seq_num, in ch_on_transport_params()
1539 if (ch->is_server) { in ch_on_transport_params()
1544 if (ch->cur_remote_dcid.id_len == 0) { in ch_on_transport_params()
1603 if (!ch->is_server) { in ch_on_transport_params()
1609 if (ch->doing_retry && !got_retry_scid) { in ch_on_transport_params()
1615 ch->got_remote_transport_params = 1; in ch_on_transport_params()
1618 QLOG_EVENT_BEGIN(ch_get_qlog(ch), transport, parameters_set) in ch_on_transport_params()
1623 &ch->init_dcid); in ch_on_transport_params()
1626 &ch->init_dcid); in ch_on_transport_params()
1629 &ch->retry_scid); in ch_on_transport_params()
1632 ossl_quic_txfc_get_cwm(&ch->conn_txfc)); in ch_on_transport_params()
1635 ch->rx_init_max_stream_data_bidi_local); in ch_on_transport_params()
1638 ch->rx_init_max_stream_data_bidi_remote); in ch_on_transport_params()
1641 ch->rx_init_max_stream_data_uni); in ch_on_transport_params()
1644 ch->max_local_streams_bidi); in ch_on_transport_params()
1647 ch->max_local_streams_uni); in ch_on_transport_params()
1649 QLOG_U64("ack_delay_exponent", ch->rx_ack_delay_exp); in ch_on_transport_params()
1651 QLOG_U64("max_ack_delay", ch->rx_max_ack_delay); in ch_on_transport_params()
1653 QLOG_U64("max_udp_payload_size", ch->rx_max_udp_payload_size); in ch_on_transport_params()
1657 QLOG_U64("active_connection_id_limit", ch->rx_active_conn_id_limit); in ch_on_transport_params()
1682 ossl_quic_stream_map_visit(&ch->qsm, do_update, ch); in ch_on_transport_params()
1685 if (ch->is_server && !ch_generate_transport_params(ch)) { in ch_on_transport_params()
1686 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INTERNAL_ERROR, 0, in ch_on_transport_params()
1694 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_TRANSPORT_PARAMETER_ERROR, in ch_on_transport_params()
1704 static int ch_generate_transport_params(QUIC_CHANNEL *ch) in ch_generate_transport_params() argument
1712 if (ch->local_transport_params != NULL || ch->got_local_transport_params) in ch_generate_transport_params()
1727 if (ch->is_server) { in ch_generate_transport_params()
1729 &ch->init_dcid)) in ch_generate_transport_params()
1733 &ch->cur_local_cid)) in ch_generate_transport_params()
1743 ch->max_idle_timeout_local_req)) in ch_generate_transport_params()
1754 if (ch->tx_max_ack_delay != QUIC_DEFAULT_MAX_ACK_DELAY in ch_generate_transport_params()
1756 ch->tx_max_ack_delay)) in ch_generate_transport_params()
1760 ossl_quic_rxfc_get_cwm(&ch->conn_rxfc))) in ch_generate_transport_params()
1765 ch->tx_init_max_stream_data_bidi_local)) in ch_generate_transport_params()
1769 ch->tx_init_max_stream_data_bidi_remote)) in ch_generate_transport_params()
1773 ch->tx_init_max_stream_data_uni)) in ch_generate_transport_params()
1777 … ossl_quic_rxfc_get_cwm(&ch->max_streams_bidi_rxfc))) in ch_generate_transport_params()
1781 … ossl_quic_rxfc_get_cwm(&ch->max_streams_uni_rxfc))) in ch_generate_transport_params()
1792 ch->local_transport_params = (unsigned char *)buf_mem->data; in ch_generate_transport_params()
1796 if (!ossl_quic_tls_set_transport_params(ch->qtls, ch->local_transport_params, in ch_generate_transport_params()
1801 QLOG_EVENT_BEGIN(ch_get_qlog(ch), transport, parameters_set) in ch_generate_transport_params()
1804 if (ch->is_server) { in ch_generate_transport_params()
1805 QLOG_CID("original_destination_connection_id", &ch->init_dcid); in ch_generate_transport_params()
1806 QLOG_CID("initial_source_connection_id", &ch->cur_local_cid); in ch_generate_transport_params()
1810 QLOG_U64("max_idle_timeout", ch->max_idle_timeout); in ch_generate_transport_params()
1813 QLOG_U64("max_ack_delay", ch->tx_max_ack_delay); in ch_generate_transport_params()
1814 QLOG_U64("initial_max_data", ossl_quic_rxfc_get_cwm(&ch->conn_rxfc)); in ch_generate_transport_params()
1816 ch->tx_init_max_stream_data_bidi_local); in ch_generate_transport_params()
1818 ch->tx_init_max_stream_data_bidi_remote); in ch_generate_transport_params()
1820 ch->tx_init_max_stream_data_uni); in ch_generate_transport_params()
1822 ossl_quic_rxfc_get_cwm(&ch->max_streams_bidi_rxfc)); in ch_generate_transport_params()
1824 ossl_quic_rxfc_get_cwm(&ch->max_streams_uni_rxfc)); in ch_generate_transport_params()
1828 ch->got_local_transport_params = 1; in ch_generate_transport_params()
1848 void ossl_quic_channel_subtick(QUIC_CHANNEL *ch, QUIC_TICK_RESULT *res, in ossl_quic_channel_subtick() argument
1866 if (ossl_quic_channel_is_terminated(ch)) { in ossl_quic_channel_subtick()
1877 if (ossl_quic_channel_is_terminating(ch)) { in ossl_quic_channel_subtick()
1878 now = get_time(ch); in ossl_quic_channel_subtick()
1880 if (ossl_time_compare(now, ch->terminate_deadline) >= 0) { in ossl_quic_channel_subtick()
1881 ch_on_terminating_timeout(ch); in ossl_quic_channel_subtick()
1889 if (!ch->port->engine->inhibit_tick) { in ossl_quic_channel_subtick()
1891 ch_rxku_tick(ch); in ossl_quic_channel_subtick()
1895 ch->did_tls_tick = 0; in ossl_quic_channel_subtick()
1896 ch->have_new_rx_secret = 0; in ossl_quic_channel_subtick()
1897 ch_rx(ch, channel_only); in ossl_quic_channel_subtick()
1903 if (!ch->did_tls_tick) in ossl_quic_channel_subtick()
1904 ch_tick_tls(ch, channel_only); in ossl_quic_channel_subtick()
1913 } while (ch->have_new_rx_secret); in ossl_quic_channel_subtick()
1923 now = get_time(ch); in ossl_quic_channel_subtick()
1924 if (ossl_time_compare(now, ch->idle_deadline) >= 0) { in ossl_quic_channel_subtick()
1929 if (!ch->port->engine->inhibit_tick) in ossl_quic_channel_subtick()
1930 ch_on_idle_timeout(ch); in ossl_quic_channel_subtick()
1938 if (!ch->port->engine->inhibit_tick) { in ossl_quic_channel_subtick()
1939 deadline = ossl_ackm_get_loss_detection_deadline(ch->ackm); in ossl_quic_channel_subtick()
1942 ossl_ackm_on_timeout(ch->ackm); in ossl_quic_channel_subtick()
1945 if (ossl_time_compare(now, ch->ping_deadline) >= 0) { in ossl_quic_channel_subtick()
1946 int pn_space = ossl_quic_enc_level_to_pn_space(ch->tx_enc_level); in ossl_quic_channel_subtick()
1948 ossl_quic_tx_packetiser_schedule_ack_eliciting(ch->txp, pn_space); in ossl_quic_channel_subtick()
1957 ch_update_ping_deadline(ch); in ossl_quic_channel_subtick()
1961 ch_tx(ch); in ossl_quic_channel_subtick()
1964 ossl_quic_stream_map_gc(&ch->qsm); in ossl_quic_channel_subtick()
1968 res->tick_deadline = ch_determine_next_tick_deadline(ch); in ossl_quic_channel_subtick()
1975 res->net_read_desired = !ossl_quic_channel_is_terminated(ch); in ossl_quic_channel_subtick()
1979 = (!ossl_quic_channel_is_terminated(ch) in ossl_quic_channel_subtick()
1980 && ossl_qtx_get_queue_len_datagrams(ch->qtx) > 0); in ossl_quic_channel_subtick()
1983 static int ch_tick_tls(QUIC_CHANNEL *ch, int channel_only) in ch_tick_tls() argument
1992 ch->did_tls_tick = 1; in ch_tick_tls()
1993 ossl_quic_tls_tick(ch->qtls); in ch_tick_tls()
1995 if (ossl_quic_tls_get_error(ch->qtls, &error_code, &error_msg, in ch_tick_tls()
1997 ossl_quic_channel_raise_protocol_error_state(ch, error_code, 0, in ch_tick_tls()
2006 static void ch_rx_check_forged_pkt_limit(QUIC_CHANNEL *ch) in ch_rx_check_forged_pkt_limit() argument
2019 if ((ch->el_discarded & (1U << enc_level)) != 0) in ch_rx_check_forged_pkt_limit()
2022 if (enc_level > ch->rx_enc_level) in ch_rx_check_forged_pkt_limit()
2025 l = ossl_qrx_get_max_forged_pkt_count(ch->qrx, enc_level); in ch_rx_check_forged_pkt_limit()
2030 if (ossl_qrx_get_cur_forged_pkt_count(ch->qrx) < limit) in ch_rx_check_forged_pkt_limit()
2033 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_AEAD_LIMIT_REACHED, 0, in ch_rx_check_forged_pkt_limit()
2038 static int ch_rx(QUIC_CHANNEL *ch, int channel_only) in ch_rx() argument
2041 const int closing = ossl_quic_channel_is_closing(ch); in ch_rx()
2043 if (!ch->is_server && !ch->have_sent_any_pkt) in ch_rx()
2051 assert(ch->qrx_pkt == NULL); in ch_rx()
2053 if (!ossl_qrx_read_pkt(ch->qrx, &ch->qrx_pkt)) in ch_rx()
2059 ch->txp, ch->qrx_pkt->hdr->len); in ch_rx()
2062 ch_update_idle(ch); in ch_rx()
2063 ch_update_ping_deadline(ch); in ch_rx()
2066 ch_rx_handle_packet(ch, channel_only); /* best effort */ in ch_rx()
2073 ossl_qrx_pkt_release(ch->qrx_pkt); in ch_rx()
2074 ch->qrx_pkt = NULL; in ch_rx()
2076 ch->have_sent_ack_eliciting_since_rx = 0; in ch_rx()
2080 ch_rx_check_forged_pkt_limit(ch); in ch_rx()
2087 ch->conn_close_queued = 1; in ch_rx()
2118 static void ch_rx_handle_packet(QUIC_CHANNEL *ch, int channel_only) in ch_rx_handle_packet() argument
2121 int old_have_processed_any_pkt = ch->have_processed_any_pkt; in ch_rx_handle_packet()
2124 assert(ch->qrx_pkt != NULL); in ch_rx_handle_packet()
2131 if (!ossl_quic_channel_is_active(ch)) in ch_rx_handle_packet()
2134 if (ossl_quic_pkt_type_is_encrypted(ch->qrx_pkt->hdr->type)) { in ch_rx_handle_packet()
2135 if (!ch->have_received_enc_pkt) { in ch_rx_handle_packet()
2136 ch->cur_remote_dcid = ch->init_scid = ch->qrx_pkt->hdr->src_conn_id; in ch_rx_handle_packet()
2137 ch->have_received_enc_pkt = 1; in ch_rx_handle_packet()
2143 ossl_quic_tx_packetiser_set_cur_dcid(ch->txp, &ch->init_scid); in ch_rx_handle_packet()
2146 enc_level = ossl_quic_pkt_type_to_enc_level(ch->qrx_pkt->hdr->type); in ch_rx_handle_packet()
2147 if ((ch->el_discarded & (1U << enc_level)) != 0) in ch_rx_handle_packet()
2162 if (!ch->is_server in ch_rx_handle_packet()
2163 && ch->qrx_pkt->peer != NULL in ch_rx_handle_packet()
2165 BIO_ADDR_family(&ch->cur_peer_addr) == AF_INET in ch_rx_handle_packet()
2167 || BIO_ADDR_family(&ch->cur_peer_addr) == AF_INET6 in ch_rx_handle_packet()
2170 && !bio_addr_eq(ch->qrx_pkt->peer, &ch->cur_peer_addr)) in ch_rx_handle_packet()
2173 if (!ch->is_server in ch_rx_handle_packet()
2174 && ch->have_received_enc_pkt in ch_rx_handle_packet()
2175 && ossl_quic_pkt_type_has_scid(ch->qrx_pkt->hdr->type)) { in ch_rx_handle_packet()
2181 if (!ossl_quic_conn_id_eq(&ch->qrx_pkt->hdr->src_conn_id, in ch_rx_handle_packet()
2182 &ch->init_scid)) in ch_rx_handle_packet()
2186 if (ossl_quic_pkt_type_has_version(ch->qrx_pkt->hdr->type) in ch_rx_handle_packet()
2187 && ch->qrx_pkt->hdr->version != QUIC_VERSION_1) in ch_rx_handle_packet()
2195 ch->have_processed_any_pkt = 1; in ch_rx_handle_packet()
2202 if (ossl_quic_pkt_type_is_encrypted(ch->qrx_pkt->hdr->type) in ch_rx_handle_packet()
2203 && ch->qrx_pkt->hdr->reserved != 0) { in ch_rx_handle_packet()
2204 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_PROTOCOL_VIOLATION, in ch_rx_handle_packet()
2209 iovec.buf = ch->qrx_pkt->hdr->data; in ch_rx_handle_packet()
2210 iovec.buf_len = ch->qrx_pkt->hdr->len; in ch_rx_handle_packet()
2211 ossl_qlog_event_transport_packet_received(ch_get_qlog(ch), ch->qrx_pkt->hdr, in ch_rx_handle_packet()
2212 ch->qrx_pkt->pn, &iovec, 1, in ch_rx_handle_packet()
2213 ch->qrx_pkt->datagram_id); in ch_rx_handle_packet()
2216 switch (ch->qrx_pkt->hdr->type) { in ch_rx_handle_packet()
2218 if (ch->doing_retry || ch->is_server) in ch_rx_handle_packet()
2230 if (ch->have_received_enc_pkt) in ch_rx_handle_packet()
2233 if (ch->qrx_pkt->hdr->len <= QUIC_RETRY_INTEGRITY_TAG_LEN) in ch_rx_handle_packet()
2246 if (!ossl_quic_validate_retry_integrity_tag(ch->port->engine->libctx, in ch_rx_handle_packet()
2247 ch->port->engine->propq, in ch_rx_handle_packet()
2248 ch->qrx_pkt->hdr, in ch_rx_handle_packet()
2249 &ch->init_dcid)) in ch_rx_handle_packet()
2253 if (!ch_retry(ch, ch->qrx_pkt->hdr->data, in ch_rx_handle_packet()
2254 ch->qrx_pkt->hdr->len - QUIC_RETRY_INTEGRITY_TAG_LEN, in ch_rx_handle_packet()
2255 &ch->qrx_pkt->hdr->src_conn_id)) in ch_rx_handle_packet()
2256 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INTERNAL_ERROR, in ch_rx_handle_packet()
2261 if (!ch->is_server) in ch_rx_handle_packet()
2275 if (ch->is_server && ch->qrx_pkt->hdr->type == QUIC_PKT_TYPE_HANDSHAKE) in ch_rx_handle_packet()
2280 ch_discard_el(ch, QUIC_ENC_LEVEL_INITIAL); in ch_rx_handle_packet()
2282 if (ch->rxku_in_progress in ch_rx_handle_packet()
2283 && ch->qrx_pkt->hdr->type == QUIC_PKT_TYPE_1RTT in ch_rx_handle_packet()
2284 && ch->qrx_pkt->pn >= ch->rxku_trigger_pn in ch_rx_handle_packet()
2285 && ch->qrx_pkt->key_epoch < ossl_qrx_get_key_epoch(ch->qrx)) { in ch_rx_handle_packet()
2294 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_KEY_UPDATE_ERROR, in ch_rx_handle_packet()
2299 if (!ch->is_server in ch_rx_handle_packet()
2300 && ch->qrx_pkt->hdr->type == QUIC_PKT_TYPE_INITIAL in ch_rx_handle_packet()
2301 && ch->qrx_pkt->hdr->token_len > 0) { in ch_rx_handle_packet()
2319 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_PROTOCOL_VIOLATION, in ch_rx_handle_packet()
2325 ossl_quic_handle_frames(ch, ch->qrx_pkt); /* best effort */ in ch_rx_handle_packet()
2327 if (ch->did_crypto_frame) in ch_rx_handle_packet()
2328 ch_tick_tls(ch, channel_only); in ch_rx_handle_packet()
2338 ch_rx_handle_version_neg(ch, ch->qrx_pkt); in ch_rx_handle_packet()
2348 static void ch_rx_handle_version_neg(QUIC_CHANNEL *ch, OSSL_QRX_PKT *pkt) in ch_rx_handle_version_neg() argument
2371 ch_raise_version_neg_failure(ch); in ch_rx_handle_version_neg()
2374 static void ch_raise_version_neg_failure(QUIC_CHANNEL *ch) in ch_raise_version_neg_failure() argument
2386 ch_start_terminating(ch, &tcause, 1); in ch_raise_version_neg_failure()
2390 static int ch_tx(QUIC_CHANNEL *ch) in ch_tx() argument
2402 if (ossl_quic_channel_is_draining(ch)) in ch_tx()
2405 if (ossl_quic_channel_is_closing(ch)) { in ch_tx()
2416 if (!ch->conn_close_queued) in ch_tx()
2419 ch->conn_close_queued = 0; in ch_tx()
2423 ch_maybe_trigger_spontaneous_txku(ch); in ch_tx()
2425 ch->rxku_pending_confirm_done = 0; in ch_tx()
2436 res = ossl_quic_tx_packetiser_generate(ch->txp, &status); in ch_tx()
2438 ch->have_sent_any_pkt = 1; /* Packet(s) were sent */ in ch_tx()
2439 ch->port->have_sent_any_pkt = 1; in ch_tx()
2447 && !ch->have_sent_ack_eliciting_since_rx) { in ch_tx()
2448 ch_update_idle(ch); in ch_tx()
2449 ch->have_sent_ack_eliciting_since_rx = 1; in ch_tx()
2452 if (!ch->is_server && status.sent_handshake) in ch_tx()
2457 ch_discard_el(ch, QUIC_ENC_LEVEL_INITIAL); in ch_tx()
2459 if (ch->rxku_pending_confirm_done) in ch_tx()
2460 ch->rxku_pending_confirm = 0; in ch_tx()
2462 ch_update_ping_deadline(ch); in ch_tx()
2478 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INTERNAL_ERROR, in ch_tx()
2486 switch (ossl_qtx_flush_net(ch->qtx)) { in ch_tx()
2495 ossl_quic_port_raise_net_error(ch->port, ch); in ch_tx()
2503 static OSSL_TIME ch_determine_next_tick_deadline(QUIC_CHANNEL *ch) in ch_determine_next_tick_deadline() argument
2508 if (ossl_quic_channel_is_terminated(ch)) in ch_determine_next_tick_deadline()
2511 deadline = ossl_ackm_get_loss_detection_deadline(ch->ackm); in ch_determine_next_tick_deadline()
2520 if (ossl_qtx_is_enc_level_provisioned(ch->qtx, i)) { in ch_determine_next_tick_deadline()
2522 ossl_ackm_get_ack_deadline(ch->ackm, in ch_determine_next_tick_deadline()
2531 if (!ossl_time_is_infinite(ch->ping_deadline)) in ch_determine_next_tick_deadline()
2532 deadline = ossl_time_min(deadline, ch->ping_deadline); in ch_determine_next_tick_deadline()
2536 ossl_quic_tx_packetiser_get_deadline(ch->txp)); in ch_determine_next_tick_deadline()
2539 if (ossl_quic_channel_is_terminating(ch)) in ch_determine_next_tick_deadline()
2541 ch->terminate_deadline); in ch_determine_next_tick_deadline()
2542 else if (!ossl_time_is_infinite(ch->idle_deadline)) in ch_determine_next_tick_deadline()
2544 ch->idle_deadline); in ch_determine_next_tick_deadline()
2547 if (ch->rxku_in_progress) in ch_determine_next_tick_deadline()
2548 deadline = ossl_time_min(deadline, ch->rxku_update_end_deadline); in ch_determine_next_tick_deadline()
2562 static void ch_record_state_transition(QUIC_CHANNEL *ch, uint32_t new_state) in ch_record_state_transition() argument
2564 uint32_t old_state = ch->state; in ch_record_state_transition()
2566 ch->state = new_state; in ch_record_state_transition()
2568 ossl_qlog_event_connectivity_connection_state_updated(ch_get_qlog(ch), in ch_record_state_transition()
2571 ch->handshake_complete, in ch_record_state_transition()
2572 ch->handshake_confirmed); in ch_record_state_transition()
2575 int ossl_quic_channel_start(QUIC_CHANNEL *ch) in ossl_quic_channel_start() argument
2577 if (ch->is_server) in ossl_quic_channel_start()
2584 if (ch->state != QUIC_CHANNEL_STATE_IDLE) in ossl_quic_channel_start()
2589 if (!ossl_quic_tx_packetiser_set_peer(ch->txp, &ch->cur_peer_addr)) in ossl_quic_channel_start()
2593 if (!ossl_quic_provide_initial_secret(ch->port->engine->libctx, in ossl_quic_channel_start()
2594 ch->port->engine->propq, in ossl_quic_channel_start()
2595 &ch->init_dcid, in ossl_quic_channel_start()
2596 ch->is_server, in ossl_quic_channel_start()
2597 ch->qrx, ch->qtx)) in ossl_quic_channel_start()
2605 if (!ch->is_server && !ch->got_local_transport_params in ossl_quic_channel_start()
2606 && !ch_generate_transport_params(ch)) in ossl_quic_channel_start()
2610 ch_record_state_transition(ch, QUIC_CHANNEL_STATE_ACTIVE); in ossl_quic_channel_start()
2611 ch->doing_proactive_ver_neg = 0; /* not currently supported */ in ossl_quic_channel_start()
2613 ossl_qlog_event_connectivity_connection_started(ch_get_qlog(ch), in ossl_quic_channel_start()
2614 &ch->init_dcid); in ossl_quic_channel_start()
2617 if (!ch_tick_tls(ch, /*channel_only=*/0)) in ossl_quic_channel_start()
2620 ossl_quic_reactor_tick(ossl_quic_port_get0_reactor(ch->port), 0); /* best effort */ in ossl_quic_channel_start()
2625 void ossl_quic_channel_local_close(QUIC_CHANNEL *ch, uint64_t app_error_code, in ossl_quic_channel_local_close() argument
2630 if (ossl_quic_channel_is_term_any(ch)) in ossl_quic_channel_local_close()
2637 ch_start_terminating(ch, &tcause, 0); in ossl_quic_channel_local_close()
2646 static int ch_retry(QUIC_CHANNEL *ch, in ch_retry() argument
2657 if (ossl_quic_conn_id_eq(&ch->init_dcid, retry_scid)) in ch_retry()
2661 if (!ossl_quic_tx_packetiser_set_cur_dcid(ch->txp, retry_scid)) in ch_retry()
2671 if (!ossl_quic_tx_packetiser_set_initial_token(ch->txp, buf, in ch_retry()
2678 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_INVALID_TOKEN, 0, in ch_retry()
2684 ch->retry_scid = *retry_scid; in ch_retry()
2685 ch->doing_retry = 1; in ch_retry()
2697 if (!ossl_ackm_mark_packet_pseudo_lost(ch->ackm, QUIC_PN_SPACE_INITIAL, in ch_retry()
2705 if (!ossl_quic_provide_initial_secret(ch->port->engine->libctx, in ch_retry()
2706 ch->port->engine->propq, in ch_retry()
2707 &ch->retry_scid, in ch_retry()
2709 ch->qrx, ch->qtx)) in ch_retry()
2716 static int ch_discard_el(QUIC_CHANNEL *ch, in ch_discard_el() argument
2722 if ((ch->el_discarded & (1U << enc_level)) != 0) in ch_discard_el()
2727 ossl_quic_tx_packetiser_discard_enc_level(ch->txp, enc_level); in ch_discard_el()
2728 ossl_qrx_discard_enc_level(ch->qrx, enc_level); in ch_discard_el()
2729 ossl_qtx_discard_enc_level(ch->qtx, enc_level); in ch_discard_el()
2734 ossl_ackm_on_pkt_space_discarded(ch->ackm, pn_space); in ch_discard_el()
2737 if (!ossl_assert(ch->crypto_send[pn_space] != NULL) in ch_discard_el()
2738 || !ossl_assert(ch->crypto_recv[pn_space] != NULL)) in ch_discard_el()
2742 ossl_quic_sstream_free(ch->crypto_send[pn_space]); in ch_discard_el()
2743 ch->crypto_send[pn_space] = NULL; in ch_discard_el()
2745 ossl_quic_rstream_free(ch->crypto_recv[pn_space]); in ch_discard_el()
2746 ch->crypto_recv[pn_space] = NULL; in ch_discard_el()
2749 ch->el_discarded |= (1U << enc_level); in ch_discard_el()
2754 int ossl_quic_channel_on_handshake_confirmed(QUIC_CHANNEL *ch) in ossl_quic_channel_on_handshake_confirmed() argument
2756 if (ch->handshake_confirmed) in ossl_quic_channel_on_handshake_confirmed()
2759 if (!ch->handshake_complete) { in ossl_quic_channel_on_handshake_confirmed()
2764 ossl_quic_channel_raise_protocol_error(ch, OSSL_QUIC_ERR_PROTOCOL_VIOLATION, in ossl_quic_channel_on_handshake_confirmed()
2771 ch_discard_el(ch, QUIC_ENC_LEVEL_HANDSHAKE); in ossl_quic_channel_on_handshake_confirmed()
2772 ch->handshake_confirmed = 1; in ossl_quic_channel_on_handshake_confirmed()
2773 ch_record_state_transition(ch, ch->state); in ossl_quic_channel_on_handshake_confirmed()
2774 ossl_ackm_on_handshake_confirmed(ch->ackm); in ossl_quic_channel_on_handshake_confirmed()
2854 static void ch_start_terminating(QUIC_CHANNEL *ch, in ch_start_terminating() argument
2859 if (!ch->have_sent_any_pkt) in ch_start_terminating()
2862 switch (ch->state) { in ch_start_terminating()
2865 copy_tcause(&ch->terminate_cause, tcause); in ch_start_terminating()
2866 ch_on_terminating_timeout(ch); in ch_start_terminating()
2870 copy_tcause(&ch->terminate_cause, tcause); in ch_start_terminating()
2872 ossl_qlog_event_connectivity_connection_closed(ch_get_qlog(ch), tcause); in ch_start_terminating()
2875 ch_record_state_transition(ch, tcause->remote in ch_start_terminating()
2883 ch->terminate_deadline in ch_start_terminating()
2884 = ossl_time_add(get_time(ch), in ch_start_terminating()
2885 ossl_time_multiply(ossl_ackm_get_pto_duration(ch->ackm), in ch_start_terminating()
2892 f.error_code = ch->terminate_cause.error_code; in ch_start_terminating()
2893 f.frame_type = ch->terminate_cause.frame_type; in ch_start_terminating()
2894 f.is_app = ch->terminate_cause.app; in ch_start_terminating()
2895 f.reason = (char *)ch->terminate_cause.reason; in ch_start_terminating()
2896 f.reason_len = ch->terminate_cause.reason_len; in ch_start_terminating()
2897 ossl_quic_tx_packetiser_schedule_conn_close(ch->txp, &f); in ch_start_terminating()
2905 ch->conn_close_queued = 1; in ch_start_terminating()
2908 ch_on_terminating_timeout(ch); in ch_start_terminating()
2914 ch_on_terminating_timeout(ch); in ch_start_terminating()
2922 ch_record_state_transition(ch, QUIC_CHANNEL_STATE_TERMINATING_DRAINING); in ch_start_terminating()
2932 ch_on_terminating_timeout(ch); in ch_start_terminating()
2943 void ossl_quic_channel_on_remote_conn_close(QUIC_CHANNEL *ch, in ossl_quic_channel_on_remote_conn_close() argument
2948 if (!ossl_quic_channel_is_active(ch)) in ossl_quic_channel_on_remote_conn_close()
2957 ch_start_terminating(ch, &tcause, 0); in ossl_quic_channel_on_remote_conn_close()
2965 static int ch_enqueue_retire_conn_id(QUIC_CHANNEL *ch, uint64_t seq_num) in ch_enqueue_retire_conn_id() argument
2971 ossl_quic_srtm_remove(ch->srtm, ch, seq_num); in ch_enqueue_retire_conn_id()
2988 if (ossl_quic_cfq_add_frame(ch->cfq, 1, QUIC_PN_SPACE_APP, in ch_enqueue_retire_conn_id()
2999 ossl_quic_channel_raise_protocol_error(ch, in ch_enqueue_retire_conn_id()
3007 void ossl_quic_channel_on_new_conn_id(QUIC_CHANNEL *ch, in ossl_quic_channel_on_new_conn_id() argument
3010 uint64_t new_remote_seq_num = ch->cur_remote_seq_num; in ossl_quic_channel_on_new_conn_id()
3011 uint64_t new_retire_prior_to = ch->cur_retire_prior_to; in ossl_quic_channel_on_new_conn_id()
3013 if (!ossl_quic_channel_is_active(ch)) in ossl_quic_channel_on_new_conn_id()
3017 if (ch->cur_remote_dcid.id_len == 0) { in ossl_quic_channel_on_new_conn_id()
3019 ossl_quic_channel_raise_protocol_error(ch, in ossl_quic_channel_on_new_conn_id()
3043 ossl_quic_channel_raise_protocol_error(ch, in ossl_quic_channel_on_new_conn_id()
3065 if (new_retire_prior_to - ch->cur_retire_prior_to > 10) { in ossl_quic_channel_on_new_conn_id()
3066 ossl_quic_channel_raise_protocol_error(ch, in ossl_quic_channel_on_new_conn_id()
3074 if (new_remote_seq_num > ch->cur_remote_seq_num) { in ossl_quic_channel_on_new_conn_id()
3076 if (!ossl_quic_srtm_add(ch->srtm, ch, new_remote_seq_num, in ossl_quic_channel_on_new_conn_id()
3079 ch, OSSL_QUIC_ERR_CONNECTION_ID_LIMIT_ERROR, in ossl_quic_channel_on_new_conn_id()
3085 ch->cur_remote_seq_num = new_remote_seq_num; in ossl_quic_channel_on_new_conn_id()
3086 ch->cur_remote_dcid = f->conn_id; in ossl_quic_channel_on_new_conn_id()
3087 ossl_quic_tx_packetiser_set_cur_dcid(ch->txp, &ch->cur_remote_dcid); in ossl_quic_channel_on_new_conn_id()
3110 while (new_retire_prior_to > ch->cur_retire_prior_to) { in ossl_quic_channel_on_new_conn_id()
3111 if (!ch_enqueue_retire_conn_id(ch, ch->cur_retire_prior_to)) in ossl_quic_channel_on_new_conn_id()
3113 ++ch->cur_retire_prior_to; in ossl_quic_channel_on_new_conn_id()
3117 static void ch_save_err_state(QUIC_CHANNEL *ch) in ch_save_err_state() argument
3119 if (ch->err_state == NULL) in ch_save_err_state()
3120 ch->err_state = OSSL_ERR_STATE_new(); in ch_save_err_state()
3122 if (ch->err_state == NULL) in ch_save_err_state()
3125 OSSL_ERR_STATE_save(ch->err_state); in ch_save_err_state()
3128 void ossl_quic_channel_inject(QUIC_CHANNEL *ch, QUIC_URXE *e) in ossl_quic_channel_inject() argument
3130 ossl_qrx_inject_urxe(ch->qrx, e); in ossl_quic_channel_inject()
3133 void ossl_quic_channel_on_stateless_reset(QUIC_CHANNEL *ch) in ossl_quic_channel_on_stateless_reset() argument
3139 ch_start_terminating(ch, &tcause, 0); in ossl_quic_channel_on_stateless_reset()
3142 void ossl_quic_channel_raise_net_error(QUIC_CHANNEL *ch) in ossl_quic_channel_raise_net_error() argument
3146 if (ch->net_error) in ossl_quic_channel_raise_net_error()
3149 ch->net_error = 1; in ossl_quic_channel_raise_net_error()
3159 ch_start_terminating(ch, &tcause, 1); in ossl_quic_channel_raise_net_error()
3162 int ossl_quic_channel_net_error(QUIC_CHANNEL *ch) in ossl_quic_channel_net_error() argument
3164 return ch->net_error; in ossl_quic_channel_net_error()
3167 void ossl_quic_channel_restore_err_state(QUIC_CHANNEL *ch) in ossl_quic_channel_restore_err_state() argument
3169 if (ch == NULL) in ossl_quic_channel_restore_err_state()
3172 if (!ossl_quic_port_is_running(ch->port)) in ossl_quic_channel_restore_err_state()
3173 ossl_quic_port_restore_err_state(ch->port); in ossl_quic_channel_restore_err_state()
3175 OSSL_ERR_STATE_restore(ch->err_state); in ossl_quic_channel_restore_err_state()
3178 void ossl_quic_channel_raise_protocol_error_loc(QUIC_CHANNEL *ch, in ossl_quic_channel_raise_protocol_error_loc() argument
3195 if (ch->protocol_error) in ossl_quic_channel_raise_protocol_error_loc()
3239 ch_save_err_state(ch); in ossl_quic_channel_raise_protocol_error_loc()
3246 ch->protocol_error = 1; in ossl_quic_channel_raise_protocol_error_loc()
3247 ch_start_terminating(ch, &tcause, 0); in ossl_quic_channel_raise_protocol_error_loc()
3254 static void ch_on_terminating_timeout(QUIC_CHANNEL *ch) in ch_on_terminating_timeout() argument
3256 ch_record_state_transition(ch, QUIC_CHANNEL_STATE_TERMINATED); in ch_on_terminating_timeout()
3264 static OSSL_TIME ch_get_effective_idle_timeout_duration(QUIC_CHANNEL *ch) in ch_get_effective_idle_timeout_duration() argument
3268 if (ch->max_idle_timeout == 0) in ch_get_effective_idle_timeout_duration()
3279 pto = ossl_ackm_get_pto_duration(ch->ackm); in ch_get_effective_idle_timeout_duration()
3280 return ossl_time_max(ossl_ms2time(ch->max_idle_timeout), in ch_get_effective_idle_timeout_duration()
3288 static void ch_update_idle(QUIC_CHANNEL *ch) in ch_update_idle() argument
3290 ch->idle_deadline = ossl_time_add(get_time(ch), in ch_update_idle()
3291 ch_get_effective_idle_timeout_duration(ch)); in ch_update_idle()
3298 static void ch_update_ping_deadline(QUIC_CHANNEL *ch) in ch_update_ping_deadline() argument
3302 idle_duration = ch_get_effective_idle_timeout_duration(ch); in ch_update_ping_deadline()
3304 ch->ping_deadline = ossl_time_infinite(); in ch_update_ping_deadline()
3316 ch->ping_deadline = ossl_time_add(get_time(ch), max_span); in ch_update_ping_deadline()
3320 static void ch_on_idle_timeout(QUIC_CHANNEL *ch) in ch_on_idle_timeout() argument
3327 ch->terminate_cause.app = 0; in ch_on_idle_timeout()
3328 ch->terminate_cause.error_code = OSSL_QUIC_LOCAL_ERR_IDLE_TIMEOUT; in ch_on_idle_timeout()
3329 ch->terminate_cause.frame_type = 0; in ch_on_idle_timeout()
3331 ch_record_state_transition(ch, QUIC_CHANNEL_STATE_TERMINATED); in ch_on_idle_timeout()
3335 int ossl_quic_channel_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer, in ossl_quic_channel_on_new_conn() argument
3339 if (!ossl_assert(ch->state == QUIC_CHANNEL_STATE_IDLE && ch->is_server)) in ossl_quic_channel_on_new_conn()
3343 if (!ossl_quic_lcidm_generate_initial(ch->lcidm, ch, &ch->cur_local_cid)) in ossl_quic_channel_on_new_conn()
3347 ch->cur_peer_addr = *peer; in ossl_quic_channel_on_new_conn()
3348 ch->init_dcid = *peer_dcid; in ossl_quic_channel_on_new_conn()
3349 ch->cur_remote_dcid = *peer_scid; in ossl_quic_channel_on_new_conn()
3352 if (!ossl_quic_tx_packetiser_set_peer(ch->txp, &ch->cur_peer_addr)) in ossl_quic_channel_on_new_conn()
3356 if (!ossl_quic_tx_packetiser_set_cur_dcid(ch->txp, &ch->cur_remote_dcid)) in ossl_quic_channel_on_new_conn()
3359 if (!ossl_quic_tx_packetiser_set_cur_scid(ch->txp, &ch->cur_local_cid)) in ossl_quic_channel_on_new_conn()
3363 ossl_qtx_set_qlog_cb(ch->qtx, ch_get_qlog_cb, ch); in ossl_quic_channel_on_new_conn()
3364 ossl_quic_tx_packetiser_set_qlog_cb(ch->txp, ch_get_qlog_cb, ch); in ossl_quic_channel_on_new_conn()
3367 if (!ossl_quic_provide_initial_secret(ch->port->engine->libctx, in ossl_quic_channel_on_new_conn()
3368 ch->port->engine->propq, in ossl_quic_channel_on_new_conn()
3369 &ch->init_dcid, in ossl_quic_channel_on_new_conn()
3371 ch->qrx, ch->qtx)) in ossl_quic_channel_on_new_conn()
3375 if (!ossl_quic_lcidm_enrol_odcid(ch->lcidm, ch, &ch->init_dcid)) in ossl_quic_channel_on_new_conn()
3379 ch_record_state_transition(ch, QUIC_CHANNEL_STATE_ACTIVE); in ossl_quic_channel_on_new_conn()
3380 ch->doing_proactive_ver_neg = 0; /* not currently supported */ in ossl_quic_channel_on_new_conn()
3384 SSL *ossl_quic_channel_get0_ssl(QUIC_CHANNEL *ch) in ossl_quic_channel_get0_ssl() argument
3386 return ch->tls; in ossl_quic_channel_get0_ssl()
3389 static int ch_init_new_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs, in ch_init_new_stream() argument
3394 int local_init = (ch->is_server == server_init); in ch_init_new_stream()
3406 if (!ossl_quic_txfc_init(&qs->txfc, &ch->conn_txfc)) in ch_init_new_stream()
3409 if (ch->got_remote_transport_params) { in ch_init_new_stream()
3419 cwm = ch->rx_init_max_stream_data_uni; in ch_init_new_stream()
3421 cwm = ch->rx_init_max_stream_data_bidi_local; in ch_init_new_stream()
3423 cwm = ch->rx_init_max_stream_data_bidi_remote; in ch_init_new_stream()
3433 rxfc_wnd = ch->tx_init_max_stream_data_uni; in ch_init_new_stream()
3435 rxfc_wnd = ch->tx_init_max_stream_data_bidi_local; in ch_init_new_stream()
3437 rxfc_wnd = ch->tx_init_max_stream_data_bidi_remote; in ch_init_new_stream()
3439 if (!ossl_quic_rxfc_init(&qs->rxfc, &ch->conn_rxfc, in ch_init_new_stream()
3442 get_time, ch)) in ch_init_new_stream()
3455 static uint64_t *ch_get_local_stream_next_ordinal_ptr(QUIC_CHANNEL *ch, in ch_get_local_stream_next_ordinal_ptr() argument
3458 return is_uni ? &ch->next_local_stream_ordinal_uni in ch_get_local_stream_next_ordinal_ptr()
3459 : &ch->next_local_stream_ordinal_bidi; in ch_get_local_stream_next_ordinal_ptr()
3462 static const uint64_t *ch_get_local_stream_max_ptr(const QUIC_CHANNEL *ch, in ch_get_local_stream_max_ptr() argument
3465 return is_uni ? &ch->max_local_streams_uni in ch_get_local_stream_max_ptr()
3466 : &ch->max_local_streams_bidi; in ch_get_local_stream_max_ptr()
3469 static const QUIC_RXFC *ch_get_remote_stream_count_rxfc(const QUIC_CHANNEL *ch, in ch_get_remote_stream_count_rxfc() argument
3472 return is_uni ? &ch->max_streams_uni_rxfc in ch_get_remote_stream_count_rxfc()
3473 : &ch->max_streams_bidi_rxfc; in ch_get_remote_stream_count_rxfc()
3476 int ossl_quic_channel_is_new_local_stream_admissible(QUIC_CHANNEL *ch, in ossl_quic_channel_is_new_local_stream_admissible() argument
3479 const uint64_t *p_next_ordinal = ch_get_local_stream_next_ordinal_ptr(ch, is_uni); in ossl_quic_channel_is_new_local_stream_admissible()
3481 return ossl_quic_stream_map_is_local_allowed_by_stream_limit(&ch->qsm, in ossl_quic_channel_is_new_local_stream_admissible()
3486 uint64_t ossl_quic_channel_get_local_stream_count_avail(const QUIC_CHANNEL *ch, in ossl_quic_channel_get_local_stream_count_avail() argument
3491 p_next_ordinal = ch_get_local_stream_next_ordinal_ptr((QUIC_CHANNEL *)ch, in ossl_quic_channel_get_local_stream_count_avail()
3493 p_max = ch_get_local_stream_max_ptr(ch, is_uni); in ossl_quic_channel_get_local_stream_count_avail()
3498 uint64_t ossl_quic_channel_get_remote_stream_count_avail(const QUIC_CHANNEL *ch, in ossl_quic_channel_get_remote_stream_count_avail() argument
3501 return ossl_quic_rxfc_get_credit(ch_get_remote_stream_count_rxfc(ch, is_uni)); in ossl_quic_channel_get_remote_stream_count_avail()
3504 QUIC_STREAM *ossl_quic_channel_new_stream_local(QUIC_CHANNEL *ch, int is_uni) in ossl_quic_channel_new_stream_local() argument
3511 type = ch->is_server ? QUIC_STREAM_INITIATOR_SERVER in ossl_quic_channel_new_stream_local()
3514 p_next_ordinal = ch_get_local_stream_next_ordinal_ptr(ch, is_uni); in ossl_quic_channel_new_stream_local()
3526 if ((qs = ossl_quic_stream_map_alloc(&ch->qsm, stream_id, type)) == NULL) in ossl_quic_channel_new_stream_local()
3530 if (!ch_init_new_stream(ch, qs, /*can_send=*/1, /*can_recv=*/!is_uni)) in ossl_quic_channel_new_stream_local()
3537 ossl_quic_stream_map_release(&ch->qsm, qs); in ossl_quic_channel_new_stream_local()
3541 QUIC_STREAM *ossl_quic_channel_new_stream_remote(QUIC_CHANNEL *ch, in ossl_quic_channel_new_stream_remote() argument
3548 peer_role = ch->is_server in ossl_quic_channel_new_stream_remote()
3557 qs = ossl_quic_stream_map_alloc(&ch->qsm, stream_id, in ossl_quic_channel_new_stream_remote()
3563 if (!ch_init_new_stream(ch, qs, /*can_send=*/!is_uni, /*can_recv=*/1)) in ossl_quic_channel_new_stream_remote()
3566 if (ch->incoming_stream_auto_reject) in ossl_quic_channel_new_stream_remote()
3567 ossl_quic_channel_reject_stream(ch, qs); in ossl_quic_channel_new_stream_remote()
3569 ossl_quic_stream_map_push_accept_queue(&ch->qsm, qs); in ossl_quic_channel_new_stream_remote()
3574 ossl_quic_stream_map_release(&ch->qsm, qs); in ossl_quic_channel_new_stream_remote()
3578 void ossl_quic_channel_set_incoming_stream_auto_reject(QUIC_CHANNEL *ch, in ossl_quic_channel_set_incoming_stream_auto_reject() argument
3582 ch->incoming_stream_auto_reject = (enable != 0); in ossl_quic_channel_set_incoming_stream_auto_reject()
3583 ch->incoming_stream_auto_reject_aec = aec; in ossl_quic_channel_set_incoming_stream_auto_reject()
3586 void ossl_quic_channel_reject_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs) in ossl_quic_channel_reject_stream() argument
3588 ossl_quic_stream_map_stop_sending_recv_part(&ch->qsm, qs, in ossl_quic_channel_reject_stream()
3589 ch->incoming_stream_auto_reject_aec); in ossl_quic_channel_reject_stream()
3591 ossl_quic_stream_map_reset_stream_send_part(&ch->qsm, qs, in ossl_quic_channel_reject_stream()
3592 ch->incoming_stream_auto_reject_aec); in ossl_quic_channel_reject_stream()
3595 ossl_quic_stream_map_update_state(&ch->qsm, qs); in ossl_quic_channel_reject_stream()
3599 int ossl_quic_channel_replace_local_cid(QUIC_CHANNEL *ch, in ossl_quic_channel_replace_local_cid() argument
3603 if (!ossl_quic_lcidm_debug_remove(ch->lcidm, &ch->cur_local_cid)) in ossl_quic_channel_replace_local_cid()
3605 ch->cur_local_cid = *conn_id; in ossl_quic_channel_replace_local_cid()
3607 if (!ossl_quic_tx_packetiser_set_cur_scid(ch->txp, &ch->cur_local_cid)) in ossl_quic_channel_replace_local_cid()
3610 if (!ossl_quic_lcidm_debug_add(ch->lcidm, ch, &ch->cur_local_cid, in ossl_quic_channel_replace_local_cid()
3616 void ossl_quic_channel_set_msg_callback(QUIC_CHANNEL *ch, in ossl_quic_channel_set_msg_callback() argument
3620 ch->msg_callback = msg_callback; in ossl_quic_channel_set_msg_callback()
3621 ch->msg_callback_ssl = msg_callback_ssl; in ossl_quic_channel_set_msg_callback()
3622 ossl_qtx_set_msg_callback(ch->qtx, msg_callback, msg_callback_ssl); in ossl_quic_channel_set_msg_callback()
3623 ossl_quic_tx_packetiser_set_msg_callback(ch->txp, msg_callback, in ossl_quic_channel_set_msg_callback()
3625 ossl_qrx_set_msg_callback(ch->qrx, msg_callback, msg_callback_ssl); in ossl_quic_channel_set_msg_callback()
3628 void ossl_quic_channel_set_msg_callback_arg(QUIC_CHANNEL *ch, in ossl_quic_channel_set_msg_callback_arg() argument
3631 ch->msg_callback_arg = msg_callback_arg; in ossl_quic_channel_set_msg_callback_arg()
3632 ossl_qtx_set_msg_callback_arg(ch->qtx, msg_callback_arg); in ossl_quic_channel_set_msg_callback_arg()
3633 ossl_quic_tx_packetiser_set_msg_callback_arg(ch->txp, msg_callback_arg); in ossl_quic_channel_set_msg_callback_arg()
3634 ossl_qrx_set_msg_callback_arg(ch->qrx, msg_callback_arg); in ossl_quic_channel_set_msg_callback_arg()
3637 void ossl_quic_channel_set_txku_threshold_override(QUIC_CHANNEL *ch, in ossl_quic_channel_set_txku_threshold_override() argument
3640 ch->txku_threshold_override = tx_pkt_threshold; in ossl_quic_channel_set_txku_threshold_override()
3643 uint64_t ossl_quic_channel_get_tx_key_epoch(QUIC_CHANNEL *ch) in ossl_quic_channel_get_tx_key_epoch() argument
3645 return ossl_qtx_get_key_epoch(ch->qtx); in ossl_quic_channel_get_tx_key_epoch()
3648 uint64_t ossl_quic_channel_get_rx_key_epoch(QUIC_CHANNEL *ch) in ossl_quic_channel_get_rx_key_epoch() argument
3650 return ossl_qrx_get_key_epoch(ch->qrx); in ossl_quic_channel_get_rx_key_epoch()
3653 int ossl_quic_channel_trigger_txku(QUIC_CHANNEL *ch) in ossl_quic_channel_trigger_txku() argument
3655 if (!txku_allowed(ch)) in ossl_quic_channel_trigger_txku()
3658 ch->ku_locally_initiated = 1; in ossl_quic_channel_trigger_txku()
3659 ch_trigger_txku(ch); in ossl_quic_channel_trigger_txku()
3663 int ossl_quic_channel_ping(QUIC_CHANNEL *ch) in ossl_quic_channel_ping() argument
3665 int pn_space = ossl_quic_enc_level_to_pn_space(ch->tx_enc_level); in ossl_quic_channel_ping()
3667 ossl_quic_tx_packetiser_schedule_ack_eliciting(ch->txp, pn_space); in ossl_quic_channel_ping()
3672 uint16_t ossl_quic_channel_get_diag_num_rx_ack(QUIC_CHANNEL *ch) in ossl_quic_channel_get_diag_num_rx_ack() argument
3674 return ch->diag_num_rx_ack; in ossl_quic_channel_get_diag_num_rx_ack()
3677 void ossl_quic_channel_get_diag_local_cid(QUIC_CHANNEL *ch, QUIC_CONN_ID *cid) in ossl_quic_channel_get_diag_local_cid() argument
3679 *cid = ch->cur_local_cid; in ossl_quic_channel_get_diag_local_cid()
3682 int ossl_quic_channel_have_generated_transport_params(const QUIC_CHANNEL *ch) in ossl_quic_channel_have_generated_transport_params() argument
3684 return ch->got_local_transport_params; in ossl_quic_channel_have_generated_transport_params()
3687 void ossl_quic_channel_set_max_idle_timeout_request(QUIC_CHANNEL *ch, uint64_t ms) in ossl_quic_channel_set_max_idle_timeout_request() argument
3689 ch->max_idle_timeout_local_req = ms; in ossl_quic_channel_set_max_idle_timeout_request()
3691 uint64_t ossl_quic_channel_get_max_idle_timeout_request(const QUIC_CHANNEL *ch) in ossl_quic_channel_get_max_idle_timeout_request() argument
3693 return ch->max_idle_timeout_local_req; in ossl_quic_channel_get_max_idle_timeout_request()
3696 uint64_t ossl_quic_channel_get_max_idle_timeout_peer_request(const QUIC_CHANNEL *ch) in ossl_quic_channel_get_max_idle_timeout_peer_request() argument
3698 return ch->max_idle_timeout_remote_req; in ossl_quic_channel_get_max_idle_timeout_peer_request()
3701 uint64_t ossl_quic_channel_get_max_idle_timeout_actual(const QUIC_CHANNEL *ch) in ossl_quic_channel_get_max_idle_timeout_actual() argument
3703 return ch->max_idle_timeout; in ossl_quic_channel_get_max_idle_timeout_actual()