From e535fbe6a715808fe1fee7f691ec77984467923c Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 23 Sep 2025 10:55:45 +0200 Subject: [PATCH] Replace impossible ID mismatch checks with DevAssert in NGAP functions - Replace error handling for impossible ID mismatches with DevAssert statements - If ngap_get_ue_context() succeeds, returned context must have matching NGAP gNB UE IDs by definition - This catches potential bugs in the lookup function immediately - Affects: handover_required, handover_notify, handover_cancel, ul_ran_status_transfer These checks were logically impossible since we looked up the context using the same IDs we were then checking for mismatch. --- openair3/NGAP/ngap_gNB.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/openair3/NGAP/ngap_gNB.c b/openair3/NGAP/ngap_gNB.c index 8c9ac6a973..46bcf93cad 100644 --- a/openair3/NGAP/ngap_gNB.c +++ b/openair3/NGAP/ngap_gNB.c @@ -293,12 +293,7 @@ int ngap_handover_required(instance_t instance, ngap_handover_required_t *msg) return -1; } - if ((ue_context_p->gNB_ue_ngap_id != msg->gNB_ue_ngap_id)) { - NGAP_ERROR("ue_context_p->gNB_ue_ngap_id %d does not match msg->gNB_ue_ngap_id %d\n", - ue_context_p->gNB_ue_ngap_id, - msg->gNB_ue_ngap_id); - return -1; - } + DevAssert(ue_context_p->gNB_ue_ngap_id == msg->gNB_ue_ngap_id); NGAP_NGAP_PDU_t *pdu = encode_ng_handover_required(msg); if (!pdu) { @@ -434,11 +429,7 @@ static int ngap_gNB_handover_notify(instance_t instance, const ngap_handover_not NGAP_ERROR("Failed to encode Handover Notify: no ue context associated with gNB_ue_ngap_id=%d\n", msg->gNB_ue_ngap_id); return -1; } - - if (ue_context_p->gNB_ue_ngap_id != msg->gNB_ue_ngap_id) { - NGAP_ERROR("Failed to encode Handover Notify: unknown gNB_ue_ngap_id=%d\n", msg->gNB_ue_ngap_id); - return -1; - } + DevAssert(ue_context_p->gNB_ue_ngap_id == msg->gNB_ue_ngap_id); if (ue_context_p->amf_ue_ngap_id != msg->amf_ue_ngap_id) { NGAP_ERROR("Failed to encode Handover Notify: unknown amf_ue_ngap_id=%ld\n", msg->amf_ue_ngap_id); @@ -479,11 +470,7 @@ static int ngap_gNB_handover_cancel(instance_t instance, const ngap_handover_can NGAP_ERROR("Failed to encode Handover Cancel: no UE context for gNB_ue_ngap_id=%d\n", msg->gNB_ue_ngap_id); return -1; } - - if (ue_context_p->gNB_ue_ngap_id != msg->gNB_ue_ngap_id) { - NGAP_ERROR("Failed to encode Handover Cancel: mismatched gNB_ue_ngap_id=%d\n", msg->gNB_ue_ngap_id); - return -1; - } + DevAssert(ue_context_p->gNB_ue_ngap_id == msg->gNB_ue_ngap_id); if (ue_context_p->amf_ue_ngap_id != msg->amf_ue_ngap_id) { NGAP_ERROR("Failed to encode Handover Cancel: mismatched amf_ue_ngap_id=%ld\n", msg->amf_ue_ngap_id); @@ -522,11 +509,13 @@ int ngap_gNB_handle_ul_ran_status_transfer(instance_t instance, const ngap_ran_s DevAssert(ngap_gNB_instance_p != NULL); ngap_gNB_ue_context_t *ue_context_p = ngap_get_ue_context(msg->gnb_ue_ngap_id); - if (!ue_context_p || ue_context_p->gNB_ue_ngap_id != msg->gnb_ue_ngap_id) { + if (!ue_context_p) { NGAP_ERROR("Could not find UE context for gNB_ue_ngap_id %d\n", msg->gnb_ue_ngap_id); return -1; } + DevAssert(ue_context_p->gNB_ue_ngap_id == msg->gnb_ue_ngap_id); + NGAP_NGAP_PDU_t *pdu = encode_ng_ul_ran_status_transfer(msg); if (!pdu) { NGAP_ERROR("Failed to encode UL RAN Status Transfer\n");