Coverage Report

Created: 2026-01-10 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/app/ogs-config.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2019-2023 by Sukchan Lee <acetcom@gmail.com>
3
 *
4
 * This file is part of Open5GS.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
#include "ogs-app.h"
21
22
static ogs_app_global_conf_t global_conf;
23
static ogs_app_local_conf_t local_conf;
24
25
static OGS_POOL(policy_conf_pool, ogs_app_policy_conf_t);
26
static OGS_POOL(slice_conf_pool, ogs_app_slice_conf_t);
27
static OGS_POOL(session_conf_pool, ogs_app_session_conf_t);
28
29
static int initialized = 0;
30
31
int ogs_app_config_init(void)
32
0
{
33
0
    ogs_assert(initialized == 0);
34
35
0
    memset(&global_conf, 0, sizeof(ogs_app_global_conf_t));
36
0
    memset(&local_conf, 0, sizeof(ogs_app_local_conf_t));
37
38
0
    ogs_pool_init(&policy_conf_pool, OGS_MAX_NUM_OF_PLMN);
39
0
    ogs_pool_init(&slice_conf_pool, OGS_MAX_NUM_OF_SLICE);
40
0
    ogs_pool_init(&session_conf_pool,
41
0
            OGS_MAX_NUM_OF_SLICE*OGS_MAX_NUM_OF_SESS);
42
43
0
    initialized = 1;
44
45
0
    return OGS_OK;
46
0
}
47
48
void ogs_app_config_final(void)
49
0
{
50
0
    ogs_assert(initialized == 1);
51
52
0
    ogs_app_policy_conf_remove_all();
53
54
0
    ogs_pool_final(&policy_conf_pool);
55
0
    ogs_pool_final(&slice_conf_pool);
56
0
    ogs_pool_final(&session_conf_pool);
57
58
0
    initialized = 0;
59
0
}
60
61
static void recalculate_pool_size(void)
62
0
{
63
0
    ogs_app()->pool.gtpu =
64
0
        global_conf.max.ue * OGS_MAX_NUM_OF_GTPU_BUFFER;
65
66
0
#define MAX_NUM_OF_TUNNEL       3   /* Num of Tunnel per Bearer */
67
0
    ogs_app()->pool.sess = global_conf.max.ue * OGS_MAX_NUM_OF_SESS;
68
0
    ogs_app()->pool.bearer = ogs_app()->pool.sess * OGS_MAX_NUM_OF_BEARER;
69
0
    ogs_app()->pool.tunnel = ogs_app()->pool.bearer * MAX_NUM_OF_TUNNEL;
70
71
0
#define POOL_NUM_PER_UE 16
72
0
    ogs_app()->pool.timer = global_conf.max.ue * POOL_NUM_PER_UE;
73
0
    ogs_app()->pool.message = global_conf.max.ue * POOL_NUM_PER_UE;
74
0
    ogs_app()->pool.event = global_conf.max.ue * POOL_NUM_PER_UE;
75
0
    ogs_app()->pool.socket = global_conf.max.ue * POOL_NUM_PER_UE;
76
0
    ogs_app()->pool.xact = global_conf.max.ue * POOL_NUM_PER_UE;
77
0
    ogs_app()->pool.stream = global_conf.max.ue * POOL_NUM_PER_UE;
78
79
0
    ogs_app()->pool.nf = global_conf.max.peer;
80
0
#define NF_SERVICE_PER_NF_INSTANCE 16
81
0
    ogs_app()->pool.nf_service =
82
0
        ogs_app()->pool.nf * NF_SERVICE_PER_NF_INSTANCE;
83
0
    ogs_app()->pool.subscription =
84
0
        ogs_app()->pool.nf * NF_SERVICE_PER_NF_INSTANCE;
85
86
0
    ogs_app()->pool.gtp_node = ogs_app()->pool.nf;
87
0
    if (global_conf.max.gtp_peer)
88
0
        ogs_app()->pool.gtp_node = global_conf.max.gtp_peer;
89
90
    /* Num of TAI-LAI Mapping Table */
91
0
    ogs_app()->pool.csmap = ogs_app()->pool.nf;
92
93
0
#define MAX_NUM_OF_IMPU         8
94
0
    ogs_app()->pool.impi = global_conf.max.ue;
95
0
    ogs_app()->pool.impu = ogs_app()->pool.impi * MAX_NUM_OF_IMPU;
96
97
0
#define MAX_NUM_EMERG           8
98
0
    ogs_app()->pool.emerg = MAX_NUM_EMERG;
99
0
}
100
101
ogs_app_global_conf_t *ogs_global_conf(void)
102
0
{
103
0
    return &global_conf;
104
0
}
105
106
ogs_app_local_conf_t *ogs_local_conf(void)
107
0
{
108
0
    return &local_conf;
109
0
}
110
111
int ogs_app_global_conf_prepare(void)
112
0
{
113
0
    global_conf.sockopt.no_delay = true;
114
115
0
#define MAX_NUM_OF_UE               1024    /* Num of UEs */
116
0
#define MAX_NUM_OF_PEER             64      /* Num of Peer */
117
118
0
    global_conf.max.ue = MAX_NUM_OF_UE;
119
0
    global_conf.max.peer = MAX_NUM_OF_PEER;
120
121
0
    ogs_pkbuf_default_init(&global_conf.pkbuf_config);
122
123
0
    recalculate_pool_size();
124
125
0
    return OGS_OK;
126
0
}
127
128
static int global_conf_validation(void)
129
0
{
130
0
    if (global_conf.parameter.no_ipv4 == 1 &&
131
0
        global_conf.parameter.no_ipv6 == 1) {
132
0
        ogs_error("Both `no_ipv4` and `no_ipv6` set to `true` in `%s`",
133
0
                ogs_app()->file);
134
0
        return OGS_ERROR;
135
0
    }
136
137
0
    return OGS_OK;
138
0
}
139
140
int ogs_app_count_nf_conf_sections(const char *conf_section)
141
0
{
142
0
    if (!strcmp(conf_section, "amf"))
143
0
        global_conf.parameter.amf_count++;
144
0
    else if (!strcmp(conf_section, "smf"))
145
0
        global_conf.parameter.smf_count++;
146
0
    else if (!strcmp(conf_section, "upf"))
147
0
        global_conf.parameter.upf_count++;
148
0
    else if (!strcmp(conf_section, "ausf"))
149
0
        global_conf.parameter.ausf_count++;
150
0
    else if (!strcmp(conf_section, "udm"))
151
0
        global_conf.parameter.udm_count++;
152
0
    else if (!strcmp(conf_section, "pcf"))
153
0
        global_conf.parameter.pcf_count++;
154
0
    else if (!strcmp(conf_section, "nssf"))
155
0
        global_conf.parameter.nssf_count++;
156
0
    else if (!strcmp(conf_section, "bsf"))
157
0
        global_conf.parameter.bsf_count++;
158
0
    else if (!strcmp(conf_section, "udr"))
159
0
        global_conf.parameter.udr_count++;
160
161
0
    return OGS_OK;
162
0
}
163
164
int ogs_app_parse_global_conf(ogs_yaml_iter_t *parent)
165
0
{
166
0
    int rv;
167
0
    ogs_yaml_iter_t global_iter;
168
169
0
    ogs_assert(parent);
170
171
0
    ogs_yaml_iter_recurse(parent, &global_iter);
172
0
    while (ogs_yaml_iter_next(&global_iter)) {
173
0
        const char *global_key = ogs_yaml_iter_key(&global_iter);
174
0
        ogs_assert(global_key);
175
0
        if (!strcmp(global_key, "parameter")) {
176
0
            ogs_yaml_iter_t parameter_iter;
177
0
            ogs_yaml_iter_recurse(&global_iter, &parameter_iter);
178
0
            while (ogs_yaml_iter_next(&parameter_iter)) {
179
0
                const char *parameter_key = ogs_yaml_iter_key(&parameter_iter);
180
0
                ogs_assert(parameter_key);
181
0
                if (!strcmp(parameter_key, "no_hss")) {
182
0
                    global_conf.parameter.no_hss =
183
0
                        ogs_yaml_iter_bool(&parameter_iter);
184
0
                } else if (!strcmp(parameter_key, "no_mme")) {
185
0
                    global_conf.parameter.no_mme =
186
0
                        ogs_yaml_iter_bool(&parameter_iter);
187
0
                } else if (!strcmp(parameter_key, "no_sgwu")) {
188
0
                    global_conf.parameter.no_sgwu =
189
0
                        ogs_yaml_iter_bool(&parameter_iter);
190
0
                } else if (!strcmp(parameter_key, "no_sgwc")) {
191
0
                    global_conf.parameter.no_sgwc =
192
0
                        ogs_yaml_iter_bool(&parameter_iter);
193
0
                } else if (!strcmp(parameter_key, "no_sgw")) {
194
0
                    global_conf.parameter.no_sgw =
195
0
                        ogs_yaml_iter_bool(&parameter_iter);
196
0
                } else if (!strcmp(parameter_key, "no_pgw")) {
197
0
                    global_conf.parameter.no_pgw =
198
0
                        ogs_yaml_iter_bool(&parameter_iter);
199
0
                } else if (!strcmp(parameter_key, "no_pcrf")) {
200
0
                    global_conf.parameter.no_pcrf =
201
0
                        ogs_yaml_iter_bool(&parameter_iter);
202
0
                } else if (!strcmp(parameter_key, "no_nrf")) {
203
0
                    global_conf.parameter.no_nrf =
204
0
                        ogs_yaml_iter_bool(&parameter_iter);
205
0
                } else if (!strcmp(parameter_key, "no_scp")) {
206
0
                    global_conf.parameter.no_scp =
207
0
                        ogs_yaml_iter_bool(&parameter_iter);
208
0
                } else if (!strcmp(parameter_key, "no_sepp")) {
209
0
                    global_conf.parameter.no_sepp =
210
0
                        ogs_yaml_iter_bool(&parameter_iter);
211
0
                } else if (!strcmp(parameter_key, "no_amf")) {
212
0
                    global_conf.parameter.no_amf =
213
0
                        ogs_yaml_iter_bool(&parameter_iter);
214
0
                } else if (!strcmp(parameter_key, "no_smf")) {
215
0
                    global_conf.parameter.no_smf =
216
0
                        ogs_yaml_iter_bool(&parameter_iter);
217
0
                } else if (!strcmp(parameter_key, "no_upf")) {
218
0
                    global_conf.parameter.no_upf =
219
0
                        ogs_yaml_iter_bool(&parameter_iter);
220
0
                } else if (!strcmp(parameter_key, "no_ausf")) {
221
0
                    global_conf.parameter.no_ausf =
222
0
                        ogs_yaml_iter_bool(&parameter_iter);
223
0
                } else if (!strcmp(parameter_key, "no_udm")) {
224
0
                    global_conf.parameter.no_udm =
225
0
                        ogs_yaml_iter_bool(&parameter_iter);
226
0
                } else if (!strcmp(parameter_key, "no_pcf")) {
227
0
                    global_conf.parameter.no_pcf =
228
0
                        ogs_yaml_iter_bool(&parameter_iter);
229
0
                } else if (!strcmp(parameter_key, "no_nssf")) {
230
0
                    global_conf.parameter.no_nssf =
231
0
                        ogs_yaml_iter_bool(&parameter_iter);
232
0
                } else if (!strcmp(parameter_key, "no_bsf")) {
233
0
                    global_conf.parameter.no_bsf =
234
0
                        ogs_yaml_iter_bool(&parameter_iter);
235
0
                } else if (!strcmp(parameter_key, "no_udr")) {
236
0
                    global_conf.parameter.no_udr =
237
0
                        ogs_yaml_iter_bool(&parameter_iter);
238
0
                } else if (!strcmp(parameter_key, "no_ipv4")) {
239
0
                    global_conf.parameter.no_ipv4 =
240
0
                        ogs_yaml_iter_bool(&parameter_iter);
241
0
                } else if (!strcmp(parameter_key, "no_ipv6")) {
242
0
                    global_conf.parameter.no_ipv6 =
243
0
                        ogs_yaml_iter_bool(&parameter_iter);
244
0
                } else if (!strcmp(parameter_key, "prefer_ipv4")) {
245
0
                    global_conf.parameter.prefer_ipv4 =
246
0
                        ogs_yaml_iter_bool(&parameter_iter);
247
0
                } else if (!strcmp(parameter_key, "multicast")) {
248
0
                    global_conf.parameter.multicast =
249
0
                        ogs_yaml_iter_bool(&parameter_iter);
250
0
                } else if (!strcmp(parameter_key, "use_openair")) {
251
0
                    global_conf.parameter.use_openair =
252
0
                        ogs_yaml_iter_bool(&parameter_iter);
253
0
                } else if (!strcmp(parameter_key, "use_upg_vpp")) {
254
0
                    global_conf.parameter.use_upg_vpp =
255
0
                        ogs_yaml_iter_bool(&parameter_iter);
256
0
                } else if (!strcmp(parameter_key, "fake_csfb")) {
257
0
                    global_conf.parameter.fake_csfb =
258
0
                        ogs_yaml_iter_bool(&parameter_iter);
259
0
                } else if (!strcmp(parameter_key,
260
0
                            "no_ipv4v6_local_addr_in_packet_filter")) {
261
0
                    global_conf.parameter.
262
0
                        no_ipv4v6_local_addr_in_packet_filter =
263
0
                        ogs_yaml_iter_bool(&parameter_iter);
264
0
                } else if (!strcmp(parameter_key,
265
0
                            "no_pfcp_rr_select")) {
266
0
                    global_conf.parameter.no_pfcp_rr_select =
267
0
                        ogs_yaml_iter_bool(&parameter_iter);
268
0
                } else if (!strcmp(parameter_key,
269
0
                            "no_time_zone_information")) {
270
0
                    global_conf.parameter.no_time_zone_information =
271
0
                        ogs_yaml_iter_bool(&parameter_iter);
272
0
                } else
273
0
                    ogs_warn("unknown key `%s`", parameter_key);
274
0
            }
275
0
        } else if (!strcmp(global_key, "sockopt")) {
276
0
            ogs_yaml_iter_t sockopt_iter;
277
0
            ogs_yaml_iter_recurse(&global_iter, &sockopt_iter);
278
0
            while (ogs_yaml_iter_next(&sockopt_iter)) {
279
0
                const char *sockopt_key =
280
0
                    ogs_yaml_iter_key(&sockopt_iter);
281
0
                ogs_assert(sockopt_key);
282
0
                if (!strcmp(sockopt_key, "no_delay")) {
283
0
                    global_conf.sockopt.no_delay =
284
0
                        ogs_yaml_iter_bool(&sockopt_iter);
285
0
                } else if (!strcmp(sockopt_key, "linger")) {
286
0
                    const char *v = ogs_yaml_iter_value(&sockopt_iter);
287
0
                    if (v)
288
0
                        global_conf.sockopt.l_linger = atoi(v);
289
0
                    global_conf.sockopt.l_onoff = true;
290
0
                } else
291
0
                    ogs_warn("unknown key `%s`", sockopt_key);
292
0
            }
293
0
        } else if (!strcmp(global_key, "max")) {
294
0
            ogs_yaml_iter_t max_iter;
295
0
            ogs_yaml_iter_recurse(&global_iter, &max_iter);
296
0
            while (ogs_yaml_iter_next(&max_iter)) {
297
0
                const char *max_key = ogs_yaml_iter_key(&max_iter);
298
0
                ogs_assert(max_key);
299
0
                if (!strcmp(max_key, "ue")) {
300
0
                    const char *v = ogs_yaml_iter_value(&max_iter);
301
0
                    if (v) global_conf.max.ue = atoi(v);
302
0
                } else if (!strcmp(max_key, "peer") ||
303
0
                            !strcmp(max_key, "enb")) {
304
0
                    const char *v = ogs_yaml_iter_value(&max_iter);
305
0
                    if (v) global_conf.max.peer = atoi(v);
306
0
                } else if (!strcmp(max_key, "gtp_peer") ||
307
0
                            !strcmp(max_key, "enb")) {
308
0
                    const char *v = ogs_yaml_iter_value(&max_iter);
309
0
                    if (v) global_conf.max.gtp_peer = atoi(v);
310
0
                } else
311
0
                    ogs_warn("unknown key `%s`", max_key);
312
0
            }
313
314
0
            recalculate_pool_size();
315
316
0
        } else if (!strcmp(global_key, "pool")) {
317
0
            ogs_yaml_iter_t pool_iter;
318
0
            ogs_yaml_iter_recurse(&global_iter, &pool_iter);
319
0
            while (ogs_yaml_iter_next(&pool_iter)) {
320
0
                const char *pool_key = ogs_yaml_iter_key(&pool_iter);
321
0
                ogs_assert(pool_key);
322
0
                if (!strcmp(pool_key, "128")) {
323
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
324
0
                    if (v) global_conf.pkbuf_config.cluster_128_pool = atoi(v);
325
0
                } else if (!strcmp(pool_key, "256")) {
326
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
327
0
                    if (v) global_conf.pkbuf_config.cluster_256_pool = atoi(v);
328
0
                } else if (!strcmp(pool_key, "512")) {
329
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
330
0
                    if (v) global_conf.pkbuf_config.cluster_512_pool = atoi(v);
331
0
                } else if (!strcmp(pool_key, "1024")) {
332
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
333
0
                    if (v) global_conf.pkbuf_config.cluster_1024_pool = atoi(v);
334
0
                } else if (!strcmp(pool_key, "2048")) {
335
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
336
0
                    if (v) global_conf.pkbuf_config.cluster_2048_pool = atoi(v);
337
0
                } else if (!strcmp(pool_key, "8192")) {
338
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
339
0
                    if (v) global_conf.pkbuf_config.cluster_8192_pool = atoi(v);
340
0
                } else if (!strcmp(pool_key, "32768")) {
341
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
342
0
                    if (v) global_conf.pkbuf_config.cluster_32768_pool =
343
0
                        atoi(v);
344
0
                } else if (!strcmp(pool_key, "big")) {
345
0
                    const char *v = ogs_yaml_iter_value(&pool_iter);
346
0
                    if (v) global_conf.pkbuf_config.cluster_big_pool = atoi(v);
347
0
                } else
348
0
                    ogs_warn("unknown key `%s`", pool_key);
349
0
            }
350
0
        }
351
0
    }
352
353
0
    rv = global_conf_validation();
354
0
    if (rv != OGS_OK) return rv;
355
356
0
    return OGS_OK;
357
0
}
358
359
static void regenerate_all_timer_duration(void)
360
0
{
361
0
    ogs_assert(local_conf.time.message.duration);
362
363
0
    local_conf.time.message.sbi.client_wait_duration =
364
0
        local_conf.time.message.duration;
365
0
    local_conf.time.message.sbi.connection_deadline =
366
0
        local_conf.time.message.sbi.client_wait_duration + ogs_time_from_sec(1);
367
0
    local_conf.time.message.sbi.reconnect_interval =
368
0
        ogs_max(ogs_time_from_sec(3),
369
0
            local_conf.time.message.sbi.client_wait_duration +
370
0
            ogs_time_from_sec(1));
371
0
    local_conf.time.message.sbi.reconnect_interval_in_exception =
372
0
                ogs_time_from_sec(2);
373
374
0
#define PFCP_N1_RESPONSE_RETRY_COUNT  3
375
0
    local_conf.time.message.pfcp.n1_response_rcount =
376
0
        PFCP_N1_RESPONSE_RETRY_COUNT;
377
0
    local_conf.time.message.pfcp.t1_response_duration =
378
0
        (local_conf.time.message.duration /
379
0
         (local_conf.time.message.pfcp.n1_response_rcount + 1));
380
0
    ogs_assert(local_conf.time.message.pfcp.t1_response_duration);
381
382
0
#define PFCP_N1_HOLDING_RETRY_COUNT 1
383
0
    local_conf.time.message.pfcp.n1_holding_rcount =
384
0
        PFCP_N1_HOLDING_RETRY_COUNT;
385
0
    local_conf.time.message.pfcp.t1_holding_duration =
386
0
        local_conf.time.message.pfcp.n1_response_rcount *
387
0
        local_conf.time.message.pfcp.t1_response_duration;
388
0
    ogs_assert(local_conf.time.message.pfcp.t1_holding_duration);
389
390
0
    local_conf.time.message.pfcp.association_interval =
391
0
        ogs_max(ogs_time_from_sec(3),
392
0
            local_conf.time.message.sbi.client_wait_duration +
393
0
            ogs_time_from_sec(1));
394
395
0
    local_conf.time.message.pfcp.no_heartbeat_duration =
396
0
        ogs_max(ogs_time_from_sec(10),
397
0
            local_conf.time.message.sbi.client_wait_duration +
398
0
            ogs_time_from_sec(1));
399
400
0
#define GTP_N3_RESPONSE_RETRY_COUNT  3
401
0
    local_conf.time.message.gtp.n3_response_rcount =
402
0
        GTP_N3_RESPONSE_RETRY_COUNT;
403
0
    local_conf.time.message.gtp.t3_response_duration =
404
0
        (local_conf.time.message.duration /
405
0
         (local_conf.time.message.gtp.n3_response_rcount + 1));
406
0
    ogs_assert(local_conf.time.message.gtp.t3_response_duration);
407
408
0
#define GTP_N3_HOLDING_RETRY_COUNT 1
409
0
    local_conf.time.message.gtp.n3_holding_rcount = GTP_N3_HOLDING_RETRY_COUNT;
410
0
    local_conf.time.message.gtp.t3_holding_duration =
411
0
        local_conf.time.message.gtp.n3_response_rcount *
412
0
        local_conf.time.message.gtp.t3_response_duration;
413
0
    ogs_assert(local_conf.time.message.gtp.t3_holding_duration);
414
415
#if 0
416
    ogs_trace("%lld, %lld, %lld, %d, %lld, %d %lld, %d, %lld, %d, %lld",
417
        (long long)local_conf.time.message.duration,
418
        (long long)local_conf.time.message.sbi.client_wait_duration,
419
        (long long)local_conf.time.message.sbi.connection_deadline,
420
        local_conf.time.message.pfcp.n1_response_rcount,
421
        (long long)local_conf.time.message.pfcp.t1_response_duration,
422
        local_conf.time.message.pfcp.n1_holding_rcount,
423
        (long long)local_conf.time.message.pfcp.t1_holding_duration,
424
        local_conf.time.message.gtp.n3_response_rcount,
425
        (long long)local_conf.time.message.gtp.t3_response_duration,
426
        local_conf.time.message.gtp.n3_holding_rcount,
427
        (long long)local_conf.time.message.gtp.t3_holding_duration);
428
    ogs_trace("%lld, %lld, %lld",
429
        (long long)local_conf.time.message.sbi.reconnect_interval,
430
        (long long)local_conf.time.message.pfcp.association_interval,
431
        (long long)local_conf.time.message.pfcp.no_heartbeat_duration);
432
#endif
433
0
}
434
435
static int local_conf_prepare(void)
436
0
{
437
    /* <Heartbeat Checking Interval>
438
     *  Heartbeat Interval(e.g: 10 seconds) + No Heartbeat Margin(1 second) */
439
0
    local_conf.time.nf_instance.no_heartbeat_margin = 1;
440
441
    /* 30 seconds */
442
0
    local_conf.time.nf_instance.validity_duration = 30;
443
444
    /* 86400 seconds = 1 day */
445
0
    local_conf.time.subscription.validity_duration = 86400;
446
447
    /*
448
     * Message Wait Duration : 10 seconds (Default)
449
     *
450
     * The paging retry timer is 2 seconds and the retry count is 3.
451
     *
452
     * It is recomended to set at least 9 seconds to reflect
453
     * the paging failure result to GTPv2-C or HTTP2(SBI).
454
     */
455
0
    local_conf.time.message.duration = ogs_time_from_sec(10);
456
457
    /*
458
     * Handover Wait Duration : 300 ms (Default)
459
     *
460
     * Time to wait for AMF/MME to send UEContextReleaseCommand
461
     * to the source gNB/eNB after receiving HandoverNotify
462
     */
463
0
    local_conf.time.handover.duration = ogs_time_from_msec(300);
464
465
    /* Size of internal metrics pool (amount of ogs_metrics_spec_t) */
466
0
    ogs_app()->metrics.max_specs = 512;
467
468
0
    regenerate_all_timer_duration();
469
470
0
    return OGS_OK;
471
0
}
472
473
static int local_conf_validation(void)
474
0
{
475
0
    if (local_conf.time.nf_instance.validity_duration == 0) {
476
0
        ogs_error("NF Instance validity-time should not 0");
477
0
        ogs_error("time:");
478
0
        ogs_error("  nf_instance:");
479
0
        ogs_error("    validity: 0");
480
481
0
        return OGS_ERROR;
482
0
    }
483
484
0
    return OGS_OK;
485
0
}
486
487
int ogs_app_parse_local_conf(const char *local)
488
0
{
489
0
    int rv;
490
0
    yaml_document_t *document = NULL;
491
0
    ogs_yaml_iter_t root_iter;
492
0
    int idx = 0;
493
494
0
    document = ogs_app()->document;
495
0
    ogs_assert(document);
496
497
0
    rv = local_conf_prepare();
498
0
    if (rv != OGS_OK) return rv;
499
500
0
    ogs_yaml_iter_init(&root_iter, document);
501
0
    while (ogs_yaml_iter_next(&root_iter)) {
502
0
        const char *root_key = ogs_yaml_iter_key(&root_iter);
503
0
        ogs_assert(root_key);
504
0
        if (!strcmp(root_key, local) &&
505
0
            (idx++ == ogs_app()->config_section_id)) {
506
0
            ogs_yaml_iter_t local_iter;
507
0
            ogs_yaml_iter_recurse(&root_iter, &local_iter);
508
0
            while (ogs_yaml_iter_next(&local_iter)) {
509
0
                const char *local_key = ogs_yaml_iter_key(&local_iter);
510
0
                ogs_assert(local_key);
511
0
                if (!strcmp(local_key, "serving")) {
512
0
                    ogs_yaml_iter_t serving_array, serving_iter;
513
0
                    ogs_yaml_iter_recurse(&local_iter, &serving_array);
514
0
                    do {
515
0
                        const char *mnc = NULL, *mcc = NULL;
516
0
                        ogs_assert(local_conf.num_of_serving_plmn_id <
517
0
                                OGS_MAX_NUM_OF_PLMN);
518
519
0
                        OGS_YAML_ARRAY_NEXT(&serving_array, &serving_iter);
520
0
                        while (ogs_yaml_iter_next(&serving_iter)) {
521
0
                            const char *serving_key =
522
0
                                ogs_yaml_iter_key(&serving_iter);
523
0
                            ogs_assert(serving_key);
524
0
                            if (!strcmp(serving_key, "plmn_id")) {
525
0
                                ogs_yaml_iter_t plmn_id_iter;
526
527
0
                                ogs_yaml_iter_recurse(&serving_iter,
528
0
                                        &plmn_id_iter);
529
0
                                while (ogs_yaml_iter_next(&plmn_id_iter)) {
530
0
                                    const char *id_key =
531
0
                                        ogs_yaml_iter_key(&plmn_id_iter);
532
0
                                    ogs_assert(id_key);
533
0
                                    if (!strcmp(id_key, "mcc")) {
534
0
                                        mcc = ogs_yaml_iter_value(
535
0
                                                &plmn_id_iter);
536
0
                                    } else if (!strcmp(id_key, "mnc")) {
537
0
                                        mnc = ogs_yaml_iter_value(
538
0
                                                &plmn_id_iter);
539
0
                                    }
540
0
                                }
541
542
0
                                if (mcc && mnc) {
543
0
                                    ogs_plmn_id_build(
544
0
                                            &local_conf.serving_plmn_id[
545
0
                                                local_conf.
546
0
                                                num_of_serving_plmn_id],
547
0
                                            atoi(mcc), atoi(mnc), strlen(mnc));
548
0
                                    local_conf.num_of_serving_plmn_id++;
549
0
                                } else {
550
0
                                    ogs_error("Invalid [MCC:%s, MNC:%s]",
551
0
                                            mcc, mnc);
552
0
                                }
553
0
                            } else
554
0
                                ogs_warn("unknown key `%s`", serving_key);
555
0
                        }
556
0
                    } while (ogs_yaml_iter_type(&serving_array) ==
557
0
                            YAML_SEQUENCE_NODE);
558
0
                } else if (!strcmp(local_key, "time")) {
559
0
                    ogs_yaml_iter_t time_iter;
560
0
                    ogs_yaml_iter_recurse(&local_iter, &time_iter);
561
0
                    while (ogs_yaml_iter_next(&time_iter)) {
562
0
                        const char *time_key = ogs_yaml_iter_key(&time_iter);
563
0
                        ogs_assert(time_key);
564
0
                        if (!strcmp(time_key, "nf_instance")) {
565
0
                            ogs_yaml_iter_t sbi_iter;
566
0
                            ogs_yaml_iter_recurse(&time_iter, &sbi_iter);
567
568
0
                            while (ogs_yaml_iter_next(&sbi_iter)) {
569
0
                                const char *sbi_key =
570
0
                                    ogs_yaml_iter_key(&sbi_iter);
571
0
                                ogs_assert(sbi_key);
572
573
0
                                if (!strcmp(sbi_key, "heartbeat")) {
574
0
                                    const char *v = ogs_yaml_iter_value(
575
0
                                            &sbi_iter);
576
0
                                    if (v)
577
0
                                        local_conf.time.nf_instance.
578
0
                                            heartbeat_interval = atoi(v);
579
0
                                } else if (!strcmp(sbi_key, "validity")) {
580
0
                                    const char *v =
581
0
                                        ogs_yaml_iter_value(&sbi_iter);
582
0
                                    if (v)
583
0
                                        local_conf.time.nf_instance.
584
0
                                            validity_duration = atoi(v);
585
0
                                } else
586
0
                                    ogs_warn("unknown key `%s`", sbi_key);
587
0
                            }
588
0
                        } else if (!strcmp(time_key, "subscription")) {
589
0
                            ogs_yaml_iter_t sbi_iter;
590
0
                            ogs_yaml_iter_recurse(&time_iter, &sbi_iter);
591
592
0
                            while (ogs_yaml_iter_next(&sbi_iter)) {
593
0
                                const char *sbi_key =
594
0
                                    ogs_yaml_iter_key(&sbi_iter);
595
0
                                ogs_assert(sbi_key);
596
597
0
                                if (!strcmp(sbi_key, "validity")) {
598
0
                                    const char *v =
599
0
                                        ogs_yaml_iter_value(&sbi_iter);
600
0
                                    if (v)
601
0
                                        local_conf.time.subscription.
602
0
                                            validity_duration = atoi(v);
603
0
                                } else
604
0
                                    ogs_warn("unknown key `%s`", sbi_key);
605
0
                            }
606
0
                        } else if (!strcmp(time_key, "message")) {
607
0
                            ogs_yaml_iter_t msg_iter;
608
0
                            ogs_yaml_iter_recurse(&time_iter, &msg_iter);
609
610
0
                            while (ogs_yaml_iter_next(&msg_iter)) {
611
0
                                const char *msg_key =
612
0
                                    ogs_yaml_iter_key(&msg_iter);
613
0
                                ogs_assert(msg_key);
614
615
0
                                if (!strcmp(msg_key, "duration")) {
616
0
                                    const char *v =
617
0
                                        ogs_yaml_iter_value(&msg_iter);
618
0
                                    if (v) {
619
0
                                        local_conf.time.message.duration =
620
0
                                            ogs_time_from_msec(atoll(v));
621
0
                                        regenerate_all_timer_duration();
622
0
                                    }
623
0
                                } else
624
0
                                    ogs_warn("unknown key `%s`", msg_key);
625
0
                            }
626
0
                        } else if (!strcmp(time_key, "handover")) {
627
0
                            ogs_yaml_iter_t msg_iter;
628
0
                            ogs_yaml_iter_recurse(&time_iter, &msg_iter);
629
630
0
                            while (ogs_yaml_iter_next(&msg_iter)) {
631
0
                                const char *msg_key =
632
0
                                    ogs_yaml_iter_key(&msg_iter);
633
0
                                ogs_assert(msg_key);
634
635
0
                                if (!strcmp(msg_key, "duration")) {
636
0
                                    const char *v =
637
0
                                        ogs_yaml_iter_value(&msg_iter);
638
0
                                    if (v) {
639
0
                                        local_conf.time.handover.duration =
640
0
                                            ogs_time_from_msec(atoll(v));
641
0
                                    }
642
0
                                } else
643
0
                                    ogs_warn("unknown key `%s`", msg_key);
644
0
                            }
645
0
                        } else if (!strcmp(time_key, "t3502")) {
646
                            /* handle config in amf */
647
0
                        } else if (!strcmp(time_key, "t3512")) {
648
                            /* handle config in amf */
649
0
                        } else if (!strcmp(time_key, "t3402")) {
650
                            /* handle config in mme */
651
0
                        } else if (!strcmp(time_key, "t3412")) {
652
                            /* handle config in mme */
653
0
                        } else if (!strcmp(time_key, "t3423")) {
654
                            /* handle config in mme */
655
0
                        } else
656
0
                            ogs_warn("unknown key `%s`", time_key);
657
0
                    }
658
0
                }
659
0
            }
660
0
        }
661
0
    }
662
663
0
    rv = local_conf_validation();
664
0
    if (rv != OGS_OK) return rv;
665
666
0
    return OGS_OK;
667
0
}
668
669
int ogs_app_parse_sockopt_config(
670
        ogs_yaml_iter_t *parent, ogs_sockopt_t *option)
