From 546a647a3d6ea8cfbf200d5603369b2c665e5201 Mon Sep 17 00:00:00 2001 From: Leonardo Parente Date: Fri, 16 Dec 2022 09:46:57 -0400 Subject: [PATCH] Proper lock the callbacks due to diffrent threads calls --- src/inputs/netprobe/PingProbe.cpp | 6 +++++- src/inputs/netprobe/PingProbe.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/inputs/netprobe/PingProbe.cpp b/src/inputs/netprobe/PingProbe.cpp index 98d0896f7..4c5481f29 100644 --- a/src/inputs/netprobe/PingProbe.cpp +++ b/src/inputs/netprobe/PingProbe.cpp @@ -171,7 +171,10 @@ bool PingProbe::start(std::shared_ptr io_loop) } }); - _recv_connection = PingReceiver::recv_signal.connect([this](pcpp::Packet &packet, timespec stamp) { _recv(packet, TestType::Ping, _name, stamp); }); + _recv_connection = PingReceiver::recv_signal.connect([this](pcpp::Packet &packet, timespec stamp) { + std::unique_lock lock(_mutex); + _recv(packet, TestType::Ping, _name, stamp); + }); (_sequence == UCHAR_MAX) ? _sequence = 0 : _sequence++; _send_icmp_v4(_internal_sequence); @@ -296,6 +299,7 @@ void PingProbe::_send_icmp_v4(uint8_t sequence) if (rc != SOCKET_ERROR) { pcpp::Packet packet; packet.addLayer(&icmp); + std::unique_lock lock(_mutex); _send(packet, TestType::Ping, _name, stamp); } } diff --git a/src/inputs/netprobe/PingProbe.h b/src/inputs/netprobe/PingProbe.h index 2c1e413e8..f52901be0 100644 --- a/src/inputs/netprobe/PingProbe.h +++ b/src/inputs/netprobe/PingProbe.h @@ -90,6 +90,7 @@ class PingProbe final : public NetProbe sockaddr_in _sa; sockaddr_in6 _sa6; sigslot::connection _recv_connection; + std::mutex _mutex; void _send_icmp_v4(uint8_t sequence); std::optional _get_addr();