Coverage Report

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