Lines Matching refs:ctx

27 static int qc_try_create_default_xso_for_write(QCTX *ctx);
28 static int qc_wait_for_default_xso_for_read(QCTX *ctx, int peek);
31 static void quic_lock_for_io(QCTX *ctx);
32 static int quic_do_handshake(QCTX *ctx);
38 static SSL *quic_conn_stream_new(QCTX *ctx, uint64_t flags, int need_lock);
43 static void qctx_maybe_autotick(QCTX *ctx);
44 static int qctx_should_autotick(QCTX *ctx);
118 static void quic_set_last_error(QCTX *ctx, int last_error) in quic_set_last_error() argument
120 if (!ctx->in_io) in quic_set_last_error()
123 if (ctx->is_stream && ctx->xso != NULL) in quic_set_last_error()
124 ctx->xso->last_error = last_error; in quic_set_last_error()
125 else if (!ctx->is_stream && ctx->qc != NULL) in quic_set_last_error()
126 ctx->qc->last_error = last_error; in quic_set_last_error()
135 static int quic_raise_normal_error(QCTX *ctx, in quic_raise_normal_error() argument
138 assert(ctx->in_io); in quic_raise_normal_error()
139 quic_set_last_error(ctx, err); in quic_raise_normal_error()
155 static int quic_raise_non_normal_error(QCTX *ctx, in quic_raise_non_normal_error() argument
165 if (ctx != NULL) { in quic_raise_non_normal_error()
166 quic_set_last_error(ctx, SSL_ERROR_SSL); in quic_raise_non_normal_error()
168 if (reason == SSL_R_PROTOCOL_IS_SHUTDOWN && ctx->qc != NULL) in quic_raise_non_normal_error()
169 ossl_quic_channel_restore_err_state(ctx->qc->ch); in quic_raise_non_normal_error()
182 #define QUIC_RAISE_NORMAL_ERROR(ctx, err) \ argument
183 quic_raise_normal_error((ctx), (err))
185 #define QUIC_RAISE_NON_NORMAL_ERROR(ctx, reason, msg) \ argument
186 quic_raise_non_normal_error((ctx), \
200 static int expect_quic(const SSL *s, QCTX *ctx) in expect_quic() argument
205 ctx->qc = NULL; in expect_quic()
206 ctx->xso = NULL; in expect_quic()
207 ctx->is_stream = 0; in expect_quic()
215 ctx->qc = qc; in expect_quic()
216 ctx->xso = qc->default_xso; in expect_quic()
217 ctx->is_stream = 0; in expect_quic()
218 ctx->in_io = 0; in expect_quic()
223 ctx->qc = xso->conn; in expect_quic()
224 ctx->xso = xso; in expect_quic()
225 ctx->is_stream = 1; in expect_quic()
226 ctx->in_io = 0; in expect_quic()
246 int in_io, QCTX *ctx) in expect_quic_with_stream_lock() argument
248 if (!expect_quic(s, ctx)) in expect_quic_with_stream_lock()
252 quic_lock_for_io(ctx); in expect_quic_with_stream_lock()
254 quic_lock(ctx->qc); in expect_quic_with_stream_lock()
256 if (ctx->xso == NULL && remote_init >= 0) { in expect_quic_with_stream_lock()
257 if (!quic_mutation_allowed(ctx->qc, /*req_active=*/0)) { in expect_quic_with_stream_lock()
258 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in expect_quic_with_stream_lock()
263 if (quic_do_handshake(ctx) < 1) in expect_quic_with_stream_lock()
268 if (!qc_try_create_default_xso_for_write(ctx)) in expect_quic_with_stream_lock()
271 if (!qc_wait_for_default_xso_for_read(ctx, /*peek=*/0)) in expect_quic_with_stream_lock()
275 ctx->xso = ctx->qc->default_xso; in expect_quic_with_stream_lock()
278 if (ctx->xso == NULL) { in expect_quic_with_stream_lock()
279 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_NO_STREAM, NULL); in expect_quic_with_stream_lock()
286 quic_unlock(ctx->qc); in expect_quic_with_stream_lock()
294 static int ossl_unused expect_quic_conn_only(const SSL *s, QCTX *ctx) in expect_quic_conn_only() argument
296 if (!expect_quic(s, ctx)) in expect_quic_conn_only()
299 if (ctx->is_stream) in expect_quic_conn_only()
300 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_CONN_USE_ONLY, NULL); in expect_quic_conn_only()
318 static void quic_lock_for_io(QCTX *ctx) in quic_lock_for_io() argument
320 quic_lock(ctx->qc); in quic_lock_for_io()
321 ctx->in_io = 1; in quic_lock_for_io()
329 quic_set_last_error(ctx, SSL_ERROR_NONE); in quic_lock_for_io()
380 SSL *ossl_quic_new(SSL_CTX *ctx) in ossl_quic_new() argument
400 if (!ossl_ssl_init(ssl_base, ctx, ctx->method, SSL_TYPE_QUIC_CONNECTION)) { in ossl_quic_new()
406 qc->tls = ossl_ssl_connection_new_int(ctx, ssl_base, TLS_method()); in ossl_quic_new()
428 qc->default_ssl_mode = qc->ssl.ctx->mode; in ossl_quic_new()
429 qc->default_ssl_options = qc->ssl.ctx->options & OSSL_QUIC_PERMITTED_OPTIONS; in ossl_quic_new()
438 ossl_quic_channel_set_msg_callback(qc->ch, ctx->msg_callback, ssl_base); in ossl_quic_new()
439 ossl_quic_channel_set_msg_callback_arg(qc->ch, ctx->msg_callback_arg); in ossl_quic_new()
471 QCTX ctx; in ossl_quic_free() local
475 if (!expect_quic(s, &ctx)) in ossl_quic_free()
478 quic_lock(ctx.qc); in ossl_quic_free()
480 if (ctx.is_stream) { in ossl_quic_free()
488 assert(ctx.qc->num_xso > 0); in ossl_quic_free()
489 --ctx.qc->num_xso; in ossl_quic_free()
492 if (( ctx.xso->stream->send_state == QUIC_SSTREAM_STATE_READY in ossl_quic_free()
493 || ctx.xso->stream->send_state == QUIC_SSTREAM_STATE_SEND) in ossl_quic_free()
494 && !ossl_quic_sstream_get_final_size(ctx.xso->stream->sstream, NULL)) in ossl_quic_free()
495 ossl_quic_stream_map_reset_stream_send_part(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
496 ctx.xso->stream, 0); in ossl_quic_free()
499 if ( ctx.xso->stream->recv_state == QUIC_RSTREAM_STATE_RECV in ossl_quic_free()
500 || ctx.xso->stream->recv_state == QUIC_RSTREAM_STATE_SIZE_KNOWN) in ossl_quic_free()
501 ossl_quic_stream_map_stop_sending_recv_part(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
502 ctx.xso->stream, 0); in ossl_quic_free()
505 ctx.xso->stream->deleted = 1; in ossl_quic_free()
506 ossl_quic_stream_map_update_state(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
507 ctx.xso->stream); in ossl_quic_free()
509 is_default = (ctx.xso == ctx.qc->default_xso); in ossl_quic_free()
510 quic_unlock(ctx.qc); in ossl_quic_free()
520 SSL_free(&ctx.qc->ssl); in ossl_quic_free()
530 if (ctx.qc->default_xso != NULL) { in ossl_quic_free()
531 QUIC_XSO *xso = ctx.qc->default_xso; in ossl_quic_free()
533 quic_unlock(ctx.qc); in ossl_quic_free()
535 quic_lock(ctx.qc); in ossl_quic_free()
536 ctx.qc->default_xso = NULL; in ossl_quic_free()
540 assert(ctx.qc->num_xso == 0); in ossl_quic_free()
543 if (ctx.qc->is_thread_assisted && ctx.qc->started) { in ossl_quic_free()
544 ossl_quic_thread_assist_wait_stopped(&ctx.qc->thread_assist); in ossl_quic_free()
545 ossl_quic_thread_assist_cleanup(&ctx.qc->thread_assist); in ossl_quic_free()
549 SSL_free(ctx.qc->tls); in ossl_quic_free()
551 ossl_quic_channel_free(ctx.qc->ch); in ossl_quic_free()
552 ossl_quic_port_free(ctx.qc->port); in ossl_quic_free()
553 ossl_quic_engine_free(ctx.qc->engine); in ossl_quic_free()
555 BIO_free_all(ctx.qc->net_rbio); in ossl_quic_free()
556 BIO_free_all(ctx.qc->net_wbio); in ossl_quic_free()
558 quic_unlock(ctx.qc); /* tsan doesn't like freeing locked mutexes */ in ossl_quic_free()
560 ossl_crypto_mutex_free(&ctx.qc->mutex); in ossl_quic_free()
585 QCTX ctx; in ossl_quic_reset() local
587 if (!expect_quic(s, &ctx)) in ossl_quic_reset()
597 QCTX ctx; in ossl_quic_clear() local
599 if (!expect_quic(s, &ctx)) in ossl_quic_clear()
610 QCTX ctx; in ossl_quic_conn_set_override_now_cb() local
612 if (!expect_quic(s, &ctx)) in ossl_quic_conn_set_override_now_cb()
615 quic_lock(ctx.qc); in ossl_quic_conn_set_override_now_cb()
617 ctx.qc->override_now_cb = now_cb; in ossl_quic_conn_set_override_now_cb()
618 ctx.qc->override_now_cb_arg = now_cb_arg; in ossl_quic_conn_set_override_now_cb()
620 quic_unlock(ctx.qc); in ossl_quic_conn_set_override_now_cb()
626 QCTX ctx; in ossl_quic_conn_force_assist_thread_wake() local
628 if (!expect_quic(s, &ctx)) in ossl_quic_conn_force_assist_thread_wake()
632 if (ctx.qc->is_thread_assisted && ctx.qc->started) in ossl_quic_conn_force_assist_thread_wake()
633 ossl_quic_thread_assist_notify_deadline_changed(&ctx.qc->thread_assist); in ossl_quic_conn_force_assist_thread_wake()
732 QCTX ctx; in quic_mask_or_options() local
735 if (!expect_quic(ssl, &ctx)) in quic_mask_or_options()
738 quic_lock(ctx.qc); in quic_mask_or_options()
740 if (!ctx.is_stream) { in quic_mask_or_options()
748 SSL_clear_options(ctx.qc->tls, hs_mask_value); in quic_mask_or_options()
749 SSL_set_options(ctx.qc->tls, hs_or_value); in quic_mask_or_options()
752 ctx.qc->default_ssl_options in quic_mask_or_options()
753 = ((ctx.qc->default_ssl_options & ~mask_value) | or_value) in quic_mask_or_options()
757 if (ctx.xso != NULL) { in quic_mask_or_options()
758 ctx.xso->ssl_options in quic_mask_or_options()
759 = ((ctx.xso->ssl_options & ~mask_value) | or_value) in quic_mask_or_options()
762 xso_update_options(ctx.xso); in quic_mask_or_options()
765 ret = ctx.is_stream ? ctx.xso->ssl_options : ctx.qc->default_ssl_options; in quic_mask_or_options()
767 quic_unlock(ctx.qc); in quic_mask_or_options()
877 QCTX ctx; in ossl_quic_conn_set0_net_rbio() local
879 if (!expect_quic(s, &ctx)) in ossl_quic_conn_set0_net_rbio()
882 if (ctx.qc->net_rbio == net_rbio) in ossl_quic_conn_set0_net_rbio()
885 if (!ossl_quic_port_set_net_rbio(ctx.qc->port, net_rbio)) in ossl_quic_conn_set0_net_rbio()
888 BIO_free_all(ctx.qc->net_rbio); in ossl_quic_conn_set0_net_rbio()
889 ctx.qc->net_rbio = net_rbio; in ossl_quic_conn_set0_net_rbio()
898 qc_update_can_support_blocking(ctx.qc); in ossl_quic_conn_set0_net_rbio()
899 qc_update_blocking_mode(ctx.qc); in ossl_quic_conn_set0_net_rbio()
904 QCTX ctx; in ossl_quic_conn_set0_net_wbio() local
906 if (!expect_quic(s, &ctx)) in ossl_quic_conn_set0_net_wbio()
909 if (ctx.qc->net_wbio == net_wbio) in ossl_quic_conn_set0_net_wbio()
912 if (!ossl_quic_port_set_net_wbio(ctx.qc->port, net_wbio)) in ossl_quic_conn_set0_net_wbio()
915 BIO_free_all(ctx.qc->net_wbio); in ossl_quic_conn_set0_net_wbio()
916 ctx.qc->net_wbio = net_wbio; in ossl_quic_conn_set0_net_wbio()
925 qc_update_can_support_blocking(ctx.qc); in ossl_quic_conn_set0_net_wbio()
926 qc_update_blocking_mode(ctx.qc); in ossl_quic_conn_set0_net_wbio()
931 QCTX ctx; in ossl_quic_conn_get_net_rbio() local
933 if (!expect_quic(s, &ctx)) in ossl_quic_conn_get_net_rbio()
936 return ctx.qc->net_rbio; in ossl_quic_conn_get_net_rbio()
941 QCTX ctx; in ossl_quic_conn_get_net_wbio() local
943 if (!expect_quic(s, &ctx)) in ossl_quic_conn_get_net_wbio()
946 return ctx.qc->net_wbio; in ossl_quic_conn_get_net_wbio()
951 QCTX ctx; in ossl_quic_conn_get_blocking_mode() local
953 if (!expect_quic(s, &ctx)) in ossl_quic_conn_get_blocking_mode()
956 if (ctx.is_stream) in ossl_quic_conn_get_blocking_mode()
957 return xso_blocking_mode(ctx.xso); in ossl_quic_conn_get_blocking_mode()
959 return qc_blocking_mode(ctx.qc); in ossl_quic_conn_get_blocking_mode()
966 QCTX ctx; in ossl_quic_conn_set_blocking_mode() local
968 if (!expect_quic(s, &ctx)) in ossl_quic_conn_set_blocking_mode()
971 quic_lock(ctx.qc); in ossl_quic_conn_set_blocking_mode()
979 if (!ctx.is_stream) in ossl_quic_conn_set_blocking_mode()
980 qc_update_can_support_blocking(ctx.qc); in ossl_quic_conn_set_blocking_mode()
983 if (!qc_can_support_blocking_cached(ctx.qc)) { in ossl_quic_conn_set_blocking_mode()
984 ret = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_UNSUPPORTED, NULL); in ossl_quic_conn_set_blocking_mode()
989 if (!ctx.is_stream) in ossl_quic_conn_set_blocking_mode()
994 ctx.qc->desires_blocking = (blocking != 0); in ossl_quic_conn_set_blocking_mode()
996 if (ctx.xso != NULL) { in ossl_quic_conn_set_blocking_mode()
1001 ctx.xso->desires_blocking = (blocking != 0); in ossl_quic_conn_set_blocking_mode()
1002 ctx.xso->desires_blocking_set = 1; in ossl_quic_conn_set_blocking_mode()
1007 qc_update_blocking_mode(ctx.qc); in ossl_quic_conn_set_blocking_mode()
1008 quic_unlock(ctx.qc); in ossl_quic_conn_set_blocking_mode()
1015 QCTX ctx; in ossl_quic_conn_set_initial_peer_addr() local
1017 if (!expect_quic(s, &ctx)) in ossl_quic_conn_set_initial_peer_addr()
1020 if (ctx.qc->started) in ossl_quic_conn_set_initial_peer_addr()
1021 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, in ossl_quic_conn_set_initial_peer_addr()
1025 BIO_ADDR_clear(&ctx.qc->init_peer_addr); in ossl_quic_conn_set_initial_peer_addr()
1029 ctx.qc->init_peer_addr = *peer_addr; in ossl_quic_conn_set_initial_peer_addr()
1062 QCTX ctx; in ossl_quic_handle_events() local
1064 if (!expect_quic(s, &ctx)) in ossl_quic_handle_events()
1067 quic_lock(ctx.qc); in ossl_quic_handle_events()
1068 if (ctx.qc->started) in ossl_quic_handle_events()
1069 ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(ctx.qc->ch), 0); in ossl_quic_handle_events()
1070 quic_unlock(ctx.qc); in ossl_quic_handle_events()
1084 QCTX ctx; in ossl_quic_get_event_timeout() local
1087 if (!expect_quic(s, &ctx)) in ossl_quic_get_event_timeout()
1090 quic_lock(ctx.qc); in ossl_quic_get_event_timeout()
1092 if (ctx.qc->started) in ossl_quic_get_event_timeout()
1094 = ossl_quic_reactor_get_tick_deadline(ossl_quic_channel_get_reactor(ctx.qc->ch)); in ossl_quic_get_event_timeout()
1106 quic_unlock(ctx.qc); in ossl_quic_get_event_timeout()
1110 *tv = ossl_time_to_timeval(ossl_time_subtract(deadline, get_time(ctx.qc))); in ossl_quic_get_event_timeout()
1112 quic_unlock(ctx.qc); in ossl_quic_get_event_timeout()
1119 QCTX ctx; in ossl_quic_get_rpoll_descriptor() local
1121 if (!expect_quic(s, &ctx)) in ossl_quic_get_rpoll_descriptor()
1124 if (desc == NULL || ctx.qc->net_rbio == NULL) in ossl_quic_get_rpoll_descriptor()
1125 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_INVALID_ARGUMENT, in ossl_quic_get_rpoll_descriptor()
1128 return BIO_get_rpoll_descriptor(ctx.qc->net_rbio, desc); in ossl_quic_get_rpoll_descriptor()
1134 QCTX ctx; in ossl_quic_get_wpoll_descriptor() local
1136 if (!expect_quic(s, &ctx)) in ossl_quic_get_wpoll_descriptor()
1139 if (desc == NULL || ctx.qc->net_wbio == NULL) in ossl_quic_get_wpoll_descriptor()
1140 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_INVALID_ARGUMENT, in ossl_quic_get_wpoll_descriptor()
1143 return BIO_get_wpoll_descriptor(ctx.qc->net_wbio, desc); in ossl_quic_get_wpoll_descriptor()
1150 QCTX ctx; in ossl_quic_get_net_read_desired() local
1153 if (!expect_quic(s, &ctx)) in ossl_quic_get_net_read_desired()
1156 quic_lock(ctx.qc); in ossl_quic_get_net_read_desired()
1157 ret = ossl_quic_reactor_net_read_desired(ossl_quic_channel_get_reactor(ctx.qc->ch)); in ossl_quic_get_net_read_desired()
1158 quic_unlock(ctx.qc); in ossl_quic_get_net_read_desired()
1167 QCTX ctx; in ossl_quic_get_net_write_desired() local
1169 if (!expect_quic(s, &ctx)) in ossl_quic_get_net_write_desired()
1172 quic_lock(ctx.qc); in ossl_quic_get_net_write_desired()
1173 ret = ossl_quic_reactor_net_write_desired(ossl_quic_channel_get_reactor(ctx.qc->ch)); in ossl_quic_get_net_write_desired()
1174 quic_unlock(ctx.qc); in ossl_quic_get_net_write_desired()
1245 QCTX ctx; in ossl_quic_conn_shutdown() local
1250 if (!expect_quic(s, &ctx)) in ossl_quic_conn_shutdown()
1253 if (ctx.is_stream) { in ossl_quic_conn_shutdown()
1254 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_CONN_USE_ONLY, NULL); in ossl_quic_conn_shutdown()
1258 quic_lock(ctx.qc); in ossl_quic_conn_shutdown()
1260 if (ossl_quic_channel_is_terminated(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1261 quic_unlock(ctx.qc); in ossl_quic_conn_shutdown()
1267 qc_shutdown_flush_init(ctx.qc); in ossl_quic_conn_shutdown()
1269 if (!qc_shutdown_flush_finished(ctx.qc)) { in ossl_quic_conn_shutdown()
1270 if (!no_block && qc_blocking_mode(ctx.qc)) { in ossl_quic_conn_shutdown()
1271 ret = block_until_pred(ctx.qc, quic_shutdown_flush_wait, ctx.qc, 0); in ossl_quic_conn_shutdown()
1277 qctx_maybe_autotick(&ctx); in ossl_quic_conn_shutdown()
1281 if (!qc_shutdown_flush_finished(ctx.qc)) { in ossl_quic_conn_shutdown()
1282 quic_unlock(ctx.qc); in ossl_quic_conn_shutdown()
1288 if (wait_peer && !ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1289 if (!no_block && qc_blocking_mode(ctx.qc)) { in ossl_quic_conn_shutdown()
1290 ret = block_until_pred(ctx.qc, quic_shutdown_peer_wait, ctx.qc, 0); in ossl_quic_conn_shutdown()
1296 qctx_maybe_autotick(&ctx); in ossl_quic_conn_shutdown()
1299 if (!ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1311 ctx.qc->shutting_down = 1; in ossl_quic_conn_shutdown()
1317 ossl_quic_channel_local_close(ctx.qc->ch, in ossl_quic_conn_shutdown()
1321 SSL_set_shutdown(ctx.qc->tls, SSL_SENT_SHUTDOWN); in ossl_quic_conn_shutdown()
1323 if (ossl_quic_channel_is_terminated(ctx.qc->ch)) { in ossl_quic_conn_shutdown()
1324 quic_unlock(ctx.qc); in ossl_quic_conn_shutdown()
1329 if (!no_block && qc_blocking_mode(ctx.qc) in ossl_quic_conn_shutdown()
1331 ret = block_until_pred(ctx.qc, quic_shutdown_wait, ctx.qc, 0); in ossl_quic_conn_shutdown()
1337 qctx_maybe_autotick(&ctx); in ossl_quic_conn_shutdown()
1340 ret = ossl_quic_channel_is_terminated(ctx.qc->ch); in ossl_quic_conn_shutdown()
1342 quic_unlock(ctx.qc); in ossl_quic_conn_shutdown()
1349 QCTX ctx; in ossl_quic_ctrl() local
1351 if (!expect_quic(s, &ctx)) in ossl_quic_ctrl()
1357 if (!ctx.is_stream) in ossl_quic_ctrl()
1358 ctx.qc->default_ssl_mode |= (uint32_t)larg; in ossl_quic_ctrl()
1364 if (ctx.xso != NULL) { in ossl_quic_ctrl()
1366 if (ctx.xso->aon_write_in_progress) in ossl_quic_ctrl()
1369 ctx.xso->ssl_mode |= (uint32_t)larg; in ossl_quic_ctrl()
1370 return ctx.xso->ssl_mode; in ossl_quic_ctrl()
1373 return ctx.qc->default_ssl_mode; in ossl_quic_ctrl()
1375 if (!ctx.is_stream) in ossl_quic_ctrl()
1376 ctx.qc->default_ssl_mode &= ~(uint32_t)larg; in ossl_quic_ctrl()
1378 if (ctx.xso != NULL) { in ossl_quic_ctrl()
1379 ctx.xso->ssl_mode &= ~(uint32_t)larg; in ossl_quic_ctrl()
1380 return ctx.xso->ssl_mode; in ossl_quic_ctrl()
1383 return ctx.qc->default_ssl_mode; in ossl_quic_ctrl()
1386 ossl_quic_channel_set_msg_callback_arg(ctx.qc->ch, parg); in ossl_quic_ctrl()
1388 return SSL_ctrl(ctx.qc->tls, cmd, larg, parg); in ossl_quic_ctrl()
1420 return ossl_ctrl_internal(&ctx.qc->ssl, cmd, larg, parg, /*no_quic=*/1); in ossl_quic_ctrl()
1427 QCTX ctx; in ossl_quic_set_connect_state() local
1429 if (!expect_quic(s, &ctx)) in ossl_quic_set_connect_state()
1433 if (ctx.qc->started || ctx.is_stream) in ossl_quic_set_connect_state()
1436 ctx.qc->as_server_state = 0; in ossl_quic_set_connect_state()
1442 QCTX ctx; in ossl_quic_set_accept_state() local
1444 if (!expect_quic(s, &ctx)) in ossl_quic_set_accept_state()
1448 if (ctx.qc->started || ctx.is_stream) in ossl_quic_set_accept_state()
1451 ctx.qc->as_server_state = 1; in ossl_quic_set_accept_state()
1505 engine_args.libctx = qc->ssl.ctx->libctx; in create_channel()
1506 engine_args.propq = qc->ssl.ctx->propq; in create_channel()
1516 port_args.channel_ctx = qc->ssl.ctx; in create_channel()
1540 static int ensure_channel_started(QCTX *ctx) in ensure_channel_started() argument
1542 QUIC_CONNECTION *qc = ctx->qc; in ensure_channel_started()
1546 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, in ensure_channel_started()
1553 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, in ensure_channel_started()
1563 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, in ensure_channel_started()
1575 static int quic_do_handshake(QCTX *ctx) in quic_do_handshake() argument
1578 QUIC_CONNECTION *qc = ctx->qc; in quic_do_handshake()
1585 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_do_handshake()
1588 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_PASSED_INVALID_ARGUMENT, NULL); in quic_do_handshake()
1594 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_BIO_NOT_SET, NULL); in quic_do_handshake()
1668 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_REMOTE_PEER_ADDRESS_NOT_SET, NULL); in quic_do_handshake()
1676 if (!ensure_channel_started(ctx)) /* raises on failure */ in quic_do_handshake()
1685 qctx_maybe_autotick(ctx); in quic_do_handshake()
1692 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_do_handshake()
1719 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_do_handshake()
1722 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_do_handshake()
1727 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_get_error(qc->tls, 0)); in quic_do_handshake()
1736 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_get_error(qc->tls, 0)); in quic_do_handshake()
1744 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_WANT_READ); in quic_do_handshake()
1752 QCTX ctx; in ossl_quic_do_handshake() local
1754 if (!expect_quic(s, &ctx)) in ossl_quic_do_handshake()
1757 quic_lock_for_io(&ctx); in ossl_quic_do_handshake()
1759 ret = quic_do_handshake(&ctx); in ossl_quic_do_handshake()
1760 quic_unlock(ctx.qc); in ossl_quic_do_handshake()
1798 static int qc_try_create_default_xso_for_write(QCTX *ctx) in qc_try_create_default_xso_for_write() argument
1801 QUIC_CONNECTION *qc = ctx->qc; in qc_try_create_default_xso_for_write()
1809 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_NO_STREAM, NULL); in qc_try_create_default_xso_for_write()
1815 qc_set_default_xso(qc, (QUIC_XSO *)quic_conn_stream_new(ctx, flags, in qc_try_create_default_xso_for_write()
1819 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in qc_try_create_default_xso_for_write()
1828 QCTX *ctx; member
1839 QUIC_RAISE_NON_NORMAL_ERROR(args->ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_wait_for_stream()
1856 static int qc_wait_for_default_xso_for_read(QCTX *ctx, int peek) in qc_wait_for_default_xso_for_read() argument
1860 QUIC_CONNECTION *qc = ctx->qc; in qc_wait_for_default_xso_for_read()
1872 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_NO_STREAM, NULL); in qc_wait_for_default_xso_for_read()
1891 qctx_maybe_autotick(ctx); in qc_wait_for_default_xso_for_read()
1903 return QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_WANT_READ); in qc_wait_for_default_xso_for_read()
1908 wargs.ctx = ctx; in qc_wait_for_default_xso_for_read()
1913 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in qc_wait_for_default_xso_for_read()
1934 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in qc_wait_for_default_xso_for_read()
1950 if (!ossl_ssl_init(&xso->ssl, qc->ssl.ctx, qc->ssl.method, SSL_TYPE_QUIC_XSO)) { in create_xso_from_stream()
1998 static SSL *quic_conn_stream_new(QCTX *ctx, uint64_t flags, int need_lock) in quic_conn_stream_new() argument
2001 QUIC_CONNECTION *qc = ctx->qc; in quic_conn_stream_new()
2012 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_conn_stream_new()
2025 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_STREAM_COUNT_LIMITED, NULL); in quic_conn_stream_new()
2033 ret = block_until_pred(ctx->qc, quic_new_stream_wait, &args, 0); in quic_conn_stream_new()
2035 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_conn_stream_new()
2038 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_conn_stream_new()
2045 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_conn_stream_new()
2072 QCTX ctx; in ossl_quic_conn_stream_new() local
2074 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_conn_stream_new()
2077 return quic_conn_stream_new(&ctx, flags, /*need_lock=*/1); in ossl_quic_conn_stream_new()
2103 QCTX ctx; in ossl_quic_get_error() local
2106 if (!expect_quic(s, &ctx)) in ossl_quic_get_error()
2109 quic_lock(ctx.qc); in ossl_quic_get_error()
2110 net_error = ossl_quic_channel_net_error(ctx.qc->ch); in ossl_quic_get_error()
2111 last_error = ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error; in ossl_quic_get_error()
2112 quic_unlock(ctx.qc); in ossl_quic_get_error()
2150 QCTX ctx; in ossl_quic_want() local
2153 if (!expect_quic(s, &ctx)) in ossl_quic_want()
2156 quic_lock(ctx.qc); in ossl_quic_want()
2158 w = error_to_want(ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error); in ossl_quic_want()
2160 quic_unlock(ctx.qc); in ossl_quic_want()
2303 static int quic_write_blocking(QCTX *ctx, const void *buf, size_t len, in quic_write_blocking() argument
2307 QUIC_XSO *xso = ctx->xso; in quic_write_blocking()
2315 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_write_blocking()
2341 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_write_blocking()
2343 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, args.err, NULL); in quic_write_blocking()
2374 static int quic_write_nonblocking_aon(QCTX *ctx, const void *buf, in quic_write_nonblocking_aon() argument
2378 QUIC_XSO *xso = ctx->xso; in quic_write_nonblocking_aon()
2396 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_BAD_WRITE_RETRY, NULL); in quic_write_nonblocking_aon()
2410 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_write_nonblocking_aon()
2414 flags, qctx_should_autotick(ctx)); in quic_write_nonblocking_aon()
2443 return QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_WANT_WRITE); in quic_write_nonblocking_aon()
2459 return QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_WANT_WRITE); in quic_write_nonblocking_aon()
2463 static int quic_write_nonblocking_epw(QCTX *ctx, const void *buf, size_t len, in quic_write_nonblocking_epw() argument
2466 QUIC_XSO *xso = ctx->xso; in quic_write_nonblocking_epw()
2472 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_write_nonblocking_epw()
2476 qctx_should_autotick(ctx)); in quic_write_nonblocking_epw()
2480 return QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_WANT_READ); in quic_write_nonblocking_epw()
2532 QCTX ctx; in ossl_quic_write_flags() local
2539 if (!expect_quic(s, &ctx)) in ossl_quic_write_flags()
2542 quic_lock_for_io(&ctx); in ossl_quic_write_flags()
2544 if (!expect_quic_with_stream_lock(s, /*remote_init=*/0, /*io=*/1, &ctx)) in ossl_quic_write_flags()
2548 partial_write = ((ctx.xso != NULL) in ossl_quic_write_flags()
2549 ? ((ctx.xso->ssl_mode & SSL_MODE_ENABLE_PARTIAL_WRITE) != 0) : 0); in ossl_quic_write_flags()
2552 ret = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_UNSUPPORTED_WRITE_FLAG, NULL); in ossl_quic_write_flags()
2556 if (!quic_mutation_allowed(ctx.qc, /*req_active=*/0)) { in ossl_quic_write_flags()
2557 ret = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in ossl_quic_write_flags()
2565 if (quic_do_handshake(&ctx) < 1) { in ossl_quic_write_flags()
2571 if (len > 0 && !quic_validate_for_write(ctx.xso, &err)) { in ossl_quic_write_flags()
2572 ret = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, err, NULL); in ossl_quic_write_flags()
2578 quic_post_write(ctx.xso, 0, 1, flags, in ossl_quic_write_flags()
2579 qctx_should_autotick(&ctx)); in ossl_quic_write_flags()
2585 if (xso_blocking_mode(ctx.xso)) in ossl_quic_write_flags()
2586 ret = quic_write_blocking(&ctx, buf, len, flags, written); in ossl_quic_write_flags()
2588 ret = quic_write_nonblocking_epw(&ctx, buf, len, flags, written); in ossl_quic_write_flags()
2590 ret = quic_write_nonblocking_aon(&ctx, buf, len, flags, written); in ossl_quic_write_flags()
2593 quic_unlock(ctx.qc); in ossl_quic_write_flags()
2608 QCTX *ctx; member
2655 static int quic_read_actual(QCTX *ctx, in quic_read_actual() argument
2662 QUIC_CONNECTION *qc = ctx->qc; in quic_read_actual()
2664 if (!quic_validate_for_read(ctx->xso, &err, &eos)) { in quic_read_actual()
2666 ctx->xso->retired_fin = 1; in quic_read_actual()
2667 return QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_ZERO_RETURN); in quic_read_actual()
2669 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, err, NULL); in quic_read_actual()
2676 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_read_actual()
2681 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_read_actual()
2698 return QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_read_actual()
2702 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(ctx->qc->ch); in quic_read_actual()
2704 ossl_quic_stream_map_notify_totally_read(qsm, ctx->xso->stream); in quic_read_actual()
2713 ctx->xso->retired_fin = 1; in quic_read_actual()
2714 return QUIC_RAISE_NORMAL_ERROR(ctx, SSL_ERROR_ZERO_RETURN); in quic_read_actual()
2725 if (!quic_mutation_allowed(args->ctx->qc, /*req_active=*/1)) { in quic_read_again()
2727 QUIC_RAISE_NON_NORMAL_ERROR(args->ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_read_again()
2731 if (!quic_read_actual(args->ctx, args->stream, in quic_read_again()
2747 QCTX ctx; in quic_read() local
2752 if (!expect_quic(s, &ctx)) in quic_read()
2755 quic_lock_for_io(&ctx); in quic_read()
2757 if (!quic_mutation_allowed(ctx.qc, /*req_active=*/0)) { in quic_read()
2758 ret = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in quic_read()
2763 if (quic_do_handshake(&ctx) < 1) { in quic_read()
2768 if (ctx.xso == NULL) { in quic_read()
2775 if (!qc_wait_for_default_xso_for_read(&ctx, /*peek=*/0)) { in quic_read()
2780 ctx.xso = ctx.qc->default_xso; in quic_read()
2783 if (!quic_read_actual(&ctx, ctx.xso->stream, buf, len, bytes_read, peek)) { in quic_read()
2793 qctx_maybe_autotick(&ctx); in quic_read()
2795 } else if (xso_blocking_mode(ctx.xso)) { in quic_read()
2801 args.ctx = &ctx; in quic_read()
2802 args.stream = ctx.xso->stream; in quic_read()
2808 res = block_until_pred(ctx.qc, quic_read_again, &args, 0); in quic_read()
2810 ret = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_INTERNAL_ERROR, NULL); in quic_read()
2823 qctx_maybe_autotick(&ctx); in quic_read()
2826 if (!quic_read_actual(&ctx, ctx.xso->stream, buf, len, bytes_read, peek)) { in quic_read()
2834 ret = QUIC_RAISE_NORMAL_ERROR(&ctx, SSL_ERROR_WANT_READ); in quic_read()
2838 quic_unlock(ctx.qc); in quic_read()
2860 QCTX ctx; in ossl_quic_pending_int() local
2863 if (!expect_quic(s, &ctx)) in ossl_quic_pending_int()
2866 quic_lock(ctx.qc); in ossl_quic_pending_int()
2868 if (!ctx.qc->started) in ossl_quic_pending_int()
2871 if (ctx.xso == NULL) { in ossl_quic_pending_int()
2873 if (qc_wait_for_default_xso_for_read(&ctx, /*peek=*/1)) { in ossl_quic_pending_int()
2874 ctx.xso = ctx.qc->default_xso; in ossl_quic_pending_int()
2876 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_NO_STREAM, NULL); in ossl_quic_pending_int()
2881 if (ctx.xso->stream == NULL) { in ossl_quic_pending_int()
2882 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_INTERNAL_ERROR, NULL); in ossl_quic_pending_int()
2887 avail = ossl_quic_stream_recv_pending(ctx.xso->stream, in ossl_quic_pending_int()
2889 || ossl_quic_channel_has_pending(ctx.qc->ch) in ossl_quic_pending_int()
2890 || ossl_quic_channel_is_term_any(ctx.qc->ch); in ossl_quic_pending_int()
2892 avail = ossl_quic_stream_recv_pending(ctx.xso->stream, in ossl_quic_pending_int()
2896 quic_unlock(ctx.qc); in ossl_quic_pending_int()
2918 QCTX ctx; in ossl_quic_conn_stream_conclude() local
2922 if (!expect_quic_with_stream_lock(s, /*remote_init=*/0, /*io=*/0, &ctx)) in ossl_quic_conn_stream_conclude()
2925 qs = ctx.xso->stream; in ossl_quic_conn_stream_conclude()
2927 if (!quic_mutation_allowed(ctx.qc, /*req_active=*/1)) { in ossl_quic_conn_stream_conclude()
2928 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2929 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in ossl_quic_conn_stream_conclude()
2932 if (!quic_validate_for_write(ctx.xso, &err)) { in ossl_quic_conn_stream_conclude()
2933 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2934 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, err, NULL); in ossl_quic_conn_stream_conclude()
2938 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2943 quic_post_write(ctx.xso, 1, 0, 0, qctx_should_autotick(&ctx)); in ossl_quic_conn_stream_conclude()
2944 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2959 QCTX ctx; in SSL_inject_net_dgram() local
2962 if (!expect_quic(s, &ctx)) in SSL_inject_net_dgram()
2965 quic_lock(ctx.qc); in SSL_inject_net_dgram()
2967 demux = ossl_quic_channel_get0_demux(ctx.qc->ch); in SSL_inject_net_dgram()
2970 quic_unlock(ctx.qc); in SSL_inject_net_dgram()
2980 QCTX ctx; in ossl_quic_get0_connection() local
2982 if (!expect_quic(s, &ctx)) in ossl_quic_get0_connection()
2985 return &ctx.qc->ssl; in ossl_quic_get0_connection()
2994 QCTX ctx; in ossl_quic_get_stream_type() local
2996 if (!expect_quic(s, &ctx)) in ossl_quic_get_stream_type()
2999 if (ctx.xso == NULL) { in ossl_quic_get_stream_type()
3007 if (ctx.qc->default_xso_created in ossl_quic_get_stream_type()
3008 || ctx.qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in ossl_quic_get_stream_type()
3014 if (ossl_quic_stream_is_bidi(ctx.xso->stream)) in ossl_quic_get_stream_type()
3017 if (ossl_quic_stream_is_server_init(ctx.xso->stream) != ctx.qc->as_server) in ossl_quic_get_stream_type()
3030 QCTX ctx; in ossl_quic_get_stream_id() local
3033 if (!expect_quic_with_stream_lock(s, /*remote_init=*/-1, /*io=*/0, &ctx)) in ossl_quic_get_stream_id()
3036 id = ctx.xso->stream->id; in ossl_quic_get_stream_id()
3037 quic_unlock(ctx.qc); in ossl_quic_get_stream_id()
3049 QCTX ctx; in ossl_quic_is_stream_local() local
3052 if (!expect_quic_with_stream_lock(s, /*remote_init=*/-1, /*io=*/0, &ctx)) in ossl_quic_is_stream_local()
3055 is_local = ossl_quic_stream_is_local_init(ctx.xso->stream); in ossl_quic_is_stream_local()
3056 quic_unlock(ctx.qc); in ossl_quic_is_stream_local()
3068 QCTX ctx; in ossl_quic_set_default_stream_mode() local
3070 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_set_default_stream_mode()
3073 quic_lock(ctx.qc); in ossl_quic_set_default_stream_mode()
3075 if (ctx.qc->default_xso_created) { in ossl_quic_set_default_stream_mode()
3076 quic_unlock(ctx.qc); in ossl_quic_set_default_stream_mode()
3077 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, in ossl_quic_set_default_stream_mode()
3085 ctx.qc->default_stream_mode = mode; in ossl_quic_set_default_stream_mode()
3088 quic_unlock(ctx.qc); in ossl_quic_set_default_stream_mode()
3089 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_INVALID_ARGUMENT, in ossl_quic_set_default_stream_mode()
3093 quic_unlock(ctx.qc); in ossl_quic_set_default_stream_mode()
3104 QCTX ctx; in ossl_quic_detach_stream() local
3107 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_detach_stream()
3110 quic_lock(ctx.qc); in ossl_quic_detach_stream()
3114 qc_set_default_xso_keep_ref(ctx.qc, NULL, /*touch=*/1, &xso); in ossl_quic_detach_stream()
3116 quic_unlock(ctx.qc); in ossl_quic_detach_stream()
3128 QCTX ctx; in ossl_quic_attach_stream() local
3132 if (!expect_quic_conn_only(conn, &ctx)) in ossl_quic_attach_stream()
3136 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_NULL_PARAMETER, in ossl_quic_attach_stream()
3141 quic_lock(ctx.qc); in ossl_quic_attach_stream()
3143 if (ctx.qc->default_xso != NULL) { in ossl_quic_attach_stream()
3144 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3145 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, in ossl_quic_attach_stream()
3154 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3155 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_INTERNAL_ERROR, in ossl_quic_attach_stream()
3160 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3161 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_INVALID_ARGUMENT, in ossl_quic_attach_stream()
3168 qc_set_default_xso(ctx.qc, xso, /*touch=*/1); in ossl_quic_attach_stream()
3170 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3210 QCTX ctx; in ossl_quic_set_incoming_stream_policy() local
3212 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_set_incoming_stream_policy()
3215 quic_lock(ctx.qc); in ossl_quic_set_incoming_stream_policy()
3221 ctx.qc->incoming_stream_policy = policy; in ossl_quic_set_incoming_stream_policy()
3222 ctx.qc->incoming_stream_aec = aec; in ossl_quic_set_incoming_stream_policy()
3226 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_INVALID_ARGUMENT, NULL); in ossl_quic_set_incoming_stream_policy()
3231 qc_update_reject_policy(ctx.qc); in ossl_quic_set_incoming_stream_policy()
3232 quic_unlock(ctx.qc); in ossl_quic_set_incoming_stream_policy()
3241 static int qc_getset_idle_timeout(QCTX *ctx, uint32_t class_, in qc_getset_idle_timeout() argument
3247 quic_lock(ctx->qc); in qc_getset_idle_timeout()
3251 value_out = ossl_quic_channel_get_max_idle_timeout_request(ctx->qc->ch); in qc_getset_idle_timeout()
3256 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_PASSED_INVALID_ARGUMENT, in qc_getset_idle_timeout()
3261 if (ossl_quic_channel_have_generated_transport_params(ctx->qc->ch)) { in qc_getset_idle_timeout()
3262 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_FEATURE_NOT_RENEGOTIABLE, in qc_getset_idle_timeout()
3267 ossl_quic_channel_set_max_idle_timeout_request(ctx->qc->ch, value_in); in qc_getset_idle_timeout()
3274 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_UNSUPPORTED_CONFIG_VALUE_OP, in qc_getset_idle_timeout()
3279 if (!ossl_quic_channel_is_handshake_complete(ctx->qc->ch)) { in qc_getset_idle_timeout()
3280 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_FEATURE_NEGOTIATION_NOT_COMPLETE, in qc_getset_idle_timeout()
3286 ? ossl_quic_channel_get_max_idle_timeout_actual(ctx->qc->ch) in qc_getset_idle_timeout()
3287 : ossl_quic_channel_get_max_idle_timeout_peer_request(ctx->qc->ch); in qc_getset_idle_timeout()
3291 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_UNSUPPORTED_CONFIG_VALUE_CLASS, in qc_getset_idle_timeout()
3298 quic_unlock(ctx->qc); in qc_getset_idle_timeout()
3306 static int qc_get_stream_avail(QCTX *ctx, uint32_t class_, in qc_get_stream_avail() argument
3313 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_UNSUPPORTED_CONFIG_VALUE_CLASS, in qc_get_stream_avail()
3318 quic_lock(ctx->qc); in qc_get_stream_avail()
3321 ? ossl_quic_channel_get_remote_stream_count_avail(ctx->qc->ch, is_uni) in qc_get_stream_avail()
3322 : ossl_quic_channel_get_local_stream_count_avail(ctx->qc->ch, is_uni); in qc_get_stream_avail()
3325 quic_unlock(ctx->qc); in qc_get_stream_avail()
3330 static int qctx_should_autotick(QCTX *ctx) in qctx_should_autotick() argument
3334 if (ctx->is_stream) { in qctx_should_autotick()
3335 event_handling_mode = ctx->xso->event_handling_mode; in qctx_should_autotick()
3340 event_handling_mode = ctx->qc->event_handling_mode; in qctx_should_autotick()
3345 static void qctx_maybe_autotick(QCTX *ctx) in qctx_maybe_autotick() argument
3347 if (!qctx_should_autotick(ctx)) in qctx_maybe_autotick()
3350 ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(ctx->qc->ch), 0); in qctx_maybe_autotick()
3354 static int qc_getset_event_handling(QCTX *ctx, uint32_t class_, in qc_getset_event_handling() argument
3361 quic_lock(ctx->qc); in qc_getset_event_handling()
3364 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_UNSUPPORTED_CONFIG_VALUE_CLASS, in qc_getset_event_handling()
3376 QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_PASSED_INVALID_ARGUMENT, in qc_getset_event_handling()
3382 if (ctx->is_stream) in qc_getset_event_handling()
3383 ctx->xso->event_handling_mode = (int)value_out; in qc_getset_event_handling()
3385 ctx->qc->event_handling_mode = (int)value_out; in qc_getset_event_handling()
3387 value_out = ctx->is_stream in qc_getset_event_handling()
3388 ? ctx->xso->event_handling_mode in qc_getset_event_handling()
3389 : ctx->qc->event_handling_mode; in qc_getset_event_handling()
3394 quic_unlock(ctx->qc); in qc_getset_event_handling()
3402 static int qc_get_stream_write_buf_stat(QCTX *ctx, uint32_t class_, in qc_get_stream_write_buf_stat() argument
3409 quic_lock(ctx->qc); in qc_get_stream_write_buf_stat()
3412 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_UNSUPPORTED_CONFIG_VALUE_CLASS, in qc_get_stream_write_buf_stat()
3417 if (ctx->xso == NULL) { in qc_get_stream_write_buf_stat()
3418 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_NO_STREAM, NULL); in qc_get_stream_write_buf_stat()
3422 if (!ossl_quic_stream_has_send(ctx->xso->stream)) { in qc_get_stream_write_buf_stat()
3423 QUIC_RAISE_NON_NORMAL_ERROR(ctx, SSL_R_STREAM_RECV_ONLY, NULL); in qc_get_stream_write_buf_stat()
3427 if (ossl_quic_stream_has_send_buffer(ctx->xso->stream)) in qc_get_stream_write_buf_stat()
3428 value = getter(ctx->xso->stream->sstream); in qc_get_stream_write_buf_stat()
3432 quic_unlock(ctx->qc); in qc_get_stream_write_buf_stat()
3438 static int expect_quic_for_value(SSL *s, QCTX *ctx, uint32_t id) in expect_quic_for_value() argument
3445 return expect_quic(s, ctx); in expect_quic_for_value()
3447 return expect_quic_conn_only(s, ctx); in expect_quic_for_value()
3455 QCTX ctx; in ossl_quic_get_value_uint() local
3457 if (!expect_quic_for_value(s, &ctx, id)) in ossl_quic_get_value_uint()
3461 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, in ossl_quic_get_value_uint()
3466 return qc_getset_idle_timeout(&ctx, class_, value, NULL); in ossl_quic_get_value_uint()
3469 return qc_get_stream_avail(&ctx, class_, /*uni=*/0, /*remote=*/0, value); in ossl_quic_get_value_uint()
3471 return qc_get_stream_avail(&ctx, class_, /*uni=*/0, /*remote=*/1, value); in ossl_quic_get_value_uint()
3473 return qc_get_stream_avail(&ctx, class_, /*uni=*/1, /*remote=*/0, value); in ossl_quic_get_value_uint()
3475 return qc_get_stream_avail(&ctx, class_, /*uni=*/1, /*remote=*/1, value); in ossl_quic_get_value_uint()
3478 return qc_getset_event_handling(&ctx, class_, value, NULL); in ossl_quic_get_value_uint()
3481 return qc_get_stream_write_buf_stat(&ctx, class_, value, in ossl_quic_get_value_uint()
3484 return qc_get_stream_write_buf_stat(&ctx, class_, value, in ossl_quic_get_value_uint()
3487 return qc_get_stream_write_buf_stat(&ctx, class_, value, in ossl_quic_get_value_uint()
3491 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, in ossl_quic_get_value_uint()
3502 QCTX ctx; in ossl_quic_set_value_uint() local
3504 if (!expect_quic_for_value(s, &ctx, id)) in ossl_quic_set_value_uint()
3509 return qc_getset_idle_timeout(&ctx, class_, NULL, &value); in ossl_quic_set_value_uint()
3512 return qc_getset_event_handling(&ctx, class_, NULL, &value); in ossl_quic_set_value_uint()
3515 return QUIC_RAISE_NON_NORMAL_ERROR(&ctx, in ossl_quic_set_value_uint()
3527 QCTX *ctx; member
3535 QUIC_CONNECTION *qc = args->ctx->qc; in wait_for_incoming_stream()
3540 QUIC_RAISE_NON_NORMAL_ERROR(args->ctx, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL); in wait_for_incoming_stream()
3554 QCTX ctx; in ossl_quic_accept_stream() local
3562 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_accept_stream()
3565 quic_lock(ctx.qc); in ossl_quic_accept_stream()
3567 if (qc_get_effective_incoming_stream_policy(ctx.qc) in ossl_quic_accept_stream()
3569 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, NULL); in ossl_quic_accept_stream()
3573 qsm = ossl_quic_channel_get_qsm(ctx.qc->ch); in ossl_quic_accept_stream()
3577 if (qc_blocking_mode(ctx.qc) in ossl_quic_accept_stream()
3581 args.ctx = &ctx; in ossl_quic_accept_stream()
3584 ret = block_until_pred(ctx.qc, wait_for_incoming_stream, &args, 0); in ossl_quic_accept_stream()
3586 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_INTERNAL_ERROR, NULL); in ossl_quic_accept_stream()
3598 xso = create_xso_from_stream(ctx.qc, qs); in ossl_quic_accept_stream()
3602 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(ctx.qc->ch), &rtt_info); in ossl_quic_accept_stream()
3608 qc_touch_default_xso(ctx.qc); /* inhibits default XSO */ in ossl_quic_accept_stream()
3611 quic_unlock(ctx.qc); in ossl_quic_accept_stream()
3622 QCTX ctx; in ossl_quic_get_accept_stream_queue_len() local
3625 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_get_accept_stream_queue_len()
3628 quic_lock(ctx.qc); in ossl_quic_get_accept_stream_queue_len()
3630 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()
3632 quic_unlock(ctx.qc); in ossl_quic_get_accept_stream_queue_len()
3644 QCTX ctx; in ossl_quic_stream_reset() local
3650 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/0, /*io=*/0, &ctx)) in ossl_quic_stream_reset()
3653 qsm = ossl_quic_channel_get_qsm(ctx.qc->ch); in ossl_quic_stream_reset()
3654 qs = ctx.xso->stream; in ossl_quic_stream_reset()
3657 if (!quic_validate_for_write(ctx.xso, &err)) { in ossl_quic_stream_reset()
3658 ok = QUIC_RAISE_NON_NORMAL_ERROR(&ctx, err, NULL); in ossl_quic_stream_reset()
3664 ctx.xso->requested_reset = 1; in ossl_quic_stream_reset()
3667 quic_unlock(ctx.qc); in ossl_quic_stream_reset()
3737 QCTX ctx; in quic_get_stream_state() local
3740 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, /*io=*/0, &ctx)) in quic_get_stream_state()
3743 quic_classify_stream(ctx.qc, ctx.xso->stream, is_write, &state, NULL); in quic_get_stream_state()
3744 quic_unlock(ctx.qc); in quic_get_stream_state()
3769 QCTX ctx; in quic_get_stream_error_code() local
3772 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, /*io=*/0, &ctx)) in quic_get_stream_error_code()
3775 quic_classify_stream(ctx.qc, ctx.xso->stream, /*is_write=*/0, in quic_get_stream_error_code()
3778 quic_unlock(ctx.qc); in quic_get_stream_error_code()
3811 QCTX ctx; in ossl_quic_set_write_buffer_size() local
3813 if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, /*io=*/0, &ctx)) in ossl_quic_set_write_buffer_size()
3816 if (!ossl_quic_stream_has_send(ctx.xso->stream)) { in ossl_quic_set_write_buffer_size()
3818 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, NULL); in ossl_quic_set_write_buffer_size()
3822 if (!ossl_quic_stream_has_send_buffer(ctx.xso->stream)) { in ossl_quic_set_write_buffer_size()
3831 if (!ossl_quic_sstream_set_buffer_size(ctx.xso->stream->sstream, size)) { in ossl_quic_set_write_buffer_size()
3832 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_INTERNAL_ERROR, NULL); in ossl_quic_set_write_buffer_size()
3839 quic_unlock(ctx.qc); in ossl_quic_set_write_buffer_size()
3851 QCTX ctx; in ossl_quic_get_conn_close_info() local
3854 if (!expect_quic_conn_only(ssl, &ctx)) in ossl_quic_get_conn_close_info()
3857 tc = ossl_quic_channel_get_terminate_cause(ctx.qc->ch); in ossl_quic_get_conn_close_info()
3879 QCTX ctx; in ossl_quic_key_update() local
3881 if (!expect_quic_conn_only(ssl, &ctx)) in ossl_quic_key_update()
3894 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, ERR_R_PASSED_INVALID_ARGUMENT, NULL); in ossl_quic_key_update()
3898 quic_lock(ctx.qc); in ossl_quic_key_update()
3901 if (!ossl_quic_channel_trigger_txku(ctx.qc->ch)) { in ossl_quic_key_update()
3902 QUIC_RAISE_NON_NORMAL_ERROR(&ctx, SSL_R_TOO_MANY_KEY_UPDATES, NULL); in ossl_quic_key_update()
3903 quic_unlock(ctx.qc); in ossl_quic_key_update()
3907 quic_unlock(ctx.qc); in ossl_quic_key_update()
3929 long ossl_quic_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg) in ossl_quic_ctx_ctrl() argument
3933 return ssl3_ctx_ctrl(ctx, cmd, larg, parg); in ossl_quic_ctx_ctrl()
3939 QCTX ctx; in ossl_quic_callback_ctrl() local
3941 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_callback_ctrl()
3946 ossl_quic_channel_set_msg_callback(ctx.qc->ch, (ossl_msg_cb)fp, in ossl_quic_callback_ctrl()
3947 &ctx.qc->ssl); in ossl_quic_callback_ctrl()
3949 return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp);; in ossl_quic_callback_ctrl()
3953 return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp); in ossl_quic_callback_ctrl()
3957 long ossl_quic_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp) (void)) in ossl_quic_ctx_callback_ctrl() argument
3959 return ssl3_ctx_callback_ctrl(ctx, cmd, fp); in ossl_quic_ctx_callback_ctrl()
3999 QCTX ctx; in ossl_quic_get_shutdown() local
4002 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_get_shutdown()
4005 if (ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_get_shutdown()
4007 if (!ossl_quic_channel_is_closing(ctx.qc->ch)) in ossl_quic_get_shutdown()
4112 QCTX ctx; in ossl_quic_conn_poll_events() local
4115 if (!expect_quic(ssl, &ctx)) in ossl_quic_conn_poll_events()
4118 quic_lock(ctx.qc); in ossl_quic_conn_poll_events()
4120 if (!ctx.qc->started) { in ossl_quic_conn_poll_events()
4128 ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(ctx.qc->ch), 0); in ossl_quic_conn_poll_events()
4130 if (ctx.xso != NULL) { in ossl_quic_conn_poll_events()
4134 && test_poll_event_r(ctx.xso)) in ossl_quic_conn_poll_events()
4138 && test_poll_event_er(ctx.xso)) in ossl_quic_conn_poll_events()
4142 && test_poll_event_w(ctx.xso)) in ossl_quic_conn_poll_events()
4146 && test_poll_event_ew(ctx.xso)) in ossl_quic_conn_poll_events()
4150 if (!ctx.is_stream) { in ossl_quic_conn_poll_events()
4152 && test_poll_event_ec(ctx.qc)) in ossl_quic_conn_poll_events()
4156 && test_poll_event_ecd(ctx.qc)) in ossl_quic_conn_poll_events()
4160 && test_poll_event_is(ctx.qc, /*uni=*/0)) in ossl_quic_conn_poll_events()
4164 && test_poll_event_is(ctx.qc, /*uni=*/1)) in ossl_quic_conn_poll_events()
4168 && test_poll_event_os(ctx.qc, /*uni=*/0)) in ossl_quic_conn_poll_events()
4172 && test_poll_event_os(ctx.qc, /*uni=*/1)) in ossl_quic_conn_poll_events()
4177 quic_unlock(ctx.qc); in ossl_quic_conn_poll_events()
4189 QCTX ctx; in ossl_quic_conn_get_channel() local
4191 if (!expect_quic_conn_only(s, &ctx)) in ossl_quic_conn_get_channel()
4194 return ctx.qc->ch; in ossl_quic_conn_get_channel()
4197 int ossl_quic_set_diag_title(SSL_CTX *ctx, const char *title) in ossl_quic_set_diag_title() argument
4200 OPENSSL_free(ctx->qlog_title); in ossl_quic_set_diag_title()
4201 ctx->qlog_title = NULL; in ossl_quic_set_diag_title()
4206 if ((ctx->qlog_title = OPENSSL_strdup(title)) == NULL) in ossl_quic_set_diag_title()