From b1d982a1eeb0af4c56c8273b14b517be88eddd35 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Thu, 30 Jun 2022 10:35:03 +0900 Subject: [PATCH] [PFCP] Refine error code path without assertion Refer to #1635, #1620 --- src/sgwc/pfcp-path.c | 4 ++++ src/sgwc/pfcp-sm.c | 30 +++++++++++++----------------- src/sgwc/s11-handler.c | 1 + src/smf/pfcp-path.c | 2 -- src/smf/pfcp-sm.c | 18 ++++++------------ src/smf/s5c-handler.c | 1 + 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/sgwc/pfcp-path.c b/src/sgwc/pfcp-path.c index 598c4b932..59bacf2d3 100644 --- a/src/sgwc/pfcp-path.c +++ b/src/sgwc/pfcp-path.c @@ -246,6 +246,7 @@ int sgwc_pfcp_send_session_establishment_request( xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); ogs_expect_or_return_val(xact->gtpbuf, OGS_ERROR); } + xact->local_seid = sess->sgwc_sxa_seid; memset(&h, 0, sizeof(ogs_pfcp_header_t)); h.type = OGS_PFCP_SESSION_ESTABLISHMENT_REQUEST_TYPE; @@ -281,6 +282,7 @@ int sgwc_pfcp_send_session_modification_request( xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); ogs_expect_or_return_val(xact->gtpbuf, OGS_ERROR); } + xact->local_seid = sess->sgwc_sxa_seid; ogs_list_for_each(&sess->bearer_list, bearer) ogs_list_add(&xact->bearer_to_modify_list, &bearer->to_modify_node); @@ -311,6 +313,7 @@ int sgwc_pfcp_send_bearer_modification_request( xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); ogs_expect_or_return_val(xact->gtpbuf, OGS_ERROR); } + xact->local_seid = sess->sgwc_sxa_seid; ogs_list_add(&xact->bearer_to_modify_list, &bearer->to_modify_node); @@ -348,6 +351,7 @@ int sgwc_pfcp_send_session_deletion_request( xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); ogs_expect_or_return_val(xact->gtpbuf, OGS_ERROR); } + xact->local_seid = sess->sgwc_sxa_seid; memset(&h, 0, sizeof(ogs_pfcp_header_t)); h.type = OGS_PFCP_SESSION_DELETION_REQUEST_TYPE; diff --git a/src/sgwc/pfcp-sm.c b/src/sgwc/pfcp-sm.c index c962759ae..76bdb8371 100644 --- a/src/sgwc/pfcp-sm.c +++ b/src/sgwc/pfcp-sm.c @@ -183,8 +183,16 @@ void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e) xact = e->pfcp_xact; ogs_assert(xact); - if (message->h.seid_presence && message->h.seid != 0) + if (message->h.seid_presence && message->h.seid != 0) { sess = sgwc_sess_find_by_seid(message->h.seid); + } else if (xact->local_seid) { /* rx no SEID or SEID=0 */ + /* 3GPP TS 29.244 7.2.2.4.2: we receive SEID=0 under some + * conditions, such as cause "Session context not found". In those + * cases, we still want to identify the local session which + * originated the message, so try harder by using the SEID we + * locacally stored in xact when sending the original request: */ + sess = sgwc_sess_find_by_seid(xact->local_seid); + } switch (message->h.type) { case OGS_PFCP_HEARTBEAT_REQUEST_TYPE: @@ -208,10 +216,7 @@ void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e) &message->pfcp_association_setup_response); break; case OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE: - if (!message->h.seid_presence) { - ogs_error("No SEID"); - break; - } + if (!message->h.seid_presence) ogs_error("No SEID"); sgwc_sxa_handle_session_establishment_response( sess, xact, e->gtp_message, @@ -219,10 +224,7 @@ void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e) break; case OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE: - if (!message->h.seid_presence) { - ogs_error("No SEID"); - break; - } + if (!message->h.seid_presence) ogs_error("No SEID"); sgwc_sxa_handle_session_modification_response( sess, xact, e->gtp_message, @@ -230,10 +232,7 @@ void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e) break; case OGS_PFCP_SESSION_DELETION_RESPONSE_TYPE: - if (!message->h.seid_presence) { - ogs_error("No SEID"); - break; - } + if (!message->h.seid_presence) ogs_error("No SEID"); sgwc_sxa_handle_session_deletion_response( sess, xact, e->gtp_message, @@ -241,10 +240,7 @@ void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e) break; case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE: - if (!message->h.seid_presence) { - ogs_error("No SEID"); - break; - } + if (!message->h.seid_presence) ogs_error("No SEID"); sgwc_sxa_handle_session_report_request( sess, xact, &message->pfcp_session_report_request); diff --git a/src/sgwc/s11-handler.c b/src/sgwc/s11-handler.c index 1b580ed29..708679a19 100644 --- a/src/sgwc/s11-handler.c +++ b/src/sgwc/s11-handler.c @@ -480,6 +480,7 @@ void sgwc_s11_handle_modify_bearer_request( current_xact->gtpbuf = ogs_pkbuf_copy(gtpbuf); ogs_assert(current_xact->gtpbuf); } + current_xact->local_seid = sess->sgwc_sxa_seid; ogs_list_add(&pfcp_xact_list, ¤t_xact->tmpnode); } diff --git a/src/smf/pfcp-path.c b/src/smf/pfcp-path.c index e2b9e1c0f..0c9425ccd 100644 --- a/src/smf/pfcp-path.c +++ b/src/smf/pfcp-path.c @@ -329,8 +329,6 @@ int smf_pfcp_send_modify_list( ogs_assert(sess); ogs_assert(xact); - xact->local_seid = sess->smf_n4_seid; - memset(&h, 0, sizeof(ogs_pfcp_header_t)); h.type = OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE; h.seid = sess->upf_n4_seid; diff --git a/src/smf/pfcp-sm.c b/src/smf/pfcp-sm.c index 329b60e74..55cc78293 100644 --- a/src/smf/pfcp-sm.c +++ b/src/smf/pfcp-sm.c @@ -220,8 +220,8 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) &message->pfcp_association_setup_response); break; case OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE: - if (!message->h.seid_presence) - ogs_error("No SEID"); + if (!message->h.seid_presence) ogs_error("No SEID"); + if (!sess) { ogs_gtp_xact_t *gtp_xact = xact->assoc_xact; ogs_assert(gtp_xact); @@ -239,10 +239,7 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) break; case OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE: - if (!message->h.seid_presence) { - ogs_error("No SEID"); - break; - } + if (!message->h.seid_presence) ogs_error("No SEID"); if (xact->epc) smf_epc_n4_handle_session_modification_response( @@ -254,8 +251,8 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) break; case OGS_PFCP_SESSION_DELETION_RESPONSE_TYPE: - if (!message->h.seid_presence) - ogs_error("No SEID"); + if (!message->h.seid_presence) ogs_error("No SEID"); + if (!sess) { ogs_gtp_xact_t *gtp_xact = xact->assoc_xact; if (!gtp_xact) @@ -275,10 +272,7 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) break; case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE: - if (!message->h.seid_presence) { - ogs_error("No SEID"); - break; - } + if (!message->h.seid_presence) ogs_error("No SEID"); smf_n4_handle_session_report_request( sess, xact, &message->pfcp_session_report_request); diff --git a/src/smf/s5c-handler.c b/src/smf/s5c-handler.c index a7b30c979..cbc232056 100644 --- a/src/smf/s5c-handler.c +++ b/src/smf/s5c-handler.c @@ -556,6 +556,7 @@ void smf_s5c_handle_modify_bearer_request( pfcp_xact->gtp_pti = OGS_NAS_PROCEDURE_TRANSACTION_IDENTITY_UNASSIGNED; pfcp_xact->gtp_cause = OGS_GTP2_CAUSE_UNDEFINED_VALUE; + pfcp_xact->local_seid = sess->smf_n4_seid; ogs_assert(gtpbuf); pfcp_xact->gtpbuf = ogs_pkbuf_copy(gtpbuf);