Lines Matching refs:qc
25 static int create_channel(QUIC_CONNECTION *qc);
26 static QUIC_XSO *create_xso_from_stream(QUIC_CONNECTION *qc, QUIC_STREAM *qs);
29 static void quic_lock(QUIC_CONNECTION *qc);
30 static void quic_unlock(QUIC_CONNECTION *qc);
33 static void qc_update_reject_policy(QUIC_CONNECTION *qc);
34 static void qc_touch_default_xso(QUIC_CONNECTION *qc);
35 static void qc_set_default_xso(QUIC_CONNECTION *qc, QUIC_XSO *xso, int touch);
36 static void qc_set_default_xso_keep_ref(QUIC_CONNECTION *qc, QUIC_XSO *xso,
40 static int quic_mutation_allowed(QUIC_CONNECTION *qc, int req_active);
41 static int qc_blocking_mode(const QUIC_CONNECTION *qc);
58 static int block_until_pred(QUIC_CONNECTION *qc, in block_until_pred() argument
64 assert(qc->ch != NULL); in block_until_pred()
70 ossl_quic_engine_set_inhibit_tick(qc->engine, 0); in block_until_pred()
72 rtor = ossl_quic_channel_get_reactor(qc->ch); in block_until_pred()
74 qc->mutex); in block_until_pred()
77 static OSSL_TIME get_time(QUIC_CONNECTION *qc) in get_time() argument
79 if (qc->override_now_cb != NULL) in get_time()
80 return qc->override_now_cb(qc->override_now_cb_arg); in get_time()
87 QUIC_CONNECTION *qc = arg; in get_time_cb() local
89 return get_time(qc); in get_time_cb()
112 QUIC_CONNECTION *qc; member
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()
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()
202 QUIC_CONNECTION *qc; in expect_quic() local
205 ctx->qc = NULL; in expect_quic()
214 qc = (QUIC_CONNECTION *)s; in expect_quic()
215 ctx->qc = qc; in expect_quic()
216 ctx->xso = qc->default_xso; in expect_quic()
223 ctx->qc = xso->conn; in expect_quic()
254 quic_lock(ctx->qc); in expect_quic_with_stream_lock()
257 if (!quic_mutation_allowed(ctx->qc, /*req_active=*/0)) { in expect_quic_with_stream_lock()
275 ctx->xso = ctx->qc->default_xso; in expect_quic_with_stream_lock()
286 quic_unlock(ctx->qc); in expect_quic_with_stream_lock()
311 static void quic_lock(QUIC_CONNECTION *qc) in quic_lock() argument
314 ossl_crypto_mutex_lock(qc->mutex); in quic_lock()
320 quic_lock(ctx->qc); in quic_lock_for_io()
334 static void quic_unlock(QUIC_CONNECTION *qc) in quic_unlock() argument
337 ossl_crypto_mutex_unlock(qc->mutex); in quic_unlock()
351 static int quic_mutation_allowed(QUIC_CONNECTION *qc, int req_active) in quic_mutation_allowed() argument
353 if (qc->shutting_down || ossl_quic_channel_is_term_any(qc->ch)) in quic_mutation_allowed()
356 if (req_active && !ossl_quic_channel_is_active(qc->ch)) in quic_mutation_allowed()
382 QUIC_CONNECTION *qc = NULL; in ossl_quic_new() local
386 qc = OPENSSL_zalloc(sizeof(*qc)); in ossl_quic_new()
387 if (qc == NULL) { in ossl_quic_new()
392 if ((qc->mutex = ossl_crypto_mutex_new()) == NULL) { in ossl_quic_new()
399 ssl_base = &qc->ssl; in ossl_quic_new()
406 qc->tls = ossl_ssl_connection_new_int(ctx, ssl_base, TLS_method()); in ossl_quic_new()
407 if (qc->tls == NULL || (sc = SSL_CONNECTION_FROM_SSL(qc->tls)) == NULL) { in ossl_quic_new()
420 qc->is_thread_assisted in ossl_quic_new()
424 qc->as_server = 0; /* TODO(QUIC SERVER): add server support */ in ossl_quic_new()
425 qc->as_server_state = qc->as_server; in ossl_quic_new()
427 qc->default_stream_mode = SSL_DEFAULT_STREAM_MODE_AUTO_BIDI; 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()
430 qc->desires_blocking = 1; in ossl_quic_new()
431 qc->blocking = 0; in ossl_quic_new()
432 qc->incoming_stream_policy = SSL_INCOMING_STREAM_POLICY_AUTO; in ossl_quic_new()
433 qc->last_error = SSL_ERROR_NONE; in ossl_quic_new()
435 if (!create_channel(qc)) 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()
441 qc_update_reject_policy(qc); in ossl_quic_new()
458 ossl_crypto_mutex_free(&qc->mutex); in ossl_quic_new()
460 OPENSSL_free(qc); in ossl_quic_new()
478 quic_lock(ctx.qc); in ossl_quic_free()
488 assert(ctx.qc->num_xso > 0); in ossl_quic_free()
489 --ctx.qc->num_xso; 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()
501 ossl_quic_stream_map_stop_sending_recv_part(ossl_quic_channel_get_qsm(ctx.qc->ch), in ossl_quic_free()
506 ossl_quic_stream_map_update_state(ossl_quic_channel_get_qsm(ctx.qc->ch), 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()
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()
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()
638 static void qc_touch_default_xso(QUIC_CONNECTION *qc) in qc_touch_default_xso() argument
640 qc->default_xso_created = 1; in qc_touch_default_xso()
641 qc_update_reject_policy(qc); in qc_touch_default_xso()
649 static void qc_set_default_xso_keep_ref(QUIC_CONNECTION *qc, QUIC_XSO *xso, in qc_set_default_xso_keep_ref() argument
657 if (qc->default_xso != xso) { in qc_set_default_xso_keep_ref()
658 *old_xso = qc->default_xso; /* transfer old XSO ref to caller */ in qc_set_default_xso_keep_ref()
660 qc->default_xso = xso; in qc_set_default_xso_keep_ref()
667 if (!ossl_assert(SSL_up_ref(&qc->ssl))) in qc_set_default_xso_keep_ref()
681 CRYPTO_DOWN_REF(&qc->ssl.references, &refs); in qc_set_default_xso_keep_ref()
687 qc_touch_default_xso(qc); in qc_set_default_xso_keep_ref()
695 static void qc_set_default_xso(QUIC_CONNECTION *qc, QUIC_XSO *xso, int touch) in qc_set_default_xso() argument
699 qc_set_default_xso_keep_ref(qc, xso, touch, &old_xso); in qc_set_default_xso()
738 quic_lock(ctx.qc); 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()
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()
857 static int qc_can_support_blocking_cached(QUIC_CONNECTION *qc) in qc_can_support_blocking_cached() argument
859 QUIC_REACTOR *rtor = ossl_quic_channel_get_reactor(qc->ch); in qc_can_support_blocking_cached()
865 static void qc_update_can_support_blocking(QUIC_CONNECTION *qc) in qc_update_can_support_blocking() argument
867 ossl_quic_port_update_poll_descriptors(qc->port); /* best effort */ in qc_update_can_support_blocking()
870 static void qc_update_blocking_mode(QUIC_CONNECTION *qc) in qc_update_blocking_mode() argument
872 qc->blocking = qc->desires_blocking && qc_can_support_blocking_cached(qc); in qc_update_blocking_mode()
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()
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()
936 return ctx.qc->net_rbio; in ossl_quic_conn_get_net_rbio()
946 return ctx.qc->net_wbio; in ossl_quic_conn_get_net_wbio()
959 return qc_blocking_mode(ctx.qc); in ossl_quic_conn_get_blocking_mode()
971 quic_lock(ctx.qc); 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()
994 ctx.qc->desires_blocking = (blocking != 0); 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()
1020 if (ctx.qc->started) 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()
1044 static int qc_blocking_mode(const QUIC_CONNECTION *qc) in qc_blocking_mode() argument
1046 return qc->blocking; in qc_blocking_mode()
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()
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()
1124 if (desc == NULL || ctx.qc->net_rbio == NULL) in ossl_quic_get_rpoll_descriptor()
1128 return BIO_get_rpoll_descriptor(ctx.qc->net_rbio, desc); in ossl_quic_get_rpoll_descriptor()
1139 if (desc == NULL || ctx.qc->net_wbio == NULL) in ossl_quic_get_wpoll_descriptor()
1143 return BIO_get_wpoll_descriptor(ctx.qc->net_wbio, desc); in ossl_quic_get_wpoll_descriptor()
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()
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()
1193 static void qc_shutdown_flush_init(QUIC_CONNECTION *qc) in qc_shutdown_flush_init() argument
1197 if (qc->shutting_down) in qc_shutdown_flush_init()
1200 qsm = ossl_quic_channel_get_qsm(qc->ch); in qc_shutdown_flush_init()
1203 qc->shutting_down = 1; in qc_shutdown_flush_init()
1208 static int qc_shutdown_flush_finished(QUIC_CONNECTION *qc) in qc_shutdown_flush_finished() argument
1210 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(qc->ch); in qc_shutdown_flush_finished()
1212 return qc->shutting_down in qc_shutdown_flush_finished()
1219 QUIC_CONNECTION *qc = arg; in quic_shutdown_wait() local
1221 return ossl_quic_channel_is_terminated(qc->ch); in quic_shutdown_wait()
1227 QUIC_CONNECTION *qc = arg; in quic_shutdown_flush_wait() local
1229 return ossl_quic_channel_is_term_any(qc->ch) in quic_shutdown_flush_wait()
1230 || qc_shutdown_flush_finished(qc); in quic_shutdown_flush_wait()
1235 QUIC_CONNECTION *qc = arg; in quic_shutdown_peer_wait() local
1236 return ossl_quic_channel_is_term_any(qc->ch); in quic_shutdown_peer_wait()
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()
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()
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()
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()
1358 ctx.qc->default_ssl_mode |= (uint32_t)larg; in ossl_quic_ctrl()
1373 return ctx.qc->default_ssl_mode; in ossl_quic_ctrl()
1376 ctx.qc->default_ssl_mode &= ~(uint32_t)larg; 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()
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()
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()
1456 QUIC_CONNECTION *qc; member
1459 static int tls_wants_non_io_retry(QUIC_CONNECTION *qc) in tls_wants_non_io_retry() argument
1461 int want = SSL_want(qc->tls); in tls_wants_non_io_retry()
1475 if (!quic_mutation_allowed(args->qc, /*req_active=*/1)) in quic_handshake_wait()
1478 if (ossl_quic_channel_is_handshake_complete(args->qc->ch)) in quic_handshake_wait()
1481 if (tls_wants_non_io_retry(args->qc)) in quic_handshake_wait()
1487 static int configure_channel(QUIC_CONNECTION *qc) in configure_channel() argument
1489 assert(qc->ch != NULL); in configure_channel()
1491 if (!ossl_quic_port_set_net_rbio(qc->port, qc->net_rbio) in configure_channel()
1492 || !ossl_quic_port_set_net_wbio(qc->port, qc->net_wbio) in configure_channel()
1493 || !ossl_quic_channel_set_peer_addr(qc->ch, &qc->init_peer_addr)) in configure_channel()
1500 static int create_channel(QUIC_CONNECTION *qc) in create_channel() argument
1505 engine_args.libctx = qc->ssl.ctx->libctx; in create_channel()
1506 engine_args.propq = qc->ssl.ctx->propq; in create_channel()
1507 engine_args.mutex = qc->mutex; in create_channel()
1509 engine_args.now_cb_arg = qc; in create_channel()
1510 qc->engine = ossl_quic_engine_new(&engine_args); in create_channel()
1511 if (qc->engine == NULL) { in create_channel()
1516 port_args.channel_ctx = qc->ssl.ctx; in create_channel()
1517 qc->port = ossl_quic_engine_create_port(qc->engine, &port_args); in create_channel()
1518 if (qc->port == NULL) { in create_channel()
1520 ossl_quic_engine_free(qc->engine); in create_channel()
1524 qc->ch = ossl_quic_port_create_outgoing(qc->port, qc->tls); in create_channel()
1525 if (qc->ch == NULL) { in create_channel()
1527 ossl_quic_port_free(qc->port); in create_channel()
1528 ossl_quic_engine_free(qc->engine); in create_channel()
1542 QUIC_CONNECTION *qc = ctx->qc; in ensure_channel_started() local
1544 if (!qc->started) { in ensure_channel_started()
1545 if (!configure_channel(qc)) { in ensure_channel_started()
1551 if (!ossl_quic_channel_start(qc->ch)) { in ensure_channel_started()
1552 ossl_quic_channel_restore_err_state(qc->ch); in ensure_channel_started()
1559 if (qc->is_thread_assisted) in ensure_channel_started()
1560 if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch, in ensure_channel_started()
1561 qc->override_now_cb, in ensure_channel_started()
1562 qc->override_now_cb_arg)) { in ensure_channel_started()
1570 qc->started = 1; in ensure_channel_started()
1578 QUIC_CONNECTION *qc = ctx->qc; in quic_do_handshake() local
1580 if (ossl_quic_channel_is_handshake_complete(qc->ch)) in quic_do_handshake()
1584 if (!quic_mutation_allowed(qc, /*req_active=*/0)) in quic_do_handshake()
1587 if (qc->as_server != qc->as_server_state) { in quic_do_handshake()
1592 if (qc->net_rbio == NULL || qc->net_wbio == NULL) { in quic_do_handshake()
1631 if (!qc->started && !qc->addressing_probe_done) { in quic_do_handshake()
1632 long rcaps = BIO_dgram_get_effective_caps(qc->net_rbio); in quic_do_handshake()
1633 long wcaps = BIO_dgram_get_effective_caps(qc->net_wbio); in quic_do_handshake()
1635 qc->addressed_mode_r = ((rcaps & BIO_DGRAM_CAP_PROVIDES_SRC_ADDR) != 0); in quic_do_handshake()
1636 qc->addressed_mode_w = ((wcaps & BIO_DGRAM_CAP_HANDLES_DST_ADDR) != 0); in quic_do_handshake()
1637 qc->addressing_probe_done = 1; in quic_do_handshake()
1640 if (!qc->started && qc->addressed_mode_w in quic_do_handshake()
1641 && BIO_ADDR_family(&qc->init_peer_addr) == AF_UNSPEC) { in quic_do_handshake()
1654 if (!csm_analyse_init_peer_addr(qc->net_wbio, &qc->init_peer_addr)) in quic_do_handshake()
1656 BIO_ADDR_clear(&qc->init_peer_addr); in quic_do_handshake()
1658 ossl_quic_channel_set_peer_addr(qc->ch, &qc->init_peer_addr); in quic_do_handshake()
1661 if (!qc->started in quic_do_handshake()
1662 && qc->addressed_mode_w in quic_do_handshake()
1663 && BIO_ADDR_family(&qc->init_peer_addr) == AF_UNSPEC) { in quic_do_handshake()
1679 if (ossl_quic_channel_is_handshake_complete(qc->ch)) in quic_do_handshake()
1683 if (!qc_blocking_mode(qc)) { in quic_do_handshake()
1687 if (ossl_quic_channel_is_handshake_complete(qc->ch)) in quic_do_handshake()
1691 if (ossl_quic_channel_is_term_any(qc->ch)) { in quic_do_handshake()
1694 } else if (qc->desires_blocking) { in quic_do_handshake()
1702 assert(!qc->blocking); in quic_do_handshake()
1703 qc_update_can_support_blocking(qc); in quic_do_handshake()
1704 qc_update_blocking_mode(qc); in quic_do_handshake()
1711 if (qc_blocking_mode(qc)) { in quic_do_handshake()
1715 args.qc = qc; in quic_do_handshake()
1717 ret = block_until_pred(qc, quic_handshake_wait, &args, 0); in quic_do_handshake()
1718 if (!quic_mutation_allowed(qc, /*req_active=*/1)) { in quic_do_handshake()
1726 if (tls_wants_non_io_retry(qc)) { in quic_do_handshake()
1727 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_get_error(qc->tls, 0)); in quic_do_handshake()
1731 assert(ossl_quic_channel_is_handshake_complete(qc->ch)); in quic_do_handshake()
1735 if (tls_wants_non_io_retry(qc)) { in quic_do_handshake()
1736 QUIC_RAISE_NORMAL_ERROR(ctx, SSL_get_error(qc->tls, 0)); in quic_do_handshake()
1760 quic_unlock(ctx.qc); in ossl_quic_do_handshake()
1801 QUIC_CONNECTION *qc = ctx->qc; in qc_try_create_default_xso_for_write() local
1803 if (qc->default_xso_created in qc_try_create_default_xso_for_write()
1804 || qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in qc_try_create_default_xso_for_write()
1812 if (qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_AUTO_UNI) 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()
1818 if (qc->default_xso == NULL) in qc_try_create_default_xso_for_write()
1821 qc_touch_default_xso(qc); in qc_try_create_default_xso_for_write()
1826 QUIC_CONNECTION *qc; member
1837 if (!quic_mutation_allowed(args->qc, /*req_active=*/1)) { in quic_wait_for_stream()
1843 args->qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(args->qc->ch), in quic_wait_for_stream()
1846 args->qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(args->qc->ch), in quic_wait_for_stream()
1860 QUIC_CONNECTION *qc = ctx->qc; in qc_wait_for_default_xso_for_read() local
1870 if (qc->default_xso_created in qc_wait_for_default_xso_for_read()
1871 || qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in qc_wait_for_default_xso_for_read()
1880 expect_id = qc->as_server in qc_wait_for_default_xso_for_read()
1884 qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
1887 qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
1893 qs = ossl_quic_stream_map_get_by_id(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
1901 if (!qc_blocking_mode(qc)) in qc_wait_for_default_xso_for_read()
1906 wargs.qc = qc; in qc_wait_for_default_xso_for_read()
1911 res = block_until_pred(qc, quic_wait_for_stream, &wargs, 0); in qc_wait_for_default_xso_for_read()
1925 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(qc->ch), &rtt_info); in qc_wait_for_default_xso_for_read()
1926 ossl_quic_stream_map_remove_from_accept_queue(ossl_quic_channel_get_qsm(qc->ch), in qc_wait_for_default_xso_for_read()
1932 qc_set_default_xso(qc, create_xso_from_stream(qc, qs), /*touch=*/0); in qc_wait_for_default_xso_for_read()
1933 if (qc->default_xso == NULL) in qc_wait_for_default_xso_for_read()
1936 qc_touch_default_xso(qc); /* inhibits default XSO */ in qc_wait_for_default_xso_for_read()
1941 static QUIC_XSO *create_xso_from_stream(QUIC_CONNECTION *qc, QUIC_STREAM *qs) in create_xso_from_stream() argument
1950 if (!ossl_ssl_init(&xso->ssl, qc->ssl.ctx, qc->ssl.method, SSL_TYPE_QUIC_XSO)) { in create_xso_from_stream()
1956 if (!SSL_up_ref(&qc->ssl)) { in create_xso_from_stream()
1961 xso->conn = qc; in create_xso_from_stream()
1962 xso->ssl_mode = qc->default_ssl_mode; in create_xso_from_stream()
1964 = qc->default_ssl_options & OSSL_QUIC_PERMITTED_OPTIONS_STREAM; in create_xso_from_stream()
1969 ++qc->num_xso; in create_xso_from_stream()
1979 QUIC_CONNECTION *qc; member
1986 QUIC_CONNECTION *qc = args->qc; in quic_new_stream_wait() local
1988 if (!quic_mutation_allowed(qc, /*req_active=*/1)) in quic_new_stream_wait()
1991 if (ossl_quic_channel_is_new_local_stream_admissible(qc->ch, args->is_uni)) in quic_new_stream_wait()
2001 QUIC_CONNECTION *qc = ctx->qc; in quic_conn_stream_new() local
2009 quic_lock(qc); in quic_conn_stream_new()
2011 if (!quic_mutation_allowed(qc, /*req_active=*/0)) { in quic_conn_stream_new()
2017 && !ossl_quic_channel_is_new_local_stream_admissible(qc->ch, is_uni)) { in quic_conn_stream_new()
2024 if (no_blocking || !qc_blocking_mode(qc)) { in quic_conn_stream_new()
2029 args.qc = qc; in quic_conn_stream_new()
2033 ret = block_until_pred(ctx->qc, quic_new_stream_wait, &args, 0); in quic_conn_stream_new()
2034 if (!quic_mutation_allowed(qc, /*req_active=*/1)) { in quic_conn_stream_new()
2043 qs = ossl_quic_channel_new_stream_local(qc->ch, is_uni); in quic_conn_stream_new()
2049 xso = create_xso_from_stream(qc, qs); in quic_conn_stream_new()
2053 qc_touch_default_xso(qc); /* inhibits default XSO */ in quic_conn_stream_new()
2055 quic_unlock(qc); in quic_conn_stream_new()
2061 ossl_quic_stream_map_release(ossl_quic_channel_get_qsm(qc->ch), qs); in quic_conn_stream_new()
2063 quic_unlock(qc); in quic_conn_stream_new()
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()
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()
2558 if (!quic_mutation_allowed(ctx.qc, /*req_active=*/0)) { in ossl_quic_write_flags()
2595 quic_unlock(ctx.qc); in ossl_quic_write_flags()
2664 QUIC_CONNECTION *qc = ctx->qc; in quic_read_actual() local
2696 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(qc->ch), &rtt_info); in quic_read_actual()
2704 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(ctx->qc->ch); in quic_read_actual()
2710 ossl_quic_stream_map_update_state(ossl_quic_channel_get_qsm(qc->ch), in quic_read_actual()
2727 if (!quic_mutation_allowed(args->ctx->qc, /*req_active=*/1)) { in quic_read_again()
2759 if (!quic_mutation_allowed(ctx.qc, /*req_active=*/0)) { in quic_read()
2782 ctx.xso = ctx.qc->default_xso; in quic_read()
2810 res = block_until_pred(ctx.qc, quic_read_again, &args, 0); in quic_read()
2840 quic_unlock(ctx.qc); in quic_read()
2868 quic_lock(ctx.qc); in ossl_quic_pending_int()
2870 if (!ctx.qc->started) in ossl_quic_pending_int()
2876 ctx.xso = ctx.qc->default_xso; in ossl_quic_pending_int()
2891 || ossl_quic_channel_has_pending(ctx.qc->ch) in ossl_quic_pending_int()
2892 || ossl_quic_channel_is_term_any(ctx.qc->ch); in ossl_quic_pending_int()
2898 quic_unlock(ctx.qc); in ossl_quic_pending_int()
2929 if (!quic_mutation_allowed(ctx.qc, /*req_active=*/1)) { in ossl_quic_conn_stream_conclude()
2930 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2935 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2940 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2946 quic_unlock(ctx.qc); in ossl_quic_conn_stream_conclude()
2967 quic_lock(ctx.qc); in SSL_inject_net_dgram()
2969 demux = ossl_quic_channel_get0_demux(ctx.qc->ch); in SSL_inject_net_dgram()
2972 quic_unlock(ctx.qc); in SSL_inject_net_dgram()
2987 return &ctx.qc->ssl; in ossl_quic_get0_connection()
3009 if (ctx.qc->default_xso_created in ossl_quic_get_stream_type()
3010 || ctx.qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in ossl_quic_get_stream_type()
3019 if (ossl_quic_stream_is_server_init(ctx.xso->stream) != ctx.qc->as_server) in ossl_quic_get_stream_type()
3039 quic_unlock(ctx.qc); in ossl_quic_get_stream_id()
3058 quic_unlock(ctx.qc); in ossl_quic_is_stream_local()
3075 quic_lock(ctx.qc); in ossl_quic_set_default_stream_mode()
3077 if (ctx.qc->default_xso_created) { in ossl_quic_set_default_stream_mode()
3078 quic_unlock(ctx.qc); in ossl_quic_set_default_stream_mode()
3087 ctx.qc->default_stream_mode = mode; in ossl_quic_set_default_stream_mode()
3090 quic_unlock(ctx.qc); in ossl_quic_set_default_stream_mode()
3095 quic_unlock(ctx.qc); in ossl_quic_set_default_stream_mode()
3112 quic_lock(ctx.qc); in ossl_quic_detach_stream()
3116 qc_set_default_xso_keep_ref(ctx.qc, NULL, /*touch=*/1, &xso); in ossl_quic_detach_stream()
3118 quic_unlock(ctx.qc); in ossl_quic_detach_stream()
3143 quic_lock(ctx.qc); in ossl_quic_attach_stream()
3145 if (ctx.qc->default_xso != NULL) { in ossl_quic_attach_stream()
3146 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3156 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3162 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3170 qc_set_default_xso(ctx.qc, xso, /*touch=*/1); in ossl_quic_attach_stream()
3172 quic_unlock(ctx.qc); in ossl_quic_attach_stream()
3181 static int qc_get_effective_incoming_stream_policy(QUIC_CONNECTION *qc) in qc_get_effective_incoming_stream_policy() argument
3183 switch (qc->incoming_stream_policy) { in qc_get_effective_incoming_stream_policy()
3185 if ((qc->default_xso == NULL && !qc->default_xso_created) in qc_get_effective_incoming_stream_policy()
3186 || qc->default_stream_mode == SSL_DEFAULT_STREAM_MODE_NONE) in qc_get_effective_incoming_stream_policy()
3192 return qc->incoming_stream_policy; in qc_get_effective_incoming_stream_policy()
3197 static void qc_update_reject_policy(QUIC_CONNECTION *qc) in qc_update_reject_policy() argument
3199 int policy = qc_get_effective_incoming_stream_policy(qc); in qc_update_reject_policy()
3202 ossl_quic_channel_set_incoming_stream_auto_reject(qc->ch, in qc_update_reject_policy()
3204 qc->incoming_stream_aec); in qc_update_reject_policy()
3217 quic_lock(ctx.qc); in ossl_quic_set_incoming_stream_policy()
3223 ctx.qc->incoming_stream_policy = policy; in ossl_quic_set_incoming_stream_policy()
3224 ctx.qc->incoming_stream_aec = aec; in ossl_quic_set_incoming_stream_policy()
3233 qc_update_reject_policy(ctx.qc); in ossl_quic_set_incoming_stream_policy()
3234 quic_unlock(ctx.qc); in ossl_quic_set_incoming_stream_policy()
3249 quic_lock(ctx->qc); in qc_getset_idle_timeout()
3253 value_out = ossl_quic_channel_get_max_idle_timeout_request(ctx->qc->ch); in qc_getset_idle_timeout()
3263 if (ossl_quic_channel_have_generated_transport_params(ctx->qc->ch)) { in qc_getset_idle_timeout()
3269 ossl_quic_channel_set_max_idle_timeout_request(ctx->qc->ch, value_in); in qc_getset_idle_timeout()
3281 if (!ossl_quic_channel_is_handshake_complete(ctx->qc->ch)) { in qc_getset_idle_timeout()
3288 ? ossl_quic_channel_get_max_idle_timeout_actual(ctx->qc->ch) in qc_getset_idle_timeout()
3289 : ossl_quic_channel_get_max_idle_timeout_peer_request(ctx->qc->ch); in qc_getset_idle_timeout()
3300 quic_unlock(ctx->qc); in qc_getset_idle_timeout()
3320 quic_lock(ctx->qc); in qc_get_stream_avail()
3323 ? ossl_quic_channel_get_remote_stream_count_avail(ctx->qc->ch, is_uni) in qc_get_stream_avail()
3324 : ossl_quic_channel_get_local_stream_count_avail(ctx->qc->ch, is_uni); in qc_get_stream_avail()
3327 quic_unlock(ctx->qc); in qc_get_stream_avail()
3342 event_handling_mode = ctx->qc->event_handling_mode; in qctx_should_autotick()
3352 ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(ctx->qc->ch), 0); in qctx_maybe_autotick()
3363 quic_lock(ctx->qc); in qc_getset_event_handling()
3387 ctx->qc->event_handling_mode = (int)value_out; in qc_getset_event_handling()
3391 : ctx->qc->event_handling_mode; in qc_getset_event_handling()
3396 quic_unlock(ctx->qc); in qc_getset_event_handling()
3411 quic_lock(ctx->qc); in qc_get_stream_write_buf_stat()
3434 quic_unlock(ctx->qc); in qc_get_stream_write_buf_stat()
3537 QUIC_CONNECTION *qc = args->ctx->qc; in wait_for_incoming_stream() local
3538 QUIC_STREAM_MAP *qsm = ossl_quic_channel_get_qsm(qc->ch); in wait_for_incoming_stream()
3540 if (!quic_mutation_allowed(qc, /*req_active=*/1)) { in wait_for_incoming_stream()
3567 quic_lock(ctx.qc); in ossl_quic_accept_stream()
3569 if (qc_get_effective_incoming_stream_policy(ctx.qc) in ossl_quic_accept_stream()
3575 qsm = ossl_quic_channel_get_qsm(ctx.qc->ch); in ossl_quic_accept_stream()
3579 if (qc_blocking_mode(ctx.qc) in ossl_quic_accept_stream()
3586 ret = block_until_pred(ctx.qc, wait_for_incoming_stream, &args, 0); in ossl_quic_accept_stream()
3600 xso = create_xso_from_stream(ctx.qc, qs); in ossl_quic_accept_stream()
3604 ossl_statm_get_rtt_info(ossl_quic_channel_get_statm(ctx.qc->ch), &rtt_info); in ossl_quic_accept_stream()
3610 qc_touch_default_xso(ctx.qc); /* inhibits default XSO */ in ossl_quic_accept_stream()
3613 quic_unlock(ctx.qc); in ossl_quic_accept_stream()
3630 quic_lock(ctx.qc); in ossl_quic_get_accept_stream_queue_len()
3632 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()
3634 quic_unlock(ctx.qc); in ossl_quic_get_accept_stream_queue_len()
3655 qsm = ossl_quic_channel_get_qsm(ctx.qc->ch); in ossl_quic_stream_reset()
3669 quic_unlock(ctx.qc); in ossl_quic_stream_reset()
3677 static void quic_classify_stream(QUIC_CONNECTION *qc, in quic_classify_stream() argument
3686 local_init = (ossl_quic_stream_is_server_init(qs) == qc->as_server); in quic_classify_stream()
3699 } else if (ossl_quic_channel_is_term_any(qc->ch)) { in quic_classify_stream()
3745 quic_classify_stream(ctx.qc, ctx.xso->stream, is_write, &state, NULL); in quic_get_stream_state()
3746 quic_unlock(ctx.qc); in quic_get_stream_state()
3777 quic_classify_stream(ctx.qc, ctx.xso->stream, /*is_write=*/0, in quic_get_stream_error_code()
3780 quic_unlock(ctx.qc); in quic_get_stream_error_code()
3841 quic_unlock(ctx.qc); in ossl_quic_set_write_buffer_size()
3859 tc = ossl_quic_channel_get_terminate_cause(ctx.qc->ch); in ossl_quic_get_conn_close_info()
3900 quic_lock(ctx.qc); in ossl_quic_key_update()
3903 if (!ossl_quic_channel_trigger_txku(ctx.qc->ch)) { in ossl_quic_key_update()
3905 quic_unlock(ctx.qc); in ossl_quic_key_update()
3909 quic_unlock(ctx.qc); in ossl_quic_key_update()
3948 ossl_quic_channel_set_msg_callback(ctx.qc->ch, (ossl_msg_cb)fp, in ossl_quic_callback_ctrl()
3949 &ctx.qc->ssl); in ossl_quic_callback_ctrl()
3951 return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp);; in ossl_quic_callback_ctrl()
3955 return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp); in ossl_quic_callback_ctrl()
4007 if (ossl_quic_channel_is_term_any(ctx.qc->ch)) { in ossl_quic_get_shutdown()
4009 if (!ossl_quic_channel_is_closing(ctx.qc->ch)) in ossl_quic_get_shutdown()
4081 static int test_poll_event_ec(QUIC_CONNECTION *qc) in test_poll_event_ec() argument
4083 return ossl_quic_channel_is_term_any(qc->ch); in test_poll_event_ec()
4088 static int test_poll_event_ecd(QUIC_CONNECTION *qc) in test_poll_event_ecd() argument
4090 return ossl_quic_channel_is_terminated(qc->ch); in test_poll_event_ecd()
4095 static int test_poll_event_is(QUIC_CONNECTION *qc, int is_uni) in test_poll_event_is() argument
4097 return ossl_quic_stream_map_get_accept_queue_len(ossl_quic_channel_get_qsm(qc->ch), in test_poll_event_is()
4103 static int test_poll_event_os(QUIC_CONNECTION *qc, int is_uni) in test_poll_event_os() argument
4106 return quic_mutation_allowed(qc, /*req_active=*/1) in test_poll_event_os()
4107 && ossl_quic_channel_get_local_stream_count_avail(qc->ch, is_uni) > 0; in test_poll_event_os()
4120 quic_lock(ctx.qc); in ossl_quic_conn_poll_events()
4122 if (!ctx.qc->started) { in ossl_quic_conn_poll_events()
4130 ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(ctx.qc->ch), 0); in ossl_quic_conn_poll_events()
4154 && test_poll_event_ec(ctx.qc)) in ossl_quic_conn_poll_events()
4158 && test_poll_event_ecd(ctx.qc)) in ossl_quic_conn_poll_events()
4162 && test_poll_event_is(ctx.qc, /*uni=*/0)) in ossl_quic_conn_poll_events()
4166 && test_poll_event_is(ctx.qc, /*uni=*/1)) in ossl_quic_conn_poll_events()
4170 && test_poll_event_os(ctx.qc, /*uni=*/0)) in ossl_quic_conn_poll_events()
4174 && test_poll_event_os(ctx.qc, /*uni=*/1)) in ossl_quic_conn_poll_events()
4179 quic_unlock(ctx.qc); in ossl_quic_conn_poll_events()
4196 return ctx.qc->ch; in ossl_quic_conn_get_channel()