Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/ssl/quic/quic_port.c
Line
Count
Source
1
/*
2
 * Copyright 2023-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include "internal/quic_port.h"
11
#include "internal/quic_channel.h"
12
#include "internal/quic_lcidm.h"
13
#include "internal/quic_srtm.h"
14
#include "quic_port_local.h"
15
#include "quic_channel_local.h"
16
#include "quic_engine_local.h"
17
#include "../ssl_local.h"
18
19
/*
20
 * QUIC Port Structure
21
 * ===================
22
 */
23
10.2k
#define INIT_DCID_LEN 8
24
25
static int port_init(QUIC_PORT *port);
26
static void port_cleanup(QUIC_PORT *port);
27
static OSSL_TIME get_time(void *arg);
28
static void port_default_packet_handler(QUIC_URXE *e, void *arg,
29
    const QUIC_CONN_ID *dcid);
30
static void port_rx_pre(QUIC_PORT *port);
31
32
142M
DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
quic_port.c:ossl_list_ch_head
Line
Count
Source
32
DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
quic_port.c:ossl_list_ch_next
Line
Count
Source
32
DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
33
106k
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
quic_port.c:ossl_list_port_insert_tail
Line
Count
Source
33
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
quic_port.c:ossl_list_port_remove
Line
Count
Source
33
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
34
35
QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args)
36
53.4k
{
37
53.4k
    QUIC_PORT *port;
38
39
53.4k
    if ((port = OPENSSL_zalloc(sizeof(QUIC_PORT))) == NULL)
40
0
        return NULL;
41
42
53.4k
    port->engine = args->engine;
43
53.4k
    port->channel_ctx = args->channel_ctx;
44
53.4k
    port->is_multi_conn = args->is_multi_conn;
45
46
53.4k
    if (!port_init(port)) {
47
0
        OPENSSL_free(port);
48
0
        return NULL;
49
0
    }
50
51
53.4k
    return port;
52
53.4k
}
53
54
void ossl_quic_port_free(QUIC_PORT *port)
55
53.4k
{
56
53.4k
    if (port == NULL)
57
0
        return;
58
59
53.4k
    port_cleanup(port);
60
53.4k
    OPENSSL_free(port);
61
53.4k
}
62
63
static int port_init(QUIC_PORT *port)
64
10.2k
{
65
10.2k
    size_t rx_short_dcid_len = (port->is_multi_conn ? INIT_DCID_LEN : 0);
66
67
10.2k
    if (port->engine == NULL || port->channel_ctx == NULL)
68
0
        goto err;
69
70
10.2k
    if ((port->err_state = OSSL_ERR_STATE_new()) == NULL)
71
0
        goto err;
72
73
10.2k
    if ((port->demux = ossl_quic_demux_new(/*BIO=*/NULL,
74
10.2k
             /*Short CID Len=*/rx_short_dcid_len,
75
10.2k
             get_time, port))
76
10.2k
        == NULL)
77
0
        goto err;
78
79
10.2k
    ossl_quic_demux_set_default_handler(port->demux,
80
10.2k
        port_default_packet_handler,
81
10.2k
        port);
82
83
10.2k
    if ((port->srtm = ossl_quic_srtm_new(port->engine->libctx,
84
10.2k
             port->engine->propq))
85
10.2k
        == NULL)
86
0
        goto err;
87
88
10.2k
    if ((port->lcidm = ossl_quic_lcidm_new(port->engine->libctx,
89
10.2k
             rx_short_dcid_len))
90
10.2k
        == NULL)
91
0
        goto err;
92
93
10.2k
    port->rx_short_dcid_len = (unsigned char)rx_short_dcid_len;
94
10.2k
    port->tx_init_dcid_len = INIT_DCID_LEN;
95
10.2k
    port->state = QUIC_PORT_STATE_RUNNING;
96
97
10.2k
    ossl_list_port_insert_tail(&port->engine->port_list, port);
98
10.2k
    port->on_engine_list = 1;
99
10.2k
    return 1;
100
101
0
err:
102
0
    port_cleanup(port);
103
0
    return 0;
104
10.2k
}
105
106
static void port_cleanup(QUIC_PORT *port)
107
53.4k
{
108
53.4k
    assert(ossl_list_ch_num(&port->channel_list) == 0);
109
110
53.4k
    ossl_quic_demux_free(port->demux);
111
53.4k
    port->demux = NULL;
112
113
53.4k
    ossl_quic_srtm_free(port->srtm);
114
53.4k
    port->srtm = NULL;
115
116
53.4k
    ossl_quic_lcidm_free(port->lcidm);
117
53.4k
    port->lcidm = NULL;
118
119
53.4k
    OSSL_ERR_STATE_free(port->err_state);
120
53.4k
    port->err_state = NULL;
121
122
53.4k
    if (port->on_engine_list) {
123
53.4k
        ossl_list_port_remove(&port->engine->port_list, port);
124
53.4k
        port->on_engine_list = 0;
125
53.4k
    }
126
53.4k
}
127
128
static void port_transition_failed(QUIC_PORT *port)
129
0
{
130
0
    if (port->state == QUIC_PORT_STATE_FAILED)
131
0
        return;
132
133
0
    port->state = QUIC_PORT_STATE_FAILED;
134
0
}
135
136
int ossl_quic_port_is_running(const QUIC_PORT *port)
137
142M
{
138
142M
    return port->state == QUIC_PORT_STATE_RUNNING;
139
142M
}
140
141
QUIC_ENGINE *ossl_quic_port_get0_engine(QUIC_PORT *port)
142
0
{
143
0
    return port->engine;
144
0
}
145
146
QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port)
147
27.4M
{
148
27.4M
    return ossl_quic_engine_get0_reactor(port->engine);
149
27.4M
}
150
151
QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port)
152
0
{
153
0
    return port->demux;
154
0
}
155
156
CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port)
157
0
{
158
0
    return ossl_quic_engine_get0_mutex(port->engine);
159
0
}
160
161
OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port)
162
171M
{
163
171M
    return ossl_quic_engine_get_time(port->engine);
164
171M
}
165
166
static OSSL_TIME get_time(void *port)
167
9.12M
{
168
9.12M
    return ossl_quic_port_get_time((QUIC_PORT *)port);
169
9.12M
}
170
171
int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port)
172
53.0k
{
173
53.0k
    return port->rx_short_dcid_len;
174
53.0k
}
175
176
int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port)
177
53.0k
{
178
53.0k
    return port->tx_init_dcid_len;
179
53.0k
}
180
181
/*
182
 * QUIC Port: Network BIO Configuration
183
 * ====================================
184
 */
185
186
/* Determines whether we can support a given poll descriptor. */
187
static int validate_poll_descriptor(const BIO_POLL_DESCRIPTOR *d)
188
87.8M
{
189
87.8M
    if (d->type == BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD && d->value.fd < 0) {
190
0
        ERR_raise(ERR_LIB_SSL, ERR_R_PASSED_INVALID_ARGUMENT);
191
0
        return 0;
192
0
    }
193
194
87.8M
    return 1;
195
87.8M
}
196
197
BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port)
198
39.5M
{
199
39.5M
    return port->net_rbio;
200
39.5M
}
201
202
BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port)
203
39.5M
{
204
39.5M
    return port->net_wbio;
205
39.5M
}
206
207
static int port_update_poll_desc(QUIC_PORT *port, BIO *net_bio, int for_write)
208
87.8M
{
209
87.8M
    BIO_POLL_DESCRIPTOR d = { 0 };
210
211
87.8M
    if (net_bio == NULL
212
87.8M
        || (!for_write && !BIO_get_rpoll_descriptor(net_bio, &d))
213
43.9M
        || (for_write && !BIO_get_wpoll_descriptor(net_bio, &d)))
214
        /* Non-pollable BIO */
215
87.8M
        d.type = BIO_POLL_DESCRIPTOR_TYPE_NONE;
216
217
87.8M
    if (!validate_poll_descriptor(&d))
218
0
        return 0;
219
220
    /*
221
     * TODO(QUIC MULTIPORT): We currently only support one port per
222
     * engine/domain. This is necessitated because QUIC_REACTOR only supports a
223
     * single pollable currently. In the future, once complete polling
224
     * infrastructure has been implemented, this limitation can be removed.
225
     *
226
     * For now, just update the descriptor on the engine's reactor as we are
227
     * guaranteed to be the only port under it.
228
     */
229
87.8M
    if (for_write)
230
43.9M
        ossl_quic_reactor_set_poll_w(&port->engine->rtor, &d);
231
43.9M
    else
232
43.9M
        ossl_quic_reactor_set_poll_r(&port->engine->rtor, &d);
233
234
87.8M
    return 1;
235
87.8M
}
236
237
int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port)
238
4.47M
{
239
4.47M
    int ok = 1;
240
241
4.47M
    if (!port_update_poll_desc(port, port->net_rbio, /*for_write=*/0))
242
0
        ok = 0;
243
244
4.47M
    if (!port_update_poll_desc(port, port->net_wbio, /*for_write=*/1))
245
0
        ok = 0;
246
247
4.47M
    return ok;
248
4.47M
}
249
250
/*
251
 * QUIC_PORT does not ref any BIO it is provided with, nor is any ref
252
 * transferred to it. The caller (e.g., QUIC_CONNECTION) is responsible for
253
 * ensuring the BIO lasts until the channel is freed or the BIO is switched out
254
 * for another BIO by a subsequent successful call to this function.
255
 */
