2019-07-11 13:22:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
#include "ogs-dbi.h"
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "pcrf-context.h"
|
2017-08-17 05:15:08 +00:00
|
|
|
|
|
|
|
static pcrf_context_t self;
|
2019-09-13 12:07:47 +00:00
|
|
|
static ogs_diam_config_t g_diam_conf;
|
2018-01-05 07:25:02 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int __pcrf_log_domain;
|
|
|
|
|
2017-08-17 05:15:08 +00:00
|
|
|
static int context_initialized = 0;
|
|
|
|
|
|
|
|
pcrf_context_t* pcrf_self()
|
|
|
|
{
|
|
|
|
return &self;
|
|
|
|
}
|
|
|
|
|
2019-05-06 11:43:50 +00:00
|
|
|
void pcrf_context_init(void)
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(context_initialized == 0);
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2018-01-05 07:25:02 +00:00
|
|
|
/* Initial FreeDiameter Config */
|
2019-09-13 12:07:47 +00:00
|
|
|
memset(&g_diam_conf, 0, sizeof(ogs_diam_config_t));
|
2018-01-05 07:25:02 +00:00
|
|
|
|
2017-08-17 05:15:08 +00:00
|
|
|
/* Initialize PCRF context */
|
|
|
|
memset(&self, 0, sizeof(pcrf_context_t));
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config = &g_diam_conf;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_log_install_domain(&__ogs_diam_domain, "diam", ogs_core()->log.level);
|
|
|
|
ogs_log_install_domain(&__ogs_dbi_domain, "dbi", ogs_core()->log.level);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_log_install_domain(&__pcrf_log_domain, "pcrf", ogs_core()->log.level);
|
|
|
|
|
|
|
|
ogs_thread_mutex_init(&self.db_lock);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_init(&self.hash_lock);
|
|
|
|
self.ip_hash = ogs_hash_make();
|
2017-08-17 05:15:08 +00:00
|
|
|
|
|
|
|
context_initialized = 1;
|
|
|
|
}
|
|
|
|
|
2019-05-06 11:43:50 +00:00
|
|
|
void pcrf_context_final(void)
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(context_initialized == 1);
|
|
|
|
ogs_assert(self.ip_hash);
|
|
|
|
ogs_hash_destroy(self.ip_hash);
|
|
|
|
ogs_thread_mutex_destroy(&self.hash_lock);
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_destroy(&self.db_lock);
|
2017-08-17 05:15:08 +00:00
|
|
|
|
|
|
|
context_initialized = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static int pcrf_context_prepare()
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->cnf_port = DIAMETER_PORT;
|
|
|
|
self.diam_config->cnf_port_tls = DIAMETER_SECURE_PORT;
|
2018-01-05 14:31:30 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static int pcrf_context_validation()
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-09-13 12:07:47 +00:00
|
|
|
if (self.diam_conf_path == NULL &&
|
|
|
|
(self.diam_config->cnf_diamid == NULL ||
|
|
|
|
self.diam_config->cnf_diamrlm == NULL ||
|
|
|
|
self.diam_config->cnf_addr == NULL)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("No pcrf.freeDiameter in '%s'",
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_config()->file);
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_context_parse_config()
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2017-11-29 00:51:34 +00:00
|
|
|
yaml_document_t *document = NULL;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_t root_iter;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
document = ogs_config()->document;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(document);
|
2017-08-17 05:15:08 +00:00
|
|
|
|
|
|
|
rv = pcrf_context_prepare();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_init(&root_iter, document);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (ogs_yaml_iter_next(&root_iter)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
const char *root_key = ogs_yaml_iter_key(&root_iter);
|
|
|
|
ogs_assert(root_key);
|
2019-07-11 13:22:22 +00:00
|
|
|
if (!strcmp(root_key, "pcrf")) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_t pcrf_iter;
|
|
|
|
ogs_yaml_iter_recurse(&root_iter, &pcrf_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (ogs_yaml_iter_next(&pcrf_iter)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
const char *pcrf_key = ogs_yaml_iter_key(&pcrf_iter);
|
|
|
|
ogs_assert(pcrf_key);
|
2019-07-11 13:22:22 +00:00
|
|
|
if (!strcmp(pcrf_key, "freeDiameter")) {
|
2018-01-05 14:31:30 +00:00
|
|
|
yaml_node_t *node =
|
|
|
|
yaml_document_get_node(document, pcrf_iter.pair->value);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(node);
|
2019-07-11 13:22:22 +00:00
|
|
|
if (node->type == YAML_SCALAR_NODE) {
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_conf_path = ogs_yaml_iter_value(&pcrf_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (node->type == YAML_MAPPING_NODE) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_t fd_iter;
|
|
|
|
ogs_yaml_iter_recurse(&pcrf_iter, &fd_iter);
|
2018-01-05 14:31:30 +00:00
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
while (ogs_yaml_iter_next(&fd_iter)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
const char *fd_key = ogs_yaml_iter_key(&fd_iter);
|
|
|
|
ogs_assert(fd_key);
|
2019-07-11 13:22:22 +00:00
|
|
|
if (!strcmp(fd_key, "identity")) {
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->cnf_diamid =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_value(&fd_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(fd_key, "realm")) {
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->cnf_diamrlm =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_value(&fd_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(fd_key, "port")) {
|
2019-04-27 14:54:30 +00:00
|
|
|
const char *v = ogs_yaml_iter_value(&fd_iter);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (v) self.diam_config->cnf_port = atoi(v);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(fd_key, "sec_port")) {
|
2019-04-27 14:54:30 +00:00
|
|
|
const char *v = ogs_yaml_iter_value(&fd_iter);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (v) self.diam_config->cnf_port_tls = atoi(v);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(fd_key, "listen_on")) {
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->cnf_addr =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_value(&fd_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(fd_key, "load_extension")) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_t ext_array, ext_iter;
|
|
|
|
ogs_yaml_iter_recurse(&fd_iter, &ext_array);
|
2019-07-11 13:22:22 +00:00
|
|
|
do {
|
2018-01-05 14:31:30 +00:00
|
|
|
const char *module = NULL;
|
|
|
|
const char *conf = NULL;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
if (ogs_yaml_iter_type(&ext_array) ==
|
2019-07-11 13:22:22 +00:00
|
|
|
YAML_MAPPING_NODE) {
|
2018-01-05 14:31:30 +00:00
|
|
|
memcpy(&ext_iter, &ext_array,
|
2019-04-27 14:54:30 +00:00
|
|
|
sizeof(ogs_yaml_iter_t));
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (ogs_yaml_iter_type(&ext_array) ==
|
|
|
|
YAML_SEQUENCE_NODE) {
|
2019-04-27 14:54:30 +00:00
|
|
|
if (!ogs_yaml_iter_next(&ext_array))
|
2018-01-05 14:31:30 +00:00
|
|
|
break;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_recurse(
|
2018-01-05 14:31:30 +00:00
|
|
|
&ext_array, &ext_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (ogs_yaml_iter_type(&ext_array) ==
|
|
|
|
YAML_SCALAR_NODE) {
|
2018-01-05 14:31:30 +00:00
|
|
|
break;
|
2019-07-11 13:22:22 +00:00
|
|
|
} else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert_if_reached();
|
2018-01-05 14:31:30 +00:00
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
while (ogs_yaml_iter_next(&ext_iter)) {
|
2018-01-05 14:31:30 +00:00
|
|
|
const char *ext_key =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_key(&ext_iter);
|
|
|
|
ogs_assert(ext_key);
|
2018-01-05 14:31:30 +00:00
|
|
|
if (!strcmp(ext_key, "module"))
|
|
|
|
{
|
2019-07-11 13:22:22 +00:00
|
|
|
module = ogs_yaml_iter_value(
|
|
|
|
&ext_iter);
|
|
|
|
} else if (!strcmp(ext_key, "conf")) {
|
|
|
|
conf = ogs_yaml_iter_value(
|
|
|
|
&ext_iter);
|
|
|
|
} else
|
|
|
|
ogs_warn("unknown key `%s`",
|
|
|
|
ext_key);
|
2018-01-05 14:31:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
if (module) {
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->
|
|
|
|
ext[self.diam_config->num_of_ext].
|
2018-01-05 14:31:30 +00:00
|
|
|
module = module;
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->
|
|
|
|
ext[self.diam_config->num_of_ext].
|
2018-01-05 14:31:30 +00:00
|
|
|
conf = conf;
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->num_of_ext++;
|
2018-01-05 14:31:30 +00:00
|
|
|
}
|
2019-04-27 14:54:30 +00:00
|
|
|
} while(ogs_yaml_iter_type(&ext_array) ==
|
2018-01-05 14:31:30 +00:00
|
|
|
YAML_SEQUENCE_NODE);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(fd_key, "connect")) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_t conn_array, conn_iter;
|
|
|
|
ogs_yaml_iter_recurse(&fd_iter, &conn_array);
|
2019-07-11 13:22:22 +00:00
|
|
|
do {
|
2018-01-05 14:31:30 +00:00
|
|
|
const char *identity = NULL;
|
|
|
|
const char *addr = NULL;
|
2019-04-27 14:54:30 +00:00
|
|
|
uint16_t port = 0;
|
2018-01-05 14:31:30 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
if (ogs_yaml_iter_type(&conn_array) ==
|
2019-07-11 13:22:22 +00:00
|
|
|
YAML_MAPPING_NODE) {
|
2018-01-05 14:31:30 +00:00
|
|
|
memcpy(&conn_iter, &conn_array,
|
2019-04-27 14:54:30 +00:00
|
|
|
sizeof(ogs_yaml_iter_t));
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (ogs_yaml_iter_type(&conn_array)
|
|
|
|
== YAML_SEQUENCE_NODE) {
|
2019-04-27 14:54:30 +00:00
|
|
|
if (!ogs_yaml_iter_next(&conn_array))
|
2018-01-05 14:31:30 +00:00
|
|
|
break;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_recurse(&conn_array, &conn_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (ogs_yaml_iter_type(&conn_array)
|
|
|
|
== YAML_SCALAR_NODE) {
|
2018-01-05 14:31:30 +00:00
|
|
|
break;
|
2019-07-11 13:22:22 +00:00
|
|
|
} else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert_if_reached();
|
2018-01-05 14:31:30 +00:00
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
while (ogs_yaml_iter_next(&conn_iter)) {
|
2018-01-05 14:31:30 +00:00
|
|
|
const char *conn_key =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_key(&conn_iter);
|
|
|
|
ogs_assert(conn_key);
|
2019-07-11 13:22:22 +00:00
|
|
|
if (!strcmp(conn_key, "identity")) {
|
|
|
|
identity = ogs_yaml_iter_value(
|
|
|
|
&conn_iter);
|
|
|
|
} else if (!strcmp(conn_key, "addr")) {
|
|
|
|
addr = ogs_yaml_iter_value(
|
|
|
|
&conn_iter);
|
|
|
|
} else if (!strcmp(conn_key, "port")) {
|
2018-01-05 14:31:30 +00:00
|
|
|
const char *v =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_yaml_iter_value(&conn_iter);
|
2018-01-05 14:31:30 +00:00
|
|
|
if (v) port = atoi(v);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else
|
|
|
|
ogs_warn("unknown key `%s`",
|
|
|
|
conn_key);
|
2018-01-05 14:31:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
if (identity && addr) {
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->
|
|
|
|
conn[self.diam_config->num_of_conn].
|
2018-01-05 14:31:30 +00:00
|
|
|
identity = identity;
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->
|
|
|
|
conn[self.diam_config->num_of_conn].
|
2018-01-05 14:31:30 +00:00
|
|
|
addr = addr;
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->
|
|
|
|
conn[self.diam_config->num_of_conn].
|
2018-01-05 14:31:30 +00:00
|
|
|
port = port;
|
2019-09-13 12:07:47 +00:00
|
|
|
self.diam_config->num_of_conn++;
|
2018-01-05 14:31:30 +00:00
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} while (ogs_yaml_iter_type(&conn_array) ==
|
2018-01-05 14:31:30 +00:00
|
|
|
YAML_SEQUENCE_NODE);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_warn("unknown key `%s`", fd_key);
|
2018-01-05 14:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_warn("unknown key `%s`", pcrf_key);
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = pcrf_context_validation();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_db_init()
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-09-13 12:07:47 +00:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = ogs_mongoc_init(ogs_config()->db_uri);
|
|
|
|
if (rv != OGS_OK) return rv;
|
|
|
|
|
|
|
|
if (ogs_mongoc()->client && ogs_mongoc()->name) {
|
2017-08-17 05:15:08 +00:00
|
|
|
self.subscriberCollection = mongoc_client_get_collection(
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_mongoc()->client, ogs_mongoc()->name, "subscribers");
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(self.subscriberCollection);
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_db_final()
|
2017-08-17 05:15:08 +00:00
|
|
|
{
|
2019-07-11 13:22:22 +00:00
|
|
|
if (self.subscriberCollection) {
|
2017-08-17 05:15:08 +00:00
|
|
|
mongoc_collection_destroy(self.subscriberCollection);
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_mongoc_final();
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
int pcrf_db_qos_data(char *imsi_bcd, char *apn,
|
|
|
|
ogs_diam_gx_message_t *gx_message)
|
2017-08-24 08:05:10 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv = OGS_OK;
|
2017-08-24 08:05:10 +00:00
|
|
|
mongoc_cursor_t *cursor = NULL;
|
|
|
|
bson_t *query = NULL;
|
|
|
|
bson_t *opts = NULL;
|
|
|
|
bson_error_t error;
|
|
|
|
const bson_t *document;
|
|
|
|
bson_iter_t iter;
|
|
|
|
bson_iter_t child1_iter, child2_iter, child3_iter;
|
|
|
|
bson_iter_t child4_iter, child5_iter, child6_iter;
|
|
|
|
const char *utf8 = NULL;
|
2019-04-27 14:54:30 +00:00
|
|
|
uint32_t length = 0;
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(imsi_bcd);
|
|
|
|
ogs_assert(apn);
|
|
|
|
ogs_assert(gx_message);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_lock(&self.db_lock);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2017-10-11 06:08:19 +00:00
|
|
|
query = BCON_NEW(
|
|
|
|
"imsi", BCON_UTF8(imsi_bcd),
|
|
|
|
"pdn.apn", BCON_UTF8(apn));
|
|
|
|
#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 5
|
2017-08-24 08:05:10 +00:00
|
|
|
opts = BCON_NEW(
|
|
|
|
"projection", "{",
|
|
|
|
"imsi", BCON_INT64(1),
|
|
|
|
"pdn.$", BCON_INT64(1),
|
|
|
|
"}"
|
|
|
|
);
|
|
|
|
cursor = mongoc_collection_find_with_opts(
|
|
|
|
self.subscriberCollection, query, opts, NULL);
|
2017-09-26 00:19:22 +00:00
|
|
|
#else
|
2017-10-11 06:08:19 +00:00
|
|
|
opts = BCON_NEW(
|
|
|
|
"imsi", BCON_INT64(1),
|
|
|
|
"pdn.$", BCON_INT64(1)
|
2017-09-26 00:19:22 +00:00
|
|
|
);
|
|
|
|
cursor = mongoc_collection_find(self.subscriberCollection,
|
2017-10-11 06:08:19 +00:00
|
|
|
MONGOC_QUERY_NONE, 0, 0, 0, query, opts, NULL);
|
2017-09-26 00:19:22 +00:00
|
|
|
#endif
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
if (!mongoc_cursor_next(cursor, &document)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cannot find IMSI(%s)+APN(%s) in DB", imsi_bcd, apn);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = OGS_ERROR;
|
2017-08-24 08:05:10 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
if (mongoc_cursor_error(cursor, &error)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cursor Failure: %s", error.message);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = OGS_ERROR;
|
2017-08-24 08:05:10 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
if (!bson_iter_init(&iter, document)) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("bson_iter_init failed in this document");
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = OGS_ERROR;
|
2017-08-24 08:05:10 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *key = bson_iter_key(&iter);
|
|
|
|
if (!strcmp(key, "pdn") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_ARRAY(&iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
int pdn_index = 0;
|
|
|
|
|
|
|
|
bson_iter_recurse(&iter, &child1_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child1_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child1_key = bson_iter_key(&child1_iter);
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_pdn_t *pdn = NULL;
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(child1_key);
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn_index = atoi(child1_key);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pdn_index == 0);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2018-01-10 13:09:08 +00:00
|
|
|
pdn = &gx_message->pdn;
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(&child1_iter, &child2_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child2_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child2_key = bson_iter_key(&child2_iter);
|
|
|
|
if (!strcmp(child2_key, "apn") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_UTF8(&child2_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
utf8 = bson_iter_utf8(&child2_iter, &length);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_cpystrn(pdn->apn, utf8,
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_min(length, OGS_MAX_APN_LEN)+1);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child2_key, "type") &&
|
|
|
|
BSON_ITER_HOLDS_INT32(&child2_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->pdn_type = bson_iter_int32(&child2_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child2_key, "qos") &&
|
|
|
|
BSON_ITER_HOLDS_DOCUMENT(&child2_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(&child2_iter, &child3_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child3_key =
|
|
|
|
bson_iter_key(&child3_iter);
|
|
|
|
if (!strcmp(child3_key, "qci") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT32(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->qos.qci = bson_iter_int32(&child3_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child3_key, "arp") &&
|
|
|
|
BSON_ITER_HOLDS_DOCUMENT(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(&child3_iter, &child4_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child4_key =
|
|
|
|
bson_iter_key(&child4_iter);
|
|
|
|
if (!strcmp(child4_key, "priority_level") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT32(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->qos.arp.priority_level =
|
|
|
|
bson_iter_int32(&child4_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child4_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"pre_emption_capability") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT32(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->qos.arp.pre_emption_capability =
|
|
|
|
bson_iter_int32(&child4_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child4_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"pre_emption_vulnerability") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT32(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->qos.arp.pre_emption_vulnerability =
|
|
|
|
bson_iter_int32(&child4_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child2_key, "ambr") &&
|
|
|
|
BSON_ITER_HOLDS_DOCUMENT(&child2_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(&child2_iter, &child3_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child3_key =
|
|
|
|
bson_iter_key(&child3_iter);
|
|
|
|
if (!strcmp(child3_key, "uplink") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT64(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->ambr.uplink =
|
2017-08-24 10:51:16 +00:00
|
|
|
bson_iter_int64(&child3_iter) * 1024;
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child3_key, "downlink") &&
|
|
|
|
BSON_ITER_HOLDS_INT64(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pdn->ambr.downlink =
|
2017-08-24 10:51:16 +00:00
|
|
|
bson_iter_int64(&child3_iter) * 1024;
|
2017-08-24 08:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child2_key, "pcc_rule") &&
|
|
|
|
BSON_ITER_HOLDS_ARRAY(&child2_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
int pcc_rule_index = 0;
|
|
|
|
|
|
|
|
bson_iter_recurse(&child2_iter, &child3_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child3_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child3_key =
|
|
|
|
bson_iter_key(&child3_iter);
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_pcc_rule_t *pcc_rule = NULL;
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(child3_key);
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule_index = atoi(child3_key);
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_assert(pcc_rule_index < OGS_MAX_NUM_OF_PCC_RULE);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2018-01-10 13:09:08 +00:00
|
|
|
pcc_rule = &gx_message->pcc_rule[pcc_rule_index];
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(&child3_iter, &child4_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child4_key =
|
|
|
|
bson_iter_key(&child4_iter);
|
|
|
|
|
|
|
|
if (!strcmp(child4_key, "qos") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_DOCUMENT(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(
|
|
|
|
&child4_iter, &child5_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child5_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child5_key =
|
|
|
|
bson_iter_key(&child5_iter);
|
|
|
|
if (!strcmp(child5_key, "qci") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT32(
|
|
|
|
&child5_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.qci =
|
|
|
|
bson_iter_int32(&child5_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child5_key, "arp") &&
|
2017-08-24 08:05:10 +00:00
|
|
|
BSON_ITER_HOLDS_DOCUMENT(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child5_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(
|
|
|
|
&child5_iter, &child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(
|
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child6_key =
|
|
|
|
bson_iter_key(&child6_iter);
|
|
|
|
if (!strcmp(child6_key,
|
|
|
|
"priority_level") &&
|
|
|
|
BSON_ITER_HOLDS_INT32(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.arp.
|
|
|
|
priority_level =
|
|
|
|
bson_iter_int32(
|
|
|
|
&child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child6_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"pre_emption_capability") &&
|
|
|
|
BSON_ITER_HOLDS_INT32(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.arp.
|
|
|
|
pre_emption_capability =
|
|
|
|
bson_iter_int32(
|
|
|
|
&child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child6_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"pre_emption_vulnerability") &&
|
2019-07-11 13:22:22 +00:00
|
|
|
BSON_ITER_HOLDS_INT32(
|
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.arp.
|
|
|
|
pre_emption_vulnerability =
|
|
|
|
bson_iter_int32(
|
|
|
|
&child6_iter);
|
|
|
|
}
|
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child5_key, "mbr") &&
|
2017-08-24 08:05:10 +00:00
|
|
|
BSON_ITER_HOLDS_DOCUMENT(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child5_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(
|
|
|
|
&child5_iter, &child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(
|
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child6_key =
|
|
|
|
bson_iter_key(&child6_iter);
|
|
|
|
if (!strcmp(child6_key,
|
|
|
|
"downlink") &&
|
2017-08-24 10:51:16 +00:00
|
|
|
BSON_ITER_HOLDS_INT64(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.mbr.downlink =
|
2017-08-24 10:51:16 +00:00
|
|
|
bson_iter_int64(
|
2017-08-24 14:10:36 +00:00
|
|
|
&child6_iter) * 1024;
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child6_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"uplink") &&
|
2017-08-24 10:51:16 +00:00
|
|
|
BSON_ITER_HOLDS_INT64(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.mbr.uplink =
|
2017-08-24 10:51:16 +00:00
|
|
|
bson_iter_int64(
|
2017-08-24 14:10:36 +00:00
|
|
|
&child6_iter) * 1024;
|
2017-08-24 08:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child5_key, "gbr") &&
|
2017-08-24 08:05:10 +00:00
|
|
|
BSON_ITER_HOLDS_DOCUMENT(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child5_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
bson_iter_recurse(&child5_iter,
|
|
|
|
&child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(
|
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child6_key =
|
|
|
|
bson_iter_key(&child6_iter);
|
|
|
|
if (!strcmp(child6_key,
|
|
|
|
"downlink") &&
|
2017-08-24 10:51:16 +00:00
|
|
|
BSON_ITER_HOLDS_INT64(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.gbr.downlink =
|
2017-08-24 10:51:16 +00:00
|
|
|
bson_iter_int64(
|
2017-08-24 14:10:36 +00:00
|
|
|
&child6_iter) * 1024;
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child6_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"uplink") &&
|
2017-08-24 10:51:16 +00:00
|
|
|
BSON_ITER_HOLDS_INT64(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule->qos.gbr.uplink =
|
2017-08-24 10:51:16 +00:00
|
|
|
bson_iter_int64(
|
2017-08-24 14:10:36 +00:00
|
|
|
&child6_iter) * 1024;
|
2017-08-24 08:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child4_key, "flow") &&
|
|
|
|
BSON_ITER_HOLDS_ARRAY(&child4_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
int flow_index = 0;
|
|
|
|
|
|
|
|
bson_iter_recurse(&child4_iter,
|
|
|
|
&child5_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child5_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child5_key =
|
|
|
|
bson_iter_key(&child5_iter);
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_flow_t *flow = NULL;
|
2017-08-24 08:05:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(child5_key);
|
2017-08-24 08:05:10 +00:00
|
|
|
flow_index = atoi(child5_key);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(
|
2019-09-13 12:07:47 +00:00
|
|
|
flow_index < OGS_MAX_NUM_OF_FLOW);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
|
|
|
flow = &pcc_rule->flow[flow_index];
|
|
|
|
bson_iter_recurse(
|
|
|
|
&child5_iter, &child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
while (bson_iter_next(&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
const char *child6_key =
|
|
|
|
bson_iter_key(&child6_iter);
|
|
|
|
if (!strcmp(child6_key, "direction") &&
|
|
|
|
BSON_ITER_HOLDS_INT32(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
flow->direction =
|
|
|
|
bson_iter_int32(
|
|
|
|
&child6_iter);
|
2019-07-11 13:22:22 +00:00
|
|
|
} else if (!strcmp(child6_key,
|
2017-08-24 08:05:10 +00:00
|
|
|
"description") &&
|
|
|
|
BSON_ITER_HOLDS_UTF8(
|
2019-07-11 13:22:22 +00:00
|
|
|
&child6_iter)) {
|
2017-08-24 08:05:10 +00:00
|
|
|
utf8 = bson_iter_utf8(
|
|
|
|
&child6_iter, &length);
|
2017-08-25 10:40:49 +00:00
|
|
|
flow->description =
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_malloc(length+1);
|
|
|
|
ogs_cpystrn(
|
2017-08-25 10:40:49 +00:00
|
|
|
(char*)flow->description,
|
|
|
|
utf8, length+1);
|
2017-08-24 08:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
flow_index++;
|
|
|
|
}
|
|
|
|
pcc_rule->num_of_flow = flow_index;
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 09:15:38 +00:00
|
|
|
/* Charing-Rule-Name is automatically configured */
|
2019-07-11 13:22:22 +00:00
|
|
|
if (pcc_rule->name) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("PCC Rule Name has already "
|
2018-01-15 02:54:22 +00:00
|
|
|
"been defined");
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(pcc_rule->name);
|
2018-01-15 02:54:22 +00:00
|
|
|
}
|
2019-04-27 14:54:30 +00:00
|
|
|
pcc_rule->name = ogs_calloc(
|
2019-09-13 12:07:47 +00:00
|
|
|
1, OGS_MAX_PCC_RULE_NAME_LEN);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pcc_rule->name);
|
2019-09-13 12:07:47 +00:00
|
|
|
snprintf(pcc_rule->name, OGS_MAX_PCC_RULE_NAME_LEN,
|
2018-01-14 09:15:38 +00:00
|
|
|
"%s%d", apn, pcc_rule_index+1);
|
|
|
|
pcc_rule->precedence = pcc_rule_index+1;
|
2019-09-13 12:07:47 +00:00
|
|
|
pcc_rule->flow_status = OGS_FLOW_STATUS_ENABLED;
|
2017-08-24 08:05:10 +00:00
|
|
|
pcc_rule_index++;
|
|
|
|
}
|
2018-01-10 13:09:08 +00:00
|
|
|
gx_message->num_of_pcc_rule = pcc_rule_index;
|
2017-08-24 08:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (query) bson_destroy(query);
|
2017-08-25 10:40:49 +00:00
|
|
|
if (opts) bson_destroy(opts);
|
2017-08-24 08:05:10 +00:00
|
|
|
if (cursor) mongoc_cursor_destroy(cursor);
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_unlock(&self.db_lock);
|
2017-08-24 08:05:10 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_sess_set_ipv4(const void *key, uint8_t *sid)
|
2018-01-08 13:42:44 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(self.ip_hash);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_lock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_hash_set(self.ip_hash, key, OGS_IPV4_LEN, sid);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_unlock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-08 13:42:44 +00:00
|
|
|
}
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_sess_set_ipv6(const void *key, uint8_t *sid)
|
2018-01-08 13:42:44 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(self.ip_hash);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_lock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_hash_set(self.ip_hash, key, OGS_IPV6_LEN, sid);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_unlock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-08 13:42:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t *pcrf_sess_find_by_ipv4(const void *key)
|
2018-01-08 13:42:44 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t *sid = NULL;
|
|
|
|
ogs_assert(key);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_lock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
sid = (uint8_t *)ogs_hash_get(self.ip_hash, key, OGS_IPV4_LEN);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_unlock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t *pcrf_sess_find_by_ipv6(const void *key)
|
2018-01-08 13:42:44 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t *sid = NULL;
|
|
|
|
ogs_assert(key);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_lock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
sid = (uint8_t *)ogs_hash_get(self.ip_hash, key, OGS_IPV6_LEN);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_thread_mutex_unlock(&self.hash_lock);
|
2018-01-08 13:42:44 +00:00
|
|
|
|
|
|
|
return sid;
|
|
|
|
}
|
2018-01-09 13:53:09 +00:00
|
|
|
|