PCRF session state is added

This commit is contained in:
Sukchan Lee 2018-01-08 21:20:19 +09:00
parent e4397176cf
commit 38e245d467
5 changed files with 83 additions and 14 deletions

View File

@ -191,6 +191,10 @@ CORE_DECLARE(void) core_free(void *ptr);
CORE_DECLARE(void *) core_calloc(size_t nmemb, size_t size);
CORE_DECLARE(void *) core_realloc(void *ptr, size_t size);
CORE_DECLARE(char *) core_strdup(const char *s);
CORE_DECLARE(char *) core_strndup(const char *s, size_t n);
CORE_DECLARE(void *) core_memdup(const void *m, size_t n);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -613,3 +613,44 @@ void *core_realloc(void *ptr, size_t size)
}
}
char *core_strdup(const char *s)
{
char *res;
size_t len;
if (s == NULL)
return NULL;
len = strlen(s) + 1;
res = core_memdup(s, len);
return res;
}
char *core_strndup(const char *s, size_t n)
{
char *res;
const char *end;
if (s == NULL)
return NULL;
end = memchr(s, '\0', n);
if (end != NULL)
n = end - s;
res = core_malloc(n + 1);
memcpy(res, s, n);
res[n] = '\0';
return res;
}
void *core_memdup(const void *m, size_t n)
{
void *res;
if (m == NULL)
return NULL;
res = core_malloc(n);
memcpy(res, m, n);
return res;
}

View File

@ -3,6 +3,7 @@
#include "core_lib.h"
#include "core_debug.h"
#include "core_pool.h"
#include "core_pkbuf.h"
#include "fd/fd_lib.h"
#include "fd/gx/gx_dict.h"
@ -11,8 +12,8 @@
#include "pcrf_context.h"
struct sess_state {
c_uint32_t cc_request_type;
struct timespec ts; /* Time of sending the message */
c_uint32_t cc_request_type;
char *sid;
};
static struct session_handler *pcrf_gx_reg = NULL;
@ -21,10 +22,27 @@ static struct disp_hdl *hdl_gx_ccr = NULL;
pool_declare(pcrf_gx_sess_pool, struct sess_state, MAX_POOL_OF_DIAMETER_SESS);
void pcrf_gx_sess_cleanup(
static __inline__ struct sess_state *new_state(os0_t sid)
{
struct sess_state *new = NULL;
pool_alloc_node(&pcrf_gx_sess_pool, &new);
d_assert(new, return NULL,);
memset(new, 0, sizeof *new);
new->sid = core_strdup((char *)sid);
d_assert(new->sid, return NULL,);
return new;
}
static void state_cleanup(
struct sess_state *sess_data, os0_t sid, void *opaque)
{
printf("cleanup\n");
d_assert(sess_data, return,);
if (sess_data->sid)
core_free(sess_data->sid);
pool_free_node(&pcrf_gx_sess_pool, sess_data);
}
@ -61,9 +79,13 @@ static int pcrf_gx_ccr_cb( struct msg **msg, struct avp *avp,
return EINVAL,);
if (!sess_data)
{
pool_alloc_node(&pcrf_gx_sess_pool, &sess_data);
os0_t sid;
size_t sidlen;
d_assert( fd_sess_getsid(sess, &sid, &sidlen) == 0, return EINVAL,);
sess_data = new_state(sid);
d_assert(sess_data, return EINVAL,);
memset(sess_data, 0, sizeof *sess_data);
}
/* Initialize Message */
@ -341,7 +363,7 @@ static int pcrf_gx_ccr_cb( struct msg **msg, struct avp *avp,
}
else
{
pcrf_gx_sess_cleanup(sess_data, NULL, NULL);
state_cleanup(sess_data, NULL, NULL);
}
/* Send the answer */
@ -384,7 +406,7 @@ int pcrf_gx_init(void)
CHECK_FCT( gx_dict_init() );
/* Create handler for sessions */
CHECK_FCT( fd_sess_handler_create(&pcrf_gx_reg, pcrf_gx_sess_cleanup,
CHECK_FCT( fd_sess_handler_create(&pcrf_gx_reg, state_cleanup,
NULL, NULL) );
memset(&data, 0, sizeof(data));

View File

@ -110,8 +110,7 @@ typedef struct _pgw_sess_t {
c_uint32_t pgw_s5c_teid; /* PGW-S5C-TEID is derived from INDEX */
c_uint32_t sgw_s5c_teid; /* SGW-S5C-TEID is received from SGW */
c_uint8_t *gx_sid; /* Gx Session ID */
size_t gx_sidlen; /* Gx Session ID Length */
c_int8_t *gx_sid; /* Gx Session ID */
/* IMSI */
c_uint8_t imsi[MAX_IMSI_LEN];

View File

@ -55,21 +55,23 @@ void pgw_gx_send_ccr(gtp_xact_t *xact, pgw_sess_t *sess,
/* Create the request */
CHECK_FCT_DO( fd_msg_new(gx_cmd_ccr, MSGFL_ALLOC_ETEID, &req), goto out );
if (sess->gx_sid && sess->gx_sidlen)
if (sess->gx_sid)
{
/* Retrieve session by Session-Id */
CHECK_FCT_DO( fd_sess_fromsid_msg(sess->gx_sid, sess->gx_sidlen,
size_t sidlen = strlen(sess->gx_sid);
CHECK_FCT_DO( fd_sess_fromsid_msg((os0_t)sess->gx_sid, sidlen,
&session, &new), goto out );
d_assert(new == 0, return,);
/* Add Session-Id to the message */
CHECK_FCT_DO( fd_message_session_id_set(
req, sess->gx_sid, sess->gx_sidlen), goto out );
req, (os0_t)sess->gx_sid, sidlen), goto out );
/* Save the session associated with the message */
CHECK_FCT_DO( fd_msg_sess_set(req, session), goto out );
}
else
{
size_t sidlen;
/* Create a new session */
#define GX_APP_SID_OPT "app_gx"
CHECK_FCT_DO( fd_msg_new_session(req, (os0_t)GX_APP_SID_OPT,
@ -78,8 +80,9 @@ void pgw_gx_send_ccr(gtp_xact_t *xact, pgw_sess_t *sess,
goto out );
/* Store Session-Id in PGW Session Context */
CHECK_FCT_DO( fd_sess_getsid(session, &sess->gx_sid, &sess->gx_sidlen),
CHECK_FCT_DO( fd_sess_getsid(session, (os0_t *)&sess->gx_sid, &sidlen),
goto out );
d_assert(sidlen == strlen(sess->gx_sid), return,);
}
/* Retrieve session state in this session */