256
int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio)
257
63.6k
{
258
63.6k
    if (port->net_rbio == net_rbio)
259
10.2k
        return 1;
260
261
53.4k
    if (!port_update_poll_desc(port, net_rbio, /*for_write=*/0))
262
0
        return 0;
263
264
53.4k
    ossl_quic_demux_set_bio(port->demux, net_rbio);
265
53.4k
    port->net_rbio = net_rbio;
266
53.4k
    return 1;
267
53.4k
}
268
269
int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio)
270
63.6k
{
271
63.6k
    QUIC_CHANNEL *ch;
272
273
63.6k
    if (port->net_wbio == net_wbio)
274
10.2k
        return 1;
275
276
53.4k
    if (!port_update_poll_desc(port, net_wbio, /*for_write=*/1))
277
0
        return 0;
278
279
53.4k
    OSSL_LIST_FOREACH (ch, ch, &port->channel_list)
280
53.0k
        ossl_qtx_set_bio(ch->qtx, net_wbio);
281
282
53.4k
    port->net_wbio = net_wbio;
283
53.4k
    return 1;
284
53.4k
}
285
286
/*
287
 * QUIC Port: Channel Lifecycle
288
 * ============================
289
 */
290
291
static SSL *port_new_handshake_layer(QUIC_PORT *port)
292
0
{
293
0
    SSL *tls = NULL;
294
0
    SSL_CONNECTION *tls_conn = NULL;
295
296
0
    tls = ossl_ssl_connection_new_int(port->channel_ctx, NULL, TLS_method());
297
0
    if (tls == NULL || (tls_conn = SSL_CONNECTION_FROM_SSL(tls)) == NULL)
298
0
        return NULL;
299
300
    /* Override the user_ssl of the inner connection. */
301
0
    tls_conn->s3.flags |= TLS1_FLAGS_QUIC;
302
303
    /* Restrict options derived from the SSL_CTX. */
304
0
    tls_conn->options &= OSSL_QUIC_PERMITTED_OPTIONS_CONN;
305
0
    tls_conn->pha_enabled = 0;
306
0
    return tls;
307
0
}
308
309
static QUIC_CHANNEL *port_make_channel(QUIC_PORT *port, SSL *tls, int is_server)
310
10.2k
{
311
10.2k
    QUIC_CHANNEL_ARGS args = { 0 };
312
10.2k
    QUIC_CHANNEL *ch;
313
314
10.2k
    args.port = port;
315
10.2k
    args.is_server = is_server;
316
10.2k
    args.tls = (tls != NULL ? tls : port_new_handshake_layer(port));
317
10.2k
    args.lcidm = port->lcidm;
318
10.2k
    args.srtm = port->srtm;
319
10.2k
    if (args.tls == NULL)
320
0
        return NULL;
321
322
10.2k
#ifndef OPENSSL_NO_QLOG
323
10.2k
    args.use_qlog = 1; /* disabled if env not set */
324
10.2k
    args.qlog_title = args.tls->ctx->qlog_title;
325
10.2k
#endif
326
327
10.2k
    ch = ossl_quic_channel_new(&args);
328
10.2k
    if (ch == NULL) {
329
0
        if (tls == NULL)
330
0
            SSL_free(args.tls);
331
332
0
        return NULL;
333
0
    }
334
335
10.2k
    return ch;
336
10.2k
}
337
338
QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls)
339
53.0k
{
340
53.0k
    return port_make_channel(port, tls, /*is_server=*/0);
341
53.0k
}
342
343
QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls)
344
0
{
345
0
    QUIC_CHANNEL *ch;
346
347
0
    assert(port->tserver_ch == NULL);
348
349
0
    ch = port_make_channel(port, tls, /*is_server=*/1);
350
0
    port->tserver_ch = ch;
351
0
    port->is_server = 1;
352
0
    return ch;
353
0
}
354
355
/*
356
 * QUIC Port: Ticker-Mutator
357
 * =========================
358
 */
