open5gs/tests/volte/pcscf-fd-path.c

941 lines
31 KiB
C
Raw Normal View History

2019-08-03 13:08:20 +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-gtp.h"
#include "ogs-diameter-rx.h"
2018-01-05 14:49:55 +00:00
2019-06-11 05:12:31 +00:00
#include "pcscf-fd-path.h"
2018-01-05 14:49:55 +00:00
#define MAX_NUM_SESSION_STATE 32
static struct session_handler *pcscf_rx_reg = NULL;
2018-01-17 12:22:30 +00:00
static struct disp_hdl *hdl_rx_fb = NULL;
static struct disp_hdl *hdl_rx_asr = NULL;
2019-09-13 12:07:47 +00:00
static ogs_diam_config_t diam_config;
2018-01-05 14:49:55 +00:00
struct sess_state {
2018-01-17 12:22:30 +00:00
os0_t sid; /* Rx Session-Id */
struct timespec ts; /* Time of sending the message */
2018-01-05 14:49:55 +00:00
};
static void pcscf_rx_aaa_cb(void *data, struct msg **msg);
2018-01-15 08:25:14 +00:00
static void pcscf_rx_sta_cb(void *data, struct msg **msg);
2018-01-05 14:49:55 +00:00
static __inline__ struct sess_state *new_state(os0_t sid)
{
struct sess_state *new = NULL;
2019-04-27 14:54:30 +00:00
new = ogs_calloc(1, sizeof(*new));
new->sid = (os0_t)ogs_strdup((char *)sid);
ogs_assert(new->sid);
return new;
}
2018-01-15 08:25:14 +00:00
static void state_cleanup(struct sess_state *sess_data, os0_t sid, void *opaque)
{
2018-01-17 12:22:30 +00:00
if (sess_data->sid)
2019-04-27 14:54:30 +00:00
ogs_free(sess_data->sid);
2019-04-27 14:54:30 +00:00
ogs_free(sess_data);
}
2018-01-17 12:22:30 +00:00
static int pcscf_rx_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-17 12:22:30 +00:00
return ENOTSUP;
}
2019-04-27 14:54:30 +00:00
void pcscf_rx_send_aar(uint8_t **rx_sid, const char *ip,
int qos_type, int flow_presence)
2018-01-05 14:49:55 +00:00
{
2019-04-27 14:54:30 +00:00
int rv;
2018-01-10 03:45:58 +00:00
int ret;
2018-01-05 14:49:55 +00:00
struct msg *req = NULL;
struct avp *avp;
struct avp *avpch1, *avpch2;
union avp_value val;
2018-01-10 03:45:58 +00:00
struct sess_state *sess_data = NULL, *svg;
2018-01-05 14:49:55 +00:00
struct session *session = NULL;
int new;
2018-01-05 14:49:55 +00:00
2019-09-13 12:07:47 +00:00
ogs_paa_t paa;
2019-04-27 14:54:30 +00:00
ogs_ipsubnet_t ipsub;
2019-04-27 14:54:30 +00:00
ogs_assert(rx_sid);
2019-04-27 14:54:30 +00:00
ogs_assert(ip);
rv = ogs_ipsubnet(&ipsub, ip, NULL);
ogs_assert(rv == OGS_OK);
2018-01-05 14:49:55 +00:00
/* Create the request */
2019-09-13 12:07:47 +00:00
ret = fd_msg_new(ogs_diam_rx_cmd_aar, MSGFL_ALLOC_ETEID, &req);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
{
struct msg_hdr * h;
2018-01-10 03:45:58 +00:00
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_RX_APPLICATION_ID;
2018-01-05 14:49:55 +00:00
}
/* Find Diameter Rx Session */
2019-08-03 13:08:20 +00:00
if (*rx_sid) {
/* Retrieve session by Session-Id */
2018-01-17 12:22:30 +00:00
size_t sidlen = strlen((char *)*rx_sid);
ret = fd_sess_fromsid_msg(*rx_sid, sidlen, &session, &new);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(new == 0);
/* Add Session-Id to the message */
2019-09-13 12:07:47 +00:00
ret = ogs_diam_message_session_id_set(req, *rx_sid, sidlen);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
/* Save the session associated with the message */
ret = fd_msg_sess_set(req, session);
2019-08-03 13:08:20 +00:00
} else {
/* Create a new session */
2019-09-13 12:07:47 +00:00
#define OGS_DIAM_RX_APP_SID_OPT "app_rx"
ret = fd_msg_new_session(req, (os0_t)OGS_DIAM_RX_APP_SID_OPT,
CONSTSTRLEN(OGS_DIAM_RX_APP_SID_OPT));
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_sess_get(fd_g_config->cnf_dict, req, &session, NULL);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
}
/* Retrieve session state in this session */
ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data);
2019-08-03 13:08:20 +00:00
if (!sess_data) {
os0_t sid;
size_t sidlen;
ret = fd_sess_getsid(session, &sid, &sidlen);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
/* Allocate new session state memory */
sess_data = new_state(sid);
2019-04-27 14:54:30 +00:00
ogs_assert(sess_data);
/* Save Session-Id to PGW Session Context */
2018-01-17 12:22:30 +00:00
*rx_sid = sess_data->sid;
}
2018-01-05 14:49:55 +00:00
/* Set Origin-Host & Origin-Realm */
2018-01-10 03:45:58 +00:00
ret = fd_msg_add_origin(req, 0);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +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-05 14:49:55 +00:00
val.os.data = (unsigned char *)(fd_g_config->cnf_diamrlm);
val.os.len = strlen(fd_g_config->cnf_diamrlm);
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-05 14:49:55 +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_RX_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-05 14:49:55 +00:00
/* Set Subscription-Id */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_subscription_id, 0, &avp);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_subscription_id_type, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
val.i32 = OGS_DIAM_RX_SUBSCRIPTION_ID_TYPE_END_USER_IMSI;
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-05 14:49:55 +00:00
2019-09-13 12:07:47 +00:00
#define OGS_DIAM_RX_APP_IMSI_BCD "001010123456789"
ret = fd_msg_avp_new(ogs_diam_rx_subscription_id_data, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
val.os.data = (uint8_t *)OGS_DIAM_RX_APP_IMSI_BCD;
val.os.len = strlen(OGS_DIAM_RX_APP_IMSI_BCD);
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-05 14:49:55 +00:00
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-05 14:49:55 +00:00
2019-08-03 13:08:20 +00:00
if (ipsub.family == AF_INET) {
/* Set Framed-IP-Address */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_framed_ip_address, 0, &avp);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.os.data = (uint8_t*)ipsub.sub;
2019-09-13 12:07:47 +00:00
val.os.len = OGS_IPV4_LEN;
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);
2019-08-03 13:08:20 +00:00
} else if (ipsub.family == AF_INET6) {
/* Set Framed-IPv6-Prefix */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_framed_ipv6_prefix, 0, &avp);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
memset(&paa, 0, sizeof(ogs_paa_t));
2019-09-13 12:07:47 +00:00
memcpy(paa.addr6, ipsub.sub, OGS_IPV6_LEN);
paa.pdn_type = 0x03;
#define FRAMED_IPV6_PREFIX_LENGTH 128 /* from spec document */
paa.len = FRAMED_IPV6_PREFIX_LENGTH;
2019-04-27 14:54:30 +00:00
val.os.data = (uint8_t*)&paa;
2019-09-13 12:07:47 +00:00
val.os.len = OGS_PAA_IPV6_LEN;
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-05 14:49:55 +00:00
2018-01-10 10:56:10 +00:00
/* Set Media-Component-Description */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_media_component_description, 0, &avp);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_media_component_number, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-10 13:09:08 +00:00
val.i32 = 1;
2018-01-10 10:56:10 +00:00
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-10 10:56:10 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_media_type, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
val.i32 = OGS_DIAM_RX_MEDIA_TYPE_AUDIO;
2018-01-10 10:56:10 +00:00
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-10 10:56:10 +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-10 10:56:10 +00:00
2019-08-03 13:08:20 +00:00
if (qos_type == 1) {
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_max_requested_bandwidth_dl, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +00:00
val.i32 = 96000;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_max_requested_bandwidth_ul, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 96000;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, 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_rx_rr_bandwidth, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 2400;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, 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_rx_rs_bandwidth, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 2400;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-08-03 13:08:20 +00:00
} else if (qos_type == 2) {
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_max_requested_bandwidth_dl, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 96000;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, 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_rx_max_requested_bandwidth_ul, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 96000;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, 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_rx_min_requested_bandwidth_dl, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 88000;
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, 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_rx_min_requested_bandwidth_ul, 0, &avpch1);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
val.i32 = 88000;
2018-01-17 04:49:08 +00:00
ret = fd_msg_avp_setvalue (avpch1, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-17 04:49:08 +00:00
}
2018-01-10 10:56:10 +00:00
2019-08-03 13:08:20 +00:00
if (flow_presence) {
2018-01-17 04:49:08 +00:00
/* Set Media-Sub-Component #1 */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_media_sub_component, 0, &avpch1);
2018-01-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_number, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +00:00
val.i32 = 1;
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
#define TEST_OGS_DIAM_RX_FLOW_DESC1 \
2018-01-17 04:49:08 +00:00
"permit out 17 from 172.20.166.84 to 172.18.128.20 20001"
2019-09-13 12:07:47 +00:00
val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC1;
val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC1);
2018-01-17 04:49:08 +00:00
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
#define TEST_OGS_DIAM_RX_FLOW_DESC2 \
2018-01-17 04:49:08 +00:00
"permit in 17 from 172.18.128.20 to 172.20.166.84 20360"
2019-09-13 12:07:47 +00:00
val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC2;
val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC2);
2018-01-17 04:49:08 +00:00
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2018-01-17 04:49:08 +00:00
/* Set Media-Sub-Component #2 */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_media_sub_component, 0, &avpch1);
2018-01-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_number, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +00:00
val.i32 = 2;
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_usage, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
val.i32 = OGS_DIAM_RX_FLOW_USAGE_RTCP;
2018-01-17 04:49:08 +00:00
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
#define TEST_OGS_DIAM_RX_FLOW_DESC3 \
2018-01-17 04:49:08 +00:00
"permit out 17 from 172.20.166.84 to 172.18.128.20 20002"
2019-09-13 12:07:47 +00:00
val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC3;
val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC3);
2018-01-17 04:49:08 +00:00
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
#define TEST_OGS_DIAM_RX_FLOW_DESC4 \
2018-01-17 04:49:08 +00:00
"permit in 17 from 172.18.128.20 to 172.20.166.84 20361"
2019-09-13 12:07:47 +00:00
val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC4;
val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC4);
2018-01-17 04:49:08 +00:00
ret = fd_msg_avp_setvalue (avpch2, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 04:49:08 +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-10 10:56:10 +00:00
2018-01-17 04:49:08 +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-17 04:49:08 +00:00
}
2018-01-10 10:56:10 +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 10:56:10 +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-05 14:49:55 +00:00
/* Keep a pointer to the session data for debug purpose,
* in real life we would not need it */
2018-01-10 03:45:58 +00:00
svg = sess_data;
2018-01-05 14:49:55 +00:00
/* Store this value in the session */
2018-01-10 03:45:58 +00:00
ret = fd_sess_state_store(pcscf_rx_reg, session, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data == NULL);
2018-01-05 14:49:55 +00:00
/* Send the request */
2018-01-10 03:45:58 +00:00
ret = fd_msg_send(&req, pcscf_rx_aaa_cb, svg);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +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-05 14:49:55 +00:00
}
static void pcscf_rx_aaa_cb(void *data, struct msg **msg)
2018-01-05 14:49:55 +00:00
{
2018-01-10 03:45:58 +00:00
int ret;
struct sess_state *sess_data = NULL;
2018-01-05 14:49:55 +00:00
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
int result_code = 0;
2018-01-05 14:49:55 +00:00
2018-01-10 03:45:58 +00:00
ret = clock_gettime(CLOCK_REALTIME, &ts);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
/* Search the session, retrieve its data */
2018-01-10 03:45:58 +00:00
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-05 14:49:55 +00:00
2018-01-10 03:45:58 +00:00
ret = fd_sess_state_retrieve(pcscf_rx_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-05 14:49:55 +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-08-03 13:08:20 +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-05 14:49:55 +00:00
result_code = hdr->avp_value->i32;
2019-04-27 14:54:30 +00:00
ogs_debug("Result Code: %d\n", hdr->avp_value->i32);
2019-08-03 13:08:20 +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-08-03 13:08:20 +00:00
if (avp) {
2019-09-13 12:07:47 +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-08-03 13:08:20 +00:00
if (avpch1) {
2018-01-10 03:45:58 +00:00
ret = fd_msg_avp_hdr(avpch1, &hdr);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
result_code = hdr->avp_value->i32;
2019-04-27 14:54:30 +00:00
ogs_debug("Experimental Result Code: %d\n",
2018-01-05 14:49:55 +00:00
result_code);
}
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no Result-Code");
2018-01-05 14:49:55 +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-08-03 13:08:20 +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);
ogs_debug("From '%.*s' ",
2018-01-05 14:49:55 +00:00
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no_Origin-Host ");
2018-01-05 14:49:55 +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-08-03 13:08:20 +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);
ogs_debug("('%.*s') ",
2018-01-05 14:49:55 +00:00
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no_Origin-Realm ");
2018-01-05 14:49:55 +00:00
error++;
}
2019-08-03 13:08:20 +00:00
if (result_code != ER_DIAMETER_SUCCESS) {
2019-04-27 14:54:30 +00:00
ogs_warn("ERROR DIAMETER Result Code(%d)", result_code);
2018-01-05 14:49:55 +00:00
error++;
goto out;
}
out:
/* 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 03:45:58 +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-05 14:49:55 +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-05 14:49:55 +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-08-03 13:08:20 +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-05 14:49:55 +00:00
}
if (error)
2019-09-13 12:07:47 +00:00
ogs_diam_logger_self()->stats.nb_errs++;
2018-01-05 14:49:55 +00:00
else
2019-09-13 12:07:47 +00:00
ogs_diam_logger_self()->stats.nb_recv++;
2018-01-05 14:49:55 +00:00
2019-09-13 12:07:47 +00:00
ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0);
2018-01-05 14:49:55 +00:00
/* Display how long it took */
2018-01-10 03:45:58 +00:00
if (ts.tv_nsec > sess_data->ts.tv_nsec)
2019-04-27 14:54:30 +00:00
ogs_debug("in %d.%06ld sec\n",
2018-01-10 03:45:58 +00:00
(int)(ts.tv_sec - sess_data->ts.tv_sec),
(long)(ts.tv_nsec - sess_data->ts.tv_nsec) / 1000);
2018-01-05 14:49:55 +00:00
else
2019-04-27 14:54:30 +00:00
ogs_debug("in %d.%06ld sec\n",
2018-01-10 03:45:58 +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(pcscf_rx_reg, session, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data == NULL);
2018-01-05 14:49:55 +00:00
2018-01-10 03:45:58 +00:00
ret = fd_msg_free(*msg);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
*msg = NULL;
return;
}
2018-01-17 12:22:30 +00:00
static int pcscf_rx_asr_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-17 12:22:30 +00:00
int ret;
struct msg *ans, *qry;
struct avp *avpch1, *avpch2, *avpch3;
struct avp_hdr *hdr;
union avp_value val;
struct sess_state *sess_data = NULL;
os0_t sid;
size_t sidlen;
2019-04-27 14:54:30 +00:00
ogs_assert(msg);
ogs_assert(sess);
2018-01-17 12:22:30 +00:00
ret = fd_sess_state_retrieve(pcscf_rx_reg, sess, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data);
2018-01-17 12:22:30 +00:00
/* Create answer header */
qry = *msg;
ret = fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +00:00
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-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
val.i32 = OGS_DIAM_RX_APPLICATION_ID;
2018-01-17 12:22:30 +00:00
ret = fd_msg_avp_setvalue(avp, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +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-17 12:22:30 +00:00
/* Set the Auth-Request-Type AVP */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_auth_request_type, 0, &avp);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +00:00
val.i32 = 1;
ret = fd_msg_avp_setvalue(avp, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +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-17 12:22:30 +00:00
2018-01-17 13:37:11 +00:00
/* Get Abort-Cause */
2019-09-13 12:07:47 +00:00
ret = fd_msg_search_avp(qry, ogs_diam_rx_abort_cause, &avp);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-08-03 13:08:20 +00:00
if (avp) {
2018-01-17 13:37:11 +00:00
ret = fd_msg_avp_hdr(avp, &hdr);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no_Abort-Cause ");
2018-01-17 13:37:11 +00:00
}
2018-01-17 12:22:30 +00:00
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
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-17 12:22:30 +00:00
/* Store this value in the session */
sid = sess_data->sid;
2019-04-27 14:54:30 +00:00
ogs_assert(sid);
2018-01-17 12:22:30 +00:00
ret = fd_sess_state_store(pcscf_rx_reg, sess, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data == NULL);
2018-01-17 12:22:30 +00:00
/* Send the answer */
ret = fd_msg_send(msg, NULL, NULL);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +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-17 12:22:30 +00:00
pcscf_rx_send_str(sid);
return 0;
}
2019-04-27 14:54:30 +00:00
void pcscf_rx_send_str(uint8_t *rx_sid)
2018-01-15 08:25:14 +00:00
{
2019-04-27 14:54:30 +00:00
int rv;
2018-01-15 08:25:14 +00:00
int ret;
struct msg *req = NULL;
struct avp *avp;
struct avp *avpch1, *avpch2;
union avp_value val;
struct sess_state *sess_data = NULL, *svg;
struct session *session = NULL;
int new;
2019-04-27 14:54:30 +00:00
ogs_assert(rx_sid);
2018-01-15 08:25:14 +00:00
/* Create the request */
2019-09-13 12:07:47 +00:00
ret = fd_msg_new(ogs_diam_rx_cmd_str, MSGFL_ALLOC_ETEID, &req);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +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_RX_APPLICATION_ID;
2018-01-15 08:25:14 +00:00
}
/* Retrieve session by Session-Id */
2018-01-17 12:22:30 +00:00
size_t sidlen = strlen((char*)rx_sid);
ret = fd_sess_fromsid_msg(rx_sid, sidlen, &session, &new);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(new == 0);
2018-01-15 08:25:14 +00:00
/* Add Session-Id to the message */
2019-09-13 12:07:47 +00:00
ret = ogs_diam_message_session_id_set(req, rx_sid, sidlen);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +00:00
/* Save the session associated with the message */
ret = fd_msg_sess_set(req, session);
/* Retrieve session state in this session */
ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data);
2018-01-15 08:25:14 +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-15 08:25:14 +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-15 08:25:14 +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-15 08:25:14 +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-15 08:25:14 +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_RX_APPLICATION_ID;
2018-01-15 08:25:14 +00:00
ret = fd_msg_avp_setvalue(avp, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +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-15 08:25:14 +00:00
/* Set the Termination-Cause AVP */
2019-09-13 12:07:47 +00:00
ret = fd_msg_avp_new(ogs_diam_rx_termination_cause, 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_RX_TERMINATION_CAUSE_DIAMETER_LOGOUT;
2018-01-15 08:25:14 +00:00
ret = fd_msg_avp_setvalue(avp, &val);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +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-15 08:25:14 +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(pcscf_rx_reg, session, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data == NULL);
2018-01-15 08:25:14 +00:00
/* Send the request */
ret = fd_msg_send(&req, pcscf_rx_sta_cb, svg);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +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-15 08:25:14 +00:00
}
static void pcscf_rx_sta_cb(void *data, struct msg **msg)
{
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
int result_code = 0;
2018-01-15 08:25:14 +00:00
ret = clock_gettime(CLOCK_REALTIME, &ts);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +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-15 08:25:14 +00:00
ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
ogs_assert(sess_data && (void *)sess_data == data);
2018-01-15 08:25:14 +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-08-03 13:08:20 +00:00
if (avp) {
2018-01-15 08:25:14 +00:00
ret = fd_msg_avp_hdr(avp, &hdr);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +00:00
result_code = hdr->avp_value->i32;
2019-04-27 14:54:30 +00:00
ogs_debug("Result Code: %d\n", hdr->avp_value->i32);
2019-08-03 13:08:20 +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-08-03 13:08:20 +00:00
if (avp) {
2019-09-13 12:07:47 +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-08-03 13:08:20 +00:00
if (avpch1) {
2018-01-15 08:25:14 +00:00
ret = fd_msg_avp_hdr(avpch1, &hdr);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +00:00
result_code = hdr->avp_value->i32;
2019-04-27 14:54:30 +00:00
ogs_debug("Experimental Result Code: %d\n",
2018-01-15 08:25:14 +00:00
result_code);
}
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no Result-Code");
2018-01-15 08:25:14 +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-08-03 13:08:20 +00:00
if (avp) {
2018-01-15 08:25:14 +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-15 08:25:14 +00:00
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no_Origin-Host ");
2018-01-15 08:25:14 +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-08-03 13:08:20 +00:00
if (avp) {
2018-01-15 08:25:14 +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-15 08:25:14 +00:00
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
2019-08-03 13:08:20 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("no_Origin-Realm ");
2018-01-15 08:25:14 +00:00
error++;
}
2019-08-03 13:08:20 +00:00
if (result_code != ER_DIAMETER_SUCCESS) {
2019-04-27 14:54:30 +00:00
ogs_warn("ERROR DIAMETER Result Code(%d)", result_code);
2018-01-15 08:25:14 +00:00
error++;
goto out;
}
out:
/* 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-15 08:25:14 +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-15 08:25:14 +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-15 08:25:14 +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-08-03 13:08:20 +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-15 08:25:14 +00:00
}
if (error)
2019-09-13 12:07:47 +00:00
ogs_diam_logger_self()->stats.nb_errs++;
2018-01-15 08:25:14 +00:00
else
2019-09-13 12:07:47 +00:00
ogs_diam_logger_self()->stats.nb_recv++;
2018-01-15 08:25:14 +00:00
2019-09-13 12:07:47 +00:00
ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0);
2018-01-15 08:25:14 +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\n",
2018-01-15 08:25:14 +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\n",
2018-01-15 08:25:14 +00:00
(int)(ts.tv_sec + 1 - sess_data->ts.tv_sec),
(long)(1000000000 + ts.tv_nsec - sess_data->ts.tv_nsec) / 1000);
state_cleanup(sess_data, NULL, NULL);
ret = fd_msg_free(*msg);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-15 08:25:14 +00:00
*msg = NULL;
return;
}
void pcscf_diam_config(void)
2018-01-05 14:49:55 +00:00
{
2019-09-13 12:07:47 +00:00
memset(&diam_config, 0, sizeof(ogs_diam_config_t));
2018-01-05 14:49:55 +00:00
2020-08-22 03:33:45 +00:00
diam_config.cnf_diamid = "pcscf.localdomain";
diam_config.cnf_diamrlm = "localdomain";
2019-09-13 12:07:47 +00:00
diam_config.cnf_port = DIAMETER_PORT;
diam_config.cnf_port_tls = DIAMETER_SECURE_PORT;
diam_config.cnf_flags.no_sctp = 1;
diam_config.cnf_addr = "127.0.0.1";
2018-01-05 14:49:55 +00:00
2019-09-13 12:07:47 +00:00
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dbg_msg_dumps.fdx";
2019-09-13 12:07:47 +00:00
diam_config.ext[diam_config.num_of_ext].conf = "0x8888";
diam_config.num_of_ext++;
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_rfc5777.fdx";
2019-09-13 12:07:47 +00:00
diam_config.num_of_ext++;
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_mip6i.fdx";
2019-09-13 12:07:47 +00:00
diam_config.num_of_ext++;
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_nasreq.fdx";
2019-09-13 12:07:47 +00:00
diam_config.num_of_ext++;
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_nas_mipv6.fdx";
2019-09-13 12:07:47 +00:00
diam_config.num_of_ext++;
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca.fdx";
2019-09-13 12:07:47 +00:00
diam_config.num_of_ext++;
diam_config.ext[diam_config.num_of_ext].module =
FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca_3gpp.fdx";
2019-09-13 12:07:47 +00:00
diam_config.num_of_ext++;
2018-01-05 14:49:55 +00:00
2020-08-22 03:33:45 +00:00
diam_config.conn[diam_config.num_of_conn].identity = "pcrf.localdomain";
diam_config.conn[diam_config.num_of_conn].addr = "127.0.0.9";
2019-09-13 12:07:47 +00:00
diam_config.num_of_conn++;
2018-01-05 14:49:55 +00:00
}
2019-04-27 14:54:30 +00:00
int pcscf_fd_init(void)
2018-01-05 14:49:55 +00:00
{
2018-01-10 03:45:58 +00:00
int ret;
2018-01-17 12:22:30 +00:00
struct disp_when data;
2019-09-13 12:07:47 +00:00
pcscf_diam_config();
2018-01-05 14:49:55 +00:00
2019-09-13 12:07:47 +00:00
ret = ogs_diam_init(FD_MODE_CLIENT, NULL, &diam_config);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
2018-01-17 12:22:30 +00:00
/* Install objects definitions for this application */
2019-11-02 06:52:48 +00:00
ret = ogs_diam_rx_init();
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
2018-01-17 12:22:30 +00:00
/* Create handler for sessions */
2018-01-15 08:25:14 +00:00
ret = fd_sess_handler_create(&pcscf_rx_reg, state_cleanup, NULL, NULL);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
2018-01-17 12:22:30 +00:00
/* Fallback CB if command != unexpected message received */
memset(&data, 0, sizeof(data));
2019-09-13 12:07:47 +00:00
data.app = ogs_diam_rx_application;
2018-01-17 12:22:30 +00:00
ret = fd_disp_register(pcscf_rx_fb_cb, DISP_HOW_APPID, &data, NULL,
&hdl_rx_fb);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +00:00
/* Specific handler for Abort-Session-Request */
2019-09-13 12:07:47 +00:00
data.command = ogs_diam_rx_cmd_asr;
2018-01-17 12:22:30 +00:00
ret = fd_disp_register(pcscf_rx_asr_cb, DISP_HOW_CC, &data, NULL,
&hdl_rx_asr);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-17 12:22:30 +00:00
2018-01-05 14:49:55 +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_rx_application, ogs_diam_vendor, 1, 0);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2019-09-13 12:07:47 +00:00
2018-01-05 14:49:55 +00:00
return 0;
}
void pcscf_fd_final(void)
{
2018-01-10 03:45:58 +00:00
int ret;
ret = fd_sess_handler_destroy(&pcscf_rx_reg, NULL);
2019-04-27 14:54:30 +00:00
ogs_assert(ret == 0);
2018-01-05 14:49:55 +00:00
2018-01-17 12:22:30 +00:00
if (hdl_rx_fb)
(void) fd_disp_unregister(&hdl_rx_fb, NULL);
if (hdl_rx_asr)
(void) fd_disp_unregister(&hdl_rx_asr, NULL);
2019-09-13 12:07:47 +00:00
ogs_diam_final();
2018-01-05 14:49:55 +00:00
}