From 8553c77733f50f82bfa6a9a4ee57f7ca0133a815 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sat, 7 Jan 2023 21:17:14 +0900 Subject: [PATCH] [METRICS] Fixed a core dump in SMF/UPF/PCF (#1985) --- src/pcf/context.c | 5 ----- src/pcf/metrics.c | 6 ++---- src/pcf/metrics.h | 3 +++ src/pcf/sm-sm.c | 6 ++++++ src/smf/context.c | 9 --------- src/smf/gsm-sm.c | 4 ++++ src/smf/n4-handler.c | 16 ++++++++++++++-- src/upf/metrics.c | 5 ++--- src/upf/metrics.h | 3 +++ 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/pcf/context.c b/src/pcf/context.c index 3efcc13ce..71f3fa6f5 100644 --- a/src/pcf/context.c +++ b/src/pcf/context.c @@ -320,11 +320,6 @@ void pcf_sess_remove(pcf_sess_t *sess) OpenAPI_subscribed_default_qos_free(sess->subscribed_default_qos); ogs_pool_free(&pcf_sess_pool, sess); - - if (sess->s_nssai.sst != 0) { - pcf_metrics_inst_by_slice_add(&sess->pcf_ue->guami.plmn_id, - &sess->s_nssai, PCF_METR_GAUGE_PA_SESSIONNBR, -1); - } } void pcf_sess_remove_all(pcf_ue_t *pcf_ue) diff --git a/src/pcf/metrics.c b/src/pcf/metrics.c index 1b0e0d8d1..c65c1f056 100644 --- a/src/pcf/metrics.c +++ b/src/pcf/metrics.c @@ -52,12 +52,12 @@ pcf_metrics_spec_def_t pcf_metrics_spec_def_global[_PCF_METR_GLOB_MAX] = { /* Global Counters: */ /* Global Gauges: */ }; -static int pcf_metrics_init_inst_global(void) +int pcf_metrics_init_inst_global(void) { return pcf_metrics_init_inst(pcf_metrics_inst_global, pcf_metrics_spec_global, _PCF_METR_GLOB_MAX, 0, NULL); } -static int pcf_metrics_free_inst_global(void) +int pcf_metrics_free_inst_global(void) { return pcf_metrics_free_inst(pcf_metrics_inst_global, _PCF_METR_GLOB_MAX); } @@ -282,8 +282,6 @@ int pcf_metrics_close(void) ogs_hash_index_t *hi; ogs_metrics_context_t *ctx = ogs_metrics_self(); - pcf_metrics_free_inst_global(); - if (metrics_hash_by_slice) { for (hi = ogs_hash_first(metrics_hash_by_slice); hi; hi = ogs_hash_next(hi)) { pcf_metric_key_by_slice_t *key = diff --git a/src/pcf/metrics.h b/src/pcf/metrics.h index e229837af..ebe86ddb9 100644 --- a/src/pcf/metrics.h +++ b/src/pcf/metrics.h @@ -12,6 +12,9 @@ typedef enum pcf_metric_type_global_s { } pcf_metric_type_global_t; extern ogs_metrics_inst_t *pcf_metrics_inst_global[_PCF_METR_GLOB_MAX]; +int pcf_metrics_init_inst_global(void); +int pcf_metrics_free_inst_global(void); + static inline void pcf_metrics_inst_global_set(pcf_metric_type_global_t t, int val) { ogs_metrics_inst_set(pcf_metrics_inst_global[t], val); } static inline void pcf_metrics_inst_global_add(pcf_metric_type_global_t t, int val) diff --git a/src/pcf/sm-sm.c b/src/pcf/sm-sm.c index 5067a79c3..92de11b44 100644 --- a/src/pcf/sm-sm.c +++ b/src/pcf/sm-sm.c @@ -296,6 +296,9 @@ void pcf_sm_state_deleted(ogs_fsm_t *s, pcf_event_t *e) switch (e->h.id) { case OGS_FSM_ENTRY_SIG: + ogs_assert(sess->pcf_ue); + pcf_metrics_inst_by_slice_add(&sess->pcf_ue->guami.plmn_id, + &sess->s_nssai, PCF_METR_GAUGE_PA_SESSIONNBR, -1); break; case OGS_FSM_EXIT_SIG: @@ -325,6 +328,9 @@ void pcf_sm_state_exception(ogs_fsm_t *s, pcf_event_t *e) switch (e->h.id) { case OGS_FSM_ENTRY_SIG: + ogs_assert(sess->pcf_ue); + pcf_metrics_inst_by_slice_add(&sess->pcf_ue->guami.plmn_id, + &sess->s_nssai, PCF_METR_GAUGE_PA_SESSIONNBR, -1); break; case OGS_FSM_EXIT_SIG: diff --git a/src/smf/context.c b/src/smf/context.c index b078ad45d..8b8eab4e4 100644 --- a/src/smf/context.c +++ b/src/smf/context.c @@ -2441,11 +2441,6 @@ int smf_bearer_remove(smf_bearer_t *bearer) ogs_assert(bearer); ogs_assert(bearer->sess); - if (SMF_IS_QOF_FLOW(bearer)) - smf_metrics_inst_by_5qi_add(&bearer->sess->plmn_id, - &bearer->sess->s_nssai, bearer->sess->session.qos.index, - SMF_METR_GAUGE_SM_QOSFLOWNBR, -1); - ogs_list_remove(&bearer->sess->bearer_list, bearer); ogs_assert(bearer->dl_pdr); @@ -3097,10 +3092,6 @@ static void stats_remove_smf_session(smf_sess_t *sess) { ogs_assert(sess); - if (sess->s_nssai.sst != 0) { - smf_metrics_inst_by_slice_add(&sess->plmn_id, &sess->s_nssai, - SMF_METR_GAUGE_SM_SESSIONNBR, -1); - } num_of_smf_sess = num_of_smf_sess - 1; ogs_info("[Removed] Number of SMF-Sessions is now %d", num_of_smf_sess); } diff --git a/src/smf/gsm-sm.c b/src/smf/gsm-sm.c index 09e3ef7a9..3fee8d941 100644 --- a/src/smf/gsm-sm.c +++ b/src/smf/gsm-sm.c @@ -1585,6 +1585,8 @@ void smf_gsm_state_session_will_release(ogs_fsm_t *s, smf_event_t *e) switch (e->h.id) { case OGS_FSM_ENTRY_SIG: + smf_metrics_inst_by_slice_add(&sess->plmn_id, &sess->s_nssai, + SMF_METR_GAUGE_SM_SESSIONNBR, -1); SMF_SESS_CLEAR(sess); break; @@ -1615,6 +1617,8 @@ void smf_gsm_state_exception(ogs_fsm_t *s, smf_event_t *e) switch (e->h.id) { case OGS_FSM_ENTRY_SIG: ogs_error("[%s:%d] State machine exception", smf_ue->supi, sess->psi); + smf_metrics_inst_by_slice_add(&sess->plmn_id, &sess->s_nssai, + SMF_METR_GAUGE_SM_SESSIONNBR, -1); SMF_SESS_CLEAR(sess); break; diff --git a/src/smf/n4-handler.c b/src/smf/n4-handler.c index b345d8923..14687db98 100644 --- a/src/smf/n4-handler.c +++ b/src/smf/n4-handler.c @@ -495,8 +495,14 @@ void smf_5gc_n4_handle_session_modification_response( smf_namf_comm_send_n1_n2_message_transfer(sess, ¶m); ogs_list_for_each_entry_safe(&sess->qos_flow_to_modify_list, - next, qos_flow, to_modify_node) + next, qos_flow, to_modify_node) { + smf_metrics_inst_by_5qi_add( + &qos_flow->sess->plmn_id, + &qos_flow->sess->s_nssai, + qos_flow->sess->session.qos.index, + SMF_METR_GAUGE_SM_QOSFLOWNBR, -1); smf_bearer_remove(qos_flow); + } } else if (flags & OGS_PFCP_MODIFY_UE_REQUESTED) { ogs_pkbuf_t *n1smbuf = NULL, *n2smbuf = NULL; @@ -521,8 +527,14 @@ void smf_5gc_n4_handle_session_modification_response( OpenAPI_n2_sm_info_type_PDU_RES_MOD_REQ, n2smbuf); ogs_list_for_each_entry_safe(&sess->qos_flow_to_modify_list, - next, qos_flow, to_modify_node) + next, qos_flow, to_modify_node) { + smf_metrics_inst_by_5qi_add( + &qos_flow->sess->plmn_id, + &qos_flow->sess->s_nssai, + qos_flow->sess->session.qos.index, + SMF_METR_GAUGE_SM_QOSFLOWNBR, -1); smf_bearer_remove(qos_flow); + } } else { ogs_fatal("Unknown flags [0x%llx]", (long long)flags); diff --git a/src/upf/metrics.c b/src/upf/metrics.c index 3949062af..f87332a92 100644 --- a/src/upf/metrics.c +++ b/src/upf/metrics.c @@ -82,12 +82,12 @@ upf_metrics_spec_def_t upf_metrics_spec_def_global[_UPF_METR_GLOB_MAX] = { .description = "Active Sessions", }, }; -static int upf_metrics_init_inst_global(void) +int upf_metrics_init_inst_global(void) { return upf_metrics_init_inst(upf_metrics_inst_global, upf_metrics_spec_global, _UPF_METR_GLOB_MAX, 0, NULL); } -static int upf_metrics_free_inst_global(void) +int upf_metrics_free_inst_global(void) { return upf_metrics_free_inst(upf_metrics_inst_global, _UPF_METR_GLOB_MAX); } @@ -341,7 +341,6 @@ int upf_metrics_close(void) { ogs_hash_index_t *hi; ogs_metrics_context_t *ctx = ogs_metrics_self(); - upf_metrics_free_inst_global(); if (metrics_hash_by_qfi) { for (hi = ogs_hash_first(metrics_hash_by_qfi); hi; hi = ogs_hash_next(hi)) { diff --git a/src/upf/metrics.h b/src/upf/metrics.h index ebd579671..13d99179b 100644 --- a/src/upf/metrics.h +++ b/src/upf/metrics.h @@ -19,6 +19,9 @@ typedef enum upf_metric_type_global_s { } upf_metric_type_global_t; extern ogs_metrics_inst_t *upf_metrics_inst_global[_UPF_METR_GLOB_MAX]; +int upf_metrics_init_inst_global(void); +int upf_metrics_free_inst_global(void); + static inline void upf_metrics_inst_global_set(upf_metric_type_global_t t, int val) { ogs_metrics_inst_set(upf_metrics_inst_global[t], val); } static inline void upf_metrics_inst_global_add(upf_metric_type_global_t t, int val)