gw: fix race condition

GW thread was checking the default_eps_bearer variable without
protection. RRC could update it when deleting DRB or receiving RRC
connection release.
This commit is contained in:
Andre Puschmann 2021-06-28 10:01:44 +02:00
parent 4d11e5552a
commit 0a16f48869
2 changed files with 73 additions and 73 deletions

View File

@ -22,6 +22,7 @@
#include "srsran/srslog/srslog.h"
#include "tft_packet_filter.h"
#include <atomic>
#include <mutex>
#include <net/if.h>
#include <netinet/in.h>
@ -84,6 +85,7 @@ private:
static const int NOT_ASSIGNED = -1;
int32_t default_eps_bearer_id = NOT_ASSIGNED;
std::mutex gw_mutex;
srslog::basic_logger& logger;

View File

@ -165,11 +165,7 @@ void gw::write_pdu_mch(uint32_t lcid, srsran::unique_byte_buffer_t pdu)
/*******************************************************************************
NAS interface
*******************************************************************************/
int gw::setup_if_addr(uint32_t eps_bearer_id,
uint8_t pdn_type,
uint32_t ip_addr,
uint8_t* ipv6_if_addr,
char* err_str)
int gw::setup_if_addr(uint32_t eps_bearer_id, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_addr, char* err_str)
{
int err;
if (pdn_type == LIBLTE_MME_PDN_TYPE_IPV4 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6) {
@ -212,8 +208,7 @@ bool gw::is_running()
return running;
}
int gw::apply_traffic_flow_template(const uint8_t& erab_id,
const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft)
int gw::apply_traffic_flow_template(const uint8_t& erab_id, const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft)
{
return tft_matcher.apply_traffic_flow_template(erab_id, tft);
}
@ -270,6 +265,8 @@ void gw::run_thread()
break;
}
{
std::unique_lock<std::mutex> lock(gw_mutex);
// Check if IP version makes sense and get packtet length
struct iphdr* ip_pkt = (struct iphdr*)pdu->msg;
struct ipv6hdr* ip6_pkt = (struct ipv6hdr*)pdu->msg;
@ -294,7 +291,9 @@ void gw::run_thread()
if (!register_wait) {
logger.info("UE is not attached, waiting for NAS attach (%d/%d)", register_wait, REGISTER_WAIT_TOUT);
}
usleep(100000);
lock.unlock();
std::this_thread::sleep_for(std::chrono::microseconds(100));
lock.lock();
register_wait++;
}
register_wait = 0;
@ -343,13 +342,12 @@ void gw::run_thread()
idx += N_bytes;
logger.debug("Entire packet not read from socket. Total Length %d, N_Bytes %d.", ip_pkt->tot_len, pdu->N_bytes);
}
} // end of holdering gw_mutex
}
running = false;
logger.info("GW IP receiver thread exiting.");
}
/**************************/
/* TUN Interface Helpers */
/**************************/