add hash for associating Gx/Rx interface by

Framed-IP-Address/Framed-IPv6-Address
This commit is contained in:
Sukchan Lee 2018-01-08 22:42:44 +09:00
parent 38e245d467
commit 13a06479a9
4 changed files with 122 additions and 17 deletions

View File

@ -41,9 +41,7 @@ status_t pcrf_context_init(void)
rv = mutex_create(&self.hash_lock, MUTEX_DEFAULT);
d_assert(rv == CORE_OK, return CORE_ERROR, );
self.ipv4_hash = hash_make();
self.ipv6_hash = hash_make();
self.ip_hash = hash_make();
context_initialized = 1;
@ -55,11 +53,8 @@ status_t pcrf_context_final(void)
d_assert(context_initialized == 1, return CORE_ERROR,
"PCRF context already has been finalized");
d_assert(self.ipv4_hash,, );
hash_destroy(self.ipv4_hash);
d_assert(self.ipv6_hash,, );
hash_destroy(self.ipv6_hash);
d_assert(self.ip_hash,, );
hash_destroy(self.ip_hash);
mutex_delete(self.hash_lock);
mutex_delete(self.db_lock);
@ -769,3 +764,56 @@ out:
return rv;
}
status_t pcrf_sess_set_ipv4(const void *key, c_int8_t *sid)
{
d_assert(self.ip_hash, return CORE_ERROR,);
mutex_lock(self.hash_lock);
hash_set(self.ip_hash, key, IPV4_LEN, sid);
mutex_unlock(self.hash_lock);
return CORE_OK;
}
status_t pcrf_sess_set_ipv6(const void *key, c_int8_t *sid)
{
d_assert(self.ip_hash, return CORE_ERROR,);
mutex_lock(self.hash_lock);
hash_set(self.ip_hash, key, IPV6_LEN, sid);
mutex_unlock(self.hash_lock);
return CORE_OK;
}
c_int8_t *pcrf_sess_find_by_ipv4(const void *key)
{
c_int8_t *sid = NULL;
d_assert(key, return NULL,);
mutex_lock(self.hash_lock);
sid = (c_int8_t *)hash_get(self.ip_hash, key, IPV4_LEN);
mutex_unlock(self.hash_lock);
return sid;
}
c_int8_t *pcrf_sess_find_by_ipv6(const void *key)
{
c_int8_t *sid = NULL;
d_assert(key, return NULL,);
mutex_lock(self.hash_lock);
sid = (c_int8_t *)hash_get(self.ip_hash, key, IPV6_LEN);
mutex_unlock(self.hash_lock);
return sid;
}

View File

@ -20,8 +20,7 @@ typedef struct _pcrf_context_t {
void *subscriberCollection;
mutex_id db_lock;
hash_t *ipv4_hash; /* hash table for Gx Frame-IP-Address */
hash_t *ipv6_hash; /* hash table for Gx Frame-IPv6s-Prefix */
hash_t *ip_hash; /* hash table for Gx Frame IPv4/IPv6 */
mutex_id hash_lock;
} pcrf_context_t;
@ -38,6 +37,11 @@ CORE_DECLARE(status_t) pcrf_db_final(void);
CORE_DECLARE(status_t) pcrf_db_pdn_data(
c_int8_t *imsi_bcd, c_int8_t *apn, gx_cca_message_t *cca_message);
CORE_DECLARE(status_t) pcrf_sess_set_ipv4(const void *key, c_int8_t *sid);
CORE_DECLARE(status_t) pcrf_sess_set_ipv6(const void *key, c_int8_t *sid);
CORE_DECLARE(c_int8_t *) pcrf_sess_find_by_ipv4(const void *key);
CORE_DECLARE(c_int8_t *) pcrf_sess_find_by_ipv6(const void *key);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -12,8 +12,14 @@
#include "pcrf_context.h"
struct sess_state {
c_uint32_t cc_request_type;
char *sid;
c_uint32_t cc_request_type; /* CC-Request-Type */
c_int8_t *sid; /* Session-Id */
ED3(c_uint8_t ipv4:1;,
c_uint8_t ipv6:1;,
c_uint8_t reserved:6;)
c_uint32_t addr; /* Framed-IPv4-Address */
c_uint8_t addr6[IPV6_LEN]; /* Framed-IPv6-Prefix */
};
static struct session_handler *pcrf_gx_reg = NULL;
@ -40,6 +46,11 @@ static void state_cleanup(
{
d_assert(sess_data, return,);
if (sess_data->ipv4)
pcrf_sess_set_ipv4(&sess_data->addr, NULL);
if (sess_data->ipv6)
pcrf_sess_set_ipv6(sess_data->addr6, NULL);
if (sess_data->sid)
core_free(sess_data->sid);
@ -98,13 +109,51 @@ static int pcrf_gx_ccr_cb( struct msg **msg, struct avp *avp,
/* Get CC-Request-Type */
CHECK_FCT( fd_msg_search_avp(qry, gx_cc_request_type, &avp) );
CHECK_FCT( fd_msg_avp_hdr(avp, &hdr) );
sess_data->cc_request_type = hdr->avp_value->i32;
if (avp)
{
CHECK_FCT( fd_msg_avp_hdr(avp, &hdr) );
sess_data->cc_request_type = hdr->avp_value->i32;
}
else
{
d_error("no_CC-Request-Type ");
goto out;
}
/* Get CC-Request-Number */
CHECK_FCT( fd_msg_search_avp(qry, gx_cc_request_number, &avp) );
CHECK_FCT( fd_msg_avp_hdr(avp, &hdr) );
cc_request_number = hdr->avp_value->i32;
if (avp)
{
CHECK_FCT( fd_msg_avp_hdr(avp, &hdr) );
cc_request_number = hdr->avp_value->i32;
}
/* Get Framed-IP-Address */
CHECK_FCT( fd_msg_search_avp(qry, gx_framed_ip_address, &avp) );
if (avp)
{
CHECK_FCT( fd_msg_avp_hdr(avp, &hdr) );
memcpy(&sess_data->addr, hdr->avp_value->os.data,
sizeof sess_data->addr);
pcrf_sess_set_ipv4(&sess_data->addr, sess_data->sid);
sess_data->ipv4 = 1;
}
/* Get Framed-IPv6-Prefix */
CHECK_FCT( fd_msg_search_avp(qry, gx_framed_ipv6_prefix, &avp) );
if (avp)
{
paa_t *paa = NULL;
CHECK_FCT( fd_msg_avp_hdr(avp, &hdr) );
paa = (paa_t *)hdr->avp_value->os.data;
d_assert(paa, goto out,);
d_assert(paa->len == IPV6_LEN * 8 /* 128bit */, goto out,
"Invalid Framed-IPv6-Prefix Length:%d", paa->len);
memcpy(sess_data->addr6, paa->addr6, sizeof sess_data->addr6);
pcrf_sess_set_ipv6(sess_data->addr6, sess_data->sid);
sess_data->ipv6 = 1;
}
/* Set the Auth-Application-Id AVP */
CHECK_FCT_DO( fd_msg_avp_new(fd_auth_application_id, 0, &avp), goto out );

View File

@ -45,6 +45,7 @@ void pgw_gx_send_ccr(gtp_xact_t *xact, pgw_sess_t *sess,
struct session *session = NULL;
int new;
gtp_message_t *message = NULL;
paa_t paa; /* For changing Framed-IPv6-Prefix Length to 128 */
d_assert(sess, return,);
d_assert(sess->ipv4 || sess->ipv6, return,);
@ -201,7 +202,10 @@ void pgw_gx_send_ccr(gtp_xact_t *xact, pgw_sess_t *sess,
{
CHECK_FCT_DO( fd_msg_avp_new(gx_framed_ipv6_prefix, 0, &avp),
goto out );
val.os.data = (c_uint8_t*)&sess->pdn.paa;
memcpy(&paa, &sess->pdn.paa, PAA_IPV6_LEN);
#define FRAMED_IPV6_PREFIX_LENGTH 128 /* from spec document */
paa.len = FRAMED_IPV6_PREFIX_LENGTH;
val.os.data = (c_uint8_t*)&paa;
val.os.len = PAA_IPV6_LEN;
CHECK_FCT_DO( fd_msg_avp_setvalue(avp, &val), goto out );
CHECK_FCT_DO( fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp),