pfcp: Use direct hashing in the session table

The session table maps frames (which are 32 bit uints that
start at 1) to sessions (which are also 32 bit uints that
start at 1), so use GUINT_TO_POINTER and the direct hash
functions instead of creating extra file scope pointers.

see 8129b9de for reference
This commit is contained in:
Joakim Karlsson 2022-09-29 12:29:18 +02:00 committed by AndersBroman
parent 167ac34448
commit 68f77cb2aa
1 changed files with 25 additions and 25 deletions

View File

@ -1730,13 +1730,8 @@ pfcp_remove_frame_info(guint32 *f) {
static void
pfcp_add_session(guint32 frame, guint32 session) {
guint32 *f, *session_count;
g_hash_table_insert(pfcp_session_table, GUINT_TO_POINTER(frame), GUINT_TO_POINTER(session));
f = wmem_new0(wmem_file_scope(), guint32);
session_count = wmem_new0(wmem_file_scope(), guint32);
*f = frame;
*session_count = session;
g_hash_table_insert(pfcp_session_table, f, session_count);
}
static gboolean
@ -1789,9 +1784,11 @@ pfcp_fill_map(wmem_list_t *seid_list, wmem_list_t *ip_list, guint32 frame) {
wmem_list_frame_t *elem_ip, *elem_seid;
pfcp_info_t *pfcp_info;
wmem_list_t * info_list; /* List of <seids,frames>*/
guint32 *f, *session, *fr, *session_count;
guint32 *f;
gpointer session_p, fr_p;
GHashTableIter iter;
guint64 seid;
guint32 session, fr;
gchar *ip;
elem_ip = wmem_list_head(ip_list);
@ -1815,17 +1812,20 @@ pfcp_fill_map(wmem_list_t *seid_list, wmem_list_t *ip_list, guint32 frame) {
pfcp_info->frame = *f;
if (pfcp_info_exists(pfcp_info, info_list)) {
/* If the seid and ip already existed, that means that we need to remove old info about that session */
/* If the seid and ip already maps to a session, that means
* that we need to remove old info about that session */
/* We look for its session ID */
session = (guint32 *)g_hash_table_lookup(pfcp_session_table, f);
session = GPOINTER_TO_UINT(g_hash_table_lookup(pfcp_session_table, GUINT_TO_POINTER(frame)));
if (session) {
g_hash_table_iter_init(&iter, pfcp_session_table);
while (g_hash_table_iter_next(&iter, (gpointer*)&fr, (gpointer*)&session_count)) {
while (g_hash_table_iter_next(&iter, &fr_p, &session_p)) {
/* If the msg has the same session ID and it's not the upd req we have to remove its info */
if (*session_count == *session) {
if (GPOINTER_TO_UINT(session_p) == session) {
/* If it's the session we are looking for, we remove all the frame information */
pfcp_remove_frame_info(fr);
fr = GPOINTER_TO_UINT(fr_p);
pfcp_remove_frame_info(&fr);
}
}
}
@ -1912,21 +1912,21 @@ pfcp_sn_equal_unmatched(gconstpointer k1, gconstpointer k2)
static void
pfcp_track_session(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, pfcp_hdr_t * pfcp_hdr, wmem_list_t *seid_list, wmem_list_t *ip_list, guint64 last_seid _U_, address last_ip _U_)
{
guint32 *session, frame_seid_cp;
guint32 session, frame_seid_cp;
proto_item *it;
/* PFCP session */
if (tree) {
session = (guint32*)g_hash_table_lookup(pfcp_session_table, &pinfo->num);
session = GPOINTER_TO_UINT(g_hash_table_lookup(pfcp_session_table, GUINT_TO_POINTER(pinfo->num)));
if (session) {
it = proto_tree_add_uint(tree, hf_pfcp_session, tvb, 0, 0, *session);
it = proto_tree_add_uint(tree, hf_pfcp_session, tvb, 0, 0, session);
proto_item_set_generated(it);
}
}
if (!PINFO_FD_VISITED(pinfo)) {
/* If the message does not have any session ID */
session = (guint32*)g_hash_table_lookup(pfcp_session_table, &pinfo->num);
session = GPOINTER_TO_UINT(g_hash_table_lookup(pfcp_session_table, GUINT_TO_POINTER(pinfo->num)));
if (!session) {
/* If the message is not a SEREQ, SERES, SMREQ, SERES, SDREQ, SDRES, SRREQ or SRRES then we remove its information from seid and ip lists */
if ((pfcp_hdr->message != PFCP_MSG_SESSION_ESTABLISHMENT_REQUEST && pfcp_hdr->message != PFCP_MSG_SESSION_ESTABLISHMENT_RESPONSE &&
@ -1947,10 +1947,10 @@ pfcp_track_session(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, pfcp_
the corresponding session ID */
if ((pfcp_get_frame(pinfo, pinfo->dst, (guint32)pfcp_hdr->seid, &frame_seid_cp) == 1)) {
/* Then we have to set its session ID */
session = (guint32*)g_hash_table_lookup(pfcp_session_table, &frame_seid_cp);
if (session != NULL) {
session = GPOINTER_TO_UINT(g_hash_table_lookup(pfcp_session_table, GUINT_TO_POINTER(frame_seid_cp)));
if (session) {
/* We add the corresponding session to the list so that when a response came we can associate its session ID*/
pfcp_add_session(pinfo->num, *session);
pfcp_add_session(pinfo->num, session);
}
}
}
@ -9277,7 +9277,7 @@ static pfcp_msg_hash_t *
pfcp_match_response(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, gint seq_nr, guint msgtype, pfcp_conv_info_t *pfcp_info, guint8 last_cause)
{
pfcp_msg_hash_t pcr, *pcrp = NULL;
guint32 *session;
guint32 session;
pcr.seq_nr = seq_nr;
pcr.req_time = pinfo->abs_ts;
@ -9410,11 +9410,11 @@ pfcp_match_response(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, gint
if (g_pfcp_session && !PINFO_FD_VISITED(pinfo)) {
/* PFCP session */
/* If it's not already in the list */
session = (guint32 *)g_hash_table_lookup(pfcp_session_table, &pinfo->num);
session = GPOINTER_TO_UINT(g_hash_table_lookup(pfcp_session_table, GUINT_TO_POINTER(pinfo->num)));
if (!session) {
session = (guint32 *)g_hash_table_lookup(pfcp_session_table, &pcrp->req_frame);
if (session != NULL) {
pfcp_add_session(pinfo->num, *session);
session = GPOINTER_TO_UINT(g_hash_table_lookup(pfcp_session_table, GUINT_TO_POINTER(pcrp->req_frame)));
if (session) {
pfcp_add_session(pinfo->num, session);
}
}
@ -11185,7 +11185,7 @@ static void
pfcp_init(void)
{
pfcp_session_count = 1;
pfcp_session_table = g_hash_table_new(g_int_hash, g_int_equal);
pfcp_session_table = g_hash_table_new(g_direct_hash, g_direct_equal);
pfcp_frame_tree = wmem_tree_new(wmem_file_scope());
}