From 6d05265d92898edbeb1d04720b7f5626013f4295 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 6 Jun 2019 14:43:59 +0100 Subject: [PATCH] Adding mutex to protect the tft_filter map. --- srsue/hdr/stack/upper/gw.h | 14 ++++++++------ srsue/src/stack/upper/gw.cc | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/srsue/hdr/stack/upper/gw.h b/srsue/hdr/stack/upper/gw.h index b7ecee10a..f89605c52 100644 --- a/srsue/hdr/stack/upper/gw.h +++ b/srsue/hdr/stack/upper/gw.h @@ -22,15 +22,16 @@ #ifndef SRSUE_GW_H #define SRSUE_GW_H -#include +#include "gw_metrics.h" #include "srslte/common/buffer_pool.h" -#include "srslte/common/log.h" #include "srslte/common/common.h" #include "srslte/common/interfaces_common.h" -#include "srslte/interfaces/ue_interfaces.h" +#include "srslte/common/log.h" #include "srslte/common/threads.h" -#include "gw_metrics.h" +#include "srslte/interfaces/ue_interfaces.h" #include "tft_packet_filter.h" +#include +#include namespace srsue { @@ -106,9 +107,10 @@ private: uint32_t mbsfn_ports[SRSLTE_N_MCH_LCIDS]; // Target ports for MBSFN data // TFT + std::mutex tft_mutex; typedef std::map tft_filter_map_t; - tft_filter_map_t tft_filter_map; - + tft_filter_map_t tft_filter_map; + uint8_t check_tft_filter_match(const srslte::unique_byte_buffer_t& pdu); }; diff --git a/srsue/src/stack/upper/gw.cc b/srsue/src/stack/upper/gw.cc index 57527709a..a2c924aff 100644 --- a/srsue/src/stack/upper/gw.cc +++ b/srsue/src/stack/upper/gw.cc @@ -223,6 +223,8 @@ int gw::apply_traffic_flow_template(const uint8_t& const uint8_t& lcid, const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft) { + int err = SRSLTE_SUCCESS; + tft_mutex.lock(); switch (tft->tft_op_code) { case LIBLTE_MME_TFT_OPERATION_CODE_CREATE_NEW_TFT: for (int i = 0; i < tft->packet_filter_list_size; i++) { @@ -231,15 +233,17 @@ int gw::apply_traffic_flow_template(const uint8_t& auto it = tft_filter_map.insert(std::make_pair(filter.eval_precedence, filter)); if (it.second == false) { gw_log->error("Error inserting TFT Packet Filter\n"); - return SRSLTE_ERROR_CANT_START; + err = SRSLTE_ERROR_CANT_START; + break; } } break; default: gw_log->error("Unhandled TFT OP code\n"); - return SRSLTE_ERROR_CANT_START; + err = SRSLTE_ERROR_CANT_START; } - return SRSLTE_SUCCESS; + tft_mutex.unlock(); + return err; } /******************************************************************************* @@ -354,16 +358,16 @@ void gw::run_thread() uint8_t gw::check_tft_filter_match(const srslte::unique_byte_buffer_t& pdu) { uint8_t lcid = default_lcid; - if(!tft_filter_map.empty()){ - for (std::pair& filter_pair : tft_filter_map) { - bool match = filter_pair.second.match(pdu); - if (match) { - lcid = filter_pair.second.lcid; - gw_log->info("Found filter match -- EPS bearer Id %d, LCID %d\n", filter_pair.second.eps_bearer_id, lcid); - break; - } + tft_mutex.lock(); + for (std::pair& filter_pair : tft_filter_map) { + bool match = filter_pair.second.match(pdu); + if (match) { + lcid = filter_pair.second.lcid; + gw_log->info("Found filter match -- EPS bearer Id %d, LCID %d\n", filter_pair.second.eps_bearer_id, lcid); + break; } } + tft_mutex.unlock(); return lcid; }