671
0
{
672
0
    ogs_yaml_iter_t sockopt_iter;
673
674
0
    ogs_assert(parent);
675
0
    ogs_assert(option);
676
677
0
    ogs_sockopt_init(option);
678
679
0
    ogs_yaml_iter_recurse(parent, &sockopt_iter);
680
0
    while (ogs_yaml_iter_next(&sockopt_iter)) {
681
0
        const char *sockopt_key = ogs_yaml_iter_key(&sockopt_iter);
682
0
        ogs_assert(sockopt_key);
683
684
0
        if (!strcmp(sockopt_key, "sctp")) {
685
0
            ogs_yaml_iter_t sctp_iter;
686
0
            ogs_yaml_iter_recurse(&sockopt_iter, &sctp_iter);
687
688
0
            while (ogs_yaml_iter_next(&sctp_iter)) {
689
0
                const char *sctp_key = ogs_yaml_iter_key(&sctp_iter);
690
0
                ogs_assert(sctp_key);
691
0
                if (!strcmp(sctp_key, "spp_hbinterval")) {
692
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
693
0
                    if (v) option->sctp.spp_hbinterval = atoi(v);
694
0
                } else if (!strcmp(sctp_key, "spp_sackdelay")) {
695
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
696
0
                    if (v) option->sctp.spp_sackdelay = atoi(v);
697
0
                } else if (!strcmp(sctp_key, "srto_initial")) {
698
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
699
0
                    if (v) option->sctp.srto_initial = atoi(v);
700
0
                } else if (!strcmp(sctp_key, "srto_min")) {
701
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
702
0
                    if (v) option->sctp.srto_min = atoi(v);
703
0
                } else if (!strcmp(sctp_key, "srto_max")) {
704
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
705
0
                    if (v) option->sctp.srto_max = atoi(v);
706
0
                } else if (!strcmp(sctp_key, "sinit_num_ostreams")) {
707
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
708
0
                    if (v) option->sctp.sinit_num_ostreams = atoi(v);
709
0
                } else if (!strcmp(sctp_key, "sinit_max_instreams")) {
710
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
711
0
                    if (v) option->sctp.sinit_max_instreams = atoi(v);
712
0
                } else if (!strcmp(sctp_key, "sinit_max_attempts")) {
713
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
714
0
                    if (v) option->sctp.sinit_max_attempts = atoi(v);
715
0
                } else if (!strcmp(sctp_key, "sinit_max_init_timeo")) {
716
0
                    const char *v = ogs_yaml_iter_value(&sctp_iter);
717
0
                    if (v) option->sctp.sinit_max_init_timeo = atoi(v);
718
0
                } else {
719
0
                    ogs_error("unknown key `%s`", sctp_key);
720
0
                    return OGS_ERROR;
721
0
                }
722
0
            }
723
0
        } else if (!strcmp(sockopt_key, "sctp_nodelay")) {
724
0
            option->sctp_nodelay = ogs_yaml_iter_bool(&sockopt_iter);
725
0
        } else if (!strcmp(sockopt_key, "tcp_nodelay")) {
726
0
            option->tcp_nodelay = ogs_yaml_iter_bool(&sockopt_iter);
727
728
0
        } else if (!strcmp(sockopt_key, "so_linger")) {
729
0
            ogs_yaml_iter_t so_linger_iter;
730
0
            ogs_yaml_iter_recurse(&sockopt_iter, &so_linger_iter);
731
732
0
            while (ogs_yaml_iter_next(&so_linger_iter)) {
733
0
                const char *so_linger_key = ogs_yaml_iter_key(&so_linger_iter);
734
0
                ogs_assert(so_linger_key);
735
0
                if (!strcmp(so_linger_key, "l_onoff")) {
736
0
                    option->so_linger.l_onoff =
737
0
                        ogs_yaml_iter_bool(&so_linger_iter);
738
0
                } else if (!strcmp(so_linger_key, "l_linger")) {
739
0
                    const char *v = ogs_yaml_iter_value(&so_linger_iter);
740
0
                    if (v) option->so_linger.l_linger = atoi(v);
741
0
                } else {
742
0
                    ogs_error("unknown key `%s`", so_linger_key);
743
0
                    return OGS_ERROR;
744
0
                }
745
0
            }
746
747
0
        } else if (!strcmp(sockopt_key, "so_bindtodevice")) {
748
0
            option->so_bindtodevice = ogs_yaml_iter_value(&sockopt_iter);
749
750
0
        } else {
751
0
            ogs_error("unknown key `%s`", sockopt_key);
752
0
            return OGS_ERROR;
753
0
        }
754
0
    }
755
756
0
    return OGS_OK;
757
0
}
758
759
/*----------------------------------------------------------------------
760
 * Function: ogs_app_parse_supi_range_conf
761
 *
762
 *   Parse the supi_range configuration from a YAML iterator.
763
 *
764
 *   The expected YAML format is:
765
 *
766
 *     supi_range:
767
 *       - 999700000000001-999700000099999
768
 *       - 310789000000005-310789000000888
769
 *
770
 *   Both start and end must be provided.
771
 *
772
 * Returns:
773
 *   OGS_OK on success, OGS_ERROR on failure.
774
 *----------------------------------------------------------------------*/
