From 1e65d1069d0a5c77edec74e06b42617186cd2292 Mon Sep 17 00:00:00 2001 From: Spencer Sevilla Date: Fri, 27 Jan 2023 19:46:18 -0800 Subject: [PATCH] [smf][sgwc] fix upf/sgwc assignment when no_pfcp_rr_select: true (#67) --- src/sgwc/context.c | 10 ++++++++-- src/sgwc/s11-handler.c | 3 +-- src/smf/context.c | 10 ++++++++-- src/smf/gn-handler.c | 5 ++--- src/smf/npcf-handler.c | 3 +-- src/smf/s5c-handler.c | 3 +-- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/sgwc/context.c b/src/sgwc/context.c index 487f53cd05..6dea6925b8 100644 --- a/src/sgwc/context.c +++ b/src/sgwc/context.c @@ -402,8 +402,9 @@ static ogs_pfcp_node_t *selected_sgwu_node( } } - ogs_error("No SGWUs are PFCP associated that are suited to RR"); - return ogs_list_first(&ogs_pfcp_self()->pfcp_peer_list); + // If we get here, it means no suitable SGWU can be found + ogs_error("No SGWUs are PFCP associated that are suited to RR for UE TAC %u", sess->sgwc_ue->e_tai.tac); + return NULL; } void sgwc_sess_select_sgwu(sgwc_sess_t *sess) @@ -423,6 +424,11 @@ void sgwc_sess_select_sgwu(sgwc_sess_t *sess) /* setup GTP session with selected SGW-U */ ogs_pfcp_self()->pfcp_node = selected_sgwu_node(ogs_pfcp_self()->pfcp_node, sess); + + if (ogs_pfcp_self()->pfcp_node == NULL) { + return; + } + ogs_assert(ogs_pfcp_self()->pfcp_node); OGS_SETUP_PFCP_NODE(sess, ogs_pfcp_self()->pfcp_node); ogs_debug("UE using SGW-U on IP[%s]", diff --git a/src/sgwc/s11-handler.c b/src/sgwc/s11-handler.c index f6fe9c319c..e0b415b5f8 100644 --- a/src/sgwc/s11-handler.c +++ b/src/sgwc/s11-handler.c @@ -260,8 +260,7 @@ void sgwc_s11_handle_create_session_request( sgwc_sess_select_sgwu(sess); /* Check if selected SGW-U is associated with SGW-C */ - ogs_assert(sess->pfcp_node); - if (!OGS_FSM_CHECK(&sess->pfcp_node->sm, sgwc_pfcp_state_associated)) { + if (!sess->pfcp_node || !OGS_FSM_CHECK(&sess->pfcp_node->sm, sgwc_pfcp_state_associated)) { ogs_gtp_send_error_message( s11_xact, sgwc_ue ? sgwc_ue->mme_s11_teid : 0, OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE, diff --git a/src/smf/context.c b/src/smf/context.c index 511aa9cad6..179c9ff883 100644 --- a/src/smf/context.c +++ b/src/smf/context.c @@ -1169,8 +1169,9 @@ static ogs_pfcp_node_t *selected_upf_node( } } - ogs_error("No UPFs are PFCP associated that are suited to RR"); - return ogs_list_first(&ogs_pfcp_self()->pfcp_peer_list); + // If we get here, it means no suitable UPF can be found + ogs_error("No UPFs are PFCP associated that are suited to RR for UE TAC %u", sess->e_tai.tac); + return NULL; } void smf_sess_select_upf(smf_sess_t *sess) @@ -1190,6 +1191,11 @@ void smf_sess_select_upf(smf_sess_t *sess) /* setup GTP session with selected UPF */ ogs_pfcp_self()->pfcp_node = selected_upf_node(ogs_pfcp_self()->pfcp_node, sess); + + if (ogs_pfcp_self()->pfcp_node == NULL) { + return; + } + ogs_assert(ogs_pfcp_self()->pfcp_node); OGS_SETUP_PFCP_NODE(sess, ogs_pfcp_self()->pfcp_node); ogs_debug("UE using UPF on IP[%s]", diff --git a/src/smf/gn-handler.c b/src/smf/gn-handler.c index 47a7ca55c3..41f0b9d271 100644 --- a/src/smf/gn-handler.c +++ b/src/smf/gn-handler.c @@ -285,10 +285,9 @@ uint8_t smf_gn_handle_create_pdp_context_request( smf_sess_select_upf(sess); /* Check if selected PGW is associated with SMF */ - ogs_assert(sess->pfcp_node); - if (!OGS_FSM_CHECK(&sess->pfcp_node->sm, smf_pfcp_state_associated)) + if (!sess->pfcp_node || !OGS_FSM_CHECK(&sess->pfcp_node->sm, smf_pfcp_state_associated)) return OGS_GTP1_CAUSE_NO_RESOURCES_AVAILABLE; - + if ((pfcp_cause = smf_sess_set_ue_ip(sess)) != OGS_PFCP_CAUSE_REQUEST_ACCEPTED) { cause_value = gtp_cause_from_pfcp(pfcp_cause, 1); return cause_value; diff --git a/src/smf/npcf-handler.c b/src/smf/npcf-handler.c index 3d2d3f46de..0a3b9cfed5 100644 --- a/src/smf/npcf-handler.c +++ b/src/smf/npcf-handler.c @@ -437,8 +437,7 @@ bool smf_npcf_smpolicycontrol_handle_create( smf_sess_select_upf(sess); /* Check if selected UPF is associated with SMF */ - ogs_assert(sess->pfcp_node); - if (!OGS_FSM_CHECK(&sess->pfcp_node->sm, smf_pfcp_state_associated)) { + if (!sess->pfcp_node || !OGS_FSM_CHECK(&sess->pfcp_node->sm, smf_pfcp_state_associated)) { ogs_error("[%s:%d] No associated UPF", smf_ue->supi, sess->psi); return false; } diff --git a/src/smf/s5c-handler.c b/src/smf/s5c-handler.c index c6bbe4b0f7..f1333ff89d 100644 --- a/src/smf/s5c-handler.c +++ b/src/smf/s5c-handler.c @@ -234,8 +234,7 @@ uint8_t smf_s5c_handle_create_session_request( smf_sess_select_upf(sess); /* Check if selected PGW is associated with SMF */ - ogs_assert(sess->pfcp_node); - if (!OGS_FSM_CHECK(&sess->pfcp_node->sm, smf_pfcp_state_associated)) + if (!sess->pfcp_node || !OGS_FSM_CHECK(&sess->pfcp_node->sm, smf_pfcp_state_associated)) return OGS_GTP2_CAUSE_REMOTE_PEER_NOT_RESPONDING; /* UE IP Address */