359
360
/*
361
 * Tick function for this port. This does everything related to network I/O for
362
 * this port's network BIOs, and services child channels.
363
 */
364
void ossl_quic_port_subtick(QUIC_PORT *port, QUIC_TICK_RESULT *res,
365
    uint32_t flags)
366
71.1M
{
367
71.1M
    QUIC_CHANNEL *ch;
368
369
71.1M
    res->net_read_desired = 0;
370
71.1M
    res->net_write_desired = 0;
371
71.1M
    res->tick_deadline = ossl_time_infinite();
372
373
71.1M
    if (!port->engine->inhibit_tick) {
374
        /* Handle any incoming data from network. */
375
71.1M
        if (ossl_quic_port_is_running(port))
376
71.1M
            port_rx_pre(port);
377
378
        /* Iterate through all channels and service them. */
379
71.1M
        OSSL_LIST_FOREACH (ch, ch, &port->channel_list) {
380
71.1M
            QUIC_TICK_RESULT subr = { 0 };
381
382
71.1M
            ossl_quic_channel_subtick(ch, &subr, flags);
383
71.1M
            ossl_quic_tick_result_merge_into(res, &subr);
384
71.1M
        }
385
71.1M
    }
386
71.1M
}
387
388
/* Process incoming datagrams, if any. */
389
static void port_rx_pre(QUIC_PORT *port)
390
71.1M
{
391
71.1M
    int ret;
392
393
    /*
394
     * Originally, this check (don't RX before we have sent anything if we are
395
     * not a server, because there can't be anything) was just intended as a
396
     * minor optimisation. However, it is actually required on Windows, and
397
     * removing this check will cause Windows to break.
398
     *
399
     * The reason is that under Win32, recvfrom() does not work on a UDP socket
400
     * which has not had bind() called (???). However, calling sendto() will
401
     * automatically bind an unbound UDP socket. Therefore, if we call a Winsock
402
     * recv-type function before calling a Winsock send-type function, that call
403
     * will fail with WSAEINVAL, which we will regard as a permanent network
404
     * error.
405
     *
406
     * Therefore, this check is essential as we do not require our API users to
407
     * bind a socket first when using the API in client mode.
408
     */
409
71.1M
    if (!port->is_server && !port->have_sent_any_pkt)
410
53.0k
        return;
411
412
    /*
413
     * Get DEMUX to BIO_recvmmsg from the network and queue incoming datagrams
414
     * to the appropriate QRX instances.
415
     */
416
71.0M
    ret = ossl_quic_demux_pump(port->demux);
417
71.0M
    if (ret == QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL)
418
        /*
419
         * We don't care about transient failure, but permanent failure means we
420
         * should tear down the port. All connections skip straight to the
421
         * Terminated state as there is no point trying to send CONNECTION_CLOSE
422
         * frames if the network BIO is not operating correctly.
423
         */
424
0
        ossl_quic_port_raise_net_error(port, NULL);
425
71.0M
}
426
427
/*
428
 * Handles an incoming connection request and potentially decides to make a
429
 * connection from it. If a new connection is made, the new channel is written
430
 * to *new_ch.
431
 */
