Coverage Report

Created: 2025-08-28 07:07

/src/openssl34/ssl/quic/quic_engine.c
Line
Count
Source (jump to first uncovered line)
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
DEFINE_LIST_OF_IMPL(port, QUIC_PORT);
25
26
QUIC_ENGINE *ossl_quic_engine_new(const QUIC_ENGINE_ARGS *args)
27
37.7k
{
28
37.7k
    QUIC_ENGINE *qeng;
29
30
37.7k
    if ((qeng = OPENSSL_zalloc(sizeof(QUIC_ENGINE))) == NULL)
31
0
        return NULL;
32
33
37.7k
    qeng->libctx            = args->libctx;
34
37.7k
    qeng->propq             = args->propq;
35
37.7k
    qeng->mutex             = args->mutex;
36
37.7k
    qeng->now_cb            = args->now_cb;
37
37.7k
    qeng->now_cb_arg        = args->now_cb_arg;
38
39
37.7k
    if (!qeng_init(qeng)) {
40
0
        OPENSSL_free(qeng);
41
0
        return NULL;
42
0
    }
43
44
37.7k
    return qeng;
45
37.7k
}
46
47
void ossl_quic_engine_free(QUIC_ENGINE *qeng)
48
37.7k
{
49
37.7k
    if (qeng == NULL)
50
0
        return;
51
52
37.7k
    qeng_cleanup(qeng);
53
37.7k
    OPENSSL_free(qeng);
54
37.7k
}
55
56
static int qeng_init(QUIC_ENGINE *qeng)
57
37.7k
{
58
37.7k
    ossl_quic_reactor_init(&qeng->rtor, qeng_tick, qeng, ossl_time_zero());
59
37.7k
    return 1;
60
37.7k
}
61
62
static void qeng_cleanup(QUIC_ENGINE *qeng)
63
37.7k
{
64
37.7k
    assert(ossl_list_port_num(&qeng->port_list) == 0);
65
37.7k
}
66
67
QUIC_REACTOR *ossl_quic_engine_get0_reactor(QUIC_ENGINE *qeng)
68
131M
{
69
131M
    return &qeng->rtor;
70
131M
}
71
72
CRYPTO_MUTEX *ossl_quic_engine_get0_mutex(QUIC_ENGINE *qeng)
73
137M
{
74
137M
    return qeng->mutex;
75
137M
}
76
77
OSSL_TIME ossl_quic_engine_get_time(QUIC_ENGINE *qeng)
78
126M
{
79
126M
    if (qeng->now_cb == NULL)
80
19.0k
        return ossl_time_now();
81
82
126M
    return qeng->now_cb(qeng->now_cb_arg);
83
126M
}
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
37.7k
{
98
37.7k
    QUIC_PORT_ARGS largs = *args;
99
100
37.7k
    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
37.7k
    if (largs.engine != NULL)
105
0
        return NULL;
106
107
37.7k
    largs.engine = qeng;
108
37.7k
    return ossl_quic_port_new(&largs);
109
37.7k
}
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
41.8M
{
123
41.8M
    QUIC_ENGINE *qeng = arg;
124
41.8M
    QUIC_PORT *port;
125
126
41.8M
    res->net_read_desired   = 0;
127
41.8M
    res->net_write_desired  = 0;
128
41.8M
    res->tick_deadline      = ossl_time_infinite();
129
130
41.8M
    if (qeng->inhibit_tick)
131
0
        return;
132
133
    /* Iterate through all ports and service them. */
134
41.8M
    OSSL_LIST_FOREACH(port, port, &qeng->port_list) {
135
41.8M
        QUIC_TICK_RESULT subr = {0};
136
137
41.8M
        ossl_quic_port_subtick(port, &subr, flags);
138
41.8M
        ossl_quic_tick_result_merge_into(res, &subr);
139
41.8M
    }
140
41.8M
}