diff --git a/3rd/fstrm/CMakeLists.txt b/3rd/fstrm/CMakeLists.txt index 982fd713a..ed7f03032 100644 --- a/3rd/fstrm/CMakeLists.txt +++ b/3rd/fstrm/CMakeLists.txt @@ -16,7 +16,7 @@ add_library(fstrm libmy/my_queue_mutex.c ) add_library(fstrm::fstrm ALIAS fstrm) -target_compile_options(fstrm PRIVATE -Wno-pedantic -Wno-unused-variable) +target_compile_options(fstrm PRIVATE -Wno-pedantic -Wno-unused-variable -Wno-unused-but-set-variable) target_include_directories(fstrm PUBLIC diff --git a/cmd/pktvisord/main.cpp b/cmd/pktvisord/main.cpp index f01563b3b..60c3bbed9 100644 --- a/cmd/pktvisord/main.cpp +++ b/cmd/pktvisord/main.cpp @@ -593,7 +593,7 @@ int main(int argc, char *argv[]) // if we are demonized, change to root directory now that (potentially) logs are open if (options.daemon) { #if __has_include() - chdir("/"); + [[maybe_unused]] int result = chdir("/"); #endif } diff --git a/conanfile.txt b/conanfile.txt index c290e3e8e..190ca3b31 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,19 +1,19 @@ [requires] catch2/3.4.0 corrade/2020.06 -cpp-httplib/0.14.0 +cpp-httplib/0.14.1 docopt.cpp/0.6.3 fast-cpp-csv-parser/cci.20211104 json-schema-validator/2.2.0 libmaxminddb/1.7.1 nlohmann_json/3.11.2 -openssl/1.1.1k +openssl/1.1.1w opentelemetry-proto/1.0.0 pcapplusplus/22.11 protobuf/3.21.12 sigslot/1.2.2 spdlog/1.12.0 -uvw/2.12.1 +uvw/3.2.0 libpcap/1.10.4 yaml-cpp/0.8.0 robin-hood-hashing/3.11.5 diff --git a/src/IpPort.h b/src/IpPort.h index bedd177e1..4f3236b81 100644 --- a/src/IpPort.h +++ b/src/IpPort.h @@ -6,6 +6,7 @@ #ifdef __GNUC__ #pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif #include diff --git a/src/Metrics.h b/src/Metrics.h index 44d76ea28..d3c716f51 100644 --- a/src/Metrics.h +++ b/src/Metrics.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include #include #ifdef __GNUC__ @@ -17,6 +16,7 @@ #include #include #include +#include #ifdef __GNUC__ #pragma GCC diagnostic pop #endif diff --git a/src/handlers/dns/v1/DnsStreamHandler.cpp b/src/handlers/dns/v1/DnsStreamHandler.cpp index b4d693528..fff191de1 100644 --- a/src/handlers/dns/v1/DnsStreamHandler.cpp +++ b/src/handlers/dns/v1/DnsStreamHandler.cpp @@ -64,7 +64,7 @@ void DnsStreamHandler::start() _f_rcodes.push_back(NoError); } else if (config_exists("only_rcode")) { std::vector rcodes; - uint64_t want_code; + uint64_t want_code{0}; try { want_code = config_get("only_rcode"); } catch (const std::exception &e) { diff --git a/src/handlers/dns/v2/DnsStreamHandler.cpp b/src/handlers/dns/v2/DnsStreamHandler.cpp index a2454e8df..64cfb4905 100644 --- a/src/handlers/dns/v2/DnsStreamHandler.cpp +++ b/src/handlers/dns/v2/DnsStreamHandler.cpp @@ -64,7 +64,7 @@ void DnsStreamHandler::start() _f_rcodes.push_back(NoError); } else if (config_exists("only_rcode")) { std::vector rcodes; - uint64_t want_code; + uint64_t want_code{0}; try { want_code = config_get("only_rcode"); } catch (const std::exception &e) { diff --git a/src/inputs/dnstap/CMakeLists.txt b/src/inputs/dnstap/CMakeLists.txt index 1da5bf540..33f3f518f 100644 --- a/src/inputs/dnstap/CMakeLists.txt +++ b/src/inputs/dnstap/CMakeLists.txt @@ -4,6 +4,13 @@ set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON) protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS pb/dnstap.proto) +if(NOT WIN32) + # Suppress the warning for the generated files + set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} + PROPERTIES COMPILE_FLAGS "-Wno-missing-declarations -Wno-unused-parameter" + ) +endif() + corrade_add_static_plugin(VisorInputDnstap ${CMAKE_CURRENT_BINARY_DIR} Dnstap.conf DnstapInputModulePlugin.cpp diff --git a/src/inputs/dnstap/DnstapInputStream.cpp b/src/inputs/dnstap/DnstapInputStream.cpp index 645319b27..741c5f356 100644 --- a/src/inputs/dnstap/DnstapInputStream.cpp +++ b/src/inputs/dnstap/DnstapInputStream.cpp @@ -6,12 +6,19 @@ #include "DnstapException.h" #include "ThreadName.h" #include +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif #include #include #include #include #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif namespace visor::input::dnstap { @@ -129,16 +136,16 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() } // main io loop, run in its own thread - _io_loop = uvw::Loop::create(); + _io_loop = uvw::loop::create(); if (!_io_loop) { throw DnstapException("unable to create io loop"); } // AsyncHandle lets us stop the loop from its own thread - _async_h = _io_loop->resource(); + _async_h = _io_loop->resource(); if (!_async_h) { throw DnstapException("unable to initialize AsyncHandle"); } - _async_h->once([this](const auto &, auto &handle) { + _async_h->on([this](const auto &, auto &handle) { _timer->stop(); _timer->close(); _tcp_server_h->stop(); @@ -147,16 +154,16 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() _io_loop->close(); handle.close(); }); - _async_h->on([this](const auto &err, auto &handle) { + _async_h->on([this](const auto &err, auto &handle) { _logger->error("[{}] AsyncEvent error: {}", _name, err.what()); handle.close(); }); - _timer = _io_loop->resource(); + _timer = _io_loop->resource(); if (!_timer) { throw DnstapException("unable to initialize TimerHandle"); } - _timer->on([this](const auto &, auto &) { + _timer->on([this](const auto &, auto &) { timespec stamp; // use now() std::timespec_get(&stamp, TIME_UTC); @@ -165,25 +172,25 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() static_cast(proxy.get())->heartbeat_cb(stamp); } }); - _timer->on([this](const auto &err, auto &handle) { + _timer->on([this](const auto &err, auto &handle) { _logger->error("[{}] TimerEvent error: {}", _name, err.what()); handle.close(); }); // setup server socket - _tcp_server_h = _io_loop->resource(); + _tcp_server_h = _io_loop->resource(); if (!_tcp_server_h) { - throw DnstapException("unable to initialize server PipeHandle"); + throw DnstapException("unable to initialize server pipe_handle"); } - _tcp_server_h->on([this](const auto &err, auto &) { + _tcp_server_h->on([this](const auto &err, auto &) { _logger->error("[{}] socket error: {}", _name, err.what()); throw DnstapException(err.what()); }); - // ListenEvent happens on client connection - _tcp_server_h->on([this](const uvw::ListenEvent &, uvw::TCPHandle &) { - auto client = _io_loop->resource(); + // listen_event happens on client connection + _tcp_server_h->on([this](const uvw::listen_event &, uvw::tcp_handle &) { + auto client = _io_loop->resource(); if (!client) { throw DnstapException("unable to initialize connected client TCPHandle"); } @@ -209,14 +216,14 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() } }; - client->on([this](const uvw::ErrorEvent &err, uvw::TCPHandle &c_sock) { + client->on([this](const uvw::error_event &err, uvw::tcp_handle &c_sock) { _logger->error("[{}]: dnstap client socket error: {}", _name, err.what()); c_sock.stop(); c_sock.close(); }); // client sent data - client->on([this](const uvw::DataEvent &data, uvw::TCPHandle &c_sock) { + client->on([this](const uvw::data_event &data, uvw::tcp_handle &c_sock) { assert(_tcp_sessions[c_sock.fd()]); try { _tcp_sessions[c_sock.fd()]->receive_socket_data(reinterpret_cast(data.data.get()), data.length); @@ -227,12 +234,12 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() } }); // client was closed - client->on([this](const uvw::CloseEvent &, uvw::TCPHandle &c_sock) { + client->on([this](const uvw::close_event &, uvw::tcp_handle &c_sock) { _logger->info("[{}]: dnstap client disconnected", _name); _tcp_sessions.erase(c_sock.fd()); }); // client read EOF - client->on([this](const uvw::EndEvent &, uvw::TCPHandle &c_sock) { + client->on([this](const uvw::end_event &, uvw::tcp_handle &c_sock) { _logger->info("[{}]: dnstap client EOF {}", _name, c_sock.peer().ip); c_sock.stop(); c_sock.close(); @@ -240,7 +247,7 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() _tcp_server_h->accept(*client); _logger->info("[{}]: dnstap client connected {}", _name, client->peer().ip); - _tcp_sessions[client->fd()] = std::make_unique>(client, CONTENT_TYPE, on_data_frame); + _tcp_sessions[client->fd()] = std::make_unique>(client, CONTENT_TYPE, on_data_frame); client->read(); }); @@ -250,7 +257,7 @@ void DnstapInputStream::_create_frame_stream_tcp_socket() // spawn the loop _io_thread = std::make_unique([this] { - _timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000}); + _timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000}); thread::change_self_name(schema_key(), name()); _io_loop->run(); }); @@ -260,16 +267,16 @@ void DnstapInputStream::_create_frame_stream_unix_socket() assert(config_exists("socket")); // main io loop, run in its own thread - _io_loop = uvw::Loop::create(); + _io_loop = uvw::loop::create(); if (!_io_loop) { throw DnstapException("unable to create io loop"); } // AsyncHandle lets us stop the loop from its own thread - _async_h = _io_loop->resource(); + _async_h = _io_loop->resource(); if (!_async_h) { throw DnstapException("unable to initialize AsyncHandle"); } - _async_h->once([this](const auto &, auto &handle) { + _async_h->on([this](const auto &, auto &handle) { _timer->stop(); _timer->close(); _unix_server_h->stop(); @@ -278,16 +285,16 @@ void DnstapInputStream::_create_frame_stream_unix_socket() _io_loop->close(); handle.close(); }); - _async_h->on([this](const auto &err, auto &handle) { + _async_h->on([this](const auto &err, auto &handle) { _logger->error("[{}] AsyncEvent error: {}", _name, err.what()); handle.close(); }); - _timer = _io_loop->resource(); + _timer = _io_loop->resource(); if (!_timer) { throw DnstapException("unable to initialize TimerHandle"); } - _timer->on([this](const auto &, auto &) { + _timer->on([this](const auto &, auto &) { timespec stamp; // use now() std::timespec_get(&stamp, TIME_UTC); @@ -296,27 +303,27 @@ void DnstapInputStream::_create_frame_stream_unix_socket() static_cast(proxy.get())->heartbeat_cb(stamp); } }); - _timer->on([this](const auto &err, auto &handle) { + _timer->on([this](const auto &err, auto &handle) { _logger->error("[{}] TimerEvent error: {}", _name, err.what()); handle.close(); }); // setup server socket - _unix_server_h = _io_loop->resource(); + _unix_server_h = _io_loop->resource(); if (!_unix_server_h) { - throw DnstapException("unable to initialize server PipeHandle"); + throw DnstapException("unable to initialize server pipe_handle"); } - _unix_server_h->on([this](const auto &err, auto &) { + _unix_server_h->on([this](const auto &err, auto &) { _logger->error("[{}] socket error: {}", _name, err.what()); throw DnstapException(err.what()); }); - // ListenEvent happens on client connection - _unix_server_h->on([this](const uvw::ListenEvent &, uvw::PipeHandle &) { - auto client = _io_loop->resource(); + // listen_event happens on client connection + _unix_server_h->on([this](const uvw::listen_event &, uvw::pipe_handle &) { + auto client = _io_loop->resource(); if (!client) { - throw DnstapException("unable to initialize connected client PipeHandle"); + throw DnstapException("unable to initialize connected client pipe_handle"); } auto on_data_frame = [this](const void *data, std::size_t len_data) { @@ -339,14 +346,14 @@ void DnstapInputStream::_create_frame_stream_unix_socket() } }; - client->on([this](const uvw::ErrorEvent &err, uvw::PipeHandle &c_sock) { + client->on([this](const uvw::error_event &err, uvw::pipe_handle &c_sock) { _logger->error("[{}]: dnstap client socket error: {}", _name, err.what()); c_sock.stop(); c_sock.close(); }); // client sent data - client->on([this](const uvw::DataEvent &data, uvw::PipeHandle &c_sock) { + client->on([this](const uvw::data_event &data, uvw::pipe_handle &c_sock) { assert(_unix_sessions[c_sock.fd()]); try { _unix_sessions[c_sock.fd()]->receive_socket_data(reinterpret_cast(data.data.get()), data.length); @@ -357,12 +364,12 @@ void DnstapInputStream::_create_frame_stream_unix_socket() } }); // client was closed - client->on([this](const uvw::CloseEvent &, uvw::PipeHandle &c_sock) { + client->on([this](const uvw::close_event &, uvw::pipe_handle &c_sock) { _logger->info("[{}]: dnstap client disconnected", _name); _unix_sessions.erase(c_sock.fd()); }); // client read EOF - client->on([this](const uvw::EndEvent &, uvw::PipeHandle &c_sock) { + client->on([this](const uvw::end_event &, uvw::pipe_handle &c_sock) { _logger->info("[{}]: dnstap client EOF {}", _name, c_sock.sock()); c_sock.stop(); c_sock.close(); @@ -370,7 +377,7 @@ void DnstapInputStream::_create_frame_stream_unix_socket() _unix_server_h->accept(*client); _logger->info("[{}]: dnstap client connected {}", _name, client->sock()); - _unix_sessions[client->fd()] = std::make_unique>(client, CONTENT_TYPE, on_data_frame); + _unix_sessions[client->fd()] = std::make_unique>(client, CONTENT_TYPE, on_data_frame); client->read(); }); @@ -383,7 +390,7 @@ void DnstapInputStream::_create_frame_stream_unix_socket() // spawn the loop _io_thread = std::make_unique([this] { - _timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000}); + _timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000}); thread::change_self_name(schema_key(), name()); _io_loop->run(); }); diff --git a/src/inputs/dnstap/DnstapInputStream.h b/src/inputs/dnstap/DnstapInputStream.h index c094c57f2..df3ccdbb0 100644 --- a/src/inputs/dnstap/DnstapInputStream.h +++ b/src/inputs/dnstap/DnstapInputStream.h @@ -30,11 +30,11 @@ #include namespace uvw { -class Loop; -class AsyncHandle; -class PipeHandle; -class TCPHandle; -class TimerHandle; +class loop; +class async_handle; +class pipe_handle; +class tcp_handle; +class timer_handle; } struct fstrm_reader; @@ -48,15 +48,15 @@ class DnstapInputStream : public visor::InputStream std::shared_ptr _logger; std::unique_ptr _io_thread; - std::shared_ptr _io_loop; - std::shared_ptr _async_h; - std::shared_ptr _timer; + std::shared_ptr _io_loop; + std::shared_ptr _async_h; + std::shared_ptr _timer; - std::shared_ptr _unix_server_h; - std::unordered_map>> _unix_sessions; + std::shared_ptr _unix_server_h; + std::unordered_map>> _unix_sessions; - std::shared_ptr _tcp_server_h; - std::unordered_map>> _tcp_sessions; + std::shared_ptr _tcp_server_h; + std::unordered_map>> _tcp_sessions; static const inline ConfigsDefType _config_defs = { "tcp", diff --git a/src/inputs/flow/FlowInputStream.cpp b/src/inputs/flow/FlowInputStream.cpp index 18bf8287f..0fc19f491 100644 --- a/src/inputs/flow/FlowInputStream.cpp +++ b/src/inputs/flow/FlowInputStream.cpp @@ -17,14 +17,13 @@ #include #include #include -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - #include #include #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif namespace visor::input::flow { @@ -134,16 +133,16 @@ void FlowInputStream::_create_frame_stream_udp_socket() auto bind = config_get("bind"); auto port = config_get("port"); // main io loop, run in its own thread - _io_loop = uvw::Loop::create(); + _io_loop = uvw::loop::create(); if (!_io_loop) { throw FlowException("unable to create io loop"); } // AsyncHandle lets us stop the loop from its own thread - _async_h = _io_loop->resource(); + _async_h = _io_loop->resource(); if (!_async_h) { throw FlowException("unable to initialize AsyncHandle"); } - _async_h->once([this](const auto &, auto &handle) { + _async_h->on([this](const auto &, auto &handle) { _timer->stop(); _timer->close(); _udp_server_h->stop(); @@ -152,16 +151,16 @@ void FlowInputStream::_create_frame_stream_udp_socket() _io_loop->close(); handle.close(); }); - _async_h->on([this](const auto &err, auto &handle) { + _async_h->on([this](const auto &err, auto &handle) { _logger->error("[{}] AsyncEvent error: {}", _name, err.what()); handle.close(); }); - _timer = _io_loop->resource(); + _timer = _io_loop->resource(); if (!_timer) { throw FlowException("unable to initialize TimerHandle"); } - _timer->on([this](const auto &, auto &) { + _timer->on([this](const auto &, auto &) { timespec stamp; // use now() std::timespec_get(&stamp, TIME_UTC); @@ -170,25 +169,25 @@ void FlowInputStream::_create_frame_stream_udp_socket() static_cast(proxy.get())->heartbeat_cb(stamp); } }); - _timer->on([this](const auto &err, auto &handle) { + _timer->on([this](const auto &err, auto &handle) { _logger->error("[{}] TimerEvent error: {}", _name, err.what()); handle.close(); }); // setup server socket - _udp_server_h = _io_loop->resource(); + _udp_server_h = _io_loop->resource(); if (!_udp_server_h) { - throw FlowException("unable to initialize server PipeHandle"); + throw FlowException("unable to initialize server pipe_handle"); } - _udp_server_h->on([this](const auto &err, auto &) { + _udp_server_h->on([this](const auto &err, auto &) { _logger->error("[{}] socket error: {}", _name, err.what()); throw FlowException(err.what()); }); - // ListenEvent happens on client connection + // listen_event happens on client connection if (_flow_type == Type::SFLOW) { - _udp_server_h->on([this](const uvw::UDPDataEvent &event, uvw::UDPHandle &) { + _udp_server_h->on([this](const uvw::udp_data_event &event, uvw::udp_handle &) { SFSample sample; sample.rawSample = reinterpret_cast(event.data.get()); sample.rawSampleLen = event.length; @@ -207,7 +206,7 @@ void FlowInputStream::_create_frame_stream_udp_socket() } }); } else if (_flow_type == Type::NETFLOW) { - _udp_server_h->on([this](const uvw::UDPDataEvent &event, uvw::UDPHandle &) { + _udp_server_h->on([this](const uvw::udp_data_event &event, uvw::udp_handle &) { NFSample sample; sample.raw_sample = reinterpret_cast(event.data.get()); sample.raw_sample_len = event.length; @@ -228,7 +227,7 @@ void FlowInputStream::_create_frame_stream_udp_socket() // spawn the loop _io_thread = std::make_unique([this] { - _timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000}); + _timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000}); thread::change_self_name(schema_key(), name()); _io_loop->run(); }); diff --git a/src/inputs/flow/FlowInputStream.h b/src/inputs/flow/FlowInputStream.h index 772a5d175..870a61997 100644 --- a/src/inputs/flow/FlowInputStream.h +++ b/src/inputs/flow/FlowInputStream.h @@ -21,10 +21,10 @@ #include namespace uvw { -class Loop; -class AsyncHandle; -class UDPHandle; -class TimerHandle; +class loop; +class async_handle; +class udp_handle; +class timer_handle; } namespace visor::input::flow { @@ -41,11 +41,11 @@ class FlowInputStream : public visor::InputStream std::shared_ptr _logger; std::unique_ptr _io_thread; - std::shared_ptr _io_loop; - std::shared_ptr _async_h; - std::shared_ptr _timer; + std::shared_ptr _io_loop; + std::shared_ptr _async_h; + std::shared_ptr _timer; - std::shared_ptr _udp_server_h; + std::shared_ptr _udp_server_h; static const inline ConfigsDefType _config_defs = { "flow_type", diff --git a/src/inputs/flow/test_flow.cpp b/src/inputs/flow/test_flow.cpp index fa00036e1..bef5e9ba1 100644 --- a/src/inputs/flow/test_flow.cpp +++ b/src/inputs/flow/test_flow.cpp @@ -4,8 +4,15 @@ #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif using namespace visor::input::flow; @@ -59,13 +66,13 @@ TEST_CASE("sflow udp socket", "[sflow][udp]") CHECK_NOTHROW(stream.start()); - auto loop = uvw::Loop::getDefault(); - auto client = loop->resource(); - client->once([](const uvw::SendEvent &, uvw::UDPHandle &handle) { + auto loop = uvw::loop::get_default(); + auto client = loop->resource(); + client->on([](const uvw::send_event &, uvw::udp_handle &handle) { handle.close(); }); auto dataSend = std::unique_ptr(new char[2]{'b', 'c'}); - client->send(uvw::Addr{bind, static_cast(port)}, dataSend.get(), 2); + client->send(uvw::socket_address{bind, static_cast(port)}, dataSend.get(), 2); client->send(bind, port, nullptr, 0); uv_sleep(100); @@ -90,13 +97,13 @@ TEST_CASE("netflow udp socket", "[netflow][udp]") CHECK_NOTHROW(stream.start()); - auto loop = uvw::Loop::getDefault(); - auto client = loop->resource(); - client->once([](const uvw::SendEvent &, uvw::UDPHandle &handle) { + auto loop = uvw::loop::get_default(); + auto client = loop->resource(); + client->on([](const uvw::send_event &, uvw::udp_handle &handle) { handle.close(); }); auto dataSend = std::unique_ptr(new char[2]{'b', 'c'}); - client->send(uvw::Addr{bind, static_cast(port)}, dataSend.get(), 2); + client->send(uvw::socket_address{bind, static_cast(port)}, dataSend.get(), 2); client->send(bind, port, nullptr, 0); uv_sleep(100); diff --git a/src/inputs/netprobe/NetProbe.h b/src/inputs/netprobe/NetProbe.h index 53eb299f9..cd7bec611 100644 --- a/src/inputs/netprobe/NetProbe.h +++ b/src/inputs/netprobe/NetProbe.h @@ -7,15 +7,16 @@ #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif #include #include +#include +#include #ifdef __GNUC__ #pragma GCC diagnostic pop #endif -#include -#include namespace visor::input::netprobe { @@ -55,15 +56,15 @@ class NetProbe std::string _name; pcpp::IPAddress _ip; std::string _dns; - std::shared_ptr _io_loop; + std::shared_ptr _io_loop; RecvCallback _recv; SendCallback _send; FailCallback _fail; std::pair _resolve_dns(bool first_match = true, bool ipv4 = false) { - auto request = _io_loop->resource(); - auto response = request->nodeAddrInfoSync(_dns); + auto request = _io_loop->resource(); + auto response = request->node_addr_info_sync(_dns); if (!response.first) { return {std::string(), false}; } @@ -109,7 +110,7 @@ class NetProbe _fail = fail; } - virtual bool start(std::shared_ptr io_loop) = 0; + virtual bool start(std::shared_ptr io_loop) = 0; virtual bool stop() = 0; }; } \ No newline at end of file diff --git a/src/inputs/netprobe/NetProbeInputStream.cpp b/src/inputs/netprobe/NetProbeInputStream.cpp index f7f77cf41..bad365871 100644 --- a/src/inputs/netprobe/NetProbeInputStream.cpp +++ b/src/inputs/netprobe/NetProbeInputStream.cpp @@ -154,32 +154,32 @@ void NetProbeInputStream::_fail_cb(ErrorType error, TestType type, const std::st void NetProbeInputStream::_create_netprobe_loop() { // main io loop, run in its own thread - _io_loop = uvw::Loop::create(); + _io_loop = uvw::loop::create(); if (!_io_loop) { throw NetProbeException("unable to create io loop"); } // AsyncHandle lets us stop the loop from its own thread - _async_h = _io_loop->resource(); + _async_h = _io_loop->resource(); if (!_async_h) { throw NetProbeException("unable to initialize AsyncHandle"); } - _async_h->once([this](const auto &, auto &handle) { + _async_h->on([this](const auto &, auto &handle) { _timer->stop(); _timer->close(); _io_loop->stop(); _io_loop->close(); handle.close(); }); - _async_h->on([this](const auto &err, auto &handle) { + _async_h->on([this](const auto &err, auto &handle) { _logger->error("[{}] AsyncEvent error: {}", _name, err.what()); handle.close(); }); - _timer = _io_loop->resource(); + _timer = _io_loop->resource(); if (!_timer) { throw NetProbeException("unable to initialize TimerHandle"); } - _timer->on([this](const auto &, auto &) { + _timer->on([this](const auto &, auto &) { timespec stamp; // use now() std::timespec_get(&stamp, TIME_UTC); @@ -188,7 +188,7 @@ void NetProbeInputStream::_create_netprobe_loop() proxy->heartbeat_cb(stamp); } }); - _timer->on([this](const auto &err, auto &handle) { + _timer->on([this](const auto &err, auto &handle) { _logger->error("[{}] TimerEvent error: {}", _name, err.what()); handle.close(); }); @@ -231,7 +231,7 @@ void NetProbeInputStream::_create_netprobe_loop() // spawn the loop _io_thread = std::make_unique([this] { - _timer->start(uvw::TimerHandle::Time{1000}, uvw::TimerHandle::Time{HEARTBEAT_INTERVAL * 1000}); + _timer->start(uvw::timer_handle::time{1000}, uvw::timer_handle::time{HEARTBEAT_INTERVAL * 1000}); thread::change_self_name(schema_key(), name()); _io_loop->run(); }); diff --git a/src/inputs/netprobe/NetProbeInputStream.h b/src/inputs/netprobe/NetProbeInputStream.h index fe9b0e129..a2d4145f0 100644 --- a/src/inputs/netprobe/NetProbeInputStream.h +++ b/src/inputs/netprobe/NetProbeInputStream.h @@ -32,9 +32,9 @@ class NetProbeInputStream : public visor::InputStream std::shared_ptr _logger; std::unique_ptr _io_thread; - std::shared_ptr _io_loop; - std::shared_ptr _async_h; - std::shared_ptr _timer; + std::shared_ptr _io_loop; + std::shared_ptr _async_h; + std::shared_ptr _timer; std::vector> _probes; diff --git a/src/inputs/netprobe/PingProbe.cpp b/src/inputs/netprobe/PingProbe.cpp index 2b408ebcd..5098377dd 100644 --- a/src/inputs/netprobe/PingProbe.cpp +++ b/src/inputs/netprobe/PingProbe.cpp @@ -38,16 +38,16 @@ PingReceiver::~PingReceiver() void PingReceiver::_setup_receiver() { - _io_loop = uvw::Loop::create(); + _io_loop = uvw::loop::create(); if (!_io_loop) { throw NetProbeException("unable to create io loop"); } // AsyncHandle lets us stop the loop from its own thread - _async_h = _io_loop->resource(); + _async_h = _io_loop->resource(); if (!_async_h) { throw NetProbeException("unable to initialize AsyncHandle"); } - _async_h->once([this](const auto &, auto &handle) { + _async_h->on([this](const auto &, auto &handle) { _io_loop->stop(); _io_loop->close(); handle.close(); @@ -75,15 +75,15 @@ void PingReceiver::_setup_receiver() } #endif - _poll = _io_loop->resource(static_cast(_sock)); + _poll = _io_loop->resource(static_cast(_sock)); if (!_poll) { throw NetProbeException("PingProbe - unable to initialize PollHandle"); } - _poll->on([](const auto &, auto &handler) { + _poll->on([](const auto &, auto &handler) { handler.close(); }); - _poll->on([this](const uvw::PollEvent &, uvw::PollHandle &) { + _poll->on([this](const uvw::poll_event &, uvw::poll_handle &) { int rc{0}; while (rc != SOCKET_ERROR) { rc = recv(_sock, _array.data(), _array.size(), 0); @@ -98,8 +98,8 @@ void PingReceiver::_setup_receiver() } }); - _timer = _io_loop->resource(); - _timer->on([this](const auto &, auto &) { + _timer = _io_loop->resource(); + _timer->on([this](const auto &, auto &) { if (!_recv_packets.empty()) { recv_packets = _recv_packets; _recv_packets.clear(); @@ -108,10 +108,10 @@ void PingReceiver::_setup_receiver() } } }); - _timer->start(uvw::TimerHandle::Time{100}, uvw::TimerHandle::Time{100}); + _timer->start(uvw::timer_handle::time{100}, uvw::timer_handle::time{100}); _poll->init(); - _poll->start(uvw::PollHandle::Event::READABLE); + _poll->start(uvw::poll_handle::poll_event_flags::READABLE); // spawn the loop _io_thread = std::make_unique([this] { @@ -120,7 +120,7 @@ void PingReceiver::_setup_receiver() }); } -bool PingProbe::start(std::shared_ptr io_loop) +bool PingProbe::start(std::shared_ptr io_loop) { if (_init || (!_ip.isValid() && _dns.empty())) { return false; @@ -145,11 +145,11 @@ bool PingProbe::start(std::shared_ptr io_loop) _receiver = std::make_unique(); } - _interval_timer = _io_loop->resource(); + _interval_timer = _io_loop->resource(); if (!_interval_timer) { throw NetProbeException("PingProbe - unable to initialize interval TimerHandle"); } - _interval_timer->on([this](const auto &, auto &) { + _interval_timer->on([this](const auto &, auto &) { _internal_sequence = 0; if (auto error = _create_socket(); error.has_value()) { @@ -162,8 +162,8 @@ bool PingProbe::start(std::shared_ptr io_loop) return; } - _internal_timer = _io_loop->resource(); - _internal_timer->on([this](const auto &, auto &handle) { + _internal_timer = _io_loop->resource(); + _internal_timer->on([this](const auto &, auto &handle) { if (_internal_sequence < static_cast(_config.packets_per_test)) { _internal_sequence++; _send_icmp_v4(_internal_sequence); @@ -176,14 +176,14 @@ bool PingProbe::start(std::shared_ptr io_loop) (_sequence == UCHAR_MAX) ? _sequence = 0 : _sequence++; _send_icmp_v4(_internal_sequence); _internal_sequence++; - _internal_timer->start(uvw::TimerHandle::Time{_config.packets_interval_msec}, uvw::TimerHandle::Time{_config.packets_interval_msec}); + _internal_timer->start(uvw::timer_handle::time{_config.packets_interval_msec}, uvw::timer_handle::time{_config.packets_interval_msec}); }); - _recv_handler = _io_loop->resource(); + _recv_handler = _io_loop->resource(); if (!_recv_handler) { throw NetProbeException("PingProbe - unable to initialize AsyncHandle receiver"); } - _recv_handler->on([this](const auto &, auto &) { + _recv_handler->on([this](const auto &, auto &) { // note this processes received packets across ALL active ping probes (because of the single receiver thread) // the expectation is that packets which did not originate from this probe will be ignored by the handler attached to this probe, // since it did not originate from it @@ -195,7 +195,7 @@ bool PingProbe::start(std::shared_ptr io_loop) _recv_handler->init(); ++sock_count; - _interval_timer->start(uvw::TimerHandle::Time{0}, uvw::TimerHandle::Time{_config.interval_msec}); + _interval_timer->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{_config.interval_msec}); _init = true; return true; } @@ -243,8 +243,8 @@ std::optional PingProbe::_get_addr() } // do Dns lookup for interval loop - auto request = _io_loop->resource(); - auto response = request->nodeAddrInfoSync(_dns); + auto request = _io_loop->resource(); + auto response = request->node_addr_info_sync(_dns); if (!response.first) { return ErrorType::DnsLookupFailure; } diff --git a/src/inputs/netprobe/PingProbe.h b/src/inputs/netprobe/PingProbe.h index 01288ad46..1120a8cb3 100644 --- a/src/inputs/netprobe/PingProbe.h +++ b/src/inputs/netprobe/PingProbe.h @@ -54,12 +54,12 @@ class PingReceiver { std::array _array; SOCKET _sock{INVALID_SOCKET}; - std::shared_ptr _poll; + std::shared_ptr _poll; std::unique_ptr _io_thread; - std::shared_ptr _io_loop; - std::shared_ptr _async_h; - std::vector> _callbacks; - std::shared_ptr _timer; + std::shared_ptr _io_loop; + std::shared_ptr _async_h; + std::vector> _callbacks; + std::shared_ptr _timer; std::vector> _recv_packets; void _setup_receiver(); @@ -69,12 +69,12 @@ class PingReceiver PingReceiver(); ~PingReceiver(); - void register_async_callback(std::shared_ptr callback) + void register_async_callback(std::shared_ptr callback) { _callbacks.push_back(callback); } - void remove_async_callback(std::shared_ptr callback) + void remove_async_callback(std::shared_ptr callback) { _callbacks.erase(std::remove(_callbacks.begin(), _callbacks.end(), callback), _callbacks.end()); } @@ -97,9 +97,9 @@ class PingProbe final : public NetProbe bool _ip_set{false}; uint8_t _sequence{0}; uint8_t _internal_sequence{0}; - std::shared_ptr _interval_timer; - std::shared_ptr _internal_timer; - std::shared_ptr _recv_handler; + std::shared_ptr _interval_timer; + std::shared_ptr _internal_timer; + std::shared_ptr _recv_handler; SOCKETLEN _sin_length{0}; std::vector _payload_array; sockaddr_in _sa; @@ -116,7 +116,7 @@ class PingProbe final : public NetProbe PingProbe(uint16_t id, const std::string &name, const pcpp::IPAddress &ip, const std::string &dns) : NetProbe(id, name, ip, dns){}; ~PingProbe() = default; - bool start(std::shared_ptr io_loop) override; + bool start(std::shared_ptr io_loop) override; bool stop() override; }; } diff --git a/src/inputs/netprobe/TcpProbe.cpp b/src/inputs/netprobe/TcpProbe.cpp index 3765937d4..2cb61f978 100644 --- a/src/inputs/netprobe/TcpProbe.cpp +++ b/src/inputs/netprobe/TcpProbe.cpp @@ -13,7 +13,7 @@ #endif namespace visor::input::netprobe { -bool TcpProbe::start(std::shared_ptr io_loop) +bool TcpProbe::start(std::shared_ptr io_loop) { if (_init || (!_ip.isValid() && _dns.empty())) { return false; @@ -25,13 +25,12 @@ bool TcpProbe::start(std::shared_ptr io_loop) } _io_loop = io_loop; - _interval_timer = _io_loop->resource(); + _interval_timer = _io_loop->resource(); if (!_interval_timer) { throw NetProbeException("Netprobe - unable to initialize interval TimerHandle"); } - _interval_timer->on([this](const auto &, auto &) { - + _interval_timer->on([this](const auto &, auto &) { if (!_dns.empty()) { auto [ip, ipv4] = _resolve_dns(); _ip_str = ip; @@ -44,23 +43,23 @@ bool TcpProbe::start(std::shared_ptr io_loop) _perform_tcp_process(); }); - _interval_timer->start(uvw::TimerHandle::Time{0}, uvw::TimerHandle::Time{_config.interval_msec}); + _interval_timer->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{_config.interval_msec}); _init = true; return true; } void TcpProbe::_perform_tcp_process() { - _client = _io_loop->resource(); - _client->on([this](const auto &, auto &) { + _client = _io_loop->resource(); + _client->on([this](const auto &, auto &) { _fail(ErrorType::ConnectFailure, TestType::TCP, _name); }); - _client->once([this](const uvw::CloseEvent &, uvw::TCPHandle &) { + _client->on([this](const uvw::close_event &, uvw::tcp_handle &) { }); - _client->once([this](const uvw::ShutdownEvent &, uvw::TCPHandle &handle) { + _client->on([this](const uvw::shutdown_event &, uvw::tcp_handle &handle) { handle.close(); }); - _client->once([this](const uvw::ConnectEvent &, uvw::TCPHandle &handle) { + _client->on([this](const uvw::connect_event &, uvw::tcp_handle &handle) { timespec stamp; std::timespec_get(&stamp, TIME_UTC); pcpp::Packet packet; @@ -75,11 +74,7 @@ void TcpProbe::_perform_tcp_process() auto layer = pcpp::TcpLayer(0, static_cast(_dst_port)); packet.addLayer(&layer); _send(packet, TestType::TCP, _name, stamp); - if (_is_ipv4) { - _client->connect(_ip_str, _dst_port); - } else { - _client->connect(_ip_str, _dst_port); - } + _client->connect(_ip_str, _dst_port); } bool TcpProbe::stop() diff --git a/src/inputs/netprobe/TcpProbe.h b/src/inputs/netprobe/TcpProbe.h index 4452601ce..db14d11af 100644 --- a/src/inputs/netprobe/TcpProbe.h +++ b/src/inputs/netprobe/TcpProbe.h @@ -17,9 +17,9 @@ class TcpProbe final : public NetProbe bool _init{false}; bool _is_ipv4{false}; std::string _ip_str; - std::shared_ptr _interval_timer; + std::shared_ptr _interval_timer; - std::shared_ptr _client; + std::shared_ptr _client; void _perform_tcp_process(); @@ -28,7 +28,7 @@ class TcpProbe final : public NetProbe : NetProbe(id, name, ip, dns) , _dst_port(port) {}; ~TcpProbe() = default; - bool start(std::shared_ptr io_loop) override; + bool start(std::shared_ptr io_loop) override; bool stop() override; }; } diff --git a/src/inputs/pcap/afpacket.cpp b/src/inputs/pcap/afpacket.cpp index 7d6952b08..d6e56d5e5 100644 --- a/src/inputs/pcap/afpacket.cpp +++ b/src/inputs/pcap/afpacket.cpp @@ -60,7 +60,7 @@ AFPacket::~AFPacket() fd = -1; } if (map != nullptr) { - munmap(map, static_cast(block_size) * num_blocks); + munmap(map, static_cast(block_size) * num_blocks); } } @@ -274,17 +274,26 @@ void filter_try_compile(const std::string &filter, struct sock_fprog *bpf, int l link_type = 1; } - ret = pcap_compile_nopcap(65535, link_type, &prog, filter.c_str(), 1, 0xffffffff); + pcap_t *handle = pcap_open_dead(link_type, 65535); + if (handle == nullptr) { + throw PcapException("Failed to open pcap handle"); + } + + ret = pcap_compile(handle, &prog, filter.c_str(), 1, 0xffffffff); if (ret < 0) { + pcap_close(handle); throw PcapException("Failed to parse bpf filter: " + filter); } bpf->len = prog.bf_len; bpf->filter = reinterpret_cast(malloc(bpf->len * sizeof(struct sock_filter))); if (bpf->filter == nullptr) { + pcap_close(handle); throw PcapException("Failed to generating bpf filter: Out of memory"); } + pcap_close(handle); + for (i = 0, ins = prog.bf_insns, out = bpf->filter; i < bpf->len; ++i, ++ins, ++out) { out->code = ins->code;