775
int ogs_app_parse_supi_range_conf(
776
        ogs_yaml_iter_t *parent, ogs_supi_range_t *supi_range)
777
0
{
778
0
    ogs_yaml_iter_t range_iter;
779
780
0
    ogs_assert(parent);
781
0
    ogs_assert(supi_range);
782
783
0
    memset(supi_range, 0, sizeof(ogs_supi_range_t));
784
785
    /* Recurse into the supi_range array node */
786
0
    ogs_yaml_iter_recurse(parent, &range_iter);
787
0
    ogs_assert(ogs_yaml_iter_type(&range_iter) != YAML_MAPPING_NODE);
788
789
0
    do {
790
0
        char *v = NULL;
791
0
        char *start_str = NULL, *end_str = NULL;
792
793
0
        if (ogs_yaml_iter_type(&range_iter) == YAML_SEQUENCE_NODE) {
794
0
            if (!ogs_yaml_iter_next(&range_iter))
795
0
                break;
796
0
        }
797
798
0
        v = (char *)ogs_yaml_iter_value(&range_iter);
799
800
0
        if (v) {
801
0
            ogs_assert(supi_range->num < OGS_MAX_NUM_OF_SUPI_RANGE);
802
803
            /* Split the string on '-' */
804
0
            start_str = strsep(&v, "-");
805
0
            if (start_str == NULL || strlen(start_str) == 0) {
806
0
                ogs_error("Invalid supi_range starter bound: %s", v);
807
0
                return OGS_ERROR;
808
0
            }
809
810
0
            end_str = v;
811
0
            if (end_str == NULL || strlen(end_str) == 0) {
812
0
                ogs_error("Invalid supi_range upper bound: %s", v);
813
0
                return OGS_ERROR;
814
0
            }
815
816
0
            supi_range->start[supi_range->num] =
817
0
                ogs_uint64_from_string_decimal(start_str);
818
0
            supi_range->end[supi_range->num] =
819
0
                ogs_uint64_from_string_decimal(end_str);
820
821
0
            supi_range->num++;
822
0
        }
823
824
0
    } while (ogs_yaml_iter_type(&range_iter) == YAML_SEQUENCE_NODE);
825
826
0
    return OGS_OK;
827
0
}
828
829
static int parse_br_conf(ogs_yaml_iter_t *parent, ogs_bitrate_t *br)
830
0
{
831
0
    ogs_yaml_iter_t br_iter;
832
833
0
    ogs_assert(parent);
834
0
    ogs_assert(br);
835
836
0
    ogs_yaml_iter_recurse(parent, &br_iter);
837
838
0
    while (ogs_yaml_iter_next(&br_iter)) {
839
0
        const char *br_key = ogs_yaml_iter_key(&br_iter);
840
0
        ogs_assert(br_key);
841
0
        if (!strcmp(br_key, OGS_DOWNLINK_STRING)) {
842
0
            uint8_t unit = 0;
843
0
            int n;
844
845
0
            ogs_yaml_iter_t downlink_iter;
846
0
            ogs_yaml_iter_recurse(&br_iter, &downlink_iter);
847
848
0
            while (ogs_yaml_iter_next(&downlink_iter)) {
849
0
                const char *downlink_key =
850
0
                    ogs_yaml_iter_key(&downlink_iter);
851
0
                ogs_assert(downlink_key);
852
0
                if (!strcmp(downlink_key, OGS_VALUE_STRING)) {
853
0
                    const char *v = ogs_yaml_iter_value(&downlink_iter);
854
0
                    if (v) br->downlink = atoi(v);
855
0
                } else if (!strcmp(downlink_key, OGS_UNIT_STRING)) {
856
0
                    const char *v = ogs_yaml_iter_value(&downlink_iter);
857
0
                    if (v) {
858
0
                        unit = atoi(v);
859
0
                        if (unit == 0 || unit == 1 || unit == 2 ||
860
0
                            unit == 3 || unit == 4) {
861
0
                        } else {
862
0
                            ogs_error("Unknown Unit [%d]", unit);
863
0
                            return OGS_ERROR;
864
0
                        }
865
0
                    }
866
0
                } else
867
0
                    ogs_warn("unknown key `%s`", downlink_key);
868
0
            }
869
870
0
            for (n = 0; n < unit; n++)
871
0
                br->downlink *= 1000;
872
0
        } else if (!strcmp(br_key, OGS_UPLINK_STRING)) {
873
0
            uint8_t unit = 0;
874
0
            int n;
875
876
0
            ogs_yaml_iter_t uplink_iter;
877
0
            ogs_yaml_iter_recurse(&br_iter, &uplink_iter);
878
879
0
            while (ogs_yaml_iter_next(&uplink_iter)) {
880
0
                const char *uplink_key =
881
0
                    ogs_yaml_iter_key(&uplink_iter);
882
0
                ogs_assert(uplink_key);
883
0
                if (!strcmp(uplink_key, OGS_VALUE_STRING)) {
884
0
                    const char *v = ogs_yaml_iter_value(&uplink_iter);
885
0
                    if (v) br->uplink = atoi(v);
886
0
                } else if (!strcmp(uplink_key, OGS_UNIT_STRING)) {
887
0
                    const char *v = ogs_yaml_iter_value(&uplink_iter);
888
0
                    if (v) {
889
0
                        unit = atoi(v);
890
0
                        if (unit == 0 || unit == 1 || unit == 2 ||
891
0
                            unit == 3 || unit == 4) {
892
0
                        } else {
893
0
                            ogs_error("Unknown Unit [%d]", unit);
894
0
                            return OGS_ERROR;
895
0
                        }
896
0
                    }
897
0
                } else
898
0
                    ogs_warn("unknown key `%s`", uplink_key);
899
0
            }
900
901
0
            for (n = 0; n < unit; n++)
902
0
                br->uplink *= 1000;
903
0
        } else
904
0
            ogs_warn("unknown key `%s`", br_key);
905
0
    }
906
907
0
    return OGS_OK;
908
0
}
909
910
static int parse_qos_conf(ogs_yaml_iter_t *parent, ogs_qos_t *qos)
911
0
{
912
0
    int rv;
913
0
    ogs_yaml_iter_t qos_iter;
914
915
0
    ogs_assert(parent);
916
0
    ogs_assert(qos);
917
918
0
    ogs_yaml_iter_recurse(parent, &qos_iter);
919
0
    while (ogs_yaml_iter_next(&qos_iter)) {
920
0
        const char *qos_key = ogs_yaml_iter_key(&qos_iter);
921
0
        ogs_assert(qos_key);
922
0
        if (!strcmp(qos_key, OGS_INDEX_STRING)) {
923
0
            const char *v = ogs_yaml_iter_value(&qos_iter);
924
0
            if (v) {
925
0
                uint8_t index = atoi(v);
926
0
                if (index == 1 || index == 2 || index == 3 || index == 4 ||
927
0
                    index == 65 || index == 66 || index == 67 || index == 75 ||
928
0
                    index == 71 || index == 72 || index == 73 || index == 74 ||
929
0
                    index == 76 || index == 5 || index == 6 || index == 7 ||
930
0
                    index == 8 || index == 9 || index == 69 || index == 70 ||
931
0
                    index == 79 || index == 80 || index == 82 || index == 83 ||
932
0
                    index == 84 || index == 85 || index == 86)
933
0
                    qos->index = index;
934
0
                else {
935
0
                    ogs_error("Unknown QCI [%d]", index);
936
0
                    return OGS_ERROR;
937
0
                }
938
0
            }
939
0
        } else if (!strcmp(qos_key, OGS_ARP_STRING)) {
940
0
            ogs_yaml_iter_t arp_iter;
941
0
            ogs_yaml_iter_recurse(&qos_iter, &arp_iter);
942
0
            while (ogs_yaml_iter_next(&arp_iter)) {
943
0
                const char *arp_key = ogs_yaml_iter_key(&arp_iter);
944
0
                ogs_assert(arp_key);
945
0
                if (!strcmp(arp_key, OGS_PRIORITY_LEVEL_STRING)) {
946
0
                    const char *v = ogs_yaml_iter_value(&arp_iter);
947
0
                    if (v) {
948
0
                        uint8_t priority_level = atoi(v);
949
0
                        if (priority_level >= 1 && priority_level <= 15)
950
0
                            qos->arp.priority_level = priority_level;
951
0
                        else {
952
0
                            ogs_error("Unknown Priority Level [%d]",
953
0
                                    priority_level);
954
0
                            return OGS_ERROR;
955
0
                        }
956
0
                    }
957
0
                } else if (!strcmp(arp_key,
958
0
                            OGS_PRE_EMPTION_CAPABILITY_STRING)) {
959
0
                    const char *v = ogs_yaml_iter_value(&arp_iter);
960
0
                    if (v) {
961
0
                        uint8_t pre_emption_capability = atoi(v);
962
0
                        if (pre_emption_capability ==
963
0
                                OGS_5GC_PRE_EMPTION_DISABLED ||
964
0
                            pre_emption_capability ==
965
0
                            OGS_5GC_PRE_EMPTION_ENABLED)
966
0
                            qos->arp.pre_emption_capability =
967
0
                                pre_emption_capability;
968
0
                        else {
969
0
                            ogs_error("Unknown Preemption Capability [%d]",
970
0
                                    pre_emption_capability);
971
0
                            return OGS_ERROR;
972
0
                        }
973
0
                    }
974
0
                } else if (!strcmp(arp_key,
975
0
                            OGS_PRE_EMPTION_VULNERABILITY_STRING)) {
976
0
                    const char *v = ogs_yaml_iter_value(&arp_iter);
977
0
                    if (v) {
978
0
                        uint8_t pre_emption_vulnerability = atoi(v);
979
0
                        if (pre_emption_vulnerability ==
980
0
                                OGS_5GC_PRE_EMPTION_DISABLED ||
981
0
                            pre_emption_vulnerability ==
982
0
                            OGS_5GC_PRE_EMPTION_ENABLED)
983
0
                            qos->arp.pre_emption_vulnerability =
984
0
                                pre_emption_vulnerability;
985
0
                        else {
986
0
                            ogs_error("Unknown Preemption Vulnerablility [%d]",
987
0
                                    pre_emption_vulnerability);
988
0
                            return OGS_ERROR;
989
0
                        }
990
0
                    }
991
0
                } else
992
0
                    ogs_warn("unknown key `%s`", arp_key);
993
0
            }
994
0
        } else if (!strcmp(qos_key, OGS_MBR_STRING)) {
995
0
            rv = parse_br_conf(&qos_iter, &qos->mbr);
996
0
            if (rv != OGS_OK) {
997
0
                ogs_error("parse_br_conf() failed");
998
0
                return rv;
999
0
            }
1000
0
        } else if (!strcmp(qos_key, OGS_GBR_STRING)) {
1001
0
            rv = parse_br_conf(&qos_iter, &qos->gbr);
1002
0
            if (rv != OGS_OK) {
1003
0
                ogs_error("parse_br_conf() failed");
1004
0
                return rv;
1005
0
            }
1006
0
        }
1007
0
    }
1008
1009
0
    return OGS_OK;
1010
0
}
1011
1012
static int session_conf_prepare(ogs_app_slice_conf_t *slice_conf)
1013
0
{
1014
0
    ogs_assert(slice_conf);
1015
0
    return OGS_OK;
1016
0
}
1017
1018
static int session_conf_validation(ogs_app_slice_conf_t *slice_conf)
1019
0
{
1020
0
    int rv, j, k;
1021
0
    ogs_app_session_conf_t *session_conf = NULL;
1022
0
    ogs_assert(slice_conf);
1023
1024
0
    ogs_list_for_each(&slice_conf->sess_list, session_conf) {
1025
0
        ogs_session_data_t *session_data = &session_conf->data;
1026
1027
0
        ogs_info("NAME[%s]", session_data->session.name);
1028
0
        ogs_info("QCI[%d]", session_data->session.qos.index);
1029
0
        ogs_info("ARP[%d:%d:%d]",
1030
0
                session_data->session.qos.arp.priority_level,
1031
0
                session_data->session.qos.arp.pre_emption_capability,
1032
0
                session_data->session.qos.arp.pre_emption_vulnerability);
1033
0
        ogs_info("AMBR[Downlink:%lld:Uplink:%lld]",
1034
0
                (long long)session_data->session.ambr.downlink,
1035
0
                (long long)session_data->session.ambr.uplink);
1036
0
        for (j = 0; j < session_data->num_of_pcc_rule; j++) {
1037
0
            ogs_info("PCC_RULE[%d]", j+1);
1038
0
            ogs_info("  ID[%s]", session_data->pcc_rule[j].id);
1039
0
            ogs_info("  NAME[%s]", session_data->pcc_rule[j].name);
1040
0
            ogs_info("  QCI[%d]", session_data->pcc_rule[j].qos.index);
1041
0
            ogs_info("  ARP[%d:%d:%d]",
1042
0
                    session_data->pcc_rule[j].qos.arp.priority_level,
1043
0
                    session_data->pcc_rule[j].qos.arp.
1044
0
                    pre_emption_capability,
1045
0
                    session_data->pcc_rule[j].qos.arp.
1046
0
                    pre_emption_vulnerability);
1047
0
            ogs_info("  MBR[Downlink:%lld:Uplink:%lld]",
1048
0
                    (long long)session_data->pcc_rule[j].qos.mbr.downlink,
1049
0
                    (long long)session_data->pcc_rule[j].qos.mbr.uplink);
1050
0
            ogs_info("  GBR[Downlink:%lld:Uplink:%lld]",
1051
0
                    (long long)session_data->pcc_rule[j].qos.gbr.downlink,
1052
0
                    (long long)session_data->pcc_rule[j].qos.gbr.uplink);
1053
0
            ogs_info("  NUM_OF_FLOW [%d]",
1054
0
                session_data->pcc_rule[j].num_of_flow);
1055
1056
0
            for (k = 0; k < session_data->pcc_rule[j].num_of_flow; k++) {
1057
0
                ogs_info("    DIRECTION[%d]",
1058
0
                        session_data->pcc_rule[j].flow[k].direction);
1059
0
                ogs_info("    DESCRIPTION[%s]",
1060
0
                        session_data->pcc_rule[j].flow[k].description);
1061
0
            }
1062
0
        }
1063
1064
0
        rv = ogs_check_br_conf(&session_data->session.ambr);
1065
0
        if (rv != OGS_OK) {
1066
0
            ogs_error("check_br_conf(AMBR) failed");
1067
0
            return rv;
1068
0
        }
1069
0
        rv = ogs_check_qos_conf(&session_data->session.qos);
1070
0
        if (rv != OGS_OK) {
1071
0
            ogs_error("check_qos_conf(SESS) failed");
1072
0
            return rv;
1073
0
        }
1074
0
    }
1075
1076
0
    return OGS_OK;
1077
0
}
1078
1079
int ogs_app_parse_session_conf(
1080
        ogs_yaml_iter_t *parent, ogs_app_slice_conf_t *slice_conf)
