mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
Clang format it all
This commit is contained in:
parent
12494aac45
commit
5cdc6e150e
18 changed files with 323 additions and 313 deletions
17
src/Flare.cc
17
src/Flare.cc
|
@ -13,7 +13,7 @@
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
||||||
#define fatalError(...) \
|
#define fatalError(...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if ( reporter ) \
|
if ( reporter ) \
|
||||||
reporter->FatalError(__VA_ARGS__); \
|
reporter->FatalError(__VA_ARGS__); \
|
||||||
|
@ -23,8 +23,7 @@ do \
|
||||||
fprintf(stderr, "\n"); \
|
fprintf(stderr, "\n"); \
|
||||||
_exit(1); \
|
_exit(1); \
|
||||||
} \
|
} \
|
||||||
} \
|
} while ( 0 )
|
||||||
while (0)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -39,28 +38,28 @@ Flare::Flare()
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if ( WSAStartup(MAKEWORD(2,2), &wsaData) != 0 )
|
if ( WSAStartup(MAKEWORD(2, 2), &wsaData) != 0 )
|
||||||
fatalError("WSAStartup failure: %d", WSAGetLastError());
|
fatalError("WSAStartup failure: %d", WSAGetLastError());
|
||||||
|
|
||||||
recvfd = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, nullptr, 0,
|
recvfd = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, nullptr, 0,
|
||||||
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
|
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
|
||||||
if ( recvfd == (int) INVALID_SOCKET )
|
if ( recvfd == (int)INVALID_SOCKET )
|
||||||
fatalError("WSASocket failure: %d", WSAGetLastError());
|
fatalError("WSASocket failure: %d", WSAGetLastError());
|
||||||
sendfd = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, nullptr, 0,
|
sendfd = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, nullptr, 0,
|
||||||
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
|
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
|
||||||
if ( sendfd == (int) INVALID_SOCKET )
|
if ( sendfd == (int)INVALID_SOCKET )
|
||||||
fatalError("WSASocket failure: %d", WSAGetLastError());
|
fatalError("WSASocket failure: %d", WSAGetLastError());
|
||||||
|
|
||||||
sockaddr_in sa;
|
sockaddr_in sa;
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sin_family = AF_INET;
|
sa.sin_family = AF_INET;
|
||||||
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
|
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||||
if ( bind(recvfd, (sockaddr*) &sa, sizeof(sa)) == SOCKET_ERROR )
|
if ( bind(recvfd, (sockaddr*)&sa, sizeof(sa)) == SOCKET_ERROR )
|
||||||
fatalError("bind failure: %d", WSAGetLastError());
|
fatalError("bind failure: %d", WSAGetLastError());
|
||||||
int salen = sizeof(sa);
|
int salen = sizeof(sa);
|
||||||
if ( getsockname(recvfd, (sockaddr*) &sa, &salen) == SOCKET_ERROR )
|
if ( getsockname(recvfd, (sockaddr*)&sa, &salen) == SOCKET_ERROR )
|
||||||
fatalError("getsockname failure: %d", WSAGetLastError());
|
fatalError("getsockname failure: %d", WSAGetLastError());
|
||||||
if ( connect(sendfd, (sockaddr*) &sa, sizeof(sa)) == SOCKET_ERROR )
|
if ( connect(sendfd, (sockaddr*)&sa, sizeof(sa)) == SOCKET_ERROR )
|
||||||
fatalError("connect failure: %d", WSAGetLastError());
|
fatalError("connect failure: %d", WSAGetLastError());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,9 +26,13 @@ public:
|
||||||
*/
|
*/
|
||||||
int FD() const
|
int FD() const
|
||||||
#if ! defined(_MSC_VER)
|
#if ! defined(_MSC_VER)
|
||||||
{ return pipe.ReadFD(); }
|
{
|
||||||
|
return pipe.ReadFD();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{ return recvfd; }
|
{
|
||||||
|
return recvfd;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3962,7 +3962,6 @@ ValManager::ValManager()
|
||||||
|
|
||||||
for ( auto i = 0u; i < PREALLOCATED_INTS; ++i )
|
for ( auto i = 0u; i < PREALLOCATED_INTS; ++i )
|
||||||
ints[i] = Val::MakeInt(PREALLOCATED_INT_LOWEST + i);
|
ints[i] = Val::MakeInt(PREALLOCATED_INT_LOWEST + i);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
|
const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
|
||||||
|
@ -3975,9 +3974,7 @@ const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
|
||||||
|
|
||||||
std::pair key{port_num, port_type};
|
std::pair key{port_num, port_type};
|
||||||
if ( ports.find(key) == ports.end() )
|
if ( ports.find(key) == ports.end() )
|
||||||
{
|
|
||||||
ports[key] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(port_num, port_type))};
|
ports[key] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(port_num, port_type))};
|
||||||
}
|
|
||||||
|
|
||||||
return ports[key];
|
return ports[key];
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ bool ARPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
|
||||||
auto ah = (const struct arp_pkthdr*)data;
|
auto ah = (const struct arp_pkthdr*)data;
|
||||||
|
|
||||||
// Check the size.
|
// Check the size.
|
||||||
size_t min_length = (ar_tpa(ah) - (caddr_t) data) + ah->ar_pln;
|
size_t min_length = (ar_tpa(ah) - (caddr_t)data) + ah->ar_pln;
|
||||||
if ( min_length > len )
|
if ( min_length > len )
|
||||||
{
|
{
|
||||||
Weird("truncated_ARP", packet);
|
Weird("truncated_ARP", packet);
|
||||||
|
|
|
@ -62,7 +62,8 @@ bool IPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_hdr = std::make_shared<IP_Hdr>((const struct ip6_hdr*)data, false, static_cast<int>(len));
|
packet->ip_hdr = std::make_shared<IP_Hdr>((const struct ip6_hdr*)data, false,
|
||||||
|
static_cast<int>(len));
|
||||||
packet->l3_proto = L3_IPV6;
|
packet->l3_proto = L3_IPV6;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "zeek/plugin/Manager.h"
|
#include "zeek/plugin/Manager.h"
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#if !defined(_MSC_VER)
|
#if ! defined(_MSC_VER)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
|
|
||||||
#include "zeek/Func.h"
|
#include <mutex>
|
||||||
#include "zeek/Event.h"
|
|
||||||
#include "zeek/Conn.h"
|
#include "zeek/Conn.h"
|
||||||
#include "zeek/Desc.h"
|
#include "zeek/Desc.h"
|
||||||
#include "zeek/threading/Formatter.h"
|
#include "zeek/Event.h"
|
||||||
|
#include "zeek/Func.h"
|
||||||
#include "zeek/RunState.h"
|
#include "zeek/RunState.h"
|
||||||
|
#include "zeek/threading/Formatter.h"
|
||||||
|
|
||||||
#include "statistics.bif.h"
|
#include "statistics.bif.h"
|
||||||
|
|
||||||
namespace zeek::plugin::statistics { Plugin plugin; }
|
namespace zeek::plugin::statistics
|
||||||
|
{
|
||||||
|
Plugin plugin;
|
||||||
|
}
|
||||||
|
|
||||||
using namespace zeek::plugin::statistics;
|
using namespace zeek::plugin::statistics;
|
||||||
|
|
||||||
|
@ -32,7 +35,7 @@ bool Plugin::HookQueueEvent(zeek::Event* event)
|
||||||
const char* name = event->Handler()->Name();
|
const char* name = event->Handler()->Name();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> scopedLock(m_lock);
|
std::lock_guard<std::mutex> scopedLock(m_lock);
|
||||||
if (m_eventNameCounters.find(name) == m_eventNameCounters.end())
|
if ( m_eventNameCounters.find(name) == m_eventNameCounters.end() )
|
||||||
{
|
{
|
||||||
m_eventNameCounters[name] = 0;
|
m_eventNameCounters[name] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "zeek/plugin/Plugin.h"
|
#include "zeek/plugin/Plugin.h"
|
||||||
|
|
||||||
namespace zeek::plugin::statistics {
|
namespace zeek::plugin::statistics
|
||||||
|
{
|
||||||
|
|
||||||
class Plugin : public zeek::plugin::Plugin
|
class Plugin : public zeek::plugin::Plugin
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
bool HookQueueEvent(zeek::Event* event) override;
|
bool HookQueueEvent(zeek::Event* event) override;
|
||||||
|
|
||||||
|
@ -22,8 +24,7 @@ public:
|
||||||
private:
|
private:
|
||||||
std::unordered_map<const char*, int> m_eventNameCounters;
|
std::unordered_map<const char*, int> m_eventNameCounters;
|
||||||
std::mutex m_lock;
|
std::mutex m_lock;
|
||||||
|
};
|
||||||
};
|
|
||||||
|
|
||||||
extern Plugin plugin;
|
extern Plugin plugin;
|
||||||
}
|
}
|
||||||
|
|
|
@ -995,12 +995,14 @@ std::optional<SupervisedNode> Stem::Poll()
|
||||||
node_pollfd_indices[name] = pfd_idx;
|
node_pollfd_indices[name] = pfd_idx;
|
||||||
|
|
||||||
if ( node.stdout_pipe.pipe )
|
if ( node.stdout_pipe.pipe )
|
||||||
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stdout_pipe.pipe->ReadFD()), POLLIN, 0};
|
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stdout_pipe.pipe->ReadFD()),
|
||||||
|
POLLIN, 0};
|
||||||
else
|
else
|
||||||
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0};
|
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0};
|
||||||
|
|
||||||
if ( node.stderr_pipe.pipe )
|
if ( node.stderr_pipe.pipe )
|
||||||
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stderr_pipe.pipe->ReadFD()), POLLIN, 0};
|
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stderr_pipe.pipe->ReadFD()),
|
||||||
|
POLLIN, 0};
|
||||||
else
|
else
|
||||||
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0};
|
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0};
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,9 @@ void BasicThread::SetName(const char* arg_name)
|
||||||
void BasicThread::SetOSName(const char* arg_name)
|
void BasicThread::SetOSName(const char* arg_name)
|
||||||
{
|
{
|
||||||
// Do it only if libc++ supports pthread_t.
|
// Do it only if libc++ supports pthread_t.
|
||||||
if constexpr(std::is_same<std::thread::native_handle_type, pthread_t>::value)
|
if constexpr ( std::is_same<std::thread::native_handle_type, pthread_t>::value )
|
||||||
zeek::util::detail::set_thread_name(arg_name, reinterpret_cast<pthread_t>(thread.native_handle()));
|
zeek::util::detail::set_thread_name(arg_name,
|
||||||
|
reinterpret_cast<pthread_t>(thread.native_handle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* BasicThread::Fmt(const char* format, ...)
|
const char* BasicThread::Fmt(const char* format, ...)
|
||||||
|
|
33
src/util.cc
33
src/util.cc
|
@ -40,9 +40,9 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <random>
|
|
||||||
|
|
||||||
#include "zeek/3rdparty/ConvertUTF.h"
|
#include "zeek/3rdparty/ConvertUTF.h"
|
||||||
#include "zeek/3rdparty/doctest.h"
|
#include "zeek/3rdparty/doctest.h"
|
||||||
|
@ -662,12 +662,13 @@ TEST_CASE("util normalize_path")
|
||||||
string normalize_path(std::string_view path)
|
string normalize_path(std::string_view path)
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (0 == path.compare(zeek::detail::ScannedFile::canonical_stdin_path)) {
|
if ( 0 == path.compare(zeek::detail::ScannedFile::canonical_stdin_path) )
|
||||||
|
{
|
||||||
return string(path);
|
return string(path);
|
||||||
}
|
}
|
||||||
// "//" interferes with std::weakly_canonical
|
// "//" interferes with std::weakly_canonical
|
||||||
string stringPath = string(path);
|
string stringPath = string(path);
|
||||||
if (stringPath._Starts_with("//"))
|
if ( stringPath._Starts_with("//") )
|
||||||
{
|
{
|
||||||
stringPath.erase(0, 2);
|
stringPath.erase(0, 2);
|
||||||
}
|
}
|
||||||
|
@ -1805,24 +1806,21 @@ FILE* open_file(const string& path, const string& mode)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("util path ops")
|
TEST_CASE("util path ops"){
|
||||||
{
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// TODO: adapt these tests to Windows paths
|
// TODO: adapt these tests to Windows paths
|
||||||
#else
|
#else
|
||||||
SUBCASE("SafeDirname")
|
SUBCASE("SafeDirname"){SafeDirname d("/this/is/a/path", false);
|
||||||
{
|
CHECK(d.result == "/this/is/a");
|
||||||
SafeDirname d("/this/is/a/path", false);
|
|
||||||
CHECK(d.result == "/this/is/a");
|
|
||||||
|
|
||||||
SafeDirname d2("invalid", false);
|
SafeDirname d2("invalid", false);
|
||||||
CHECK(d2.result == ".");
|
CHECK(d2.result == ".");
|
||||||
|
|
||||||
SafeDirname d3("./filename", false);
|
SafeDirname d3("./filename", false);
|
||||||
CHECK(d2.result == ".");
|
CHECK(d2.result == ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("SafeBasename")
|
SUBCASE("SafeBasename")
|
||||||
{
|
{
|
||||||
SafeBasename b("/this/is/a/path", false);
|
SafeBasename b("/this/is/a/path", false);
|
||||||
CHECK(b.result == "path");
|
CHECK(b.result == "path");
|
||||||
|
@ -1833,9 +1831,10 @@ TEST_CASE("util path ops")
|
||||||
CHECK(! b2.error);
|
CHECK(! b2.error);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeDirname::SafeDirname(const char* path, bool error_aborts) : SafePathOp()
|
SafeDirname::SafeDirname(const char* path, bool error_aborts)
|
||||||
|
: SafePathOp()
|
||||||
{
|
{
|
||||||
DoFunc(path ? path : "", error_aborts);
|
DoFunc(path ? path : "", error_aborts);
|
||||||
}
|
}
|
||||||
|
|
11
src/util.h
11
src/util.h
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
@ -82,13 +81,19 @@ extern "C"
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
namespace zeek { namespace filesystem = std::filesystem; }
|
namespace zeek
|
||||||
|
{
|
||||||
|
namespace filesystem = std::filesystem;
|
||||||
|
}
|
||||||
inline constexpr std::string_view path_list_separator = ";";
|
inline constexpr std::string_view path_list_separator = ";";
|
||||||
#else
|
#else
|
||||||
// Expose ghc::filesystem as zeek::filesystem until we can
|
// Expose ghc::filesystem as zeek::filesystem until we can
|
||||||
// switch to std::filesystem on all platforms.
|
// switch to std::filesystem on all platforms.
|
||||||
#include "zeek/3rdparty/ghc/filesystem.hpp"
|
#include "zeek/3rdparty/ghc/filesystem.hpp"
|
||||||
namespace zeek { namespace filesystem = ghc::filesystem; }
|
namespace zeek
|
||||||
|
{
|
||||||
|
namespace filesystem = ghc::filesystem;
|
||||||
|
}
|
||||||
inline constexpr std::string_view path_list_separator = ":";
|
inline constexpr std::string_view path_list_separator = ":";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "zeek/zeek-setup.h"
|
#include "zeek/zeek-setup.h"
|
||||||
|
|
||||||
#include "zeek/zeek-config.h"
|
#include "zeek/zeek-config.h"
|
||||||
|
@ -10,6 +8,7 @@
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -978,8 +977,8 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dns_type != DNS_PRIME )
|
if ( dns_type != DNS_PRIME )
|
||||||
run_state::detail::init_run(options.interface, options.pcap_file,
|
run_state::detail::init_run(options.interface, options.pcap_file, options.pcap_output_file,
|
||||||
options.pcap_output_file, options.use_watchdog);
|
options.use_watchdog);
|
||||||
|
|
||||||
if ( ! g_policy_debug )
|
if ( ! g_policy_debug )
|
||||||
{
|
{
|
||||||
|
@ -1107,8 +1106,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
packet_mgr->DumpDebug();
|
packet_mgr->DumpDebug();
|
||||||
analyzer_mgr->DumpDebug();
|
analyzer_mgr->DumpDebug();
|
||||||
|
|
||||||
run_state::detail::have_pending_timers = ! run_state::reading_traces &&
|
run_state::detail::have_pending_timers = ! run_state::reading_traces && timer_mgr->Size() > 0;
|
||||||
timer_mgr->Size() > 0;
|
|
||||||
|
|
||||||
return {0, std::move(options)};
|
return {0, std::move(options)};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue