Lines Matching +full:precondition +full:- +full:timeout

2  * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
53 * - a pointer to the QUIC_CONNECTION (regardless of whether a QCSO or QSSO
55 * - a pointer to any applicable QUIC_XSO (e.g. if a QSSO was passed, or if
57 * - whether a QSSO was passed (xso == NULL must not be used to determine this
58 * because it may be non-NULL when a QCSO is passed if that QCSO has a
60 * - a pointer to a QUIC_LISTENER object, if one is relevant;
61 * - whether we are in "I/O context", meaning that non-normal errors can
81 if (!ctx->in_io) in quic_set_last_error()
84 if (ctx->is_stream && ctx->xso != NULL) in quic_set_last_error()
85 ctx->xso->last_error = last_error; in quic_set_last_error()
86 else if (!ctx->is_stream && ctx->qc != NULL) in quic_set_last_error()
87 ctx->qc->last_error = last_error; in quic_set_last_error()
99 assert(ctx->in_io); in quic_raise_normal_error()
106 * Raise a 'non-normal' error, meaning any error that is not reported via
129 if (reason == SSL_R_PROTOCOL_IS_SHUTDOWN && ctx->qc != NULL) in quic_raise_non_normal_error()
130 ossl_quic_channel_restore_err_state(ctx->qc->ch); in quic_raise_non_normal_error()
169 * one may be auto-created if possible.
171 * If QCTX_REMOTE_INIT is set, an auto-created default XSO is
174 * If it is not set, an auto-created default XSO is
185 * Begin an I/O context. If not set, begins a non-I/O context.
246 * qd non-NULL maybe maybe maybe
247 * ql NULL non-NULL maybe maybe
248 * qc NULL NULL non-NULL non-NULL
249 * xso NULL NULL maybe non-NULL
266 ctx->obj = NULL; in expect_quic_as()
267 ctx->qd = NULL; in expect_quic_as()
268 ctx->ql = NULL; in expect_quic_as()
269 ctx->qc = NULL; in expect_quic_as()
270 ctx->xso = NULL; in expect_quic_as()
271 ctx->is_stream = 0; in expect_quic_as()
272 ctx->is_listener = 0; in expect_quic_as()
273 ctx->is_domain = 0; in expect_quic_as()
274 ctx->in_io = ((flags & QCTX_IO) != 0); in expect_quic_as()
281 switch (s->type) { in expect_quic_as()
289 ctx->obj = &qd->obj; in expect_quic_as()
290 ctx->qd = qd; in expect_quic_as()
291 ctx->is_domain = 1; in expect_quic_as()
301 ctx->obj = &ql->obj; in expect_quic_as()
302 ctx->qd = ql->domain; in expect_quic_as()
303 ctx->ql = ql; in expect_quic_as()
304 ctx->is_listener = 1; in expect_quic_as()
309 ctx->obj = &qc->obj; in expect_quic_as()
310 ctx->qd = qc->domain; in expect_quic_as()
311 ctx->ql = qc->listener; /* never changes, so can be read without lock */ in expect_quic_as()
312 ctx->qc = qc; in expect_quic_as()
323 if ((flags & QCTX_AUTO_S) != 0 && qc->default_xso == NULL) { in expect_quic_as()
344 && (qc->default_xso == NULL || (flags & QCTX_S) == 0)) { in expect_quic_as()
349 ctx->xso = qc->default_xso; in expect_quic_as()
359 ctx->obj = &xso->obj; in expect_quic_as()
360 ctx->qd = xso->conn->domain; in expect_quic_as()
361 ctx->ql = xso->conn->listener; in expect_quic_as()
362 ctx->qc = xso->conn; in expect_quic_as()
363 ctx->xso = xso; in expect_quic_as()
364 ctx->is_stream = 1; in expect_quic_as()
441 * not. If it is -1, do not instantiate a default XSO if one does not yet exist.
464 * Like expect_quic_cs(), but fails if called on a QUIC_XSO. ctx->xso may still
465 * be non-NULL if the QCSO has a default stream.
476 * Precondition: Domain mutex is not held (unchecked)
481 assert(ctx->obj != NULL); in qctx_lock()
482 ossl_crypto_mutex_lock(ossl_quic_obj_get0_mutex(ctx->obj)); in qctx_lock()
486 /* Precondition: Channel mutex is held (unchecked) */
491 assert(ctx->obj != NULL); in qctx_unlock()
492 ossl_crypto_mutex_unlock(ossl_quic_obj_get0_mutex(ctx->obj)); in qctx_unlock()
499 ctx->in_io = 1; in qctx_lock_for_io()
512 * *most* mutating API calls, particularly stream-related operations for send
522 if (qc->shutting_down || ossl_quic_channel_is_term_any(qc->ch)) in quic_mutation_allowed()
525 if (req_active && !ossl_quic_channel_is_active(qc->ch)) in quic_mutation_allowed()
533 return ctx->obj->parent_obj == NULL; in qctx_is_top_level()
538 return ossl_quic_obj_blocking(ctx->obj); in qctx_blocking()
544 * Precondition: Must have a channel.
545 * Precondition: Must hold channel lock (unchecked).
555 qeng = ossl_quic_obj_get0_engine(ctx->obj); in block_until_pred()
559 * Any attempt to block auto-disables tick inhibition as otherwise we will in block_until_pred()
569 * QUIC Front-End I/O API: Initialization
595 if (ctx->method == OSSL_QUIC_server_method()) { in ossl_quic_new()
608 if ((qc->mutex = ossl_crypto_mutex_new()) == NULL) { in ossl_quic_new()
615 qc->tls = ossl_ssl_connection_new_int(ctx, &qc->obj.ssl, TLS_method()); in ossl_quic_new()
616 if (qc->tls == NULL || (sc = SSL_CONNECTION_FROM_SSL(qc->tls)) == NULL) { in ossl_quic_new()
622 sc->s3.flags |= TLS1_FLAGS_QUIC | TLS1_FLAGS_QUIC_INTERNAL; in ossl_quic_new()
625 sc->options &= OSSL_QUIC_PERMITTED_OPTIONS_CONN; in ossl_quic_new()
626 sc->pha_enabled = 0; in ossl_quic_new()
630 qc->is_thread_assisted in ossl_quic_new()
631 = ((ctx->domain_flags & SSL_DOMAIN_FLAG_THREAD_ASSISTED) != 0); in ossl_quic_new()
634 qc->as_server = 0; in ossl_quic_new()
635 qc->as_server_state = qc->as_server; in ossl_quic_new()
640 ossl_quic_channel_set_msg_callback(qc->ch, ctx->msg_callback, &qc->obj.ssl); in ossl_quic_new()
641 ossl_quic_channel_set_msg_callback_arg(qc->ch, ctx->msg_callback_arg); in ossl_quic_new()
644 if (!ossl_quic_obj_init(&qc->obj, ctx, SSL_TYPE_QUIC_CONNECTION, NULL, in ossl_quic_new()
645 qc->engine, qc->port)) { in ossl_quic_new()
650 /* Initialise libssl APL-related state. */ in ossl_quic_new()
651 qc->default_stream_mode = SSL_DEFAULT_STREAM_MODE_AUTO_BIDI; in ossl_quic_new()
652 qc->default_ssl_mode = qc->obj.ssl.ctx->mode; in ossl_quic_new()
653 qc->default_ssl_options = qc->obj.ssl.ctx->options & OSSL_QUIC_PERMITTED_OPTIONS; in ossl_quic_new()
654 qc->incoming_stream_policy = SSL_INCOMING_STREAM_POLICY_AUTO; in ossl_quic_new()
655 qc->last_error = SSL_ERROR_NONE; in ossl_quic_new()
662 * or server-initiated, which depends on who transmits first. Since we do in ossl_quic_new()
663 * not know whether the application will be using a client-transmits-first in ossl_quic_new()
664 * or server-transmits-first protocol, we defer default XSO creation until in ossl_quic_new()
666 * we take that as a cue that the client is expecting a server-initiated in ossl_quic_new()
669 return &qc->obj.ssl; in ossl_quic_new()
694 SSL_free(qc->tls); in qc_cleanup()
695 qc->tls = NULL; in qc_cleanup()
697 ossl_quic_channel_free(qc->ch); in qc_cleanup()
698 qc->ch = NULL; in qc_cleanup()
700 if (qc->port != NULL && qc->listener == NULL && qc->pending == 0) { /* TODO */ in qc_cleanup()
701 quic_unref_port_bios(qc->port); in qc_cleanup()
702 ossl_quic_port_free(qc->port); in qc_cleanup()
703 qc->port = NULL; in qc_cleanup()
705 ossl_quic_engine_free(qc->engine); in qc_cleanup()
706 qc->engine = NULL; in qc_cleanup()
712 ossl_crypto_mutex_unlock(qc->mutex); in qc_cleanup()
714 if (qc->listener == NULL && qc->pending == 0) in qc_cleanup()
715 ossl_crypto_mutex_free(&qc->mutex); in qc_cleanup()
723 quic_unref_port_bios(ctx->ql->port); in quic_free_listener()
724 ossl_quic_port_drop_incoming(ctx->ql->port); in quic_free_listener()
725 ossl_quic_port_free(ctx->ql->port); in quic_free_listener()
727 if (ctx->ql->domain == NULL) { in quic_free_listener()
728 ossl_quic_engine_free(ctx->ql->engine); in quic_free_listener()
730 ossl_crypto_mutex_free(&ctx->ql->mutex); in quic_free_listener()
733 SSL_free(&ctx->ql->domain->obj.ssl); in quic_free_listener()
741 ossl_quic_engine_free(ctx->qd->engine); in quic_free_domain()
743 ossl_crypto_mutex_free(&ctx->qd->mutex); in quic_free_domain()
777 assert(ctx.qc->num_xso > 0); in ossl_quic_free()
778 --ctx.qc->num_xso; in ossl_quic_free()
780 /* If a stream's send part has not been finished, auto-reset it. */ in ossl_quic_free()
781 if (( ctx.xso->stream->send_state == QUIC_SSTREAM_STATE_READY in ossl_quic_free()
782 || ctx.xso->stream->send_state == QUIC_SSTREAM_STATE_SEND) in ossl_quic_free()
783 && !ossl_quic_sstream_get_final_size(ctx.xso->stream->sstream, NULL)) in ossl_quic_free()
784 ossl_quic_stream_map_reset_stream_send_part(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
785 ctx.xso->stream, 0); in ossl_quic_free()
788 if ( ctx.xso->stream->recv_state == QUIC_RSTREAM_STATE_RECV in ossl_quic_free()
789 || ctx.xso->stream->recv_state == QUIC_RSTREAM_STATE_SIZE_KNOWN) in ossl_quic_free()
790 ossl_quic_stream_map_stop_sending_recv_part(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
791 ctx.xso->stream, 0); in ossl_quic_free()
794 ctx.xso->stream->deleted = 1; in ossl_quic_free()
795 ossl_quic_stream_map_update_state(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
796 ctx.xso->stream); in ossl_quic_free()
798 is_default = (ctx.xso == ctx.qc->default_xso); in ossl_quic_free()
809 SSL_free(&ctx.qc->obj.ssl); in ossl_quic_free()
819 if (ctx.qc->default_xso != NULL) { in ossl_quic_free()
820 QUIC_XSO *xso = ctx.qc->default_xso; in ossl_quic_free()
823 SSL_free(&xso->obj.ssl); in ossl_quic_free()
825 ctx.qc->default_xso = NULL; in ossl_quic_free()
829 assert(ctx.qc->num_xso == 0); in ossl_quic_free()
832 if (ctx.qc->is_thread_assisted && ctx.qc->started) { in ossl_quic_free()
833 ossl_quic_thread_assist_wait_stopped(&ctx.qc->thread_assist); in ossl_quic_free()
834 ossl_quic_thread_assist_cleanup(&ctx.qc->thread_assist); in ossl_quic_free()
845 if (ctx.qc->listener != NULL) in ossl_quic_free()
846 SSL_free(&ctx.qc->listener->obj.ssl); in ossl_quic_free()
847 if (ctx.qc->domain != NULL) in ossl_quic_free()
848 SSL_free(&ctx.qc->domain->obj.ssl); in ossl_quic_free()
861 /* No-op. */ in ossl_quic_deinit()
899 ossl_quic_engine_set_time_cb(ctx.obj->engine, now_cb, now_cb_arg); in ossl_quic_set_override_now_cb()
913 if (ctx.qc->is_thread_assisted && ctx.qc->started) in ossl_quic_conn_force_assist_thread_wake()
914 ossl_quic_thread_assist_notify_deadline_changed(&ctx.qc->thread_assist); in ossl_quic_conn_force_assist_thread_wake()
921 qc->default_xso_created = 1; in qc_touch_default_xso()
938 if (qc->default_xso != xso) { in qc_set_default_xso_keep_ref()
939 *old_xso = qc->default_xso; /* transfer old XSO ref to caller */ in qc_set_default_xso_keep_ref()
941 qc->default_xso = xso; in qc_set_default_xso_keep_ref()
948 if (!ossl_assert(SSL_up_ref(&qc->obj.ssl))) in qc_set_default_xso_keep_ref()
962 CRYPTO_DOWN_REF(&qc->obj.ssl.references, &refs); in qc_set_default_xso_keep_ref()
983 SSL_free(&old_xso->obj.ssl); in qc_set_default_xso()
989 int cleanse = ((xso->ssl_options & SSL_OP_CLEANSE_PLAINTEXT) != 0); in xso_update_options()
991 if (xso->stream->rstream != NULL) in xso_update_options()
992 ossl_quic_rstream_set_cleanse(xso->stream->rstream, cleanse); in xso_update_options()
994 if (xso->stream->sstream != NULL) in xso_update_options()
995 ossl_quic_sstream_set_cleanse(xso->stream->sstream, cleanse); in xso_update_options()
1000 * ---------------
1003 * - configures the handshake-layer options;
1004 * - configures the default data-plane options for new streams;
1005 * - configures the data-plane options on the default XSO, if there is one.
1008 * - configures data-plane options for that stream only.
1029 SSL_clear_options(ctx.qc->tls, hs_mask_value); in quic_mask_or_options()
1030 SSL_set_options(ctx.qc->tls, hs_or_value); in quic_mask_or_options()
1033 ctx.qc->default_ssl_options in quic_mask_or_options()
1034 = ((ctx.qc->default_ssl_options & ~mask_value) | or_value) in quic_mask_or_options()
1038 ret = ctx.qc->default_ssl_options; in quic_mask_or_options()
1040 ctx.xso->ssl_options in quic_mask_or_options()
1041 = ((ctx.xso->ssl_options & ~mask_value) | or_value) in quic_mask_or_options()
1047 ret = ctx.xso->ssl_options; in quic_mask_or_options()
1072 * QUIC Front-End I/O API: Network BIO Configuration
1077 * - It is more or less a requirement that we use non-blocking network I/O;
1082 * non-blocking mode. We could try to do select() before calling send() or
1088 * Timeouts could be handled via setsockopt() socket timeout options, but
1094 * be made non-blocking. However some OSes (e.g. Windows) do not support
1097 * As such, we need to configure any FD in non-blocking mode. This may
1103 * - We support both blocking and non-blocking operation in terms of the API
1110 * - We need to determine our initial destination UDP address. The "natural"
1122 * - We also need to support memory BIOs (e.g. BIO_dgram_pair) or custom BIOs.
1123 * Currently we do this by only supporting non-blocking mode.
1254 /* Sanity check - can we support the request given the current network BIO? */ in ossl_quic_conn_set_blocking_mode()
1257 * If called directly on a top-level object (QCSO or QLSO), update our in ossl_quic_conn_set_blocking_mode()
1261 ossl_quic_engine_update_poll_descriptors(ctx.obj->engine, /*force=*/1); in ossl_quic_conn_set_blocking_mode()
1290 if (ctx.qc->started) in ossl_quic_conn_set_initial_peer_addr()
1295 BIO_ADDR_clear(&ctx.qc->init_peer_addr); in ossl_quic_conn_set_initial_peer_addr()
1299 return BIO_ADDR_copy(&ctx.qc->init_peer_addr, peer_addr); in ossl_quic_conn_set_initial_peer_addr()
1303 * QUIC Front-End I/O API: Asynchronous I/O Management
1312 /* SSL_handle_events; performs QUIC I/O and timeout processing. */
1331 * immediately. If no timeout is currently active, *is_infinite is set to 1 and
1356 * harmless long timeout. in ossl_quic_get_event_timeout()
1358 tv->tv_sec = 1000000; in ossl_quic_get_event_timeout()
1359 tv->tv_usec = 0; in ossl_quic_get_event_timeout()
1363 basetime = ossl_quic_engine_get_time(ctx.obj->engine); in ossl_quic_get_event_timeout()
1444 * QUIC Front-End I/O API: Connection Lifecycle Operations
1462 if (qc->shutting_down) in qc_shutdown_flush_init()
1465 qsm = ossl_quic_channel_get_qsm(qc->ch); in qc_shutdown_flush_init()
1468 qc->shutting_down = 1; in qc_shutdown_flush_init()
1471 /* Returns 1 if all shutdown-flush streams have been done with. */
1475 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(qc->ch); in qc_shutdown_flush_finished()
1477 return qc->shutting_down in qc_shutdown_flush_finished()
1486 return ossl_quic_channel_is_terminated(qc->ch); in quic_shutdown_wait()
1494 return ossl_quic_channel_is_term_any(qc->ch) in quic_shutdown_flush_wait()
1501 return ossl_quic_channel_is_term_any(qc->ch); in quic_shutdown_peer_wait()
1516 return -1; in ossl_quic_conn_shutdown()
1520 return -1; in ossl_quic_conn_shutdown()
1525 if (ossl_quic_channel_is_terminated(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1553 if (wait_peer && !ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1564 if (!ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1565 ret = 0; /* peer hasn't closed yet - still not done */ in ossl_quic_conn_shutdown()
1570 * We are at least terminating - go through the normal process of in ossl_quic_conn_shutdown()
1576 ctx.qc->shutting_down = 1; in ossl_quic_conn_shutdown()
1579 * This call is a no-op if we are already terminating, so it doesn't in ossl_quic_conn_shutdown()
1582 ossl_quic_channel_local_close(ctx.qc->ch, in ossl_quic_conn_shutdown()
1583 args != NULL ? args->quic_error_code : 0, in ossl_quic_conn_shutdown()
1584 args != NULL ? args->quic_reason : NULL); in ossl_quic_conn_shutdown()
1586 SSL_set_shutdown(ctx.qc->tls, SSL_SENT_SHUTDOWN); in ossl_quic_conn_shutdown()
1588 if (ossl_quic_channel_is_terminated(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1605 ret = ossl_quic_channel_is_terminated(ctx.qc->ch); in ossl_quic_conn_shutdown()
1626 ctx.qc->default_ssl_mode |= (uint32_t)larg; in ossl_quic_ctrl()
1634 if (ctx.xso->aon_write_in_progress) in ossl_quic_ctrl()
1637 ctx.xso->ssl_mode |= (uint32_t)larg; in ossl_quic_ctrl()
1638 return ctx.xso->ssl_mode; in ossl_quic_ctrl()
1641 return ctx.qc->default_ssl_mode; in ossl_quic_ctrl()
1647 ctx.qc->default_ssl_mode &= ~(uint32_t)larg; in ossl_quic_ctrl()
1650 ctx.xso->ssl_mode &= ~(uint32_t)larg; in ossl_quic_ctrl()
1651 return ctx.xso->ssl_mode; in ossl_quic_ctrl()
1654 return ctx.qc->default_ssl_mode; in ossl_quic_ctrl()
1660 ossl_quic_channel_set_msg_callback_arg(ctx.qc->ch, parg); in ossl_quic_ctrl()
1662 return SSL_ctrl(ctx.qc->tls, cmd, larg, parg); in ossl_quic_ctrl()
1675 return ossl_quic_handle_events(s) == 1 ? 1 : -1; in ossl_quic_ctrl()
1697 return ossl_ctrl_internal(&ctx.qc->obj.ssl, cmd, larg, parg, /*no_quic=*/1); in ossl_quic_ctrl()
1709 if (ctx.qc->as_server_state == 0) in ossl_quic_set_connect_state()
1713 if (ctx.qc->started) { in ossl_quic_set_connect_state()
1719 ctx.qc->as_server_state = 0; in ossl_quic_set_connect_state()
1731 if (ctx.qc->as_server_state == 1) in ossl_quic_set_accept_state()
1735 if (ctx.qc->started) { in ossl_quic_set_accept_state()
1741 ctx.qc->as_server_state = 1; in ossl_quic_set_accept_state()
1752 int want = SSL_want(qc->tls); in tls_wants_non_io_retry()
1766 if (!quic_mutation_allowed(args->qc, /*req_active=*/1)) in quic_handshake_wait()
1767 return -1; in quic_handshake_wait()
1769 if (ossl_quic_channel_is_handshake_complete(args->qc->ch)) in quic_handshake_wait()
1772 if (tls_wants_non_io_retry(args->qc)) in quic_handshake_wait()
1780 assert(qc->ch != NULL); in configure_channel()
1782 if (!ossl_quic_channel_set_peer_addr(qc->ch, &qc->init_peer_addr)) in configure_channel()
1801 engine_args.libctx = ctx->libctx; in create_channel()
1802 engine_args.propq = ctx->propq; in create_channel()
1804 engine_args.mutex = qc->mutex; in create_channel()
1807 if (need_notifier_for_domain_flags(ctx->domain_flags)) in create_channel()
1810 qc->engine = ossl_quic_engine_new(&engine_args); in create_channel()
1811 if (qc->engine == NULL) { in create_channel()
1817 qc->port = ossl_quic_engine_create_port(qc->engine, &port_args); in create_channel()
1818 if (qc->port == NULL) { in create_channel()
1820 ossl_quic_engine_free(qc->engine); in create_channel()
1824 qc->ch = ossl_quic_port_create_outgoing(qc->port, qc->tls); in create_channel()
1825 if (qc->ch == NULL) { in create_channel()
1827 ossl_quic_port_free(qc->port); in create_channel()
1828 ossl_quic_engine_free(qc->engine); in create_channel()
1842 QUIC_CONNECTION *qc = ctx->qc; in ensure_channel_started()
1844 if (!qc->started) { in ensure_channel_started()
1851 if (!ossl_quic_channel_start(qc->ch)) { in ensure_channel_started()
1852 ossl_quic_channel_restore_err_state(qc->ch); in ensure_channel_started()
1859 if (qc->is_thread_assisted) in ensure_channel_started()
1860 if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch)) { in ensure_channel_started()
1868 qc->started = 1; in ensure_channel_started()
1876 QUIC_CONNECTION *qc = ctx->qc; in quic_do_handshake()
1880 if (ossl_quic_channel_is_handshake_complete(qc->ch)) in quic_do_handshake()
1887 if (qc->as_server != qc->as_server_state) { in quic_do_handshake()
1889 return -1; /* Non-protocol error */ in quic_do_handshake()
1892 port = ossl_quic_obj_get0_port(ctx->obj); in quic_do_handshake()
1898 return -1; /* Non-protocol error */ in quic_do_handshake()
1901 if (!qc->started && ossl_quic_port_is_addressed_w(port) in quic_do_handshake()
1902 && BIO_ADDR_family(&qc->init_peer_addr) == AF_UNSPEC) { in quic_do_handshake()
1915 if (!csm_analyse_init_peer_addr(net_wbio, &qc->init_peer_addr)) in quic_do_handshake()
1917 BIO_ADDR_clear(&qc->init_peer_addr); in quic_do_handshake()
1919 ossl_quic_channel_set_peer_addr(qc->ch, &qc->init_peer_addr); in quic_do_handshake()
1922 if (!qc->started in quic_do_handshake()
1924 && BIO_ADDR_family(&qc->init_peer_addr) == AF_UNSPEC) { in quic_do_handshake()
1930 return -1; /* Non-protocol error */ in quic_do_handshake()
1935 * non-blocking mode, which is fine. in quic_do_handshake()
1938 return -1; /* Non-protocol error */ in quic_do_handshake()
1940 if (ossl_quic_channel_is_handshake_complete(qc->ch)) in quic_do_handshake()
1948 if (ossl_quic_channel_is_handshake_complete(qc->ch)) in quic_do_handshake()
1952 if (ossl_quic_channel_is_term_any(qc->ch)) { in quic_do_handshake()
1955 } else if (ossl_quic_obj_desires_blocking(&qc->obj)) { in quic_do_handshake()
1959 * poll descriptor-enabled. This supports BIOs such as BIO_s_connect in quic_do_handshake()
1963 ossl_quic_engine_update_poll_descriptors(qc->obj.engine, /*force=*/1); in quic_do_handshake()
1982 return -1; /* Non-protocol error */ in quic_do_handshake()
1986 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_get_error(qc->tls, 0)); in quic_do_handshake()
1987 return -1; in quic_do_handshake()
1990 assert(ossl_quic_channel_is_handshake_complete(qc->ch)); in quic_do_handshake()
1995 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_get_error(qc->tls, 0)); in quic_do_handshake()
1996 return -1; in quic_do_handshake()
2001 * We can only get here in non-blocking mode. in quic_do_handshake()
2004 return -1; /* Non-protocol error */ in quic_do_handshake()
2026 /* Ensure we are in connect state (no-op if non-idle). */ in ossl_quic_connect()
2028 return -1; in ossl_quic_connect()
2037 /* Ensure we are in accept state (no-op if non-idle). */ in ossl_quic_accept()
2039 return -1; in ossl_quic_accept()
2046 * QUIC Front-End I/O API: Stream Lifecycle Operations
2062 QUIC_CONNECTION *qc = ctx->qc; in qc_try_create_default_xso_for_write()
2064 if (qc->default_xso_created in qc_try_create_default_xso_for_write()
2065 || qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in qc_try_create_default_xso_for_write()
2068 * default XSO we don't auto-create another one. in qc_try_create_default_xso_for_write()
2072 /* Create a locally-initiated stream. */ in qc_try_create_default_xso_for_write()
2073 if (qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_AUTO_UNI) in qc_try_create_default_xso_for_write()
2079 if (qc->default_xso == NULL) in qc_try_create_default_xso_for_write()
2098 if (!quic_mutation_allowed(args->qc, /*req_active=*/1)) { in quic_wait_for_stream()
2100 QUIC_RAISE_NON_NORMAL_ERROR(args->ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_wait_for_stream()
2101 return -1; in quic_wait_for_stream()
2104 args->qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(args->qc->ch), in quic_wait_for_stream()
2105 args->expect_id | QUIC_STREAM_DIR_BIDI); in quic_wait_for_stream()
2106 if (args->qs == NULL) in quic_wait_for_stream()
2107 args->qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(args->qc->ch), in quic_wait_for_stream()
2108 args->expect_id | QUIC_STREAM_DIR_UNI); in quic_wait_for_stream()
2110 if (args->qs != NULL) in quic_wait_for_stream()
2121 QUIC_CONNECTION *qc = ctx->qc; in qc_wait_for_default_xso_for_read()
2131 if (qc->default_xso_created in qc_wait_for_default_xso_for_read()
2132 || qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in qc_wait_for_default_xso_for_read()
2141 expect_id = qc->as_server in qc_wait_for_default_xso_for_read()
2145 qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
2148 qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
2154 qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
2162 if (ossl_quic_channel_is_term_any(qc->ch)) { in qc_wait_for_default_xso_for_read()
2165 /* Non-blocking mode, so just bail immediately. */ in qc_wait_for_default_xso_for_read()
2189 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(qc->ch), &rtt_info); in qc_wait_for_default_xso_for_read()
2190 ossl_quic_stream_map_remove_from_accept_queue(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
2197 if (qc->default_xso == NULL) in qc_wait_for_default_xso_for_read()
2214 if (!ossl_quic_obj_init(&xso->obj, qc->obj.ssl.ctx, SSL_TYPE_QUIC_XSO, in create_xso_from_stream()
2215 &qc->obj.ssl, NULL, NULL)) { in create_xso_from_stream()
2221 if (!SSL_up_ref(&qc->obj.ssl)) { in create_xso_from_stream()
2226 xso->conn = qc; in create_xso_from_stream()
2227 xso->ssl_mode = qc->default_ssl_mode; in create_xso_from_stream()
2228 xso->ssl_options in create_xso_from_stream()
2229 = qc->default_ssl_options & OSSL_QUIC_PERMITTED_OPTIONS_STREAM; in create_xso_from_stream()
2230 xso->last_error = SSL_ERROR_NONE; in create_xso_from_stream()
2232 xso->stream = qs; in create_xso_from_stream()
2234 ++qc->num_xso; in create_xso_from_stream()
2251 QUIC_CONNECTION *qc = args->qc; in quic_new_stream_wait()
2254 return -1; in quic_new_stream_wait()
2256 if (ossl_quic_channel_is_new_local_stream_admissible(qc->ch, args->is_uni)) in quic_new_stream_wait()
2266 QUIC_CONNECTION *qc = ctx->qc; in quic_conn_stream_new()
2282 && !ossl_quic_channel_is_new_local_stream_admissible(qc->ch, is_uni)) { in quic_conn_stream_new()
2297 /* Blocking mode - wait until we can get a stream. */ in quic_conn_stream_new()
2304 goto err; /* Non-protocol error */ in quic_conn_stream_new()
2308 qs = ossl_quic_channel_new_stream_local(qc->ch, is_uni); in quic_conn_stream_new()
2322 return &xso->obj.ssl; in quic_conn_stream_new()
2326 ossl_quic_stream_map_release(ossl_quic_channel_get_qsm(qc->ch), qs); in quic_conn_stream_new()
2346 * QUIC Front-End I/O API: Steady-State Operations
2349 * Here we dispatch calls to the steady-state front-end I/O API functions; that
2353 * Each function must handle both blocking and non-blocking modes. As discussed
2354 * above, all QUIC I/O is implemented using non-blocking mode internally.
2376 net_error = ossl_quic_channel_net_error(ctx.qc->ch); in ossl_quic_get_error()
2377 last_error = ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error; in ossl_quic_get_error()
2390 case SSL_ERROR_WANT_CONNECT: /* never used - UDP is connectionless */ in error_to_want()
2391 case SSL_ERROR_WANT_ACCEPT: /* never used - UDP is connectionless */ in error_to_want()
2424 w = error_to_want(ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error); in ossl_quic_want()
2432 * ---------
2437 * - both blocking and non-blocking operation at the application level,
2440 * - SSL_MODE_ENABLE_PARTIAL_WRITE being on or off;
2442 * - SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER.
2455 ossl_quic_stream_map_update_state(ossl_quic_channel_get_qsm(xso->conn->ch), in quic_post_write()
2456 xso->stream); in quic_post_write()
2459 ossl_quic_sstream_fin(xso->stream->sstream); in quic_post_write()
2468 ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(xso->conn->ch), 0); in quic_post_write()
2501 growth = spare_ - avail; in sstream_ensure_spare()
2518 QUIC_SSTREAM *sstream = xso->stream->sstream; in xso_sstream_append()
2520 uint64_t cwm = ossl_quic_txfc_get_cwm(&xso->stream->txfc); in xso_sstream_append()
2521 uint64_t permitted = (cwm >= cur ? cwm - cur : 0); in xso_sstream_append()
2538 if (!quic_mutation_allowed(args->xso->conn, /*req_active=*/1)) in quic_write_again()
2540 return -2; in quic_write_again()
2542 if (!quic_validate_for_write(args->xso, &args->err)) in quic_write_again()
2547 return -2; in quic_write_again()
2549 args->err = ERR_R_INTERNAL_ERROR; in quic_write_again()
2550 if (!xso_sstream_append(args->xso, args->buf, args->len, &actual_written)) in quic_write_again()
2551 return -2; in quic_write_again()
2553 quic_post_write(args->xso, actual_written > 0, in quic_write_again()
2554 args->len == actual_written, args->flags, 0); in quic_write_again()
2556 args->buf += actual_written; in quic_write_again()
2557 args->len -= actual_written; in quic_write_again()
2558 args->total_written += actual_written; in quic_write_again()
2560 if (args->len == 0) in quic_write_again()
2573 QUIC_XSO *xso = ctx->xso; in quic_write_blocking()
2603 args.len = len - actual_written; in quic_write_blocking()
2610 if (!quic_mutation_allowed(xso->conn, /*req_active=*/1)) in quic_write_blocking()
2628 * Functions to manage All-or-Nothing (AON) (that is, non-ENABLE_PARTIAL_WRITE)
2634 assert(!xso->aon_write_in_progress); in aon_write_begin()
2636 xso->aon_write_in_progress = 1; in aon_write_begin()
2637 xso->aon_buf_base = buf; in aon_write_begin()
2638 xso->aon_buf_pos = already_sent; in aon_write_begin()
2639 xso->aon_buf_len = buf_len; in aon_write_begin()
2644 xso->aon_write_in_progress = 0; in aon_write_finish()
2645 xso->aon_buf_base = NULL; in aon_write_finish()
2646 xso->aon_buf_pos = 0; in aon_write_finish()
2647 xso->aon_buf_len = 0; in aon_write_finish()
2655 QUIC_XSO *xso = ctx->xso; in quic_write_nonblocking_aon()
2659 = ((xso->ssl_mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER) != 0); in quic_write_nonblocking_aon()
2661 if (xso->aon_write_in_progress) { in quic_write_nonblocking_aon()
2667 if ((!accept_moving_buffer && xso->aon_buf_base != buf) in quic_write_nonblocking_aon()
2668 || len != xso->aon_buf_len) in quic_write_nonblocking_aon()
2675 actual_buf = (unsigned char *)buf + xso->aon_buf_pos; in quic_write_nonblocking_aon()
2676 actual_len = len - xso->aon_buf_pos; in quic_write_nonblocking_aon()
2695 if (xso->aon_write_in_progress) { in quic_write_nonblocking_aon()
2702 *written = xso->aon_buf_len; in quic_write_nonblocking_aon()
2711 if (xso->aon_write_in_progress) { in quic_write_nonblocking_aon()
2718 xso->aon_buf_pos += actual_written; in quic_write_nonblocking_aon()
2719 assert(xso->aon_buf_pos < xso->aon_buf_len); in quic_write_nonblocking_aon()
2732 * AON - We do not publicly admit to having appended anything until AON in quic_write_nonblocking_aon()
2743 QUIC_XSO *xso = ctx->xso; in quic_write_nonblocking_epw()
2767 if (xso == NULL || xso->stream == NULL) { in quic_validate_for_write()
2772 switch (xso->stream->send_state) { in quic_validate_for_write()
2779 qsm = ossl_quic_channel_get_qsm(xso->conn->ch); in quic_validate_for_write()
2781 if (!ossl_quic_stream_map_ensure_send_part_id(qsm, xso->stream)) { in quic_validate_for_write()
2789 if (ossl_quic_sstream_get_final_size(xso->stream->sstream, NULL)) { in quic_validate_for_write()
2817 /* Do not autocreate default XSO for zero-length writes. */ in ossl_quic_write_flags()
2828 ? ((ctx.xso->ssl_mode & SSL_MODE_ENABLE_PARTIAL_WRITE) != 0) : 0); in ossl_quic_write_flags()
2884 * --------
2902 if (xso == NULL || xso->stream == NULL) { in quic_validate_for_read()
2907 switch (xso->stream->recv_state) { in quic_validate_for_read()
2923 qsm = ossl_quic_channel_get_qsm(xso->conn->ch); in quic_validate_for_read()
2924 ossl_quic_stream_map_notify_app_read_reset_recv_part(qsm, xso->stream); in quic_validate_for_read()
2941 QUIC_CONNECTION *qc = ctx->qc; in quic_read_actual()
2943 if (!quic_validate_for_read(ctx->xso, &err, &eos)) { in quic_read_actual()
2945 ctx->xso->retired_fin = 1; in quic_read_actual()
2953 if (!ossl_quic_rstream_peek(stream->rstream, buf, buf_len, in quic_read_actual()
2958 if (!ossl_quic_rstream_read(stream->rstream, buf, buf_len, in quic_read_actual()
2966 * We have read at least one byte from the stream. Inform stream-level in quic_read_actual()
2973 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(qc->ch), &rtt_info); in quic_read_actual()
2975 if (!ossl_quic_rxfc_on_retire(&stream->rxfc, *bytes_read, in quic_read_actual()
2981 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(ctx->qc->ch); in quic_read_actual()
2983 ossl_quic_stream_map_notify_totally_read(qsm, ctx->xso->stream); in quic_read_actual()
2987 ossl_quic_stream_map_update_state(ossl_quic_channel_get_qsm(qc->ch), in quic_read_actual()
2992 ctx->xso->retired_fin = 1; in quic_read_actual()
3004 if (!quic_mutation_allowed(args->ctx->qc, /*req_active=*/1)) { in quic_read_again()
3006 QUIC_RAISE_NON_NORMAL_ERROR(args->ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_read_again()
3007 return -1; in quic_read_again()
3010 if (!quic_read_actual(args->ctx, args->stream, in quic_read_again()
3011 args->buf, args->len, args->bytes_read, in quic_read_again()
3012 args->peek)) in quic_read_again()
3013 return -1; in quic_read_again()
3015 if (*args->bytes_read > 0) in quic_read_again()
3047 * fail if we don't have one yet (non-blocking mode). in quic_read()
3054 ctx.xso = ctx.qc->default_xso; in quic_read()
3057 if (!quic_read_actual(&ctx, ctx.xso->stream, buf, len, bytes_read, peek)) { in quic_read()
3081 args.stream = ctx.xso->stream; in quic_read()
3105 if (!quic_read_actual(&ctx, ctx.xso->stream, buf, len, bytes_read, peek)) { in quic_read()
3133 * -----------
3147 if (!ctx.qc->started) in ossl_quic_pending_int()
3153 ctx.xso = ctx.qc->default_xso; in ossl_quic_pending_int()
3160 if (ctx.xso->stream == NULL) { in ossl_quic_pending_int()
3166 avail = ossl_quic_stream_recv_pending(ctx.xso->stream, in ossl_quic_pending_int()
3168 || ossl_quic_channel_has_pending(ctx.qc->ch) in ossl_quic_pending_int()
3169 || ossl_quic_channel_is_term_any(ctx.qc->ch); in ossl_quic_pending_int()
3171 avail = ossl_quic_stream_recv_pending(ctx.xso->stream, in ossl_quic_pending_int()
3186 /* Do we have app-side pending data or pending URXEs or RXEs? */ in ossl_quic_has_pending()
3192 * -------------------
3204 qs = ctx.xso->stream; in ossl_quic_conn_stream_conclude()
3216 if (ossl_quic_sstream_get_final_size(qs->sstream, NULL)) { in ossl_quic_conn_stream_conclude()
3221 ossl_quic_sstream_fin(qs->sstream); in ossl_quic_conn_stream_conclude()
3229 * --------------------
3263 * -------------------
3272 return &ctx.qc->obj.ssl; in ossl_quic_get0_connection()
3277 * -----------------
3286 return ctx.ql != NULL ? &ctx.ql->obj.ssl : NULL; in ossl_quic_get0_listener()
3291 * ---------------
3300 return ctx.qd != NULL ? &ctx.qd->obj.ssl : NULL; in ossl_quic_get0_domain()
3305 * --------------------
3315 *domain_flags = ctx.obj->domain_flags; in ossl_quic_get_domain_flags()
3322 * -------------------
3339 if (ctx.qc->default_xso_created in ossl_quic_get_stream_type()
3340 || ctx.qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in ossl_quic_get_stream_type()
3346 if (ossl_quic_stream_is_bidi(ctx.xso->stream)) in ossl_quic_get_stream_type()
3349 if (ossl_quic_stream_is_server_init(ctx.xso->stream) != ctx.qc->as_server) in ossl_quic_get_stream_type()
3357 * -----------------
3365 if (!expect_quic_with_stream_lock(s, /*remote_init=*/-1, /*io=*/0, &ctx)) in ossl_quic_get_stream_id()
3368 id = ctx.xso->stream->id; in ossl_quic_get_stream_id()
3376 * -------------------
3384 if (!expect_quic_with_stream_lock(s, /*remote_init=*/-1, /*io=*/0, &ctx)) in ossl_quic_is_stream_local()
3385 return -1; in ossl_quic_is_stream_local()
3387 is_local = ossl_quic_stream_is_local_init(ctx.xso->stream); in ossl_quic_is_stream_local()
3395 * ---------------------------
3407 if (ctx.qc->default_xso_created) { in ossl_quic_set_default_stream_mode()
3417 ctx.qc->default_stream_mode = mode; in ossl_quic_set_default_stream_mode()
3431 * -----------------
3450 return xso != NULL ? &xso->obj.ssl : NULL; in ossl_quic_detach_stream()
3455 * -----------------
3467 if (stream == NULL || stream->type != SSL_TYPE_QUIC_XSO) in ossl_quic_attach_stream()
3475 if (ctx.qc->default_xso != NULL) { in ossl_quic_attach_stream()
3485 if (!CRYPTO_GET_REF(&xso->obj.ssl.references, &nref)) { in ossl_quic_attach_stream()
3508 * ------------------------------
3513 switch (qc->incoming_stream_policy) { in qc_get_effective_incoming_stream_policy()
3515 if ((qc->default_xso == NULL && !qc->default_xso_created) in qc_get_effective_incoming_stream_policy()
3516 || qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in qc_get_effective_incoming_stream_policy()
3522 return qc->incoming_stream_policy; in qc_get_effective_incoming_stream_policy()
3532 ossl_quic_channel_set_incoming_stream_auto_reject(qc->ch, in qc_update_reject_policy()
3534 qc->incoming_stream_aec); in qc_update_reject_policy()
3553 ctx.qc->incoming_stream_policy = policy; in ossl_quic_set_incoming_stream_policy()
3554 ctx.qc->incoming_stream_aec = aec; in ossl_quic_set_incoming_stream_policy()
3570 * ----------------------------
3583 value_out = ossl_quic_channel_get_max_idle_timeout_request(ctx->qc->ch); in qc_getset_idle_timeout()
3593 if (ossl_quic_channel_have_generated_transport_params(ctx->qc->ch)) { in qc_getset_idle_timeout()
3599 ossl_quic_channel_set_max_idle_timeout_request(ctx->qc->ch, value_in); in qc_getset_idle_timeout()
3611 if (!ossl_quic_channel_is_handshake_complete(ctx->qc->ch)) { in qc_getset_idle_timeout()
3618 ? ossl_quic_channel_get_max_idle_timeout_actual(ctx->qc->ch) in qc_getset_idle_timeout()
3619 : ossl_quic_channel_get_max_idle_timeout_peer_request(ctx->qc->ch); in qc_getset_idle_timeout()
3653 ? ossl_quic_channel_get_remote_stream_count_avail(ctx->qc->ch, is_uni) in qc_get_stream_avail()
3654 : ossl_quic_channel_get_local_stream_count_avail(ctx->qc->ch, is_uni); in qc_get_stream_avail()
3665 QUIC_OBJ *obj = ctx->obj; in qctx_should_autotick()
3667 for (; (event_handling_mode = obj->event_handling_mode) == SSL_VALUE_EVENT_HANDLING_MODE_INHERIT in qctx_should_autotick()
3668 && obj->parent_obj != NULL; obj = obj->parent_obj); in qctx_should_autotick()
3679 ossl_quic_reactor_tick(ossl_quic_obj_get0_reactor(ctx->obj), 0); in qctx_maybe_autotick()
3711 ctx->obj->event_handling_mode = (int)value_out; in qc_getset_event_handling()
3713 value_out = ctx->obj->event_handling_mode; in qc_getset_event_handling()
3741 if (ctx->xso == NULL) { in qc_get_stream_write_buf_stat()
3746 if (!ossl_quic_stream_has_send(ctx->xso->stream)) { in qc_get_stream_write_buf_stat()
3751 if (ossl_quic_stream_has_send_buffer(ctx->xso->stream)) in qc_get_stream_write_buf_stat()
3752 value = getter(ctx->xso->stream->sstream); in qc_get_stream_write_buf_stat()
3848 * -----------------
3859 QUIC_CONNECTION *qc = args->ctx->qc; in wait_for_incoming_stream()
3860 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(qc->ch); in wait_for_incoming_stream()
3864 QUIC_RAISE_NON_NORMAL_ERROR(args->ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in wait_for_incoming_stream()
3865 return -1; in wait_for_incoming_stream()
3868 args->qs = ossl_quic_stream_map_peek_accept_queue(qsm); in wait_for_incoming_stream()
3869 if (args->qs != NULL) in wait_for_incoming_stream()
3897 qsm = ossl_quic_channel_get_qsm(ctx.qc->ch); in ossl_quic_accept_stream()
3926 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(ctx.qc->ch), &rtt_info); in ossl_quic_accept_stream()
3929 new_s = &xso->obj.ssl; in ossl_quic_accept_stream()
3941 * -------------------------------
3954 v = ossl_quic_stream_map_get_total_accept_queue_len(ossl_quic_channel_get_qsm(ctx.qc->ch)); in ossl_quic_get_accept_stream_queue_len()
3962 * ----------------
3977 qsm = ossl_quic_channel_get_qsm(ctx.qc->ch); in ossl_quic_stream_reset()
3978 qs = ctx.xso->stream; in ossl_quic_stream_reset()
3979 error_code = (args != NULL ? args->quic_error_code : 0); in ossl_quic_stream_reset()
3988 ctx.xso->requested_reset = 1; in ossl_quic_stream_reset()
3997 * -------------------------
4008 local_init = (ossl_quic_stream_is_server_init(qs) == qc->as_server); in quic_classify_stream()
4021 } else if (ossl_quic_channel_is_term_any(qc->ch)) { in quic_classify_stream()
4024 } else if (!is_write && qs->recv_state == QUIC_RSTREAM_STATE_DATA_READ) { in quic_classify_stream()
4027 } else if ((!is_write && qs->stop_sending) in quic_classify_stream()
4036 ? qs->stop_sending_aec in quic_classify_stream()
4037 : qs->reset_stream_aec; in quic_classify_stream()
4039 || (is_write && qs->peer_stop_sending)) { in quic_classify_stream()
4044 ? qs->peer_reset_stream_aec in quic_classify_stream()
4045 : qs->peer_stop_sending_aec; in quic_classify_stream()
4046 } else if (is_write && ossl_quic_sstream_get_final_size(qs->sstream, in quic_classify_stream()
4064 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, /*io=*/0, &ctx)) in quic_get_stream_state()
4067 quic_classify_stream(ctx.qc, ctx.xso->stream, is_write, &state, NULL); in quic_get_stream_state()
4079 * --------------------------
4088 * ------------------------------
4096 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, /*io=*/0, &ctx)) in quic_get_stream_error_code()
4097 return -1; in quic_get_stream_error_code()
4099 quic_classify_stream(ctx.qc, ctx.xso->stream, /*is_write=*/0, in quic_get_stream_error_code()
4110 return -1; in quic_get_stream_error_code()
4121 * -------------------------------
4130 * --------------------------
4137 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, /*io=*/0, &ctx)) in ossl_quic_set_write_buffer_size()
4140 if (!ossl_quic_stream_has_send(ctx.xso->stream)) { in ossl_quic_set_write_buffer_size()
4141 /* Called on a unidirectional receive-only stream - error. */ in ossl_quic_set_write_buffer_size()
4146 if (!ossl_quic_stream_has_send_buffer(ctx.xso->stream)) { in ossl_quic_set_write_buffer_size()
4149 * no longer need it, this is a no-op. in ossl_quic_set_write_buffer_size()
4155 if (!ossl_quic_sstream_set_buffer_size(ctx.xso->stream->sstream, size)) { in ossl_quic_set_write_buffer_size()
4169 * -----------------------
4179 return -1; in ossl_quic_get_conn_close_info()
4181 tc = ossl_quic_channel_get_terminate_cause(ctx.qc->ch); in ossl_quic_get_conn_close_info()
4185 info->error_code = tc->error_code; in ossl_quic_get_conn_close_info()
4186 info->frame_type = tc->frame_type; in ossl_quic_get_conn_close_info()
4187 info->reason = tc->reason; in ossl_quic_get_conn_close_info()
4188 info->reason_len = tc->reason_len; in ossl_quic_get_conn_close_info()
4189 info->flags = 0; in ossl_quic_get_conn_close_info()
4190 if (!tc->remote) in ossl_quic_get_conn_close_info()
4191 info->flags |= SSL_CONN_CLOSE_FLAG_LOCAL; in ossl_quic_get_conn_close_info()
4192 if (!tc->app) in ossl_quic_get_conn_close_info()
4193 info->flags |= SSL_CONN_CLOSE_FLAG_TRANSPORT; in ossl_quic_get_conn_close_info()
4199 * --------------
4225 if (!ossl_quic_channel_trigger_txku(ctx.qc->ch)) { in ossl_quic_key_update()
4237 * -----------------------
4258 * pre-allocation of the user_ssl object when a channel is created, rather than
4271 return (qc == NULL) ? NULL : &qc->obj.ssl; in alloc_port_user_ssl()
4275 * QUIC Front-End I/O API: Listeners
4281 * ----------------
4295 if ((ql->mutex = ossl_crypto_mutex_new()) == NULL) { in ossl_quic_new_listener()
4301 engine_args.libctx = ctx->libctx; in ossl_quic_new_listener()
4302 engine_args.propq = ctx->propq; in ossl_quic_new_listener()
4304 engine_args.mutex = ql->mutex; in ossl_quic_new_listener()
4307 if (need_notifier_for_domain_flags(ctx->domain_flags)) in ossl_quic_new_listener()
4310 if ((ql->engine = ossl_quic_engine_new(&engine_args)) == NULL) { in ossl_quic_new_listener()
4321 ql->port = ossl_quic_engine_create_port(ql->engine, &port_args); in ossl_quic_new_listener()
4322 if (ql->port == NULL) { in ossl_quic_new_listener()
4329 ossl_quic_port_set_allow_incoming(ql->port, 1); in ossl_quic_new_listener()
4332 if (!ossl_quic_obj_init(&ql->obj, ctx, SSL_TYPE_QUIC_LISTENER, NULL, in ossl_quic_new_listener()
4333 ql->engine, ql->port)) in ossl_quic_new_listener()
4336 return &ql->obj.ssl; in ossl_quic_new_listener()
4340 ossl_quic_engine_free(ql->engine); in ossl_quic_new_listener()
4343 ossl_crypto_mutex_free(&ql->mutex); in ossl_quic_new_listener()
4351 * ---------------------
4362 if (!SSL_up_ref(&ctx.qd->obj.ssl)) in ossl_quic_new_listener_from()
4372 port_args.channel_ctx = ssl->ctx; in ossl_quic_new_listener_from()
4378 ql->port = ossl_quic_engine_create_port(ctx.qd->engine, &port_args); in ossl_quic_new_listener_from()
4379 if (ql->port == NULL) { in ossl_quic_new_listener_from()
4384 ql->domain = ctx.qd; in ossl_quic_new_listener_from()
4385 ql->engine = ctx.qd->engine; in ossl_quic_new_listener_from()
4387 ql->mutex = ctx.qd->mutex; in ossl_quic_new_listener_from()
4399 ossl_quic_port_set_allow_incoming(ql->port, 1); in ossl_quic_new_listener_from()
4402 if (!ossl_quic_obj_init(&ql->obj, ssl->ctx, SSL_TYPE_QUIC_LISTENER, in ossl_quic_new_listener_from()
4403 &ctx.qd->obj.ssl, NULL, ql->port)) in ossl_quic_new_listener_from()
4407 return &ql->obj.ssl; in ossl_quic_new_listener_from()
4411 ossl_quic_port_free(ql->port); in ossl_quic_new_listener_from()
4415 SSL_free(&ctx.qd->obj.ssl); in ossl_quic_new_listener_from()
4422 * ---------------------
4446 if (!SSL_up_ref(&ctx.ql->obj.ssl)) in ossl_quic_new_from_listener()
4459 if (ssl->ctx->tokencache == NULL) in ossl_quic_new_from_listener()
4460 if ((ssl->ctx->tokencache = ossl_quic_new_token_store()) == NULL) in ossl_quic_new_from_listener()
4473 qc->listener = ql; in ossl_quic_new_from_listener()
4474 qc->engine = ql->engine; in ossl_quic_new_from_listener()
4475 qc->port = ql->port; in ossl_quic_new_from_listener()
4479 qc->mutex = ql->mutex; in ossl_quic_new_from_listener()
4482 qc->is_thread_assisted in ossl_quic_new_from_listener()
4483 = ((ql->obj.domain_flags & SSL_DOMAIN_FLAG_THREAD_ASSISTED) != 0); in ossl_quic_new_from_listener()
4487 qc->tls = ossl_ssl_connection_new_int(ql->obj.ssl.ctx, NULL, TLS_method()); in ossl_quic_new_from_listener()
4488 if (qc->tls == NULL || (sc = SSL_CONNECTION_FROM_SSL(qc->tls)) == NULL) { in ossl_quic_new_from_listener()
4492 sc->s3.flags |= TLS1_FLAGS_QUIC | TLS1_FLAGS_QUIC_INTERNAL; in ossl_quic_new_from_listener()
4494 qc->default_ssl_options = OSSL_QUIC_PERMITTED_OPTIONS; in ossl_quic_new_from_listener()
4495 qc->last_error = SSL_ERROR_NONE; in ossl_quic_new_from_listener()
4502 qc->ch = ossl_quic_port_create_outgoing(qc->port, qc->tls); in ossl_quic_new_from_listener()
4504 ossl_quic_channel_set_msg_callback(qc->ch, ql->obj.ssl.ctx->msg_callback, &qc->obj.ssl); in ossl_quic_new_from_listener()
4505 ossl_quic_channel_set_msg_callback_arg(qc->ch, ql->obj.ssl.ctx->msg_callback_arg); in ossl_quic_new_from_listener()
4513 if (!ossl_quic_obj_init(&qc->obj, ql->obj.ssl.ctx, in ossl_quic_new_from_listener()
4515 &ql->obj.ssl, NULL, NULL)) { in ossl_quic_new_from_listener()
4520 /* Initialise libssl APL-related state. */ in ossl_quic_new_from_listener()
4521 qc->default_stream_mode = SSL_DEFAULT_STREAM_MODE_AUTO_BIDI; in ossl_quic_new_from_listener()
4522 qc->default_ssl_mode = qc->obj.ssl.ctx->mode; in ossl_quic_new_from_listener()
4523 qc->default_ssl_options = qc->obj.ssl.ctx->options & OSSL_QUIC_PERMITTED_OPTIONS; in ossl_quic_new_from_listener()
4524 qc->incoming_stream_policy = SSL_INCOMING_STREAM_POLICY_AUTO; in ossl_quic_new_from_listener()
4525 qc->last_error = SSL_ERROR_NONE; in ossl_quic_new_from_listener()
4531 return &qc->obj.ssl; in ossl_quic_new_from_listener()
4539 SSL_free(&ctx.ql->obj.ssl); in ossl_quic_new_from_listener()
4546 * ----------
4551 if (ql->listening) in ql_listen()
4554 ossl_quic_port_set_allow_incoming(ql->port, 1); in ql_listen()
4555 ql->listening = 1; in ql_listen()
4578 * ---------------------
4585 return -1; in quic_accept_connection_wait()
4613 new_ch = ossl_quic_port_pop_incoming(ctx.ql->port); in ossl_quic_accept_connection()
4614 if (new_ch == NULL && ossl_quic_port_is_running(ctx.ql->port)) { in ossl_quic_accept_connection()
4617 ctx.ql->port, 0); in ossl_quic_accept_connection()
4624 if (!ossl_quic_port_is_running(ctx.ql->port)) in ossl_quic_accept_connection()
4627 new_ch = ossl_quic_port_pop_incoming(ctx.ql->port); in ossl_quic_accept_connection()
4630 if (new_ch == NULL && ossl_quic_port_is_running(ctx.ql->port)) { in ossl_quic_accept_connection()
4632 ossl_quic_reactor_tick(ossl_quic_engine_get0_reactor(ctx.ql->engine), 0); in ossl_quic_accept_connection()
4634 new_ch = ossl_quic_port_pop_incoming(ctx.ql->port); in ossl_quic_accept_connection()
4638 * port_make_channel pre-allocates our user_ssl for us for each newly in ossl_quic_accept_connection()
4648 qc->listener = ctx.ql; in ossl_quic_accept_connection()
4649 qc->pending = 0; in ossl_quic_accept_connection()
4650 if (!SSL_up_ref(&ctx.ql->obj.ssl)) { in ossl_quic_accept_connection()
4670 if (!ossl_quic_obj_init(&qc->obj, ql->obj.ssl.ctx, in create_qc_from_incoming_conn()
4672 &ql->obj.ssl, NULL, NULL)) { in create_qc_from_incoming_conn()
4677 ossl_quic_channel_get_peer_addr(ch, &qc->init_peer_addr); /* best effort */ in create_qc_from_incoming_conn()
4678 qc->pending = 1; in create_qc_from_incoming_conn()
4679 qc->engine = ql->engine; in create_qc_from_incoming_conn()
4680 qc->port = ql->port; in create_qc_from_incoming_conn()
4681 qc->ch = ch; in create_qc_from_incoming_conn()
4683 qc->mutex = ql->mutex; in create_qc_from_incoming_conn()
4685 qc->tls = ossl_quic_channel_get0_tls(ch); in create_qc_from_incoming_conn()
4686 qc->started = 1; in create_qc_from_incoming_conn()
4687 qc->as_server = 1; in create_qc_from_incoming_conn()
4688 qc->as_server_state = 1; in create_qc_from_incoming_conn()
4689 qc->default_stream_mode = SSL_DEFAULT_STREAM_MODE_AUTO_BIDI; in create_qc_from_incoming_conn()
4690 qc->default_ssl_options = ql->obj.ssl.ctx->options & OSSL_QUIC_PERMITTED_OPTIONS; in create_qc_from_incoming_conn()
4691 qc->incoming_stream_policy = SSL_INCOMING_STREAM_POLICY_AUTO; in create_qc_from_incoming_conn()
4692 qc->last_error = SSL_ERROR_NONE; in create_qc_from_incoming_conn()
4711 return (unsigned long)ossl_fnv1a_hash(item->hashkey, item->hashkey_len); in quic_token_hash()
4716 if (a->hashkey_len != b->hashkey_len) in quic_token_cmp()
4718 return memcmp(a->hashkey, b->hashkey, a->hashkey_len); in quic_token_cmp()
4729 newcache->cache = lh_QUIC_TOKEN_new(quic_token_hash, quic_token_cmp); in ossl_quic_new_token_store()
4730 if (newcache->cache == NULL) in ossl_quic_new_token_store()
4734 if ((newcache->mutex = ossl_crypto_mutex_new()) == NULL) in ossl_quic_new_token_store()
4738 if (!CRYPTO_NEW_REF(&newcache->references, 1)) in ossl_quic_new_token_store()
4762 if (!CRYPTO_DOWN_REF(&hdl->references, &refs)) in ossl_quic_free_token_store()
4769 ossl_crypto_mutex_free(&hdl->mutex); in ossl_quic_free_token_store()
4770 lh_QUIC_TOKEN_doall(hdl->cache, free_this_token); in ossl_quic_free_token_store()
4771 lh_QUIC_TOKEN_free(hdl->cache); in ossl_quic_free_token_store()
4784 * +---------------+ --\
4785 * | hashkey * |---| |
4787 * | token * |---|--| |
4789 * +---------------+<--| | --/
4792 * |---------------|<-----|
4795 * +---------------+
4797 * @param peer - the peer address that sent the token
4798 * @param token - the buffer holding the token
4799 * @param token_len - the size of token
4831 if (!CRYPTO_NEW_REF(&new_token->references, 1)) { in ossl_quic_build_new_token()
4836 new_token->hashkey_len = hashkey_len; in ossl_quic_build_new_token()
4838 new_token->hashkey = (uint8_t *)(new_token + 1); in ossl_quic_build_new_token()
4840 new_token->token = new_token->hashkey + hashkey_len; in ossl_quic_build_new_token()
4841 new_token->token_len = token_len; in ossl_quic_build_new_token()
4842 famptr = (int *)new_token->hashkey; in ossl_quic_build_new_token()
4852 memcpy(new_token->token, token, token_len); in ossl_quic_build_new_token()
4859 SSL_TOKEN_STORE *c = ctx->tokencache; in ossl_quic_set_peer_token()
4862 if (ctx->tokencache == NULL) in ossl_quic_set_peer_token()
4870 ossl_crypto_mutex_lock(c->mutex); in ossl_quic_set_peer_token()
4872 old = lh_QUIC_TOKEN_retrieve(c->cache, tok); in ossl_quic_set_peer_token()
4874 lh_QUIC_TOKEN_delete(c->cache, old); in ossl_quic_set_peer_token()
4877 lh_QUIC_TOKEN_insert(c->cache, tok); in ossl_quic_set_peer_token()
4879 ossl_crypto_mutex_unlock(c->mutex); in ossl_quic_set_peer_token()
4886 SSL_TOKEN_STORE *c = ctx->tokencache; in ossl_quic_get_peer_token()
4899 ossl_crypto_mutex_lock(c->mutex); in ossl_quic_get_peer_token()
4900 tok = lh_QUIC_TOKEN_retrieve(c->cache, key); in ossl_quic_get_peer_token()
4903 CRYPTO_UP_REF(&tok->references, &ret); in ossl_quic_get_peer_token()
4907 ossl_crypto_mutex_unlock(c->mutex); in ossl_quic_get_peer_token()
4916 if (!CRYPTO_DOWN_REF(&token->references, &refs)) in ossl_quic_free_peer_token()
4922 CRYPTO_FREE_REF(&token->references); in ossl_quic_free_peer_token()
4928 * -----------------------------------
4941 ret = ossl_quic_port_get_num_incoming_channels(ctx.ql->port); in ossl_quic_get_accept_connection_queue_len()
4948 * QUIC Front-End I/O API: Domains
4954 * --------------
4962 domain_flags = ctx->domain_flags; in ossl_quic_new_domain()
4968 domain_flags = ctx->domain_flags | flags; in ossl_quic_new_domain()
4979 if ((qd->mutex = ossl_crypto_mutex_new()) == NULL) { in ossl_quic_new_domain()
4985 engine_args.libctx = ctx->libctx; in ossl_quic_new_domain()
4986 engine_args.propq = ctx->propq; in ossl_quic_new_domain()
4988 engine_args.mutex = qd->mutex; in ossl_quic_new_domain()
4994 if ((qd->engine = ossl_quic_engine_new(&engine_args)) == NULL) { in ossl_quic_new_domain()
5000 if (!ossl_quic_obj_init(&qd->obj, ctx, SSL_TYPE_QUIC_DOMAIN, NULL, in ossl_quic_new_domain()
5001 qd->engine, NULL)) in ossl_quic_new_domain()
5004 ossl_quic_obj_set_domain_flags(&qd->obj, domain_flags); in ossl_quic_new_domain()
5005 return &qd->obj.ssl; in ossl_quic_new_domain()
5008 ossl_quic_engine_free(qd->engine); in ossl_quic_new_domain()
5010 ossl_crypto_mutex_free(&qd->mutex); in ossl_quic_new_domain()
5017 * QUIC Front-End I/O API: SSL_CTX Management
5038 ossl_quic_channel_set_msg_callback(ctx.qc->ch, (ossl_msg_cb)fp, in ossl_quic_callback_ctrl()
5039 &ctx.qc->obj.ssl); in ossl_quic_callback_ctrl()
5041 return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp);; in ossl_quic_callback_ctrl()
5045 return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp); in ossl_quic_callback_ctrl()
5064 if ((ciph->algorithm2 & SSL_QUIC) == 0) in ossl_quic_get_cipher_by_char()
5087 * ------------------
5097 if (ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_get_shutdown()
5099 if (!ossl_quic_channel_is_closing(ctx.qc->ch)) in ossl_quic_get_shutdown()
5126 * stored the fin state, so its not directly know-able here. Instead in test_poll_event_r()
5131 if (xso->stream->recv_state == QUIC_RSTREAM_STATE_DATA_READ) in test_poll_event_r()
5134 return ossl_quic_stream_has_recv_buffer(xso->stream) in test_poll_event_r()
5135 && ossl_quic_rstream_available(xso->stream->rstream, &avail, &fin) in test_poll_event_r()
5136 && (avail > 0 || (fin && !xso->retired_fin)); in test_poll_event_r()
5143 return ossl_quic_stream_has_recv(xso->stream) in test_poll_event_er()
5144 && ossl_quic_stream_recv_is_reset(xso->stream) in test_poll_event_er()
5145 && !xso->retired_fin; in test_poll_event_er()
5152 return !xso->conn->shutting_down in test_poll_event_w()
5153 && ossl_quic_stream_has_send_buffer(xso->stream) in test_poll_event_w()
5154 && ossl_quic_sstream_get_buffer_avail(xso->stream->sstream) in test_poll_event_w()
5155 && !ossl_quic_sstream_get_final_size(xso->stream->sstream, NULL) in test_poll_event_w()
5156 && ossl_quic_txfc_get_cwm(&xso->stream->txfc) in test_poll_event_w()
5157 > ossl_quic_sstream_get_cur_size(xso->stream->sstream) in test_poll_event_w()
5158 && quic_mutation_allowed(xso->conn, /*req_active=*/1); in test_poll_event_w()
5165 return ossl_quic_stream_has_send(xso->stream) in test_poll_event_ew()
5166 && xso->stream->peer_stop_sending in test_poll_event_ew()
5167 && !xso->requested_reset in test_poll_event_ew()
5168 && !xso->conn->shutting_down; in test_poll_event_ew()
5175 return ossl_quic_channel_is_term_any(qc->ch); in test_poll_event_ec()
5182 return ossl_quic_channel_is_terminated(qc->ch); in test_poll_event_ecd()
5189 return ossl_quic_stream_map_get_accept_queue_len(ossl_quic_channel_get_qsm(qc->ch), in test_poll_event_is()
5199 && ossl_quic_channel_get_local_stream_count_avail(qc->ch, is_uni) > 0; in test_poll_event_os()
5206 return !ossl_quic_port_is_running(ql->port); in test_poll_event_el()
5213 return ossl_quic_port_get_num_incoming_channels(ql->port) > 0; in test_poll_event_ic()
5228 if (ctx.qc != NULL && !ctx.qc->started) { in ossl_quic_conn_poll_events()
5229 /* We can only try to write on non-started connection. */ in ossl_quic_conn_poll_events()
5306 int nfd = -1; in ossl_quic_get_notifier_fd()
5309 return -1; in ossl_quic_get_notifier_fd()
5365 return ctx.qc->ch; in ossl_quic_conn_get_channel()
5371 OPENSSL_free(ctx->qlog_title); in ossl_quic_set_diag_title()
5372 ctx->qlog_title = NULL; in ossl_quic_set_diag_title()
5377 if ((ctx->qlog_title = OPENSSL_strdup(title)) == NULL) in ossl_quic_set_diag_title()