Skip to content

Commit

Permalink
[mme][sgwc][smf] reorder sanity-checking (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencersevilla committed Jan 24, 2024
1 parent 784f15b commit 7c00997
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 69 deletions.
71 changes: 44 additions & 27 deletions src/mme/mme-s11-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************/
Expand Down Expand Up @@ -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]",
Expand All @@ -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++) {
Expand Down Expand Up @@ -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
********************/
Expand Down
28 changes: 19 additions & 9 deletions src/sgwc/s11-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************/
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
52 changes: 30 additions & 22 deletions src/sgwc/s5c-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************/
Expand All @@ -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++) {
Expand All @@ -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
********************/
Expand Down
26 changes: 15 additions & 11 deletions src/smf/s5c-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7c00997

Please sign in to comment.