From 7c009972c7942735a4ba12bdfee2fee41cfb85a5 Mon Sep 17 00:00:00 2001 From: Spencer Sevilla Date: Thu, 2 Feb 2023 11:59:53 -0800 Subject: [PATCH] [mme][sgwc][smf] reorder sanity-checking (#73) --- src/mme/mme-s11-handler.c | 71 ++++++++++++++++++++++++--------------- src/sgwc/s11-handler.c | 28 ++++++++++----- src/sgwc/s5c-handler.c | 52 ++++++++++++++++------------ src/smf/s5c-handler.c | 26 ++++++++------ 4 files changed, 108 insertions(+), 69 deletions(-) diff --git a/src/mme/mme-s11-handler.c b/src/mme/mme-s11-handler.c index e73418fade..f31a4fb63e 100644 --- a/src/mme/mme-s11-handler.c +++ b/src/mme/mme-s11-handler.c @@ -169,6 +169,47 @@ void mme_s11_handle_create_session_response( return; } + /********************* + * Check Cause Value + *********************/ + if (rsp->cause.presence == 0) { + ogs_error("[%s] No Cause [VALUE:%d]", mme_ue->imsi_bcd, session_cause); + cause_value = OGS_GTP2_CAUSE_MANDATORY_IE_MISSING; + } + + if (cause_value != OGS_GTP2_CAUSE_REQUEST_ACCEPTED) { + if (create_action == OGS_GTP_CREATE_IN_ATTACH_REQUEST) { + ogs_error("[%s] Attach reject [Cause:%d]", + mme_ue->imsi_bcd, session_cause); + r = nas_eps_send_attach_reject(mme_ue, + OGS_NAS_EMM_CAUSE_NETWORK_FAILURE, + OGS_NAS_ESM_CAUSE_NETWORK_FAILURE); + ogs_expect(r == OGS_OK); + ogs_assert(r != OGS_ERROR); + } + mme_send_delete_session_or_mme_ue_context_release(mme_ue); + return; + } + + if (session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED && + session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED_PARTIALLY && + session_cause != + OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_NETWORK_PREFERENCE && + session_cause != + OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_SINGLE_ADDRESS_BEARER_ONLY) { + ogs_error("[%s] GTP Cause [VALUE:%d]", mme_ue->imsi_bcd, session_cause); + if (create_action == OGS_GTP_CREATE_IN_ATTACH_REQUEST) { + ogs_error("[%s] Attach reject", mme_ue->imsi_bcd); + r = nas_eps_send_attach_reject(mme_ue, + OGS_NAS_EMM_CAUSE_NETWORK_FAILURE, + OGS_NAS_ESM_CAUSE_NETWORK_FAILURE); + ogs_expect(r == OGS_OK); + ogs_assert(r != OGS_ERROR); + } + mme_send_delete_session_or_mme_ue_context_release(mme_ue); + return; + } + /***************************************** * Check Mandatory/Conditional IE Missing *****************************************/ @@ -218,11 +259,6 @@ void mme_s11_handle_create_session_response( } } - if (rsp->cause.presence == 0) { - ogs_error("[%s] No Cause [VALUE:%d]", mme_ue->imsi_bcd, session_cause); - cause_value = OGS_GTP2_CAUSE_MANDATORY_IE_MISSING; - } - if (cause_value != OGS_GTP2_CAUSE_REQUEST_ACCEPTED) { if (create_action == OGS_GTP_CREATE_IN_ATTACH_REQUEST) { ogs_error("[%s] Attach reject [Cause:%d]", @@ -237,9 +273,9 @@ void mme_s11_handle_create_session_response( return; } - /******************** - * Check Cause Value - ********************/ + /***************************** + * Re-Examine Cause Value(s) + *****************************/ ogs_assert(cause_value == OGS_GTP2_CAUSE_REQUEST_ACCEPTED); for (i = 0; i < OGS_BEARER_PER_UE; i++) { @@ -270,25 +306,6 @@ void mme_s11_handle_create_session_response( } } - if (session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED && - session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED_PARTIALLY && - session_cause != - OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_NETWORK_PREFERENCE && - session_cause != - OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_SINGLE_ADDRESS_BEARER_ONLY) { - ogs_error("[%s] GTP Cause [VALUE:%d]", mme_ue->imsi_bcd, session_cause); - if (create_action == OGS_GTP_CREATE_IN_ATTACH_REQUEST) { - ogs_error("[%s] Attach reject", mme_ue->imsi_bcd); - r = nas_eps_send_attach_reject(mme_ue, - OGS_NAS_EMM_CAUSE_NETWORK_FAILURE, - OGS_NAS_ESM_CAUSE_NETWORK_FAILURE); - ogs_expect(r == OGS_OK); - ogs_assert(r != OGS_ERROR); - } - mme_send_delete_session_or_mme_ue_context_release(mme_ue); - return; - } - /******************** * Check ALL Context ********************/ diff --git a/src/sgwc/s11-handler.c b/src/sgwc/s11-handler.c index e0b415b5f8..27572a0dca 100644 --- a/src/sgwc/s11-handler.c +++ b/src/sgwc/s11-handler.c @@ -179,6 +179,25 @@ void sgwc_s11_handle_create_session_request( return; } + // sender TEID must be VERY FIRST THING we check/set so that any + // sent error-messages have the correct TEID for handling at mme + if (req->sender_f_teid_for_control_plane.presence == 0) { + ogs_error("No Sender F-TEID"); + cause_value = OGS_GTP2_CAUSE_MANDATORY_IE_MISSING; + } + + if (cause_value != OGS_GTP2_CAUSE_REQUEST_ACCEPTED) { + ogs_gtp_send_error_message( + s11_xact, sgwc_ue ? sgwc_ue->mme_s11_teid : 0, + OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE, cause_value); + return; + } + + /* Receive Control Plane(DL) : MME-S11 */ + mme_s11_teid = req->sender_f_teid_for_control_plane.data; + ogs_assert(mme_s11_teid); + sgwc_ue->mme_s11_teid = be32toh(mme_s11_teid->teid); + /***************************************** * Check Mandatory/Conditional IE Missing *****************************************/ @@ -204,10 +223,6 @@ void sgwc_s11_handle_create_session_request( ogs_error("No APN"); cause_value = OGS_GTP2_CAUSE_MANDATORY_IE_MISSING; } - if (req->sender_f_teid_for_control_plane.presence == 0) { - ogs_error("No Sender F-TEID"); - cause_value = OGS_GTP2_CAUSE_MANDATORY_IE_MISSING; - } if (req->pgw_s5_s8_address_for_control_plane_or_pmip.presence == 0) { ogs_error("No PGW IP"); cause_value = OGS_GTP2_CAUSE_CONDITIONAL_IE_MISSING; @@ -363,11 +378,6 @@ void sgwc_s11_handle_create_session_request( } } - /* Receive Control Plane(DL) : MME-S11 */ - mme_s11_teid = req->sender_f_teid_for_control_plane.data; - ogs_assert(mme_s11_teid); - sgwc_ue->mme_s11_teid = be32toh(mme_s11_teid->teid); - /* Receive Control Plane(UL) : PGW-S5C */ pgw_s5c_teid = req->pgw_s5_s8_address_for_control_plane_or_pmip.data; ogs_assert(pgw_s5c_teid); diff --git a/src/sgwc/s5c-handler.c b/src/sgwc/s5c-handler.c index 8206f68204..5acb72d3f4 100644 --- a/src/sgwc/s5c-handler.c +++ b/src/sgwc/s5c-handler.c @@ -128,6 +128,32 @@ void sgwc_s5c_handle_create_session_response( return; } + /********************* + * Check Cause Value + *********************/ + if (rsp->cause.presence == 0) { + ogs_error("No Cause [VALUE:%d]", session_cause); + cause_value = OGS_GTP2_CAUSE_CONDITIONAL_IE_MISSING; + ogs_gtp_send_error_message( + s11_xact, sgwc_ue ? sgwc_ue->mme_s11_teid : 0, + OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE, cause_value); + ogs_assert(OGS_OK == sgwc_pfcp_send_session_deletion_request(sess, NULL, NULL)); + return; + } + + if (session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED && + session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED_PARTIALLY && + session_cause != + OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_NETWORK_PREFERENCE && + session_cause != + OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_SINGLE_ADDRESS_BEARER_ONLY) { + ogs_error("GTP Cause [VALUE:%d]", session_cause); + ogs_gtp_send_error_message( + s11_xact, sgwc_ue ? sgwc_ue->mme_s11_teid : 0, + OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE, session_cause); + return; + } + /***************************************** * Check Mandatory/Conditional IE Missing *****************************************/ @@ -154,21 +180,16 @@ void sgwc_s5c_handle_create_session_response( cause_value = OGS_GTP2_CAUSE_CONDITIONAL_IE_MISSING; } - if (rsp->cause.presence == 0) { - ogs_error("No Cause [VALUE:%d]", session_cause); - cause_value = OGS_GTP2_CAUSE_CONDITIONAL_IE_MISSING; - } - if (cause_value != OGS_GTP2_CAUSE_REQUEST_ACCEPTED) { ogs_gtp_send_error_message( s11_xact, sgwc_ue ? sgwc_ue->mme_s11_teid : 0, OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE, cause_value); return; } - - /******************** - * Check Cause Value - ********************/ + + /***************************** + * Re-Examine Cause Value(s) + *****************************/ ogs_assert(cause_value == OGS_GTP2_CAUSE_REQUEST_ACCEPTED); for (i = 0; i < OGS_BEARER_PER_UE; i++) { @@ -192,19 +213,6 @@ void sgwc_s5c_handle_create_session_response( } } - if (session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED && - session_cause != OGS_GTP2_CAUSE_REQUEST_ACCEPTED_PARTIALLY && - session_cause != - OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_NETWORK_PREFERENCE && - session_cause != - OGS_GTP2_CAUSE_NEW_PDN_TYPE_DUE_TO_SINGLE_ADDRESS_BEARER_ONLY) { - ogs_error("GTP Cause [VALUE:%d]", session_cause); - ogs_gtp_send_error_message( - s11_xact, sgwc_ue ? sgwc_ue->mme_s11_teid : 0, - OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE, session_cause); - return; - } - /******************** * Check ALL Context ********************/ diff --git a/src/smf/s5c-handler.c b/src/smf/s5c-handler.c index bdabeba190..48ad87ab0c 100644 --- a/src/smf/s5c-handler.c +++ b/src/smf/s5c-handler.c @@ -97,13 +97,24 @@ uint8_t smf_s5c_handle_create_session_request( cause_value = OGS_GTP2_CAUSE_REQUEST_ACCEPTED; - if (req->imsi.presence == 0) { - ogs_error("No IMSI"); - cause_value = OGS_GTP2_CAUSE_CONDITIONAL_IE_MISSING; - } + // sender TEID must be VERY FIRST THING we check/set so that any + // sent error-messages have the correct TEID for handling at sgwc if (req->sender_f_teid_for_control_plane.presence == 0) { ogs_error("No TEID"); cause_value = OGS_GTP2_CAUSE_MANDATORY_IE_MISSING; + return cause_value; + } + + /* Control Plane(DL) : SGW-S5C */ + sgw_s5c_teid = req->sender_f_teid_for_control_plane.data; + ogs_assert(sgw_s5c_teid); + sess->sgw_s5c_teid = be32toh(sgw_s5c_teid->teid); + rv = ogs_gtp2_f_teid_to_ip(sgw_s5c_teid, &sess->sgw_s5c_ip); + ogs_assert(rv == OGS_OK); + + if (req->imsi.presence == 0) { + ogs_error("No IMSI"); + cause_value = OGS_GTP2_CAUSE_CONDITIONAL_IE_MISSING; } if (req->bearer_contexts_to_be_created[0].presence == 0) { ogs_error("No Bearer"); @@ -277,13 +288,6 @@ uint8_t smf_s5c_handle_create_session_request( sess->ipv4 ? OGS_INET_NTOP(&sess->ipv4->addr, buf1) : "", sess->ipv6 ? OGS_INET6_NTOP(&sess->ipv6->addr, buf2) : ""); - /* Control Plane(DL) : SGW-S5C */ - sgw_s5c_teid = req->sender_f_teid_for_control_plane.data; - ogs_assert(sgw_s5c_teid); - sess->sgw_s5c_teid = be32toh(sgw_s5c_teid->teid); - rv = ogs_gtp2_f_teid_to_ip(sgw_s5c_teid, &sess->sgw_s5c_ip); - ogs_assert(rv == OGS_OK); - ogs_debug(" SGW_S5C_TEID[0x%x] SMF_N4_TEID[0x%x]", sess->sgw_s5c_teid, sess->smf_n4_teid);