File size: 6,372 Bytes
258fb37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
/*
* Copyright (C) 2019-2022 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "sbi-path.h"
static ausf_context_t self;
int __ausf_log_domain;
static OGS_POOL(ausf_ue_pool, ausf_ue_t);
static int context_initialized = 0;
void ausf_context_init(void)
{
ogs_assert(context_initialized == 0);
/* Initialize AUSF context */
memset(&self, 0, sizeof(ausf_context_t));
ogs_log_install_domain(&__ausf_log_domain, "ausf", ogs_core()->log.level);
ogs_pool_init(&ausf_ue_pool, ogs_global_conf()->max.ue);
ogs_list_init(&self.ausf_ue_list);
self.suci_hash = ogs_hash_make();
ogs_assert(self.suci_hash);
self.supi_hash = ogs_hash_make();
ogs_assert(self.supi_hash);
context_initialized = 1;
}
void ausf_context_final(void)
{
ogs_assert(context_initialized == 1);
ausf_ue_remove_all();
ogs_assert(self.suci_hash);
ogs_hash_destroy(self.suci_hash);
ogs_assert(self.supi_hash);
ogs_hash_destroy(self.supi_hash);
ogs_pool_final(&ausf_ue_pool);
context_initialized = 0;
}
ausf_context_t *ausf_self(void)
{
return &self;
}
static int ausf_context_prepare(void)
{
return OGS_OK;
}
static int ausf_context_validation(void)
{
return OGS_OK;
}
int ausf_context_parse_config(void)
{
int rv;
yaml_document_t *document = NULL;
ogs_yaml_iter_t root_iter;
document = ogs_app()->document;
ogs_assert(document);
rv = ausf_context_prepare();
if (rv != OGS_OK) return rv;
ogs_yaml_iter_init(&root_iter, document);
while (ogs_yaml_iter_next(&root_iter)) {
const char *root_key = ogs_yaml_iter_key(&root_iter);
ogs_assert(root_key);
if (!strcmp(root_key, "ausf")) {
ogs_yaml_iter_t ausf_iter;
ogs_yaml_iter_recurse(&root_iter, &ausf_iter);
while (ogs_yaml_iter_next(&ausf_iter)) {
const char *ausf_key = ogs_yaml_iter_key(&ausf_iter);
ogs_assert(ausf_key);
if (!strcmp(ausf_key, "default")) {
/* handle config in sbi library */
} else if (!strcmp(ausf_key, "sbi")) {
/* handle config in sbi library */
} else if (!strcmp(ausf_key, "nrf")) {
/* handle config in sbi library */
} else if (!strcmp(ausf_key, "scp")) {
/* handle config in sbi library */
} else if (!strcmp(ausf_key, "service_name")) {
/* handle config in sbi library */
} else if (!strcmp(ausf_key, "discovery")) {
/* handle config in sbi library */
} else
ogs_warn("unknown key `%s`", ausf_key);
}
}
}
rv = ausf_context_validation();
if (rv != OGS_OK) return rv;
return OGS_OK;
}
ausf_ue_t *ausf_ue_add(char *suci)
{
ausf_event_t e;
ausf_ue_t *ausf_ue = NULL;
ogs_assert(suci);
ogs_pool_id_calloc(&ausf_ue_pool, &ausf_ue);
if (!ausf_ue) {
ogs_error("ogs_pool_id_calloc() failed");
return NULL;
}
ausf_ue->ctx_id =
ogs_msprintf("%d", (int)ogs_pool_index(&ausf_ue_pool, ausf_ue));
ogs_assert(ausf_ue->ctx_id);
ausf_ue->suci = ogs_strdup(suci);
ogs_assert(ausf_ue->suci);
ogs_hash_set(self.suci_hash, ausf_ue->suci, strlen(ausf_ue->suci), ausf_ue);
memset(&e, 0, sizeof(e));
e.ausf_ue_id = ausf_ue->id;
ogs_fsm_init(&ausf_ue->sm, ausf_ue_state_initial, ausf_ue_state_final, &e);
ogs_list_add(&self.ausf_ue_list, ausf_ue);
return ausf_ue;
}
void ausf_ue_remove(ausf_ue_t *ausf_ue)
{
ausf_event_t e;
ogs_assert(ausf_ue);
ogs_list_remove(&self.ausf_ue_list, ausf_ue);
memset(&e, 0, sizeof(e));
e.ausf_ue_id = ausf_ue->id;
ogs_fsm_fini(&ausf_ue->sm, &e);
/* Free SBI object memory */
ogs_sbi_object_free(&ausf_ue->sbi);
ogs_assert(ausf_ue->ctx_id);
ogs_free(ausf_ue->ctx_id);
ogs_assert(ausf_ue->suci);
ogs_hash_set(self.suci_hash, ausf_ue->suci, strlen(ausf_ue->suci), NULL);
ogs_free(ausf_ue->suci);
if (ausf_ue->supi) {
ogs_hash_set(self.supi_hash,
ausf_ue->supi, strlen(ausf_ue->supi), NULL);
ogs_free(ausf_ue->supi);
}
AUTH_EVENT_CLEAR(ausf_ue);
if (ausf_ue->auth_event.client)
ogs_sbi_client_remove(ausf_ue->auth_event.client);
if (ausf_ue->serving_network_name)
ogs_free(ausf_ue->serving_network_name);
ogs_pool_id_free(&ausf_ue_pool, ausf_ue);
}
void ausf_ue_remove_all(void)
{
ausf_ue_t *ausf_ue = NULL, *next = NULL;;
ogs_list_for_each_safe(&self.ausf_ue_list, next, ausf_ue)
ausf_ue_remove(ausf_ue);
}
ausf_ue_t *ausf_ue_find_by_suci(char *suci)
{
ogs_assert(suci);
return (ausf_ue_t *)ogs_hash_get(self.suci_hash, suci, strlen(suci));
}
ausf_ue_t *ausf_ue_find_by_supi(char *supi)
{
ogs_assert(supi);
return (ausf_ue_t *)ogs_hash_get(self.supi_hash, supi, strlen(supi));
}
ausf_ue_t *ausf_ue_find_by_suci_or_supi(char *suci_or_supi)
{
ogs_assert(suci_or_supi);
if (strncmp(suci_or_supi, "suci-", strlen("suci-")) == 0)
return ausf_ue_find_by_suci(suci_or_supi);
else
return ausf_ue_find_by_supi(suci_or_supi);
}
ausf_ue_t *ausf_ue_find_by_ctx_id(char *ctx_id)
{
ogs_assert(ctx_id);
return ogs_pool_find(&ausf_ue_pool, atoll(ctx_id));
}
ausf_ue_t *ausf_ue_find_by_id(ogs_pool_id_t id)
{
return ogs_pool_find_by_id(&ausf_ue_pool, id);
}
int get_ue_load(void)
{
return (((ogs_pool_size(&ausf_ue_pool) -
ogs_pool_avail(&ausf_ue_pool)) * 100) /
ogs_pool_size(&ausf_ue_pool));
}
|