Coverage Report

Created: 2026-05-24 07:14

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-2024 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
22.5k
#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
157M
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
104k
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
52.2k
{
37
52.2k
    QUIC_PORT *port;
38
39
52.2k
    if ((port = OPENSSL_zalloc(sizeof(QUIC_PORT))) == NULL)
40
0
        return NULL;
41
42
52.2k
    port->engine = args->engine;
43
52.2k
    port->channel_ctx = args->channel_ctx;
44
52.2k
    port->is_multi_conn = args->is_multi_conn;
45
46
52.2k
    if (!port_init(port)) {
47
0
        OPENSSL_free(port);
48
0
        return NULL;
49
0
    }
50
51
52.2k
    return port;
52
52.2k
}
53
54
void ossl_quic_port_free(QUIC_PORT *port)
55
52.2k
{
56
52.2k
    if (port == NULL)
57
0
        return;
58
59
52.2k
    port_cleanup(port);
60
52.2k
    OPENSSL_free(port);
61
52.2k
}
62
63
static int port_init(QUIC_PORT *port)
64
22.5k
{
65
22.5k
    size_t rx_short_dcid_len = (port->is_multi_conn ? INIT_DCID_LEN : 0);
66
67
22.5k
    if (port->engine == NULL || port->channel_ctx == NULL)
68
0
        goto err;
69
70
22.5k
    if ((port->err_state = OSSL_ERR_STATE_new()) == NULL)
71
0
        goto err;
72
73
22.5k
    if ((port->demux = ossl_quic_demux_new(/*BIO=*/NULL,
74
22.5k
             /*Short CID Len=*/rx_short_dcid_len,
75
22.5k
             get_time, port))
76
22.5k
        == NULL)
77
0
        goto err;
78
79
22.5k
    ossl_quic_demux_set_default_handler(port->demux,
80
22.5k
        port_default_packet_handler,
81
22.5k
        port);
82
83
22.5k
    if ((port->srtm = ossl_quic_srtm_new(port->engine->libctx,
84
22.5k
             port->engine->propq))
85
22.5k
        == NULL)
86
0
        goto err;
87
88
22.5k
    if ((port->lcidm = ossl_quic_lcidm_new(port->engine->libctx,
89
22.5k
             rx_short_dcid_len))
90
22.5k
        == NULL)
91
0
        goto err;
92
93
22.5k
    port->rx_short_dcid_len = (unsigned char)rx_short_dcid_len;
94
22.5k
    port->tx_init_dcid_len = INIT_DCID_LEN;
95
22.5k
    port->state = QUIC_PORT_STATE_RUNNING;
96
97
22.5k
    ossl_list_port_insert_tail(&port->engine->port_list, port);
98
22.5k
    port->on_engine_list = 1;
99
22.5k
    return 1;
100
101
0
err:
102
0
    port_cleanup(port);
103
0
    return 0;
104
22.5k
}
105
106
static void port_cleanup(QUIC_PORT *port)
107
52.2k
{
108
52.2k
    assert(ossl_list_ch_num(&port->channel_list) == 0);
109
110
52.2k
    ossl_quic_demux_free(port->demux);
111
52.2k
    port->demux = NULL;
112
113
52.2k
    ossl_quic_srtm_free(port->srtm);
114
52.2k
    port->srtm = NULL;
115
116
52.2k
    ossl_quic_lcidm_free(port->lcidm);
117
52.2k
    port->lcidm = NULL;
118
119
52.2k
    OSSL_ERR_STATE_free(port->err_state);
120
52.2k
    port->err_state = NULL;
121
122
52.2k
    if (port->on_engine_list) {
123
52.2k
        ossl_list_port_remove(&port->engine->port_list, port);
124
52.2k
        port->on_engine_list = 0;
125
52.2k
    }
126
52.2k
}
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
137M
{
138
137M
    return port->state == QUIC_PORT_STATE_RUNNING;
139
137M
}
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
91.6M
{
148
91.6M
    return ossl_quic_engine_get0_reactor(port->engine);
149
91.6M
}
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
214M
{
163
214M
    return ossl_quic_engine_get_time(port->engine);
164
214M
}
165
166
static OSSL_TIME get_time(void *port)
167
9.00M
{
168
9.00M
    return ossl_quic_port_get_time((QUIC_PORT *)port);
169
9.00M
}
170
171
int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port)
172
51.9k
{
173
51.9k
    return port->rx_short_dcid_len;
174
51.9k
}
175
176
int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port)
177
51.9k
{
178
51.9k
    return port->tx_init_dcid_len;
179
51.9k
}
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
112M
{
189
112M
    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
112M
    return 1;
195
112M
}
196
197
BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port)
198
33.3M
{
199
33.3M
    return port->net_rbio;
200
33.3M
}
201
202
BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port)
203
33.2M
{
204
33.2M
    return port->net_wbio;
205
33.2M
}
206
207
static int port_update_poll_desc(QUIC_PORT *port, BIO *net_bio, int for_write)
208
112M
{
209
112M
    BIO_POLL_DESCRIPTOR d = { 0 };
210
211
112M
    if (net_bio == NULL
212
112M
        || (!for_write && !BIO_get_rpoll_descriptor(net_bio, &d))
213
56.1M
        || (for_write && !BIO_get_wpoll_descriptor(net_bio, &d)))
214
        /* Non-pollable BIO */
215
112M
        d.type = BIO_POLL_DESCRIPTOR_TYPE_NONE;
216
217
112M
    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
112M
    if (for_write)
230
56.2M
        ossl_quic_reactor_set_poll_w(&port->engine->rtor, &d);
231
56.2M
    else
232
56.2M
        ossl_quic_reactor_set_poll_r(&port->engine->rtor, &d);
233
234
112M
    return 1;
235
112M
}
236
237
int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port)
238
22.9M
{
239
22.9M
    int ok = 1;
240
241
22.9M
    if (!port_update_poll_desc(port, port->net_rbio, /*for_write=*/0))
242
0
        ok = 0;
243
244
22.9M
    if (!port_update_poll_desc(port, port->net_wbio, /*for_write=*/1))
245
0
        ok = 0;
246
247
22.9M
    return ok;
248
22.9M
}
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
74.7k
{
258
74.7k
    if (port->net_rbio == net_rbio)
259
22.5k
        return 1;
260
261
52.2k
    if (!port_update_poll_desc(port, net_rbio, /*for_write=*/0))
262
0
        return 0;
263
264
52.2k
    ossl_quic_demux_set_bio(port->demux, net_rbio);
265
52.2k
    port->net_rbio = net_rbio;
266
52.2k
    return 1;
267
52.2k
}
268
269
int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio)
270
74.7k
{
271
74.7k
    QUIC_CHANNEL *ch;
272
273
74.7k
    if (port->net_wbio == net_wbio)
274
22.5k
        return 1;
275
276
52.2k
    if (!port_update_poll_desc(port, net_wbio, /*for_write=*/1))
277
0
        return 0;
278
279
52.2k
    OSSL_LIST_FOREACH(ch, ch, &port->channel_list)
280
51.9k
    ossl_qtx_set_bio(ch->qtx, net_wbio);
281
282
52.2k
    port->net_wbio = net_wbio;
283
52.2k
    return 1;
284
52.2k
}
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
22.5k
{
311
22.5k
    QUIC_CHANNEL_ARGS args = { 0 };
312
22.5k
    QUIC_CHANNEL *ch;
313
314
22.5k
    args.port = port;
315
22.5k
    args.is_server = is_server;
316
22.5k
    args.tls = (tls != NULL ? tls : port_new_handshake_layer(port));
317
22.5k
    args.lcidm = port->lcidm;
318
22.5k
    args.srtm = port->srtm;
319
22.5k
    if (args.tls == NULL)
320
0
        return NULL;
321
322
22.5k
#ifndef OPENSSL_NO_QLOG
323
22.5k
    args.use_qlog = 1; /* disabled if env not set */
324
22.5k
    args.qlog_title = args.tls->ctx->qlog_title;
325
22.5k
#endif
326
327
22.5k
    ch = ossl_quic_channel_new(&args);
328
22.5k
    if (ch == NULL) {
329
0
        if (tls == NULL)
330
0
            SSL_free(args.tls);
331
332
0
        return NULL;
333
0
    }
334
335
22.5k
    return ch;
336
22.5k
}
337
338
QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls)
339
51.9k
{
340
51.9k
    return port_make_channel(port, tls, /*is_server=*/0);
341
51.9k
}
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
78.8M
{
367
78.8M
    QUIC_CHANNEL *ch;
368
369
78.8M
    res->net_read_desired = 0;
370
78.8M
    res->net_write_desired = 0;
371
78.8M
    res->tick_deadline = ossl_time_infinite();
372
373
78.8M
    if (!port->engine->inhibit_tick) {
374
        /* Handle any incoming data from network. */
375
78.8M
        if (ossl_quic_port_is_running(port))
376
78.8M
            port_rx_pre(port);
377
378
        /* Iterate through all channels and service them. */
379
78.8M
        OSSL_LIST_FOREACH(ch, ch, &port->channel_list)
380
78.8M
        {
381
78.8M
            QUIC_TICK_RESULT subr = { 0 };
382
383
78.8M
            ossl_quic_channel_subtick(ch, &subr, flags);
384
78.8M
            ossl_quic_tick_result_merge_into(res, &subr);
385
78.8M
        }
386
78.8M
    }
387
78.8M
}
388
389
/* Process incoming datagrams, if any. */
390
static void port_rx_pre(QUIC_PORT *port)
391
78.8M
{
392
78.8M
    int ret;
393
394
    /*
395
     * Originally, this check (don't RX before we have sent anything if we are
396
     * not a server, because there can't be anything) was just intended as a
397
     * minor optimisation. However, it is actually required on Windows, and
398
     * removing this check will cause Windows to break.
399
     *
400
     * The reason is that under Win32, recvfrom() does not work on a UDP socket
401
     * which has not had bind() called (???). However, calling sendto() will
402
     * automatically bind an unbound UDP socket. Therefore, if we call a Winsock
403
     * recv-type function before calling a Winsock send-type function, that call
404
     * will fail with WSAEINVAL, which we will regard as a permanent network
405
     * error.
406
     *
407
     * Therefore, this check is essential as we do not require our API users to
408
     * bind a socket first when using the API in client mode.
409
     */
410
78.8M
    if (!port->is_server && !port->have_sent_any_pkt)
411
51.9k
        return;
412
413
    /*
414
     * Get DEMUX to BIO_recvmmsg from the network and queue incoming datagrams
415
     * to the appropriate QRX instances.
416
     */
417
78.7M
    ret = ossl_quic_demux_pump(port->demux);
418
78.7M
    if (ret == QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL)
419
        /*
420
         * We don't care about transient failure, but permanent failure means we
421
         * should tear down the port. All connections skip straight to the
422
         * Terminated state as there is no point trying to send CONNECTION_CLOSE
423
         * frames if the network BIO is not operating correctly.
424
         */
425
0
        ossl_quic_port_raise_net_error(port, NULL);
426
78.7M
}
427
428
/*
429
 * Handles an incoming connection request and potentially decides to make a
430
 * connection from it. If a new connection is made, the new channel is written
431
 * to *new_ch.
432
 */
