From 7274e7c4347ab969f5a2c36ff0b41680444acc81 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Thu, 6 Nov 2025 11:08:38 +0100 Subject: [PATCH] SDAP: guard RX header parsing with enable_sdap and init per-entity !3519 refactored the SDAP to use the QFI from the header rather than pass it to the rx function and got rid of the initialization of QFI to -1. However, entity roles are stored into the drb2qfi table, and the indexing implies that the QFI is known. While in TX it is not an issue since packets are forwarded based on the QFI, in RX the QFI can only be parsed from the heaedr, therefore if headers are disabled (--enable_sdap) the QFI is not there and it is wrong to access the header (`buf[0]`) and looking for it. This commit adds `enable_sdap` to `nr_sdap_entity_t` and initialize it in `nr_sdap_add_entity()` from `sdap->role` (disabled when `NO_SDAP_HEADER`). In `nr_sdap_rx_entity()`, only parse `buf[0]` for QFI and derive `sdap_ul_rx`/`sdap_dl_rx` when `enable_sdap` is true; otherwise, keep `offset=0` and forward payload unchanged. --- openair2/SDAP/nr_sdap/nr_sdap_entity.c | 20 +++++++++++++------- openair2/SDAP/nr_sdap/nr_sdap_entity.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/openair2/SDAP/nr_sdap/nr_sdap_entity.c b/openair2/SDAP/nr_sdap/nr_sdap_entity.c index 389213986e..9056c6e733 100644 --- a/openair2/SDAP/nr_sdap/nr_sdap_entity.c +++ b/openair2/SDAP/nr_sdap/nr_sdap_entity.c @@ -210,15 +210,20 @@ static void nr_sdap_rx_entity(nr_sdap_entity_t *entity, { /* The offset of the SDAP header, it might be 0 if has_sdap_rx is not true in the pdcp entity. */ int offset=0; - uint8_t qfi = buf[0] & 0x3F; // QFI is always the first 6 bits in the first octet - if (qfi >= SDAP_MAX_QFI) { - LOG_E(SDAP, "Invalid QFI %d received in SDAP header\n", qfi); - return; + bool sdap_ul_rx = false; + bool sdap_dl_rx = false; + /* If SDAP header is disabled for this entity, bypass header parsing */ + if (entity->enable_sdap) { + uint8_t qfi = buf[0] & 0x3F; // QFI is always the first 6 bits in the first octet + if (qfi >= SDAP_MAX_QFI) { + LOG_E(SDAP, "Invalid QFI %d received in SDAP header\n", qfi); + return; + } + // Fetch entity role from the qfi2drb_table + sdap_ul_rx = entity->qfi2drb_table[qfi].entity_role & SDAP_UL_RX; // gNB RX entity + sdap_dl_rx = entity->qfi2drb_table[qfi].entity_role & SDAP_DL_RX; // UE RX entity } - // Fetch entity role from the qfi2drb_table - bool sdap_ul_rx = entity->qfi2drb_table[qfi].entity_role & SDAP_UL_RX; // gNB RX entity - bool sdap_dl_rx = entity->qfi2drb_table[qfi].entity_role & SDAP_DL_RX; // UE RX entity if (is_gnb) { // gNB if (sdap_ul_rx) { // UL Data/Control PDU with SDAP header @@ -495,6 +500,7 @@ static void nr_sdap_add_entity(const int is_gnb, const ue_id_t ue_id, const sdap sdap_entity->ue_id = ue_id; sdap_entity->pdusession_id = sdap->pdusession_id; sdap_entity->is_gnb = is_gnb; + sdap_entity->enable_sdap = (sdap->role != NO_SDAP_HEADER); // rx/tx entities sdap_entity->tx_entity = nr_sdap_tx_entity; diff --git a/openair2/SDAP/nr_sdap/nr_sdap_entity.h b/openair2/SDAP/nr_sdap/nr_sdap_entity.h index e96836ac79..9f85ac21cf 100644 --- a/openair2/SDAP/nr_sdap/nr_sdap_entity.h +++ b/openair2/SDAP/nr_sdap/nr_sdap_entity.h @@ -99,6 +99,7 @@ typedef struct nr_sdap_entity_s { /// sdap_tun_read_thread needs to know if we are gNB/UE, so for noS1 mode, /// store which one we are bool is_gnb; + bool enable_sdap; int pdusession_id; int pdusession_sock; pthread_t pdusession_thread;