Coverage Report

Created: 2026-02-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/ssl/quic/quic_engine.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_engine.h"
11
#include "internal/quic_port.h"
12
#include "quic_engine_local.h"
13
#include "quic_port_local.h"
14
#include "../ssl_local.h"
15
16
/*
17
 * QUIC Engine
18
 * ===========
19
 */
20
static int qeng_init(QUIC_ENGINE *qeng);
21
static void qeng_cleanup(QUIC_ENGINE *qeng);
22
static void qeng_tick(QUIC_TICK_RESULT *res, void *arg, uint32_t flags);
23
24
274M
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
quic_engine.c:ossl_list_port_head
Line
Count
Source
24
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
quic_engine.c:ossl_list_port_next
Line
Count
Source
24
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
25
26
QUIC_ENGINE *ossl_quic_engine_new(const QUIC_ENGINE_ARGS *args)
27
51.5k
{
28
51.5k
    QUIC_ENGINE *qeng;
29
30
51.5k
    if ((qeng = OPENSSL_zalloc(sizeof(QUIC_ENGINE))) == NULL)
31
0
        return NULL;
32
33
51.5k
    qeng->libctx = args->libctx;
34
51.5k
    qeng->propq = args->propq;
35
51.5k
    qeng->mutex = args->mutex;
36
51.5k
    qeng->now_cb = args->now_cb;
37
51.5k
    qeng->now_cb_arg = args->now_cb_arg;
38
39
51.5k
    if (!qeng_init(qeng)) {
40
0
        OPENSSL_free(qeng);
41
0
        return NULL;
42
0
    }
43
44
51.5k
    return qeng;
45
51.5k
}
46
47
void ossl_quic_engine_free(QUIC_ENGINE *qeng)
48
51.5k
{
49
51.5k
    if (qeng == NULL)
50
0
        return;
51
52
51.5k
    qeng_cleanup(qeng);
53
51.5k
    OPENSSL_free(qeng);
54
51.5k
}
55
56
static int qeng_init(QUIC_ENGINE *qeng)
57
51.5k
{
58
51.5k
    ossl_quic_reactor_init(&qeng->rtor, qeng_tick, qeng, ossl_time_zero());
59
51.5k
    return 1;
60
51.5k
}
61
62
static void qeng_cleanup(QUIC_ENGINE *qeng)
63
51.5k
{
64
51.5k
    assert(ossl_list_port_num(&qeng->port_list) == 0);
65
51.5k
}
66
67
QUIC_REACTOR *ossl_quic_engine_get0_reactor(QUIC_ENGINE *qeng)
68
203M
{
69
203M
    return &qeng->rtor;
70
203M
}
71
72
CRYPTO_MUTEX *ossl_quic_engine_get0_mutex(QUIC_ENGINE *qeng)
73
206M
{
74
206M
    return qeng->mutex;
75
206M
}
76
77
OSSL_TIME ossl_quic_engine_get_time(QUIC_ENGINE *qeng)
78
202M
{
79
202M
    if (qeng->now_cb == NULL)
80
29.8k
        return ossl_time_now();
81
82
202M
    return qeng->now_cb(qeng->now_cb_arg);
83
202M
}
84
85
void ossl_quic_engine_set_inhibit_tick(QUIC_ENGINE *qeng, int inhibit)
86
0
{
87
0
    qeng->inhibit_tick = (inhibit != 0);
88
0
}
89
90
/*
91
 * QUIC Engine: Child Object Lifecycle Management
92
 * ==============================================
93
 */
94
95
QUIC_PORT *ossl_quic_engine_create_port(QUIC_ENGINE *qeng,
96
    const QUIC_PORT_ARGS *args)
97
51.5k
{
98
51.5k
    QUIC_PORT_ARGS largs = *args;
99
100
51.5k
    if (ossl_list_port_num(&qeng->port_list) > 0)
101
        /* TODO(QUIC MULTIPORT): We currently support only one port. */
102
0
        return NULL;
103
104
51.5k
    if (largs.engine != NULL)
105
0
        return NULL;
106
107
51.5k
    largs.engine = qeng;
108
51.5k
    return ossl_quic_port_new(&largs);
109
51.5k
}
110
111
/*
112
 * QUIC Engine: Ticker-Mutator
113
 * ==========================
114
 */
115
116
/*
117
 * The central ticker function called by the reactor. This does everything, or
118
 * at least everything network I/O related. Best effort - not allowed to fail
119
 * "loudly".
120
 */
121
static void qeng_tick(QUIC_TICK_RESULT *res, void *arg, uint32_t flags)
122
61.4M
{
123
61.4M
    QUIC_ENGINE *qeng = arg;
124
61.4M
    QUIC_PORT *port;
125
126
61.4M
    res->net_read_desired = 0;
127
61.4M
    res->net_write_desired = 0;
128
61.4M
    res->tick_deadline = ossl_time_infinite();
129
130
61.4M
    if (qeng->inhibit_tick)
131
0
        return;
132
133
    /* Iterate through all ports and service them. */
134
61.4M
    OSSL_LIST_FOREACH(port, port, &qeng->port_list)
135
61.4M
    {
136
61.4M
        QUIC_TICK_RESULT subr = { 0 };
137
138
61.4M
        ossl_quic_port_subtick(port, &subr, flags);
139
61.4M
        ossl_quic_tick_result_merge_into(res, &subr);
140
61.4M
    }
141
61.4M
}