433
static void port_on_new_conn(QUIC_PORT *port, const BIO_ADDR *peer,
434
    const QUIC_CONN_ID *scid,
435
    const QUIC_CONN_ID *dcid,
436
    QUIC_CHANNEL **new_ch)
437
0
{
438
0
    if (port->tserver_ch != NULL) {
439
        /* Specially assign to existing channel */
440
0
        if (!ossl_quic_channel_on_new_conn(port->tserver_ch, peer, scid, dcid))
441
0
            return;
442
443
0
        *new_ch = port->tserver_ch;
444
0
        port->tserver_ch = NULL;
445
0
        return;
446
0
    }
447
0
}
448
449
static int port_try_handle_stateless_reset(QUIC_PORT *port, const QUIC_URXE *e)
450
11.9M
{
451
11.9M
    size_t i;
452
11.9M
    const unsigned char *data = ossl_quic_urxe_data(e);
453
11.9M
    void *opaque = NULL;
454
455
    /*
456
     * Perform some fast and cheap checks for a packet not being a stateless
457
     * reset token.  RFC 9000 s. 10.3 specifies this layout for stateless
458
     * reset packets:
459
     *
460
     *  Stateless Reset {
461
     *      Fixed Bits (2) = 1,
462
     *      Unpredictable Bits (38..),
463
     *      Stateless Reset Token (128),
464
     *  }
465
     *
466
     * It also specifies:
467
     *      However, endpoints MUST treat any packet ending in a valid
468
     *      stateless reset token as a Stateless Reset, as other QUIC
469
     *      versions might allow the use of a long header.
470
     *
471
     * We can rapidly check for the minimum length and that the first pair
472
     * of bits in the first byte are 01 or 11.
473
     *
474
     * The function returns 1 if it is a stateless reset packet, 0 if it isn't
475
     * and -1 if an error was encountered.
476
     */
477
11.9M
    if (e->data_len < QUIC_STATELESS_RESET_TOKEN_LEN + 5
478
5.03M
        || (0100 & *data) != 0100)
479
7.30M
        return 0;
480
481
4.61M
    for (i = 0;; ++i) {
482
4.61M
        if (!ossl_quic_srtm_lookup(port->srtm,
483
4.61M
                (QUIC_STATELESS_RESET_TOKEN *)(data + e->data_len
484
4.61M
                    - sizeof(QUIC_STATELESS_RESET_TOKEN)),
485
4.61M
                i, &opaque, NULL))
486
4.61M
            break;
487
488
4.61M
        assert(opaque != NULL);
489
20
        ossl_quic_channel_on_stateless_reset((QUIC_CHANNEL *)opaque);
490
20
    }
491
492
4.61M
    return i > 0;
493
4.61M
}
494
495
/*
496
 * This is called by the demux when we get a packet not destined for any known
497
 * DCID.
498
 */
499
static void port_default_packet_handler(QUIC_URXE *e, void *arg,
500
    const QUIC_CONN_ID *dcid)
501
2.89M
{
502
2.89M
    QUIC_PORT *port = arg;
503
2.89M
    PACKET pkt;
504
2.89M
    QUIC_PKT_HDR hdr;
505
2.89M
    QUIC_CHANNEL *ch = NULL, *new_ch = NULL;
506
507
    /* Don't handle anything if we are no longer running. */
508
2.89M
    if (!ossl_quic_port_is_running(port))
509
0
        goto undesirable;
510
511
2.89M
    if (port_try_handle_stateless_reset(port, e))
512
2
        goto undesirable;
513
514
2.89M
    if (dcid != NULL
515
1.24M
        && ossl_quic_lcidm_lookup(port->lcidm, dcid, NULL,
516
1.24M
            (void **)&ch)) {
517
1.24M
        assert(ch != NULL);
518
1.24M
        ossl_quic_channel_inject(ch, e);
519
1.24M
        return;
520
1.24M
    }
521
522
    /*
523
     * If we have an incoming packet which doesn't match any existing connection
524
     * we assume this is an attempt to make a new connection. Currently we
525
     * require our caller to have precreated a latent 'incoming' channel via
526
     * TSERVER which then gets turned into the new connection.
527
     *
528
     * TODO(QUIC SERVER): In the future we will construct channels dynamically
529
     * in this case.
530
     */
531
1.64M
    if (port->tserver_ch == NULL)
532
1.64M
        goto undesirable;
533
534
    /*
535
     * packet without destination connection id is invalid/corrupted here.
536
     * stop wasting CPU cycles now.
537
     */
538
0
    if (dcid == NULL)
539
0
        goto undesirable;
540
541
    /*
542
     * We have got a packet for an unknown DCID. This might be an attempt to
543
     * open a new connection.
544
     */
545
0
    if (e->data_len < QUIC_MIN_INITIAL_DGRAM_LEN)
546
0
        goto undesirable;
547
548
0
    if (!PACKET_buf_init(&pkt, ossl_quic_urxe_data(e), e->data_len))
549
0
        goto undesirable;
550
551
    /*
552
     * We set short_conn_id_len to SIZE_MAX here which will cause the decode
553
     * operation to fail if we get a 1-RTT packet. This is fine since we only
554
     * care about Initial packets.
555
     */
556
0
    if (!ossl_quic_wire_decode_pkt_hdr(&pkt, SIZE_MAX, 1, 0, &hdr, NULL))
557
0
        goto undesirable;
558
559
0
    switch (hdr.version) {
560
0
    case QUIC_VERSION_1:
561
0
        break;
562
563
0
    case QUIC_VERSION_NONE:
564
0
    default:
565
        /* Unknown version or proactive version negotiation request, bail. */
566
        /* TODO(QUIC SERVER): Handle version negotiation on server side */
567
0
        goto undesirable;
568
0
    }
569
570
    /*
571
     * We only care about Initial packets which might be trying to establish a
572
     * connection.
573
     */
574
0
    if (hdr.type != QUIC_PKT_TYPE_INITIAL)
575
0
        goto undesirable;
576
577
    /*
578
     * Try to process this as a valid attempt to initiate a connection.
579
     *
580
     * The channel will do all the LCID registration needed, but as an
581
     * optimization inject this packet directly into the channel's QRX for
582
     * processing without going through the DEMUX again.
583
     */
584
0
    port_on_new_conn(port, &e->peer, &hdr.src_conn_id, &hdr.dst_conn_id,
585
0
        &new_ch);
586
0
    if (new_ch != NULL)
587
0
        ossl_qrx_inject_urxe(new_ch->qrx, e);
588
589
0
    return;
590
591
1.64M
undesirable:
592
1.64M
    ossl_quic_demux_release_urxe(port->demux, e);
593
1.64M
}
594
595
void ossl_quic_port_raise_net_error(QUIC_PORT *port,
596
    QUIC_CHANNEL *triggering_ch)
597
0
{
598
0
    QUIC_CHANNEL *ch;
599
600
0
    if (!ossl_quic_port_is_running(port))
601
0
        return;
602
603
    /*
604
     * Immediately capture any triggering error on the error stack, with a
605
     * cover error.
606
     */
607
0
    ERR_raise_data(ERR_LIB_SSL, SSL_R_QUIC_NETWORK_ERROR,
608
0
        "port failed due to network BIO I/O error");
609
0
    OSSL_ERR_STATE_save(port->err_state);
610
611
0
    port_transition_failed(port);
612
613
    /* Give the triggering channel (if any) the first notification. */
614
0
    if (triggering_ch != NULL)
615
0
        ossl_quic_channel_raise_net_error(triggering_ch);
616
617
0
    OSSL_LIST_FOREACH(ch, ch, &port->channel_list)
618
0
    if (ch != triggering_ch)
619
0
        ossl_quic_channel_raise_net_error(ch);
620
0
}
621
622
void ossl_quic_port_restore_err_state(const QUIC_PORT *port)
623
0
{
624
0
    ERR_clear_error();
625
0
    OSSL_ERR_STATE_restore(port->err_state);
626
0
}