432
static void port_on_new_conn(QUIC_PORT *port, const BIO_ADDR *peer,
433
    const QUIC_CONN_ID *scid,
434
    const QUIC_CONN_ID *dcid,
435
    QUIC_CHANNEL **new_ch)
436
0
{
437
0
    if (port->tserver_ch != NULL) {
438
        /* Specially assign to existing channel */
439
0
        if (!ossl_quic_channel_on_new_conn(port->tserver_ch, peer, scid, dcid))
440
0
            return;
441
442
0
        *new_ch = port->tserver_ch;
443
0
        port->tserver_ch = NULL;
444
0
        return;
445
0
    }
446
0
}
447
448
static int port_try_handle_stateless_reset(QUIC_PORT *port, const QUIC_URXE *e)
449
11.1M
{
450
11.1M
    size_t i;
451
11.1M
    const unsigned char *data = ossl_quic_urxe_data(e);
452
11.1M
    void *opaque = NULL;
453
454
    /*
455
     * Perform some fast and cheap checks for a packet not being a stateless
456
     * reset token.  RFC 9000 s. 10.3 specifies this layout for stateless
457
     * reset packets:
458
     *
459
     *  Stateless Reset {
460
     *      Fixed Bits (2) = 1,
461
     *      Unpredictable Bits (38..),
462
     *      Stateless Reset Token (128),
463
     *  }
464
     *
465
     * It also specifies:
466
     *      However, endpoints MUST treat any packet ending in a valid
467
     *      stateless reset token as a Stateless Reset, as other QUIC
468
     *      versions might allow the use of a long header.
469
     *
470
     * We can rapidly check for the minimum length and that the first pair
471
     * of bits in the first byte are 01 or 11.
472
     *
473
     * The function returns 1 if it is a stateless reset packet, 0 if it isn't
474
     * and -1 if an error was encountered.
475
     */
476
11.1M
    if (e->data_len < QUIC_STATELESS_RESET_TOKEN_LEN + 5
477
3.90M
        || (0100 & *data) != 0100)
478
7.57M
        return 0;
479
480
3.53M
    for (i = 0;; ++i) {
481
3.53M
        if (!ossl_quic_srtm_lookup(port->srtm,
482
3.53M
                (QUIC_STATELESS_RESET_TOKEN *)(data + e->data_len
483
3.53M
                    - sizeof(QUIC_STATELESS_RESET_TOKEN)),
484
3.53M
                i, &opaque, NULL))
485
3.53M
            break;
486
487
3.53M
        assert(opaque != NULL);
488
33
        ossl_quic_channel_on_stateless_reset((QUIC_CHANNEL *)opaque);
489
33
    }
490
491
3.53M
    return i > 0;
492
3.53M
}
493
494
/*
495
 * This is called by the demux when we get a packet not destined for any known
496
 * DCID.
497
 */
498
static void port_default_packet_handler(QUIC_URXE *e, void *arg,
499
    const QUIC_CONN_ID *dcid)
500
2.16M
{
501
2.16M
    QUIC_PORT *port = arg;
502
2.16M
    PACKET pkt;
503
2.16M
    QUIC_PKT_HDR hdr;
504
2.16M
    QUIC_CHANNEL *ch = NULL, *new_ch = NULL;
505
506
    /* Don't handle anything if we are no longer running. */
507
2.16M
    if (!ossl_quic_port_is_running(port))
508
0
        goto undesirable;
509
510
2.16M
    if (port_try_handle_stateless_reset(port, e))
511
2
        goto undesirable;
512
513
2.16M
    if (dcid != NULL
514
706k
        && ossl_quic_lcidm_lookup(port->lcidm, dcid, NULL,
515
706k
            (void **)&ch)) {
516
705k
        assert(ch != NULL);
517
705k
        ossl_quic_channel_inject(ch, e);
518
705k
        return;
519
705k
    }
520
521
    /*
522
     * If we have an incoming packet which doesn't match any existing connection
523
     * we assume this is an attempt to make a new connection. Currently we
524
     * require our caller to have precreated a latent 'incoming' channel via
525
     * TSERVER which then gets turned into the new connection.
526
     *
527
     * TODO(QUIC SERVER): In the future we will construct channels dynamically
528
     * in this case.
529
     */
530
1.46M
    if (port->tserver_ch == NULL)
531
1.46M
        goto undesirable;
532
533
    /*
534
     * packet without destination connection id is invalid/corrupted here.
535
     * stop wasting CPU cycles now.
536
     */
537
0
    if (dcid == NULL)
538
0
        goto undesirable;
539
540
    /*
541
     * We have got a packet for an unknown DCID. This might be an attempt to
542
     * open a new connection.
543
     */
544
0
    if (e->data_len < QUIC_MIN_INITIAL_DGRAM_LEN)
545
0
        goto undesirable;
546
547
0
    if (!PACKET_buf_init(&pkt, ossl_quic_urxe_data(e), e->data_len))
548
0
        goto undesirable;
549
550
    /*
551
     * We set short_conn_id_len to SIZE_MAX here which will cause the decode
552
     * operation to fail if we get a 1-RTT packet. This is fine since we only
553
     * care about Initial packets.
554
     */
555
0
    if (!ossl_quic_wire_decode_pkt_hdr(&pkt, SIZE_MAX, 1, 0, &hdr, NULL))
556
0
        goto undesirable;
557
558
0
    switch (hdr.version) {
559
0
    case QUIC_VERSION_1:
560
0
        break;
561
562
0
    case QUIC_VERSION_NONE:
563
0
    default:
564
        /* Unknown version or proactive version negotiation request, bail. */
565
        /* TODO(QUIC SERVER): Handle version negotiation on server side */
566
0
        goto undesirable;
567
0
    }
568
569
    /*
570
     * We only care about Initial packets which might be trying to establish a
571
     * connection.
572
     */
573
0
    if (hdr.type != QUIC_PKT_TYPE_INITIAL)
574
0
        goto undesirable;
575
576
    /*
577
     * Try to process this as a valid attempt to initiate a connection.
578
     *
579
     * The channel will do all the LCID registration needed, but as an
580
     * optimization inject this packet directly into the channel's QRX for
581
     * processing without going through the DEMUX again.
582
     */
583
0
    port_on_new_conn(port, &e->peer, &hdr.src_conn_id, &hdr.dst_conn_id,
584
0
        &new_ch);
585
0
    if (new_ch != NULL)
586
0
        ossl_qrx_inject_urxe(new_ch->qrx, e);
587
588
0
    return;
589
590
1.46M
undesirable:
591
1.46M
    ossl_quic_demux_release_urxe(port->demux, e);
592
1.46M
}
593
594
void ossl_quic_port_raise_net_error(QUIC_PORT *port,
595
    QUIC_CHANNEL *triggering_ch)
596
0
{
597
0
    QUIC_CHANNEL *ch;
598
599
0
    if (!ossl_quic_port_is_running(port))
600
0
        return;
601
602
    /*
603
     * Immediately capture any triggering error on the error stack, with a
604
     * cover error.
605
     */
606
0
    ERR_raise_data(ERR_LIB_SSL, SSL_R_QUIC_NETWORK_ERROR,
607
0
        "port failed due to network BIO I/O error");
608
0
    OSSL_ERR_STATE_save(port->err_state);
609
610
0
    port_transition_failed(port);
611
612
    /* Give the triggering channel (if any) the first notification. */
613
0
    if (triggering_ch != NULL)
614
0
        ossl_quic_channel_raise_net_error(triggering_ch);
615
616
0
    OSSL_LIST_FOREACH (ch, ch, &port->channel_list)
617
0
        if (ch != triggering_ch)
618
0
            ossl_quic_channel_raise_net_error(ch);
619
0
}
620
621
void ossl_quic_port_restore_err_state(const QUIC_PORT *port)
622
0
{
623
0
    ERR_clear_error();
624
0
    OSSL_ERR_STATE_restore(port->err_state);
625
0
}