2019-06-11 14:16:54 +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-06-11 13:10:47 +00:00
|
|
|
#include "pcrf-context.h"
|
|
|
|
#include "pcrf-fd-path.h"
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
struct rx_sess_state {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_lnode_t node;
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
os0_t sid; /* Rx Session-Id */
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_pcc_rule_t pcc_rule[OGS_MAX_NUM_OF_PCC_RULE];
|
|
|
|
int num_of_pcc_rule;
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
struct sess_state *gx;
|
2018-01-16 07:11:30 +00:00
|
|
|
};
|
|
|
|
|
2018-01-08 11:09:13 +00:00
|
|
|
struct sess_state {
|
2018-01-16 07:11:30 +00:00
|
|
|
os0_t sid; /* Gx Session-Id */
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
os0_t peer_host; /* Peer Host */
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
char *imsi_bcd;
|
|
|
|
char *apn;
|
2018-01-14 04:00:41 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ED3(uint8_t ipv4:1;,
|
|
|
|
uint8_t ipv6:1;,
|
|
|
|
uint8_t reserved:6;)
|
2019-09-13 12:07:47 +00:00
|
|
|
uint32_t addr; /* Framed-IPv4-Address */
|
|
|
|
uint8_t addr6[OGS_IPV6_LEN]; /* Framed-IPv6-Prefix */
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_list_t rx_list;
|
2018-01-14 04:00:41 +00:00
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
struct timespec ts; /* Time of sending the message */
|
2018-01-08 11:09:13 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 17:08:24 +00:00
|
|
|
static OGS_POOL(sess_state_pool, struct sess_state);
|
|
|
|
static OGS_POOL(rx_sess_state_pool, struct rx_sess_state);
|
|
|
|
static ogs_thread_mutex_t sess_state_mutex;
|
|
|
|
|
2018-01-08 09:34:51 +00:00
|
|
|
static struct session_handler *pcrf_gx_reg = NULL;
|
|
|
|
static struct disp_hdl *hdl_gx_fb = NULL;
|
|
|
|
static struct disp_hdl *hdl_gx_ccr = NULL;
|
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
static void pcrf_gx_raa_cb(void *data, struct msg **msg);
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static int encode_pcc_rule_definition(
|
2019-09-13 12:07:47 +00:00
|
|
|
struct avp *avp, ogs_pcc_rule_t *pcc_rule, int flow_presence);
|
|
|
|
static int matched_flow(ogs_pcc_rule_t *pcc_rule,
|
|
|
|
ogs_diam_rx_media_component_t *media_component);
|
|
|
|
static int install_flow(ogs_pcc_rule_t *pcc_rule,
|
|
|
|
ogs_diam_rx_media_component_t *media_component);
|
|
|
|
static int update_qos(ogs_pcc_rule_t *pcc_rule,
|
|
|
|
ogs_diam_rx_media_component_t *media_component);
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2018-01-08 12:20:19 +00:00
|
|
|
static __inline__ struct sess_state *new_state(os0_t sid)
|
|
|
|
{
|
|
|
|
struct sess_state *new = NULL;
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(sid);
|
2018-01-08 12:20:19 +00:00
|
|
|
|
2020-04-27 17:08:24 +00:00
|
|
|
ogs_thread_mutex_lock(&sess_state_mutex);
|
|
|
|
ogs_pool_alloc(&sess_state_pool, &new);
|
|
|
|
ogs_assert(new);
|
|
|
|
memset(new, 0, sizeof(*new));
|
|
|
|
ogs_thread_mutex_unlock(&sess_state_mutex);
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
new->sid = (os0_t)ogs_strdup((char *)sid);
|
|
|
|
ogs_assert(new->sid);
|
2018-01-08 12:20:19 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_list_init(&new->rx_list);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2018-01-08 12:20:19 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:31:49 +00:00
|
|
|
static struct rx_sess_state *add_rx_state(struct sess_state *gx, os0_t sid)
|
|
|
|
{
|
|
|
|
struct rx_sess_state *new = NULL;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(gx);
|
|
|
|
ogs_assert(sid);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2020-04-27 17:08:24 +00:00
|
|
|
ogs_thread_mutex_lock(&sess_state_mutex);
|
|
|
|
ogs_pool_alloc(&rx_sess_state_pool, &new);
|
|
|
|
ogs_assert(new);
|
|
|
|
memset(new, 0, sizeof(*new));
|
|
|
|
ogs_thread_mutex_unlock(&sess_state_mutex);
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
new->sid = (os0_t)ogs_strdup((char *)sid);
|
|
|
|
ogs_assert(new->sid);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
|
|
|
new->gx = gx;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_list_add(&gx->rx_list, new);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static int remove_rx_state(struct rx_sess_state *rx_sess_data)
|
2018-01-17 11:31:49 +00:00
|
|
|
{
|
|
|
|
struct sess_state *gx = NULL;
|
|
|
|
int i;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rx_sess_data);
|
2018-01-17 11:31:49 +00:00
|
|
|
gx = rx_sess_data->gx;
|
2020-04-27 17:08:24 +00:00
|
|
|
ogs_assert(gx);
|
|
|
|
|
|
|
|
ogs_list_remove(&gx->rx_list, rx_sess_data);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < rx_sess_data->num_of_pcc_rule; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_PCC_RULE_FREE(&rx_sess_data->pcc_rule[i]);
|
2018-01-17 11:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rx_sess_data->sid)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(rx_sess_data->sid);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2020-04-27 17:08:24 +00:00
|
|
|
ogs_thread_mutex_lock(&sess_state_mutex);
|
|
|
|
ogs_pool_free(&rx_sess_state_pool, rx_sess_data);
|
|
|
|
ogs_thread_mutex_unlock(&sess_state_mutex);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-17 11:31:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static int remove_rx_state_all(struct sess_state *gx)
|
2018-01-17 11:31:49 +00:00
|
|
|
{
|
|
|
|
struct rx_sess_state *rx_sess_data = NULL, *next_rx_sess_data = NULL;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(gx);
|
2018-01-17 11:31:49 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_list_for_each_safe(&gx->rx_list, next_rx_sess_data, rx_sess_data)
|
2018-01-17 11:31:49 +00:00
|
|
|
remove_rx_state(rx_sess_data);
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-17 11:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct rx_sess_state *find_rx_state(struct sess_state *gx, os0_t sid)
|
2018-01-08 09:34:51 +00:00
|
|
|
{
|
2018-01-17 11:31:49 +00:00
|
|
|
struct rx_sess_state *rx_sess_data = NULL;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(gx);
|
|
|
|
ogs_assert(sid);
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
ogs_list_for_each(&gx->rx_list, rx_sess_data) {
|
2018-01-17 11:31:49 +00:00
|
|
|
if (!strcmp((char *)rx_sess_data->sid, (char *)sid))
|
|
|
|
return rx_sess_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2018-01-17 11:31:49 +00:00
|
|
|
static void state_cleanup(struct sess_state *sess_data, os0_t sid, void *opaque)
|
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(sess_data);
|
2018-01-08 12:20:19 +00:00
|
|
|
|
2018-01-14 04:00:41 +00:00
|
|
|
if (sess_data->peer_host)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->peer_host);
|
2018-01-14 04:00:41 +00:00
|
|
|
|
|
|
|
if (sess_data->imsi_bcd)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->imsi_bcd);
|
2018-01-14 04:00:41 +00:00
|
|
|
if (sess_data->apn)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->apn);
|
2018-01-14 04:00:41 +00:00
|
|
|
|
2018-01-08 13:42:44 +00:00
|
|
|
if (sess_data->ipv4)
|
|
|
|
pcrf_sess_set_ipv4(&sess_data->addr, NULL);
|
|
|
|
if (sess_data->ipv6)
|
|
|
|
pcrf_sess_set_ipv6(sess_data->addr6, NULL);
|
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
if (sess_data->sid)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->sid);
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2018-01-17 11:31:49 +00:00
|
|
|
remove_rx_state_all(sess_data);
|
|
|
|
|
2020-04-27 17:08:24 +00:00
|
|
|
ogs_thread_mutex_lock(&sess_state_mutex);
|
|
|
|
ogs_pool_free(&sess_state_pool, sess_data);
|
|
|
|
ogs_thread_mutex_unlock(&sess_state_mutex);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pcrf_gx_fb_cb(struct msg **msg, struct avp *avp,
|
|
|
|
struct session *sess, void *opaque, enum disp_action *act)
|
|
|
|
{
|
|
|
|
/* This CB should never be called */
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_warn("Unexpected message received!");
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
return ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcrf_gx_ccr_cb( struct msg **msg, struct avp *avp,
|
|
|
|
struct session *sess, void *opaque, enum disp_action *act)
|
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2018-01-14 09:15:38 +00:00
|
|
|
int ret = 0, i;
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2018-01-08 09:34:51 +00:00
|
|
|
struct msg *ans, *qry;
|
2018-01-14 09:15:38 +00:00
|
|
|
struct avp *avpch1, *avpch2;
|
2018-01-08 09:34:51 +00:00
|
|
|
struct avp_hdr *hdr;
|
|
|
|
union avp_value val;
|
|
|
|
struct sess_state *sess_data = NULL;
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_gx_message_t gx_message;
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
uint32_t cc_request_type = OGS_DIAM_GX_CC_REQUEST_TYPE_INITIAL_REQUEST;
|
2019-04-27 14:54:30 +00:00
|
|
|
uint32_t cc_request_number = 0;
|
2019-09-13 12:07:47 +00:00
|
|
|
uint32_t result_code = OGS_DIAM_MISSING_AVP;
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_debug("[Credit-Control-Request]");
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(msg);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-06-14 07:55:16 +00:00
|
|
|
/* Initialize Message */
|
2019-09-13 12:07:47 +00:00
|
|
|
memset(&gx_message, 0, sizeof(ogs_diam_gx_message_t));
|
2019-06-14 07:55:16 +00:00
|
|
|
|
|
|
|
/* Create answer header */
|
|
|
|
qry = *msg;
|
|
|
|
ret = fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ans = *msg;
|
|
|
|
|
|
|
|
/* Set the Auth-Application-Id AVP */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_auth_application_id, 0, &avp);
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
val.i32 = OGS_DIAM_GX_APPLICATION_ID;
|
2019-06-14 07:55:16 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
|
|
|
|
/* Get CC-Request-Type */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_gx_cc_request_type, &avp);
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
if (avp) {
|
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
cc_request_type = hdr->avp_value->i32;
|
|
|
|
} else {
|
|
|
|
ogs_error("no_CC-Request-Type ");
|
|
|
|
ogs_assert_if_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get CC-Request-Number */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_gx_cc_request_number, &avp);
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
if (avp) {
|
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
cc_request_number = hdr->avp_value->i32;
|
|
|
|
} else {
|
|
|
|
ogs_error("no_CC-Request-Number");
|
|
|
|
ogs_assert_if_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
ogs_debug(" CC-Request-Type[%d] Number[%d]",
|
|
|
|
cc_request_type, cc_request_number);
|
|
|
|
|
|
|
|
/* Set CC-Request-Type */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_cc_request_type, 0, &avp);
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.i32 = cc_request_type;
|
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
|
|
|
|
/* Set CC-Request-Number */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_cc_request_number, 0, &avp);
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.i32 = cc_request_number;
|
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
|
|
|
|
/* Find Session */
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_sess_state_retrieve(pcrf_gx_reg, sess, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2019-06-14 07:55:16 +00:00
|
|
|
/* Check Session */
|
|
|
|
if (!sess_data &&
|
2019-09-13 12:07:47 +00:00
|
|
|
(cc_request_type == OGS_DIAM_GX_CC_REQUEST_TYPE_UPDATE_REQUEST ||
|
2020-08-29 14:53:02 +00:00
|
|
|
cc_request_type == OGS_DIAM_GX_CC_REQUEST_TYPE_TERMINATION_REQUEST)) {
|
2019-06-14 08:04:04 +00:00
|
|
|
ogs_error("No Session for CC-Request-Type: [%d]", cc_request_type);
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_UNKNOWN_SESSION_ID;
|
2019-06-14 08:04:04 +00:00
|
|
|
goto out;
|
2019-06-14 07:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (!sess_data) {
|
2018-01-08 12:20:19 +00:00
|
|
|
os0_t sid;
|
|
|
|
size_t sidlen;
|
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_sess_getsid(sess, &sid, &sidlen);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 12:20:19 +00:00
|
|
|
|
|
|
|
sess_data = new_state(sid);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(sess_data);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 07:06:19 +00:00
|
|
|
/* Get Origin-Host */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_origin_host, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
if (sess_data->peer_host)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->peer_host);
|
2018-01-10 07:06:19 +00:00
|
|
|
sess_data->peer_host =
|
2019-04-27 14:54:30 +00:00
|
|
|
(os0_t)ogs_strdup((char *)hdr->avp_value->os.data);
|
|
|
|
ogs_assert(sess_data->peer_host);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_CC-Request-Type ");
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_MISSING_AVP;
|
2018-01-10 07:06:19 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-01-08 13:42:44 +00:00
|
|
|
/* Get Framed-IP-Address */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_gx_framed_ip_address, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2018-01-08 13:42:44 +00:00
|
|
|
memcpy(&sess_data->addr, hdr->avp_value->os.data,
|
|
|
|
sizeof sess_data->addr);
|
2018-01-16 07:11:30 +00:00
|
|
|
pcrf_sess_set_ipv4(&sess_data->addr, sess_data->sid);
|
2018-01-08 13:42:44 +00:00
|
|
|
sess_data->ipv4 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Framed-IPv6-Prefix */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_gx_framed_ipv6_prefix, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_paa_t *paa = NULL;
|
2018-01-08 13:42:44 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
paa = (ogs_paa_t *)hdr->avp_value->os.data;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(paa);
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_assert(paa->len == OGS_IPV6_LEN * 8 /* 128bit */);
|
2018-01-08 13:42:44 +00:00
|
|
|
memcpy(sess_data->addr6, paa->addr6, sizeof sess_data->addr6);
|
2018-01-16 07:11:30 +00:00
|
|
|
pcrf_sess_set_ipv6(sess_data->addr6, sess_data->sid);
|
2018-01-08 13:42:44 +00:00
|
|
|
sess_data->ipv6 = 1;
|
|
|
|
}
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
/* Get IMSI + APN */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_gx_subscription_id, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-14 04:00:41 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_avp_search_avp(avp, ogs_diam_gx_subscription_id_type, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avpch1) {
|
2018-01-14 04:00:41 +00:00
|
|
|
ret = fd_msg_avp_hdr(avpch1, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2020-04-26 19:36:05 +00:00
|
|
|
if (hdr->avp_value->i32 !=
|
|
|
|
OGS_DIAM_GX_SUBSCRIPTION_ID_TYPE_END_USER_IMSI) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Not implemented Subscription-Id-Type(%d)",
|
2018-01-14 04:00:41 +00:00
|
|
|
hdr->avp_value->i32);
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_AVP_UNSUPPORTED;
|
2018-01-14 04:00:41 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_Subscription-Id-Type");
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_MISSING_AVP;
|
2018-01-14 04:00:41 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_avp_search_avp(avp, ogs_diam_gx_subscription_id_data, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avpch1) {
|
2018-01-14 04:00:41 +00:00
|
|
|
ret = fd_msg_avp_hdr(avpch1, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 04:00:41 +00:00
|
|
|
if (sess_data->imsi_bcd)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->imsi_bcd);
|
|
|
|
sess_data->imsi_bcd = ogs_strdup((char *)hdr->avp_value->os.data);
|
|
|
|
ogs_assert(sess_data->imsi_bcd);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_Subscription-Id-Data");
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_MISSING_AVP;
|
2018-01-14 04:00:41 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sess_data->imsi_bcd == NULL) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_Subscription-Id");
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_MISSING_AVP;
|
2018-01-08 09:34:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(qry, ogs_diam_gx_called_station_id, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-14 04:00:41 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 04:00:41 +00:00
|
|
|
if (sess_data->apn)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_free(sess_data->apn);
|
|
|
|
sess_data->apn = ogs_strdup((char *)hdr->avp_value->os.data);
|
|
|
|
ogs_assert(sess_data->apn);
|
2018-01-14 04:00:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sess_data->apn == NULL) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_Called-Station-Id");
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_MISSING_AVP;
|
2018-01-14 04:00:41 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-14 09:15:38 +00:00
|
|
|
/* Retrieve QoS Data from Database */
|
|
|
|
rv = pcrf_db_qos_data(sess_data->imsi_bcd, sess_data->apn, &gx_message);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cannot get data for IMSI(%s)+APN(%s)'",
|
2018-01-14 04:00:41 +00:00
|
|
|
sess_data->imsi_bcd, sess_data->apn);
|
2019-09-13 12:07:47 +00:00
|
|
|
result_code = OGS_DIAM_UNKNOWN_SESSION_ID;
|
2018-01-08 09:34:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
if (cc_request_type == OGS_DIAM_GX_CC_REQUEST_TYPE_INITIAL_REQUEST ||
|
|
|
|
cc_request_type == OGS_DIAM_GX_CC_REQUEST_TYPE_UPDATE_REQUEST) {
|
2018-01-17 12:22:30 +00:00
|
|
|
int charging_rule = 0;
|
2018-01-14 12:31:16 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < gx_message.num_of_pcc_rule; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_pcc_rule_t *pcc_rule = &gx_message.pcc_rule[i];
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->num_of_flow) {
|
|
|
|
if (charging_rule == 0) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_charging_rule_install, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 12:31:16 +00:00
|
|
|
|
2018-01-17 12:22:30 +00:00
|
|
|
charging_rule = 1;
|
2018-01-14 12:31:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
rv = encode_pcc_rule_definition(avp, pcc_rule, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rv == OGS_OK);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
2018-01-10 03:45:58 +00:00
|
|
|
}
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (charging_rule) {
|
2018-01-14 12:31:16 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 12:31:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 09:34:51 +00:00
|
|
|
/* Set QoS-Information */
|
2019-06-11 14:16:54 +00:00
|
|
|
if (gx_message.pdn.ambr.downlink || gx_message.pdn.ambr.uplink) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_qos_information, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (gx_message.pdn.ambr.uplink) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_apn_aggregate_max_bitrate_ul, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 13:09:08 +00:00
|
|
|
val.u32 = gx_message.pdn.ambr.uplink;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch1, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (gx_message.pdn.ambr.downlink) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_apn_aggregate_max_bitrate_dl, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 13:09:08 +00:00
|
|
|
val.u32 = gx_message.pdn.ambr.downlink;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch1, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Default-EPS-Bearer-QoS */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_default_eps_bearer_qos, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_qos_class_identifier, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 13:09:08 +00:00
|
|
|
val.u32 = gx_message.pdn.qos.qci;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch1, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_allocation_retention_priority, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_priority_level, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 13:09:08 +00:00
|
|
|
val.u32 = gx_message.pdn.qos.arp.priority_level;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch2, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_pre_emption_capability, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 13:09:08 +00:00
|
|
|
val.u32 = gx_message.pdn.qos.arp.pre_emption_capability;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch2, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_pre_emption_vulnerability, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 13:09:08 +00:00
|
|
|
val.u32 = gx_message.pdn.qos.arp.pre_emption_vulnerability;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch2, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
/* Set Supported Features */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_supported_features, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_feature_list_id, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
val.i32 = 1;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch1, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_feature_list, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
val.u32 = 0x0000000b;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue (avpch1, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2020-04-26 19:36:05 +00:00
|
|
|
} else if (cc_request_type ==
|
|
|
|
OGS_DIAM_GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) {
|
2018-01-17 12:22:30 +00:00
|
|
|
struct rx_sess_state *rx_sess_data = NULL, *next_rx_sess_data = NULL;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_list_for_each_safe(&sess_data->rx_list,
|
2019-06-11 14:16:54 +00:00
|
|
|
next_rx_sess_data, rx_sess_data) {
|
2018-01-17 12:22:30 +00:00
|
|
|
rv = pcrf_rx_send_asr(
|
2019-09-13 12:07:47 +00:00
|
|
|
rx_sess_data->sid, OGS_DIAM_RX_ABORT_CAUSE_BEARER_RELEASED);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rv == OGS_OK);
|
2018-01-17 12:22:30 +00:00
|
|
|
|
|
|
|
remove_rx_state(rx_sess_data);
|
|
|
|
}
|
|
|
|
}
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
|
2019-10-27 08:41:14 +00:00
|
|
|
ret = fd_msg_rescode_set(ans, (char *)"DIAMETER_SUCCESS", NULL, NULL, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
if (cc_request_type != OGS_DIAM_GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) {
|
2018-01-08 11:09:13 +00:00
|
|
|
/* Store this value in the session */
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_sess_state_store(pcrf_gx_reg, sess, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_assert(sess_data == NULL);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2018-01-08 12:20:19 +00:00
|
|
|
state_cleanup(sess_data, NULL, NULL);
|
2018-01-08 11:09:13 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 09:34:51 +00:00
|
|
|
/* Send the answer */
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_send(msg, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-06-14 07:55:16 +00:00
|
|
|
ogs_debug("[Credit-Control-Answer]");
|
2018-01-22 15:00:57 +00:00
|
|
|
|
2018-01-08 09:34:51 +00:00
|
|
|
/* Add this value to the stats */
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0);
|
|
|
|
ogs_diam_logger_self()->stats.nb_echoed++;
|
|
|
|
ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) ==0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_gx_message_free(&gx_message);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
2018-01-10 03:45:58 +00:00
|
|
|
/* Set the Result-Code */
|
2019-09-13 12:07:47 +00:00
|
|
|
if (result_code == OGS_DIAM_AVP_UNSUPPORTED) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_rescode_set(ans,
|
2019-10-27 08:41:14 +00:00
|
|
|
(char *)"DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
} else if (result_code == OGS_DIAM_UNKNOWN_SESSION_ID) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_rescode_set(ans,
|
2019-10-27 08:41:14 +00:00
|
|
|
(char *)"DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
} else if (result_code == OGS_DIAM_MISSING_AVP) {
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_rescode_set(ans,
|
2019-10-27 08:41:14 +00:00
|
|
|
(char *)"DIAMETER_MISSING_AVP", NULL, NULL, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = ogs_diam_message_experimental_rescode_set(ans, result_code);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 08:04:04 +00:00
|
|
|
if (sess_data) {
|
2020-04-26 19:36:05 +00:00
|
|
|
if (cc_request_type !=
|
|
|
|
OGS_DIAM_GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) {
|
2019-06-14 08:04:04 +00:00
|
|
|
/* Store this value in the session */
|
|
|
|
ret = fd_sess_state_store(pcrf_gx_reg, sess, &sess_data);
|
|
|
|
ogs_assert(sess_data == NULL);
|
|
|
|
} else {
|
|
|
|
state_cleanup(sess_data, NULL, NULL);
|
|
|
|
}
|
2018-01-10 03:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = fd_msg_send(msg, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_gx_message_free(&gx_message);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_gx_send_rar(
|
2019-09-13 12:07:47 +00:00
|
|
|
uint8_t *gx_sid, uint8_t *rx_sid, ogs_diam_rx_message_t *rx_message)
|
2018-01-08 09:34:51 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2018-01-18 16:23:13 +00:00
|
|
|
int ret = 0, i, j;
|
|
|
|
int count = 0;
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
struct msg *req = NULL;
|
2018-01-16 07:11:30 +00:00
|
|
|
struct avp *avp, *avpch1;
|
2018-01-10 03:45:58 +00:00
|
|
|
union avp_value val;
|
|
|
|
struct sess_state *sess_data = NULL, *svg;
|
2018-01-16 07:11:30 +00:00
|
|
|
struct rx_sess_state *rx_sess_data = NULL;
|
2018-01-10 03:45:58 +00:00
|
|
|
struct session *session = NULL;
|
|
|
|
int new;
|
|
|
|
size_t sidlen;
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_gx_message_t gx_message;
|
2018-01-17 03:41:57 +00:00
|
|
|
int charging_rule = 0;
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(gx_sid);
|
|
|
|
ogs_assert(rx_sid);
|
|
|
|
ogs_assert(rx_message);
|
2018-01-14 04:51:35 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug("[PCRF] Re-Auth-Request");
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2018-01-14 09:15:38 +00:00
|
|
|
/* Initialize Message */
|
2019-09-13 12:07:47 +00:00
|
|
|
memset(&gx_message, 0, sizeof(ogs_diam_gx_message_t));
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2018-01-14 04:51:35 +00:00
|
|
|
/* Set default error result code */
|
2019-09-13 12:07:47 +00:00
|
|
|
rx_message->result_code = OGS_DIAM_UNKNOWN_SESSION_ID;
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Create the request */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_new(ogs_diam_gx_cmd_rar, MSGFL_ALLOC_ETEID, &req);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
{
|
|
|
|
struct msg_hdr * h;
|
|
|
|
ret = fd_msg_hdr( req, &h );
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
h->msg_appl = OGS_DIAM_GX_APPLICATION_ID;
|
2018-01-10 07:06:19 +00:00
|
|
|
}
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Retrieve session by Session-Id */
|
|
|
|
sidlen = strlen((char *)gx_sid);
|
|
|
|
ret = fd_sess_fromsid_msg((os0_t)gx_sid, sidlen, &session, &new);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (new) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("No session data");
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_free(req);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
rx_message->result_code = OGS_DIAM_UNKNOWN_PEER;
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2018-01-10 07:06:19 +00:00
|
|
|
}
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Add Session-Id to the message */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = ogs_diam_message_session_id_set(req, (os0_t)gx_sid, sidlen);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Save the session associated with the message */
|
|
|
|
ret = fd_msg_sess_set(req, session);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Retrieve session state in this session */
|
|
|
|
ret = fd_sess_state_retrieve(pcrf_gx_reg, session, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sess_data == NULL) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("No session data");
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_free(req);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
rx_message->result_code = OGS_DIAM_UNKNOWN_SESSION_ID;
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2018-01-10 03:45:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
/* Find RX session state */
|
2018-01-17 11:31:49 +00:00
|
|
|
rx_sess_data = find_rx_state(sess_data, rx_sid);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (rx_message->cmd_code == OGS_DIAM_RX_CMD_CODE_AA) {
|
2019-06-11 14:16:54 +00:00
|
|
|
if (!rx_sess_data) {
|
2018-01-17 11:31:49 +00:00
|
|
|
rx_sess_data = add_rx_state(sess_data, rx_sid);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rx_sess_data);
|
2018-01-14 10:54:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
/* Retrieve QoS Data from Database */
|
|
|
|
rv = pcrf_db_qos_data(sess_data->imsi_bcd, sess_data->apn, &gx_message);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cannot get data for IMSI(%s)+APN(%s)'",
|
2018-01-16 07:11:30 +00:00
|
|
|
sess_data->imsi_bcd, sess_data->apn);
|
|
|
|
rx_message->result_code =
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_DIAM_RX_DIAMETER_IP_CAN_SESSION_NOT_AVAILABLE;
|
2018-01-14 10:54:50 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
/* Match Media-Component with PCC Rule */
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < rx_message->num_of_media_component; i++) {
|
2018-01-18 16:23:13 +00:00
|
|
|
int flow_presence = 0;
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_pcc_rule_t *pcc_rule = NULL;
|
|
|
|
ogs_pcc_rule_t *db_pcc_rule = NULL;
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t qci = 0;
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_rx_media_component_t *media_component =
|
2018-01-16 07:11:30 +00:00
|
|
|
&rx_message->media_component[i];
|
2018-01-14 10:54:50 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (media_component->media_component_number == 0) {
|
2018-01-17 03:41:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
switch(media_component->media_type) {
|
2019-09-13 12:07:47 +00:00
|
|
|
case OGS_DIAM_RX_MEDIA_TYPE_AUDIO:
|
|
|
|
qci = OGS_PDN_QCI_1;
|
2019-06-11 14:16:54 +00:00
|
|
|
break;
|
2020-01-28 15:59:50 +00:00
|
|
|
case OGS_DIAM_RX_MEDIA_TYPE_VIDEO:
|
|
|
|
qci = OGS_PDN_QCI_2;
|
|
|
|
break;
|
2019-12-17 08:57:44 +00:00
|
|
|
case OGS_DIAM_RX_MEDIA_TYPE_CONTROL:
|
|
|
|
qci = OGS_PDN_QCI_5;
|
|
|
|
break;
|
2019-06-11 14:16:54 +00:00
|
|
|
default:
|
|
|
|
ogs_error("Not implemented : [Media-Type:%d]",
|
|
|
|
media_component->media_type);
|
2019-09-13 12:07:47 +00:00
|
|
|
rx_message->result_code = OGS_DIAM_INVALID_AVP_VALUE;
|
2019-06-11 14:16:54 +00:00
|
|
|
goto out;
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (j = 0; j < gx_message.num_of_pcc_rule; j++) {
|
|
|
|
if (gx_message.pcc_rule[j].qos.qci == qci) {
|
2018-01-18 16:23:13 +00:00
|
|
|
db_pcc_rule = &gx_message.pcc_rule[j];
|
2018-01-16 07:11:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-01-14 10:54:50 +00:00
|
|
|
}
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2020-01-11 16:08:29 +00:00
|
|
|
if (!db_pcc_rule && (media_component->media_type
|
|
|
|
== OGS_DIAM_RX_MEDIA_TYPE_CONTROL)) {
|
|
|
|
/*
|
|
|
|
* Check for default bearer for IMS signalling
|
|
|
|
* QCI 5 and ARP 1
|
|
|
|
*/
|
|
|
|
if (gx_message.pdn.qos.qci != OGS_PDN_QCI_5 ||
|
|
|
|
gx_message.pdn.qos.arp.priority_level != 1) {
|
|
|
|
ogs_error("CHECK WEBUI : No APN in DB with [QCI:%d]", qci);
|
|
|
|
ogs_error("Please add APN using WEBUI");
|
|
|
|
rx_message->result_code =
|
|
|
|
OGS_DIAM_RX_DIAMETER_REQUESTED_SERVICE_NOT_AUTHORIZED;
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (!db_pcc_rule) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("CHECK WEBUI : No PCC Rule in DB [QCI:%d]", qci);
|
|
|
|
ogs_error("Please add PCC Rule using WEBUI");
|
2018-01-16 07:11:30 +00:00
|
|
|
rx_message->result_code =
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_DIAM_RX_DIAMETER_REQUESTED_SERVICE_NOT_AUTHORIZED;
|
2018-01-16 07:11:30 +00:00
|
|
|
goto out;
|
2018-01-14 10:54:50 +00:00
|
|
|
}
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (j = 0; j < rx_sess_data->num_of_pcc_rule; j++) {
|
|
|
|
if (rx_sess_data->pcc_rule[j].qos.qci == qci) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule = &rx_sess_data->pcc_rule[j];
|
|
|
|
break;
|
2018-01-17 03:41:57 +00:00
|
|
|
}
|
2018-01-14 10:54:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (!pcc_rule) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule =
|
|
|
|
&rx_sess_data->pcc_rule[rx_sess_data->num_of_pcc_rule];
|
2018-01-17 04:49:08 +00:00
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
/* Device PCC Rule Info from DB Profile */
|
2019-04-27 14:54:30 +00:00
|
|
|
pcc_rule->name = ogs_strdup(db_pcc_rule->name);
|
|
|
|
ogs_assert(pcc_rule->name);
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
memcpy(&pcc_rule->qos, &db_pcc_rule->qos, sizeof(ogs_qos_t));
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->flow_status = db_pcc_rule->flow_status;
|
|
|
|
pcc_rule->precedence = db_pcc_rule->precedence;
|
|
|
|
|
|
|
|
/* Install Flow */
|
|
|
|
flow_presence = 1;
|
|
|
|
rv = install_flow(pcc_rule, media_component);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-12-29 03:36:59 +00:00
|
|
|
rx_message->result_code =
|
|
|
|
OGS_DIAM_RX_DIAMETER_FILTER_RESTRICTIONS;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("install_flow() failed");
|
2018-01-18 16:23:13 +00:00
|
|
|
goto out;
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
2018-01-17 03:41:57 +00:00
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
rx_sess_data->num_of_pcc_rule++;
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(strcmp(pcc_rule->name, db_pcc_rule->name) == 0);
|
2018-01-17 03:41:57 +00:00
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
/* Check Flow */
|
|
|
|
count = matched_flow(pcc_rule, media_component);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (count == -1) {
|
2019-12-29 03:36:59 +00:00
|
|
|
rx_message->result_code =
|
|
|
|
OGS_DIAM_RX_DIAMETER_FILTER_RESTRICTIONS;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("matched_flow() failed");
|
2018-01-18 16:23:13 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2018-01-17 03:41:57 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->num_of_flow != count) {
|
2018-01-18 16:23:13 +00:00
|
|
|
/* Re-install Flow */
|
|
|
|
flow_presence = 1;
|
|
|
|
rv = install_flow(pcc_rule, media_component);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2018-01-18 16:23:13 +00:00
|
|
|
rx_message->result_code =
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_DIAM_RX_DIAMETER_FILTER_RESTRICTIONS;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("install_flow() failed");
|
2018-01-17 03:41:57 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
/* Update QoS */
|
|
|
|
rv = update_qos(pcc_rule, media_component);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2018-01-18 16:23:13 +00:00
|
|
|
rx_message->result_code =
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_DIAM_RX_DIAMETER_REQUESTED_SERVICE_NOT_AUTHORIZED;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("update_qos() failed");
|
2018-01-18 16:23:13 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we failed to get QoS from IMS, apply WEBUI QoS */
|
|
|
|
if (pcc_rule->qos.mbr.downlink == 0)
|
|
|
|
pcc_rule->qos.mbr.downlink = db_pcc_rule->qos.mbr.downlink;
|
|
|
|
if (pcc_rule->qos.mbr.uplink == 0)
|
|
|
|
pcc_rule->qos.mbr.uplink = db_pcc_rule->qos.mbr.uplink;
|
|
|
|
if (pcc_rule->qos.gbr.downlink == 0)
|
|
|
|
pcc_rule->qos.gbr.downlink = db_pcc_rule->qos.gbr.downlink;
|
|
|
|
if (pcc_rule->qos.gbr.uplink == 0)
|
|
|
|
pcc_rule->qos.gbr.uplink = db_pcc_rule->qos.gbr.uplink;
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (charging_rule == 0) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_charging_rule_install, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-17 03:41:57 +00:00
|
|
|
charging_rule = 1;
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
2018-01-14 10:54:50 +00:00
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
rv = encode_pcc_rule_definition(avp, pcc_rule, flow_presence);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rv == OGS_OK);
|
2018-01-14 10:54:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (charging_rule == 1) {
|
2018-01-16 07:11:30 +00:00
|
|
|
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 12:31:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 19:36:05 +00:00
|
|
|
} else if (rx_message->cmd_code ==
|
|
|
|
OGS_DIAM_RX_CMD_CODE_SESSION_TERMINATION) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rx_sess_data);
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < rx_sess_data->num_of_pcc_rule; i++) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rx_sess_data->pcc_rule[i].name);
|
2018-01-16 07:11:30 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (charging_rule == 0) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_charging_rule_remove, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-17 03:41:57 +00:00
|
|
|
charging_rule = 1;
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_charging_rule_name, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.os.data = (uint8_t *)rx_sess_data->pcc_rule[i].name;
|
2018-01-18 16:23:13 +00:00
|
|
|
val.os.len = strlen(rx_sess_data->pcc_rule[i].name);
|
2018-01-16 07:11:30 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avpch1, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-16 07:11:30 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (charging_rule == 1) {
|
2018-01-16 07:11:30 +00:00
|
|
|
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-16 07:11:30 +00:00
|
|
|
}
|
2018-01-17 11:31:49 +00:00
|
|
|
|
|
|
|
remove_rx_state(rx_sess_data);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert_if_reached();
|
2018-01-14 04:51:35 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (charging_rule == 0) {
|
2018-01-17 03:41:57 +00:00
|
|
|
rx_message->result_code = ER_DIAMETER_SUCCESS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
/* Set Origin-Host & Origin-Realm */
|
|
|
|
ret = fd_msg_add_origin(req, 0);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Set the Destination-Realm AVP */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_destination_realm, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
val.os.data = (unsigned char *)(fd_g_config->cnf_diamrlm);
|
|
|
|
val.os.len = strlen(fd_g_config->cnf_diamrlm);
|
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2018-01-10 07:06:19 +00:00
|
|
|
/* Set the Destination-Host AVP */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_destination_host, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
val.os.data = sess_data->peer_host;
|
|
|
|
val.os.len = strlen((char *)sess_data->peer_host);
|
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
/* Set the Auth-Application-Id AVP */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_auth_application_id, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
val.i32 = OGS_DIAM_GX_APPLICATION_ID;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2018-01-10 07:06:19 +00:00
|
|
|
/* Set the Re-Auth-Request-Type */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_re_auth_request_type, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
val.i32 = OGS_DIAM_RE_AUTH_REQUEST_TYPE_AUTHORIZE_ONLY;
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = clock_gettime(CLOCK_REALTIME, &sess_data->ts);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Keep a pointer to the session data for debug purpose,
|
|
|
|
* in real life we would not need it */
|
|
|
|
svg = sess_data;
|
|
|
|
|
|
|
|
/* Store this value in the session */
|
|
|
|
ret = fd_sess_state_store(pcrf_gx_reg, session, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_assert(sess_data == NULL);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Send the request */
|
|
|
|
ret = fd_msg_send(&req, pcrf_gx_raa_cb, svg);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
|
|
|
/* Increment the counter */
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0);
|
|
|
|
ogs_diam_logger_self()->stats.nb_sent++;
|
|
|
|
ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2018-01-14 04:51:35 +00:00
|
|
|
/* Set no error */
|
|
|
|
rx_message->result_code = ER_DIAMETER_SUCCESS;
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_gx_message_free(&gx_message);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-14 09:15:38 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
/* Store this value in the session */
|
|
|
|
ret = fd_sess_state_store(pcrf_gx_reg, session, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(sess_data == NULL);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_gx_message_free(&gx_message);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2018-01-10 03:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pcrf_gx_raa_cb(void *data, struct msg **msg)
|
|
|
|
{
|
2018-01-10 07:06:19 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
struct sess_state *sess_data = NULL;
|
|
|
|
struct timespec ts;
|
|
|
|
struct session *session;
|
|
|
|
struct avp *avp, *avpch1;
|
|
|
|
struct avp_hdr *hdr;
|
|
|
|
unsigned long dur;
|
|
|
|
int error = 0;
|
|
|
|
int new;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
uint32_t result_code;
|
2018-01-10 07:06:19 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug("[PCRF] Re-Auth-Answer");
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = clock_gettime(CLOCK_REALTIME, &ts);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
/* Search the session, retrieve its data */
|
|
|
|
ret = fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &session, &new);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_assert(new == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
ret = fd_sess_state_retrieve(pcrf_gx_reg, session, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:20:49 +00:00
|
|
|
ogs_assert(sess_data);
|
|
|
|
ogs_assert((void *)sess_data == data);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
/* Value of Result Code */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(*msg, ogs_diam_result_code, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
result_code = hdr->avp_value->i32;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug(" Result Code: %d", hdr->avp_value->i32);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(*msg, ogs_diam_experimental_result, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_avp_search_avp(
|
|
|
|
avp, ogs_diam_experimental_result_code, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avpch1) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_hdr(avpch1, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
result_code = hdr->avp_value->i32;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug(" Experimental Result Code: %d", result_code);
|
2018-01-10 07:06:19 +00:00
|
|
|
}
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no Result-Code");
|
2018-01-10 07:06:19 +00:00
|
|
|
error++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Value of Origin-Host */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(*msg, ogs_diam_origin_host, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_debug(" From '%.*s'",
|
2018-01-10 07:06:19 +00:00
|
|
|
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_Origin-Host");
|
2018-01-10 07:06:19 +00:00
|
|
|
error++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Value of Origin-Realm */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_search_avp(*msg, ogs_diam_origin_realm, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-10 07:06:19 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_debug(" ('%.*s')",
|
2018-01-10 07:06:19 +00:00
|
|
|
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("no_Origin-Realm");
|
2018-01-10 07:06:19 +00:00
|
|
|
error++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the message */
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
dur = ((ts.tv_sec - sess_data->ts.tv_sec) * 1000000) +
|
|
|
|
((ts.tv_nsec - sess_data->ts.tv_nsec) / 1000);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (ogs_diam_logger_self()->stats.nb_recv) {
|
2018-01-10 07:06:19 +00:00
|
|
|
/* Ponderate in the avg */
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_logger_self()->stats.avg = (ogs_diam_logger_self()->stats.avg *
|
|
|
|
ogs_diam_logger_self()->stats.nb_recv + dur) /
|
|
|
|
(ogs_diam_logger_self()->stats.nb_recv + 1);
|
2018-01-10 07:06:19 +00:00
|
|
|
/* Min, max */
|
2019-09-13 12:07:47 +00:00
|
|
|
if (dur < ogs_diam_logger_self()->stats.shortest)
|
|
|
|
ogs_diam_logger_self()->stats.shortest = dur;
|
|
|
|
if (dur > ogs_diam_logger_self()->stats.longest)
|
|
|
|
ogs_diam_logger_self()->stats.longest = dur;
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_logger_self()->stats.shortest = dur;
|
|
|
|
ogs_diam_logger_self()->stats.longest = dur;
|
|
|
|
ogs_diam_logger_self()->stats.avg = dur;
|
2018-01-10 07:06:19 +00:00
|
|
|
}
|
|
|
|
if (error)
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_logger_self()->stats.nb_errs++;
|
2018-01-10 07:06:19 +00:00
|
|
|
else
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_logger_self()->stats.nb_recv++;
|
2018-01-10 07:06:19 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
/* Display how long it took */
|
|
|
|
if (ts.tv_nsec > sess_data->ts.tv_nsec)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_trace("in %d.%06ld sec",
|
2018-01-10 07:06:19 +00:00
|
|
|
(int)(ts.tv_sec - sess_data->ts.tv_sec),
|
|
|
|
(long)(ts.tv_nsec - sess_data->ts.tv_nsec) / 1000);
|
|
|
|
else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_trace("in %d.%06ld sec",
|
2018-01-10 07:06:19 +00:00
|
|
|
(int)(ts.tv_sec + 1 - sess_data->ts.tv_sec),
|
|
|
|
(long)(1000000000 + ts.tv_nsec - sess_data->ts.tv_nsec) / 1000);
|
|
|
|
|
|
|
|
ret = fd_sess_state_store(pcrf_gx_reg, session, &sess_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_assert(sess_data == NULL);
|
2018-01-10 07:06:19 +00:00
|
|
|
|
|
|
|
ret = fd_msg_free(*msg);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 07:06:19 +00:00
|
|
|
*msg = NULL;
|
|
|
|
|
|
|
|
return;
|
2018-01-10 03:45:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pcrf_gx_init(void)
|
2018-01-10 03:45:58 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2018-01-08 09:34:51 +00:00
|
|
|
struct disp_when data;
|
|
|
|
|
2020-04-27 17:08:24 +00:00
|
|
|
ogs_thread_mutex_init(&sess_state_mutex);
|
2020-08-26 03:05:01 +00:00
|
|
|
ogs_pool_init(&sess_state_pool, ogs_app()->pool.sess);
|
|
|
|
ogs_pool_init(&rx_sess_state_pool, ogs_app()->pool.sess);
|
2020-04-27 17:08:24 +00:00
|
|
|
|
2018-01-08 11:09:13 +00:00
|
|
|
/* Install objects definitions for this application */
|
2019-11-02 06:52:48 +00:00
|
|
|
ret = ogs_diam_gx_init();
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-08 11:09:13 +00:00
|
|
|
/* Create handler for sessions */
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_sess_handler_create(&pcrf_gx_reg, state_cleanup, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
2019-09-13 12:07:47 +00:00
|
|
|
data.app = ogs_diam_gx_application;
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_disp_register(pcrf_gx_fb_cb, DISP_HOW_APPID, &data, NULL,
|
|
|
|
&hdl_gx_fb);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
data.command = ogs_diam_gx_cmd_ccr;
|
2018-01-10 03:45:58 +00:00
|
|
|
ret = fd_disp_register(pcrf_gx_ccr_cb, DISP_HOW_CC, &data, NULL,
|
|
|
|
&hdl_gx_ccr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2018-01-08 11:09:13 +00:00
|
|
|
/* Advertise the support for the application in the peer */
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_disp_app_support(ogs_diam_gx_application, ogs_diam_vendor, 1, 0);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-08 09:34:51 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcrf_gx_final(void)
|
|
|
|
{
|
2018-01-10 03:45:58 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fd_sess_handler_destroy(&pcrf_gx_reg, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 03:45:58 +00:00
|
|
|
|
2018-01-08 09:34:51 +00:00
|
|
|
if (hdl_gx_fb)
|
|
|
|
(void) fd_disp_unregister(&hdl_gx_fb, NULL);
|
|
|
|
if (hdl_gx_ccr)
|
|
|
|
(void) fd_disp_unregister(&hdl_gx_ccr, NULL);
|
2020-04-27 17:08:24 +00:00
|
|
|
|
|
|
|
ogs_pool_final(&sess_state_pool);
|
|
|
|
ogs_pool_final(&rx_sess_state_pool);
|
|
|
|
ogs_thread_mutex_destroy(&sess_state_mutex);
|
2018-01-08 09:34:51 +00:00
|
|
|
}
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static int encode_pcc_rule_definition(
|
2019-09-13 12:07:47 +00:00
|
|
|
struct avp *avp, ogs_pcc_rule_t *pcc_rule, int flow_presence)
|
2018-01-14 09:15:38 +00:00
|
|
|
{
|
2018-01-14 12:31:16 +00:00
|
|
|
struct avp *avpch1, *avpch2, *avpch3, *avpch4;
|
2018-01-14 09:15:38 +00:00
|
|
|
union avp_value val;
|
|
|
|
int ret = 0, i;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(avp);
|
|
|
|
ogs_assert(pcc_rule);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_charging_rule_definition, 0, &avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_charging_rule_name, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.os.data = (uint8_t *)pcc_rule->name;
|
2018-01-14 09:15:38 +00:00
|
|
|
val.os.len = strlen(pcc_rule->name);
|
|
|
|
ret = fd_msg_avp_setvalue(avpch2, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (flow_presence == 1) {
|
|
|
|
for (i = 0; i < pcc_rule->num_of_flow; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_flow_t *flow = &pcc_rule->flow[i];
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_flow_information, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_flow_direction, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-18 16:23:13 +00:00
|
|
|
val.i32 = flow->direction;
|
|
|
|
ret = fd_msg_avp_setvalue(avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-18 16:23:13 +00:00
|
|
|
ret = fd_msg_avp_add(avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_flow_description, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.os.data = (uint8_t *)flow->description;
|
2018-01-18 16:23:13 +00:00
|
|
|
val.os.len = strlen(flow->description);
|
|
|
|
ret = fd_msg_avp_setvalue(avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-18 16:23:13 +00:00
|
|
|
ret = fd_msg_avp_add(avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2018-01-18 16:23:13 +00:00
|
|
|
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
2018-01-14 09:15:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_flow_status, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 10:54:50 +00:00
|
|
|
val.i32 = pcc_rule->flow_status;
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avpch2, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_qos_information, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_qos_class_identifier, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.qci;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_allocation_retention_priority, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_priority_level, 0, &avpch4);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.arp.priority_level;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch4, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch3, MSG_BRW_LAST_CHILD, avpch4);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_pre_emption_capability, 0, &avpch4);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.arp.pre_emption_capability;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch4, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch3, MSG_BRW_LAST_CHILD, avpch4);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_pre_emption_vulnerability, 0, &avpch4);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.arp.pre_emption_vulnerability;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch4, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch3, MSG_BRW_LAST_CHILD, avpch4);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
|
|
|
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->qos.mbr.uplink) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_max_requested_bandwidth_ul, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.mbr.uplink;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->qos.mbr.downlink) {
|
2020-04-26 19:36:05 +00:00
|
|
|
ret = fd_msg_avp_new(
|
|
|
|
ogs_diam_gx_max_requested_bandwidth_dl, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.mbr.downlink;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->qos.gbr.uplink) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_guaranteed_bitrate_ul, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.gbr.uplink;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->qos.gbr.downlink) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_guaranteed_bitrate_dl, 0, &avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->qos.gbr.downlink;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch3, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ret = fd_msg_avp_new(ogs_diam_gx_precedence, 0, &avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
val.u32 = pcc_rule->precedence;
|
|
|
|
ret = fd_msg_avp_setvalue (avpch2, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avpch1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-14 09:15:38 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-14 09:15:38 +00:00
|
|
|
}
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
static int flow_rx_to_gx(ogs_flow_t *rx_flow, ogs_flow_t *gx_flow)
|
2018-01-18 16:23:13 +00:00
|
|
|
{
|
|
|
|
int len;
|
2020-09-21 03:35:10 +00:00
|
|
|
char *from_str, *to_str;
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(rx_flow);
|
|
|
|
ogs_assert(gx_flow);
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
if (!strncmp(rx_flow->description,
|
2019-06-11 14:16:54 +00:00
|
|
|
"permit out", strlen("permit out"))) {
|
2019-09-13 12:07:47 +00:00
|
|
|
gx_flow->direction = OGS_FLOW_DOWNLINK_ONLY;
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
len = strlen(rx_flow->description)+1;
|
2019-04-27 14:54:30 +00:00
|
|
|
gx_flow->description = ogs_malloc(len);
|
|
|
|
ogs_cpystrn(gx_flow->description, rx_flow->description, len);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else if (!strncmp(rx_flow->description,
|
|
|
|
"permit in", strlen("permit in"))) {
|
2019-09-13 12:07:47 +00:00
|
|
|
gx_flow->direction = OGS_FLOW_UPLINK_ONLY;
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
/* 'permit in' should be changed
|
|
|
|
* 'permit out' in Gx Diameter */
|
|
|
|
len = strlen(rx_flow->description)+2;
|
2019-04-27 14:54:30 +00:00
|
|
|
gx_flow->description = ogs_malloc(len);
|
2018-01-18 16:23:13 +00:00
|
|
|
strcpy(gx_flow->description, "permit out");
|
2020-09-21 03:35:10 +00:00
|
|
|
from_str = strstr(&rx_flow->description[strlen("permit in")], "from");
|
|
|
|
ogs_assert(from_str);
|
|
|
|
to_str = strstr(&rx_flow->description[strlen("permit in")], "to");
|
|
|
|
ogs_assert(to_str);
|
|
|
|
strncat(gx_flow->description,
|
|
|
|
&rx_flow->description[strlen("permit in")],
|
|
|
|
strlen(rx_flow->description) -
|
|
|
|
strlen("permit in") - strlen(from_str));
|
|
|
|
strcat(gx_flow->description, "from");
|
|
|
|
strcat(gx_flow->description, &to_str[strlen("to")]);
|
|
|
|
strcat(gx_flow->description, " to");
|
|
|
|
strncat(gx_flow->description, &from_str[strlen("from")],
|
|
|
|
strlen(from_str) - strlen(to_str) - strlen("from") - 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(len == strlen(gx_flow->description)+1);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Invalid Flow Descripton : [%s]", rx_flow->description);
|
|
|
|
return OGS_ERROR;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 03:36:59 +00:00
|
|
|
static int matched_flow(ogs_pcc_rule_t *pcc_rule,
|
|
|
|
ogs_diam_rx_media_component_t *media_component)
|
2018-01-18 16:23:13 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2018-01-18 16:23:13 +00:00
|
|
|
int i, j, k;
|
|
|
|
int matched = 0;
|
|
|
|
int new = 0;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pcc_rule);
|
|
|
|
ogs_assert(media_component);
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < media_component->num_of_sub; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sub->flow_number == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (j = 0; j < sub->num_of_flow; j++) {
|
2018-01-18 16:23:13 +00:00
|
|
|
new++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (new == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
/* No new flow in Media-Component */
|
|
|
|
return pcc_rule->num_of_flow;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < media_component->num_of_sub; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sub->flow_number == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (j = 0; j < sub->num_of_flow; j++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_flow_t gx_flow;
|
|
|
|
ogs_flow_t *rx_flow = &sub->flow[j];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
rv = flow_rx_to_gx(rx_flow, &gx_flow);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("flow reformatting error");
|
|
|
|
return OGS_ERROR;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (k = 0; k < pcc_rule->num_of_flow; k++) {
|
2018-01-18 16:23:13 +00:00
|
|
|
if (gx_flow.direction == pcc_rule->flow[k].direction &&
|
2019-06-11 14:16:54 +00:00
|
|
|
!strcmp(gx_flow.description,
|
|
|
|
pcc_rule->flow[k].description)) {
|
2018-01-18 16:23:13 +00:00
|
|
|
matched++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_FLOW_FREE(&gx_flow);
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
|
2020-04-26 19:36:05 +00:00
|
|
|
static int install_flow(ogs_pcc_rule_t *pcc_rule,
|
|
|
|
ogs_diam_rx_media_component_t *media_component)
|
2018-01-18 16:23:13 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2018-01-18 16:23:13 +00:00
|
|
|
int i, j;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pcc_rule);
|
|
|
|
ogs_assert(media_component);
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
/* Remove Flow from PCC Rule */
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < pcc_rule->num_of_flow; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_FLOW_FREE(&pcc_rule->flow[i]);
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
pcc_rule->num_of_flow = 0;
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < media_component->num_of_sub; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sub->flow_number == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy Flow to PCC Rule */
|
2019-06-11 14:16:54 +00:00
|
|
|
for (j = 0; j < sub->num_of_flow; j++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_flow_t *rx_flow = &sub->flow[j];
|
|
|
|
ogs_flow_t *gx_flow = &pcc_rule->flow[pcc_rule->num_of_flow];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
rv = flow_rx_to_gx(rx_flow, gx_flow);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("flow reformatting error");
|
|
|
|
return OGS_ERROR;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pcc_rule->num_of_flow++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 19:36:05 +00:00
|
|
|
static int update_qos(ogs_pcc_rule_t *pcc_rule,
|
|
|
|
ogs_diam_rx_media_component_t *media_component)
|
2018-01-18 16:23:13 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2018-01-18 16:23:13 +00:00
|
|
|
int i, j;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pcc_rule);
|
|
|
|
ogs_assert(media_component);
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
pcc_rule->qos.mbr.downlink = 0;
|
|
|
|
pcc_rule->qos.mbr.uplink = 0;
|
|
|
|
pcc_rule->qos.gbr.downlink = 0;
|
|
|
|
pcc_rule->qos.gbr.uplink = 0;
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < media_component->num_of_sub; i++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (sub->flow_number == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (j = 0; j < sub->num_of_flow; j++) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_flow_t gx_flow;
|
|
|
|
ogs_flow_t *rx_flow = &sub->flow[j];
|
2018-01-18 16:23:13 +00:00
|
|
|
|
|
|
|
rv = flow_rx_to_gx(rx_flow, &gx_flow);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("flow reformatting error");
|
|
|
|
return OGS_ERROR;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
if (gx_flow.direction == OGS_FLOW_DOWNLINK_ONLY) {
|
|
|
|
if (sub->flow_usage == OGS_DIAM_RX_FLOW_USAGE_RTCP) {
|
2018-01-18 16:23:13 +00:00
|
|
|
if (media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.downlink +=
|
|
|
|
(media_component->rr_bandwidth +
|
|
|
|
media_component->rs_bandwidth);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else if (media_component->max_requested_bandwidth_dl) {
|
2018-01-18 16:23:13 +00:00
|
|
|
if (media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
!media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.downlink +=
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_max(0.05 *
|
2018-01-18 16:23:13 +00:00
|
|
|
media_component->max_requested_bandwidth_dl,
|
|
|
|
media_component->rr_bandwidth);
|
|
|
|
}
|
|
|
|
if (!media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.downlink +=
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_max(0.05 *
|
2018-01-18 16:23:13 +00:00
|
|
|
media_component->max_requested_bandwidth_dl,
|
|
|
|
media_component->rs_bandwidth);
|
|
|
|
}
|
|
|
|
if (!media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
!media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.downlink +=
|
|
|
|
0.05 *
|
|
|
|
media_component->max_requested_bandwidth_dl;
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
|
|
|
if (gx_flow.description) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.downlink +=
|
|
|
|
media_component->max_requested_bandwidth_dl;
|
|
|
|
pcc_rule->qos.gbr.downlink +=
|
|
|
|
media_component->min_requested_bandwidth_dl;
|
|
|
|
}
|
|
|
|
}
|
2019-09-13 12:07:47 +00:00
|
|
|
} else if (gx_flow.direction == OGS_FLOW_UPLINK_ONLY) {
|
|
|
|
if (sub->flow_usage == OGS_DIAM_RX_FLOW_USAGE_RTCP) {
|
2018-01-18 16:23:13 +00:00
|
|
|
if (media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.uplink +=
|
|
|
|
(media_component->rr_bandwidth +
|
|
|
|
media_component->rs_bandwidth);
|
2019-06-11 14:16:54 +00:00
|
|
|
} else if (media_component->max_requested_bandwidth_ul) {
|
2018-01-18 16:23:13 +00:00
|
|
|
if (media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
!media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.uplink +=
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_max(0.05 *
|
2018-01-18 16:23:13 +00:00
|
|
|
media_component->max_requested_bandwidth_ul,
|
|
|
|
media_component->rr_bandwidth);
|
|
|
|
}
|
|
|
|
if (!media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.uplink +=
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_max(0.05 *
|
2018-01-18 16:23:13 +00:00
|
|
|
media_component->max_requested_bandwidth_ul,
|
|
|
|
media_component->rs_bandwidth);
|
|
|
|
}
|
|
|
|
if (!media_component->rr_bandwidth &&
|
2019-06-11 14:16:54 +00:00
|
|
|
!media_component->rs_bandwidth) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.uplink +=
|
|
|
|
0.05 *
|
|
|
|
media_component->max_requested_bandwidth_ul;
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
|
|
|
if (gx_flow.description) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.uplink +=
|
|
|
|
media_component->max_requested_bandwidth_ul;
|
|
|
|
pcc_rule->qos.gbr.uplink +=
|
|
|
|
media_component->min_requested_bandwidth_ul;
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 14:16:54 +00:00
|
|
|
} else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert_if_reached();
|
2018-01-18 16:23:13 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_FLOW_FREE(&gx_flow);
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->qos.mbr.downlink == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.downlink +=
|
|
|
|
media_component->max_requested_bandwidth_dl;
|
|
|
|
pcc_rule->qos.mbr.downlink +=
|
|
|
|
(media_component->rr_bandwidth + media_component->rs_bandwidth);
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pcc_rule->qos.mbr.uplink == 0) {
|
2018-01-18 16:23:13 +00:00
|
|
|
pcc_rule->qos.mbr.uplink +=
|
|
|
|
media_component->max_requested_bandwidth_ul;
|
|
|
|
pcc_rule->qos.mbr.uplink +=
|
|
|
|
(media_component->rr_bandwidth + media_component->rs_bandwidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pcc_rule->qos.gbr.downlink == 0)
|
|
|
|
pcc_rule->qos.gbr.downlink = pcc_rule->qos.mbr.downlink;
|
|
|
|
if (pcc_rule->qos.gbr.uplink == 0)
|
|
|
|
pcc_rule->qos.gbr.uplink = pcc_rule->qos.mbr.uplink;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2018-01-18 16:23:13 +00:00
|
|
|
}
|