From 415e5276baf40e93d815f30ecccbff57debe79f3 Mon Sep 17 00:00:00 2001 From: jmasterfunk84 <48972964+jmasterfunk84@users.noreply.github.com> Date: Tue, 2 Aug 2022 22:42:45 -0600 Subject: [PATCH] [MME+HSS] AVP Occurring Too Many Times Do not Set Origin-Hosts with fd_msg_rescode_set before potential use of ogs_diam_message_experimental_rescode_set. This results in multiple Origin-Host/Realm AVPs. --- src/hss/hss-s6a-path.c | 44 ++++++++++++++++----------------- src/hss/hss-swx-path.c | 56 +++++++++++++++++++++--------------------- src/mme/mme-fd-path.c | 54 ++++++++++++++++++++++++++-------------- 3 files changed, 86 insertions(+), 68 deletions(-) diff --git a/src/hss/hss-s6a-path.c b/src/hss/hss-s6a-path.c index 94b5982eb..c92f2baa0 100644 --- a/src/hss/hss-s6a-path.c +++ b/src/hss/hss-s6a-path.c @@ -370,28 +370,6 @@ static int hss_ogs_diam_s6a_ulr_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); memcpy(&visited_plmn_id, hdr->avp_value->os.data, hdr->avp_value->os.len); - /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); - ogs_assert(ret == 0); - - /* Set the Auth-Session-State AVP */ - ret = fd_msg_avp_new(ogs_diam_auth_session_state, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_AUTH_SESSION_NO_STATE_MAINTAINED; - 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 the ULA Flags */ - ret = fd_msg_avp_new(ogs_diam_s6a_ula_flags, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_S6A_ULA_FLAGS_MME_REGISTERED_FOR_SMS; - 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); - ret = fd_msg_search_avp(qry, ogs_diam_s6a_ulr_flags, &avp); ogs_assert(ret == 0); ret = fd_msg_avp_hdr(avp, &hdr); @@ -817,6 +795,28 @@ static int hss_ogs_diam_s6a_ulr_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); } + /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ + ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); + ogs_assert(ret == 0); + + /* Set the Auth-Session-State AVP */ + ret = fd_msg_avp_new(ogs_diam_auth_session_state, 0, &avp); + ogs_assert(ret == 0); + val.i32 = OGS_DIAM_AUTH_SESSION_NO_STATE_MAINTAINED; + 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 the ULA Flags */ + ret = fd_msg_avp_new(ogs_diam_s6a_ula_flags, 0, &avp); + ogs_assert(ret == 0); + val.i32 = OGS_DIAM_S6A_ULA_FLAGS_MME_REGISTERED_FOR_SMS; + 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 Vendor-Specific-Application-Id AVP */ ret = ogs_diam_message_vendor_specific_appid_set( ans, OGS_DIAM_S6A_APPLICATION_ID); diff --git a/src/hss/hss-swx-path.c b/src/hss/hss-swx-path.c index c85029fb6..d287c3b2f 100644 --- a/src/hss/hss-swx-path.c +++ b/src/hss/hss-swx-path.c @@ -428,34 +428,6 @@ static int hss_ogs_diam_swx_sar_cb( struct msg **msg, struct avp *avp, goto out; } - /* Set Vendor-Specific-Application-Id AVP */ - ret = ogs_diam_message_vendor_specific_appid_set( - ans, OGS_DIAM_SWX_APPLICATION_ID); - ogs_assert(ret == 0); - - /* Set the Auth-Session-State AVP */ - ret = fd_msg_avp_new(ogs_diam_auth_session_state, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_AUTH_SESSION_NO_STATE_MAINTAINED; - 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 the Origin-Host, Origin-Realm, and Result-Code AVPs */ - ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); - ogs_assert(ret == 0); - - /* Set the User-Name AVP */ - ret = fd_msg_avp_new(ogs_diam_user_name, 0, &avp); - ogs_assert(ret == 0); - val.os.data = (uint8_t *)user_name; - val.os.len = strlen(user_name); - 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 Server-Assignment-Type AVP (Mandatory) */ ret = fd_msg_search_avp(qry, ogs_diam_cx_server_assignment_type, &avp); @@ -840,6 +812,34 @@ static int hss_ogs_diam_swx_sar_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); } + /* Set Vendor-Specific-Application-Id AVP */ + ret = ogs_diam_message_vendor_specific_appid_set( + ans, OGS_DIAM_SWX_APPLICATION_ID); + ogs_assert(ret == 0); + + /* Set the Auth-Session-State AVP */ + ret = fd_msg_avp_new(ogs_diam_auth_session_state, 0, &avp); + ogs_assert(ret == 0); + val.i32 = OGS_DIAM_AUTH_SESSION_NO_STATE_MAINTAINED; + 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 the Origin-Host, Origin-Realm, and Result-Code AVPs */ + ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); + ogs_assert(ret == 0); + + /* Set the User-Name AVP */ + ret = fd_msg_avp_new(ogs_diam_user_name, 0, &avp); + ogs_assert(ret == 0); + val.os.data = (uint8_t *)user_name; + val.os.len = strlen(user_name); + 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); + /* Send the answer */ ret = fd_msg_send(msg, NULL, NULL); ogs_assert(ret == 0); diff --git a/src/mme/mme-fd-path.c b/src/mme/mme-fd-path.c index 43f38c2b7..827adff0c 100644 --- a/src/mme/mme-fd-path.c +++ b/src/mme/mme-fd-path.c @@ -1411,7 +1411,6 @@ static int mme_ogs_diam_s6a_clr_cb( struct msg **msg, struct avp *avp, struct session *session, void *opaque, enum disp_action *act) { int ret; - int error = 0; mme_event_t *e = NULL; mme_ue_t *mme_ue = NULL; @@ -1457,7 +1456,7 @@ static int mme_ogs_diam_s6a_clr_cb( struct msg **msg, struct avp *avp, if (!mme_ue) { ogs_error("Cancel Location for Unknown IMSI[%s]", imsi_bcd); result_code = OGS_DIAM_S6A_ERROR_USER_UNKNOWN; - error++; + goto out; } ret = fd_msg_search_avp(qry, ogs_diam_s6a_cancellation_type, &avp); @@ -1502,25 +1501,44 @@ static int mme_ogs_diam_s6a_clr_cb( struct msg **msg, struct avp *avp, ogs_diam_logger_self()->stats.nb_echoed++; ogs_assert( pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); - if (!error) { - int rv; - e = mme_event_new(MME_EVT_S6A_MESSAGE); - ogs_assert(e); - e->mme_ue = mme_ue; - e->s6a_message = s6a_message; - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed:%d", (int)rv); - ogs_free(s6a_message); - mme_event_free(e); - } else { - ogs_pollset_notify(ogs_app()->pollset); - } + int rv; + e = mme_event_new(MME_EVT_S6A_MESSAGE); + ogs_assert(e); + e->mme_ue = mme_ue; + e->s6a_message = s6a_message; + rv = ogs_queue_push(ogs_app()->queue, e); + if (rv != OGS_OK) { + ogs_error("ogs_queue_push() failed:%d", (int)rv); + ogs_free(s6a_message); + mme_event_free(e); } else { - ret = ogs_diam_message_experimental_rescode_set(ans, result_code); - ogs_assert(ret == 0); + ogs_pollset_notify(ogs_app()->pollset); } + return 0; + +out: + ret = ogs_diam_message_experimental_rescode_set(ans, result_code); + ogs_assert(ret == 0); + + /* Set the Auth-Session-State AVP */ + ret = fd_msg_avp_new(ogs_diam_auth_session_state, 0, &avp); + ogs_assert(ret == 0); + val.i32 = OGS_DIAM_AUTH_SESSION_NO_STATE_MAINTAINED; + 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 Vendor-Specific-Application-Id AVP */ + ret = ogs_diam_message_vendor_specific_appid_set( + ans, OGS_DIAM_S6A_APPLICATION_ID); + ogs_assert(ret == 0); + + /* Send the answer */ + ret = fd_msg_send(msg, NULL, NULL); + ogs_assert(ret == 0); + return 0; }