1081
0
{
1082
0
    int rv;
1083
0
    ogs_yaml_iter_t session_array, session_iter;
1084
1085
0
    ogs_assert(parent);
1086
0
    ogs_assert(slice_conf);
1087
1088
0
    rv = session_conf_prepare(slice_conf);
1089
0
    if (rv != OGS_OK) return rv;
1090
1091
0
    ogs_yaml_iter_recurse(parent, &session_array);
1092
0
    do {
1093
0
        const char *name = NULL;
1094
0
        ogs_app_session_conf_t *session_conf = NULL;
1095
0
        ogs_session_data_t *session_data = NULL;
1096
1097
0
        OGS_YAML_ARRAY_NEXT(&session_array, &session_iter);
1098
0
        while (ogs_yaml_iter_next(&session_iter)) {
1099
0
            const char *session_key = ogs_yaml_iter_key(&session_iter);
1100
0
            ogs_assert(session_key);
1101
0
            if (!strcmp(session_key, OGS_NAME_STRING)) {
1102
0
                name = (char *)ogs_yaml_iter_value(&session_iter);
1103
0
            }
1104
0
        }
1105
1106
0
        if (name) {
1107
0
            session_conf = ogs_app_session_conf_add(slice_conf, (char *)name);
1108
0
            if (!session_conf) {
1109
0
                ogs_error("ogs_app_session_conf_add() failed [DNN:%s]", name);
1110
0
                return OGS_ERROR;
1111
0
            }
1112
0
        } else {
1113
0
            ogs_error("No APN/DNN");
1114
0
            return OGS_ERROR;
1115
0
        }
1116
1117
0
        session_data = &session_conf->data;
1118
0
        OGS_YAML_ARRAY_RECURSE(&session_array, &session_iter);
1119
0
        while (ogs_yaml_iter_next(&session_iter)) {
1120
0
            const char *session_key = ogs_yaml_iter_key(&session_iter);
1121
0
            ogs_assert(session_key);
1122
0
            if (!strcmp(session_key, OGS_TYPE_STRING)) {
1123
0
                const char *v = ogs_yaml_iter_value(&session_iter);
1124
0
                if (v) {
1125
0
                    uint8_t session_type = atoi(v);
1126
0
                    if (session_type == OGS_PDU_SESSION_TYPE_IPV4 ||
1127
0
                        session_type == OGS_PDU_SESSION_TYPE_IPV6 ||
1128
0
                        session_type == OGS_PDU_SESSION_TYPE_IPV4V6 ||
1129
0
                        session_type == OGS_PDU_SESSION_TYPE_UNSTRUCTURED ||
1130
0
                        session_type == OGS_PDU_SESSION_TYPE_ETHERNET)
1131
0
                        session_data->session.session_type = session_type;
1132
0
                    else {
1133
0
                        ogs_error("Unknown Session Type [%d]", session_type);
1134
0
                        return OGS_ERROR;
1135
0
                    }
1136
0
                }
1137
0
            } else if (!strcmp(session_key, OGS_AMBR_STRING)) {
1138
0
                rv = parse_br_conf(&session_iter, &session_data->session.ambr);
1139
0
                if (rv != OGS_OK) {
1140
0
                    ogs_error("parse_qos_conf() failed");
1141
0
                    return rv;
1142
0
                }
1143
0
            } else if (!strcmp(session_key, OGS_QOS_STRING)) {
1144
0
                rv = parse_qos_conf(&session_iter, &session_data->session.qos);
1145
0
                if (rv != OGS_OK) {
1146
0
                    ogs_error("parse_qos_conf() failed");
1147
0
                    return rv;
1148
0
                }
1149
0
            } else if (!strcmp(session_key, OGS_PCC_RULE_STRING)) {
1150
0
                int pcc_rule_index = 0;
1151
0
                ogs_yaml_iter_t pcc_rule_array, pcc_rule_iter;
1152
0
                ogs_yaml_iter_recurse(&session_iter, &pcc_rule_array);
1153
0
                do {
1154
0
                    ogs_pcc_rule_t *pcc_rule = NULL;
1155
1156
0
                    ogs_assert(session_data->num_of_pcc_rule <
1157
0
                            OGS_MAX_NUM_OF_PCC_RULE);
1158
0
                    pcc_rule = &session_data->
1159
0
                        pcc_rule[session_data->num_of_pcc_rule];
1160
1161
0
                    OGS_YAML_ARRAY_NEXT(&pcc_rule_array, &pcc_rule_iter);
1162
0
                    while (ogs_yaml_iter_next(&pcc_rule_iter)) {
1163
0
                        const char *pcc_rule_key =
1164
0
                            ogs_yaml_iter_key(&pcc_rule_iter);
1165
0
                        ogs_assert(pcc_rule_key);
1166
0
                        if (!strcmp(pcc_rule_key, OGS_QOS_STRING)) {
1167
0
                            rv = parse_qos_conf(&pcc_rule_iter, &pcc_rule->qos);
1168
0
                            if (rv != OGS_OK) {
1169
0
                                ogs_error("parse_qos_conf() failed");
1170
0
                                return rv;
1171
0
                            }
1172
0
                        } else if (!strcmp(pcc_rule_key, OGS_FLOW_STRING)) {
1173
0
                            ogs_yaml_iter_t flow_array, flow_iter;
1174
0
                            ogs_yaml_iter_recurse( &pcc_rule_iter, &flow_array);
1175
0
                            do {
1176
0
                                ogs_flow_t *flow = NULL;
1177
1178
0
                                ogs_assert(pcc_rule->num_of_flow <
1179
0
                                        OGS_MAX_NUM_OF_FLOW_IN_PCC_RULE);
1180
0
                                flow = &pcc_rule->flow[pcc_rule->num_of_flow];
1181
1182
0
                                OGS_YAML_ARRAY_NEXT(&flow_array, &flow_iter);
1183
0
                                while (ogs_yaml_iter_next(&flow_iter)) {
1184
0
                                    const char *flow_key =
1185
0
                                        ogs_yaml_iter_key(&flow_iter);
1186
0
                                    ogs_assert(flow_key);
1187
0
                                    if (!strcmp(flow_key,
1188
0
                                                OGS_DIRECTION_STRING)) {
1189
0
                                        const char *v =
1190
0
                                            ogs_yaml_iter_value(&flow_iter);
1191
0
                                        if (v) {
1192
0
                                            uint8_t direction = atoi(v);
1193
0
                                            if (direction ==
1194
0
                                                    OGS_FLOW_DOWNLINK_ONLY ||
1195
0
                                                direction ==
1196
0
                                                OGS_FLOW_UPLINK_ONLY)
1197
0
                                                flow->direction = direction;
1198
0
                                            else {
1199
0
                                                ogs_error(
1200
0
                                                    "Unknown Direction [%d]",
1201
0
                                                    direction);
1202
0
                                                return OGS_ERROR;
1203
0
                                            }
1204
0
                                        }
1205
0
                                    } else if (!strcmp(flow_key,
1206
0
                                        OGS_DESCRIPTION_STRING)) {
1207
0
                                        const char *v =
1208
0
                                            (char *)ogs_yaml_iter_value(
1209
0
                                                    &flow_iter);
1210
0
                                        if (v) {
1211
0
                                            flow->description = ogs_strdup(v);
1212
0
                                            ogs_assert(flow->description);
1213
0
                                        }
1214
0
                                    }
1215
0
                                }
1216
1217
0
                                if (flow->direction && flow->description)
1218
0
                                    pcc_rule->num_of_flow++;
1219
1220
0
                            } while (ogs_yaml_iter_type(&flow_array) ==
1221
0
                                    YAML_SEQUENCE_NODE);
1222
1223
0
                        } else
1224
0
                            ogs_warn("unknown key `%s`", pcc_rule_key);
1225
0
                    }
1226
1227
0
                    if (pcc_rule->qos.index &&
1228
0
                        pcc_rule->qos.arp.priority_level &&
1229
0
                        pcc_rule->qos.arp.pre_emption_capability &&
1230
0
                        pcc_rule->qos.arp.pre_emption_vulnerability) {
1231
1232
                        /* EPC: Charing-Rule-Name */
1233
0
                        ogs_assert(!pcc_rule->name);
1234
0
                        pcc_rule->name = ogs_msprintf("%s-g%d",
1235
0
                                session_data->session.name, pcc_rule_index+1);
1236
0
                        ogs_assert(pcc_rule->name);
1237
1238
                        /* 5GC: PCC-Rule-Id */
1239
0
                        ogs_assert(!pcc_rule->id);
1240
0
                        pcc_rule->id = ogs_msprintf("%s-n%d",
1241
0
                                session_data->session.name, pcc_rule_index+1);
1242
0
                        ogs_assert(pcc_rule->id);
1243
1244
0
                        pcc_rule->precedence = pcc_rule_index+1;
1245
0
                        pcc_rule_index++;
1246
1247
0
                        session_data->num_of_pcc_rule++;
1248
0
                    } else
1249
0
                        ogs_warn("Mandatory is MISSING - "
1250
0
                                "QCI[%d], ARP[%d:%d:%d]",
1251
0
                            pcc_rule->qos.index,
1252
0
                            pcc_rule->qos.arp.priority_level,
1253
0
                            pcc_rule->qos.arp.
1254
0
                            pre_emption_capability,
1255
0
                            pcc_rule->qos.arp.
1256
0
                            pre_emption_vulnerability);
1257
1258
0
                } while (ogs_yaml_iter_type(&pcc_rule_array) ==
1259
0
                        YAML_SEQUENCE_NODE);
1260
0
            }
1261
0
        }
1262
1263
0
    } while (ogs_yaml_iter_type(&session_array) == YAML_SEQUENCE_NODE);
1264
1265
0
    rv = session_conf_validation(slice_conf);
1266
0
    if (rv != OGS_OK) return rv;
1267
1268
0
    return OGS_OK;
1269
0
}
1270
1271
ogs_app_policy_conf_t *ogs_app_policy_conf_add(
1272
        ogs_supi_range_t *supi_range, ogs_plmn_id_t *plmn_id)
1273
0
{
1274
0
    ogs_app_policy_conf_t *policy_conf = NULL;
1275
1276
0
    ogs_assert(supi_range || plmn_id);
1277
1278
0
    ogs_pool_alloc(&policy_conf_pool, &policy_conf);
1279
0
    if (!policy_conf) {
1280
0
        ogs_error("Maximum number of policy_conf[%d] reached",
1281
0
                OGS_MAX_NUM_OF_PLMN);
1282
0
        return NULL;
1283
0
    }
1284
0
    memset(policy_conf, 0, sizeof *policy_conf);
1285
1286
0
    if (supi_range) {
1287
0
        int i;
1288
1289
0
        memcpy(&policy_conf->supi_range, supi_range, sizeof(ogs_supi_range_t));
1290
1291
0
        ogs_info("SUPI[%d]", policy_conf->supi_range.num);
1292
0
        for (i = 0; i < policy_conf->supi_range.num; i++)
1293
0
            ogs_info("    START[%lld]-END[%lld]",
1294
0
                    (long long)policy_conf->supi_range.start[i],
1295
0
                    (long long)policy_conf->supi_range.end[i]);
1296
1297
0
    }
1298
0
    if (plmn_id) {
1299
0
        policy_conf->plmn_id_valid = true;
1300
0
        memcpy(&policy_conf->plmn_id, plmn_id, sizeof(ogs_plmn_id_t));
1301
0
        ogs_info("PLMN_ID[MCC:%03d.MNC:%03d]",
1302
0
                ogs_plmn_id_mcc(&policy_conf->plmn_id),
1303
0
                ogs_plmn_id_mnc(&policy_conf->plmn_id));
1304
0
    }
1305
1306
0
    ogs_list_init(&policy_conf->slice_list);
1307
1308
0
    ogs_list_add(&local_conf.policy_list, policy_conf);
1309
1310
0
    ogs_info("POLICY config added [%d]",
1311
0
            ogs_list_count(&local_conf.policy_list));
1312
0
    return policy_conf;
1313
0
}
1314
1315
ogs_app_policy_conf_t *ogs_app_policy_conf_find(
1316
        const char *supi, const ogs_plmn_id_t *plmn_id)
1317
0
{
1318
0
    ogs_app_policy_conf_t *policy_conf;
1319
0
    int i;
1320
1321
0
    char *supi_type = NULL;
1322
0
    char *supi_id = NULL;
1323
0
    uint64_t supi_decimal;
1324
1325
0
    ogs_assert(supi);
1326
1327
0
    supi_type = ogs_id_get_type(supi);
1328
0
    ogs_assert(supi_type);
1329
0
    supi_id = ogs_id_get_value(supi);
1330
0
    ogs_assert(supi_id);
1331
1332
0
    supi_decimal = ogs_uint64_from_string_decimal(supi_id);
1333
1334
0
    ogs_free(supi_type);
1335
0
    ogs_free(supi_id);
1336
1337
0
    ogs_list_for_each(&local_conf.policy_list, policy_conf) {
1338
        /* If supi_range is set, check if supi_decimal falls within
1339
         * any of the defined ranges.
1340
         */
1341
0
        if (policy_conf->supi_range.num > 0) {
1342
0
            int in_range = 0;
1343
0
            for (i = 0; i < policy_conf->supi_range.num; i++) {
1344
0
                if ((supi_decimal >= policy_conf->supi_range.start[i]) &&
1345
0
                    (supi_decimal <= policy_conf->supi_range.end[i])) {
1346
0
                    in_range = 1;
1347
0
                    break;
1348
0
                }
1349
0
            }
1350
0
            if (!in_range) {
1351
0
                continue;
1352
0
            }
1353
0
        }
1354
1355
        /* If a plmn_id is set and it does not match the
1356
         * current policy's plmn_id, skip this policy.
1357
         */
1358
0
        if (policy_conf->plmn_id_valid &&
1359
0
            memcmp(&policy_conf->plmn_id, plmn_id,
1360
0
                   sizeof(ogs_plmn_id_t)) != 0) {
1361
0
            continue;
1362
0
        }
1363
1364
        /* Both conditions met; return this policy configuration */
1365
0
        return policy_conf;
1366
0
    }
1367
1368
0
    return NULL;
1369
0
}
1370
void ogs_app_policy_conf_remove(ogs_app_policy_conf_t *policy_conf)
1371
0
{
1372
0
    ogs_assert(policy_conf);
1373
1374
0
    ogs_list_remove(&local_conf.policy_list, policy_conf);
1375
1376
0
    ogs_app_slice_conf_remove_all(policy_conf);
1377
1378
0
    ogs_pool_free(&policy_conf_pool, policy_conf);
1379
1380
0
    ogs_info("POLICY config removed [%d]",
1381
0
            ogs_list_count(&local_conf.policy_list));
1382
0
}
1383
void ogs_app_policy_conf_remove_all(void)
1384
0
{
1385
0
    ogs_app_policy_conf_t *policy_conf = NULL, *next_conf = NULL;;
1386
1387
0
    ogs_list_for_each_safe(&local_conf.policy_list, next_conf, policy_conf)
1388
0
        ogs_app_policy_conf_remove(policy_conf);
1389
0
}
1390
1391
ogs_app_slice_conf_t *ogs_app_slice_conf_add(
1392
        ogs_app_policy_conf_t *policy_conf, const ogs_s_nssai_t *s_nssai)
1393
0
{
1394
0
    ogs_app_slice_conf_t *slice_conf = NULL;
1395
1396
0
    ogs_assert(policy_conf);
1397
0
    ogs_assert(s_nssai);
1398
1399
0
    ogs_pool_alloc(&slice_conf_pool, &slice_conf);
1400
0
    if (!slice_conf) {
1401
0
        ogs_error("Maximum number of slice_conf[%d] reached",
1402
0
                OGS_MAX_NUM_OF_SLICE);
1403
0
        return NULL;
1404
0
    }
1405
0
    memset(slice_conf, 0, sizeof *slice_conf);
1406
1407
0
    slice_conf->data.s_nssai.sst = s_nssai->sst;
1408
0
    slice_conf->data.s_nssai.sd.v = s_nssai->sd.v;
1409
1410
0
    ogs_list_init(&slice_conf->sess_list);
1411
1412
0
    ogs_list_add(&policy_conf->slice_list, slice_conf);
1413
1414
0
    slice_conf->policy_conf = policy_conf;
1415
1416
0
    ogs_info("SLICE config added [%d]",
1417
0
            ogs_list_count(&policy_conf->slice_list));
1418
0
    return slice_conf;
1419
0
}
1420
1421
ogs_app_slice_conf_t *ogs_app_slice_conf_find_by_s_nssai(
1422
        ogs_app_policy_conf_t *policy_conf, const ogs_s_nssai_t *s_nssai)
1423
0
{
1424
0
    ogs_app_slice_conf_t *slice_conf = NULL;
1425
1426
0
    ogs_assert(policy_conf);
1427
0
    ogs_assert(s_nssai);
1428
1429
0
    ogs_list_for_each(&policy_conf->slice_list, slice_conf) {
1430
0
        if (slice_conf->data.s_nssai.sst == s_nssai->sst &&
1431
0
                slice_conf->data.s_nssai.sd.v == s_nssai->sd.v)
1432
0
            break;
1433
0
    }
1434
1435
0
    return slice_conf;
1436
0
}
1437
void ogs_app_slice_conf_remove(ogs_app_slice_conf_t *slice_conf)
1438
0
{
1439
0
    ogs_app_policy_conf_t *policy_conf = NULL;
1440
1441
0
    ogs_assert(slice_conf);
1442
0
    policy_conf = slice_conf->policy_conf;
1443
0
    ogs_assert(policy_conf);
1444
1445
0
    ogs_list_remove(&policy_conf->slice_list, slice_conf);
1446
1447
0
    ogs_app_session_conf_remove_all(slice_conf);
1448
1449
0
    ogs_pool_free(&slice_conf_pool, slice_conf);
1450
1451
0
    ogs_info("SLICE config removed [%d]",
1452
0
            ogs_list_count(&policy_conf->slice_list));
1453
0
}
1454
void ogs_app_slice_conf_remove_all(ogs_app_policy_conf_t *policy_conf)
1455
0
{
1456
0
    ogs_app_slice_conf_t *slice_conf = NULL, *next_conf = NULL;;
1457
1458
0
    ogs_assert(policy_conf);
1459
1460
0
    ogs_list_for_each_safe(&policy_conf->slice_list, next_conf, slice_conf)
1461
0
        ogs_app_slice_conf_remove(slice_conf);
1462
0
}
1463
1464
int ogs_app_check_policy_conf(void)
1465
0
{
1466
0
    ogs_app_policy_conf_t *policy_conf = NULL;
1467
1468
0
    ogs_list_for_each(&ogs_local_conf()->policy_list, policy_conf) {
1469
0
        ogs_app_slice_conf_t *slice_conf = NULL;
1470
0
        bool default_indicator = false;
1471
1472
0
        ogs_list_for_each(&policy_conf->slice_list, slice_conf) {
1473
0
            if (slice_conf->data.default_indicator == true)
1474
0
                default_indicator = true;
1475
1476
0
            if (ogs_list_count(&slice_conf->sess_list) == 0) {
1477
0
                ogs_error("At least 1 Session is required");
1478
0
                return OGS_ERROR;
1479
0
            }
1480
0
        }
1481
1482
0
        if (default_indicator == false) {
1483
0
            ogs_error("At least 1 Default S-NSSAI is required");
1484
0
            return OGS_ERROR;
1485
0
        }
1486
0
    }
1487
1488
0
    return OGS_OK;
1489
0
}
1490
1491
ogs_app_session_conf_t *ogs_app_session_conf_add(
1492
        ogs_app_slice_conf_t *slice_conf, const char *name)
1493
0
{
1494
0
    ogs_app_session_conf_t *session_conf = NULL;
1495
1496
0
    ogs_assert(slice_conf);
1497
0
    ogs_assert(name);
1498
1499
0
    ogs_pool_alloc(&session_conf_pool, &session_conf);
1500
0
    if (!session_conf) {
1501
0
        ogs_error("Maximum number of session_conf[%d] reached",
1502
0
                OGS_MAX_NUM_OF_SLICE*OGS_MAX_NUM_OF_SESS);
1503
0
        return NULL;
1504
0
    }
1505
0
    memset(session_conf, 0, sizeof *session_conf);
1506
1507
0
    session_conf->data.session.name = ogs_strdup(name);
1508
0
    if (!session_conf->data.session.name) {
1509
0
        ogs_error("No memory for DNN[%s]", name);
1510
0
        ogs_pool_free(&session_conf_pool, session_conf);
1511
0
        return NULL;
1512
0
    }
1513
1514
0
    ogs_list_add(&slice_conf->sess_list, session_conf);
1515
1516
0
    session_conf->slice_conf = slice_conf;
1517
1518
0
    ogs_info("SESSION config added [%d]",
1519
0
            ogs_list_count(&slice_conf->sess_list));
1520
1521
0
    return session_conf;
1522
0
}
1523
ogs_app_session_conf_t *ogs_app_session_conf_find_by_dnn(
1524
        ogs_app_slice_conf_t *slice_conf, const char *name)
1525
0
{
1526
0
    ogs_app_session_conf_t *session_conf = NULL;
1527
1528
0
    ogs_assert(slice_conf);
1529
0
    ogs_assert(name);
1530
1531
0
    ogs_list_for_each(&slice_conf->sess_list, session_conf) {
1532
0
        ogs_assert(session_conf->data.session.name);
1533
0
        if (strcmp(session_conf->data.session.name, name) == 0)
1534
0
            break;
1535
0
    }
1536
1537
0
    return session_conf;
1538
0
}
1539
void ogs_app_session_conf_remove(ogs_app_session_conf_t *session_conf)
1540
0
{
1541
0
    ogs_app_slice_conf_t *slice_conf = NULL;
1542
1543
0
    ogs_assert(session_conf);
1544
0
    slice_conf = session_conf->slice_conf;
1545
0
    ogs_assert(slice_conf);
1546
1547
0
    ogs_list_remove(&slice_conf->sess_list, session_conf);
1548
1549
0
    OGS_SESSION_DATA_FREE(&session_conf->data);
1550
1551
0
    ogs_pool_free(&session_conf_pool, session_conf);
1552
1553
0
    ogs_info("SESSION config removed [%d]",
1554
0
            ogs_list_count(&slice_conf->sess_list));
1555
0
}
1556
void ogs_app_session_conf_remove_all(ogs_app_slice_conf_t *slice_conf)
1557
0
{
1558
0
    ogs_app_session_conf_t *session_conf = NULL, *next_conf = NULL;;
1559
1560
0
    ogs_assert(slice_conf);
1561
1562
0
    ogs_list_for_each_safe(&slice_conf->sess_list, next_conf, session_conf)
1563
0
        ogs_app_session_conf_remove(session_conf);
1564
0
}
1565
1566
int ogs_app_config_session_data(
1567
        const char *supi, const ogs_plmn_id_t *plmn_id,
1568
        const ogs_s_nssai_t *s_nssai, const char *dnn,
1569
        ogs_session_data_t *session_data)
1570
0
{
1571
0
    ogs_app_policy_conf_t *policy_conf = NULL;
1572
0
    ogs_app_slice_conf_t *slice_conf = NULL;
1573
0
    ogs_app_session_conf_t *session_conf = NULL;
1574
1575
0
    ogs_assert(supi);
1576
0
    ogs_assert(dnn);
1577
0
    ogs_assert(session_data);
1578
1579
0
    policy_conf = ogs_app_policy_conf_find(supi, plmn_id);
1580
0
    if (!policy_conf) {
1581
0
        if (plmn_id)
1582
0
            ogs_error("No POLICY [SUPI:%s] [MCC:%03d,MNC:%03d]",
1583
0
                    supi, ogs_plmn_id_mcc(plmn_id), ogs_plmn_id_mnc(plmn_id));
1584
0
        else
1585
0
            ogs_error("No POLICY [SUPI:%s]", supi);
1586
1587
0
        return OGS_ERROR;
1588
0
    }
1589
1590
0
    if (s_nssai) {
1591
0
        slice_conf = ogs_app_slice_conf_find_by_s_nssai(policy_conf, s_nssai);
1592
0
        if (!slice_conf) {
1593
0
            ogs_error("No SLICE [SST:%d, SD:0x%x]",
1594
0
                    s_nssai->sst, s_nssai->sd.v);
1595
0
            return OGS_ERROR;
1596
0
        }
1597
0
    } else {
1598
0
        slice_conf = ogs_list_first(&policy_conf->slice_list);
1599
0
        if (!slice_conf) {
1600
0
            ogs_error("No default SLICE for EPC");
1601
0
            return OGS_ERROR;
1602
0
        }
1603
0
    }
1604
0
    session_conf = ogs_app_session_conf_find_by_dnn(slice_conf, dnn);
1605
0
    if (!session_conf) {
1606
0
        ogs_error("No SESSION [%s]", dnn);
1607
0
        return OGS_ERROR;
1608
0
    }
1609
1610
0
    OGS_STORE_SESSION_DATA(session_data, &session_conf->data);
1611
1612
0
    return OGS_OK;
1613
0
}