Skip to content

Commit 4db69e1

Browse files
alvasMancodebot
authored andcommitted
gtpu: fix gtpu segfault
This was occuring due to the io_broker thread trying to access the map to get the right executor, while the tunnel was being removed from the map by the UE executor.
1 parent 59a10f9 commit 4db69e1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/gtpu/gtpu_demux_impl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ bool gtpu_demux_impl::add_tunnel(gtpu_teid_t teid,
2424
task_executor& tunnel_exec,
2525
gtpu_tunnel_rx_upper_layer_interface* tunnel)
2626
{
27+
std::lock_guard<std::mutex> guard(map_mutex);
2728
if (teid_to_tunnel.find(teid) != teid_to_tunnel.end()) {
2829
logger.error("Tunnel already exists. teid={}", teid);
2930
return false;
@@ -35,6 +36,7 @@ bool gtpu_demux_impl::add_tunnel(gtpu_teid_t teid,
3536

3637
bool gtpu_demux_impl::remove_tunnel(gtpu_teid_t teid)
3738
{
39+
std::lock_guard<std::mutex> guard(map_mutex);
3840
if (teid_to_tunnel.find(teid) == teid_to_tunnel.end()) {
3941
logger.error("Tunnel not found. teid={}", teid);
4042
return false;
@@ -53,7 +55,8 @@ void gtpu_demux_impl::handle_pdu(byte_buffer pdu, const sockaddr_storage& src_ad
5355
}
5456
gtpu_teid_t teid{read_teid};
5557

56-
const auto& it = teid_to_tunnel.find(teid);
58+
std::lock_guard<std::mutex> guard(map_mutex);
59+
const auto& it = teid_to_tunnel.find(teid);
5760
if (it == teid_to_tunnel.end()) {
5861
logger.info("Dropped GTP-U PDU, tunnel not found. teid={}", teid);
5962
return;

lib/gtpu/gtpu_demux_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "srsran/support/executors/task_executor.h"
1616
#include "fmt/format.h"
1717
#include <memory>
18+
#include <mutex>
1819
#include <unordered_map>
1920

2021
namespace srsran {
@@ -47,6 +48,9 @@ class gtpu_demux_impl final : public gtpu_demux
4748
const gtpu_demux_cfg_t cfg;
4849
dlt_pcap& gtpu_pcap;
4950

51+
// The map is modified by accessed the io_broker (to get the right executor)
52+
// and the modified by UE executors when setting up/tearing down.
53+
std::mutex map_mutex;
5054
std::unordered_map<gtpu_teid_t, gtpu_demux_tunnel_ctx_t, gtpu_teid_hasher_t> teid_to_tunnel;
5155

5256
srslog::basic_logger& logger;

0 commit comments

Comments
 (0)