Reformat Zeek in Spicy style

This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
This commit is contained in:
Benjamin Bannier 2023-10-10 21:13:34 +02:00
parent 7b8e7ed72c
commit f5a76c1aed
786 changed files with 131714 additions and 153609 deletions

View file

@ -11,13 +11,11 @@
#include "zeek/NetVar.h"
#include "zeek/session/Session.h"
namespace zeek
{
namespace zeek {
namespace detail
{
namespace detail {
class PacketFilter;
}
}
class EncapsulationStack;
class Packet;
@ -25,88 +23,84 @@ class Connection;
struct ConnTuple;
class StatBlocks;
namespace session
{
namespace session {
namespace detail
{
namespace detail {
class ProtocolStats;
}
}
struct Stats
{
size_t num_TCP_conns;
size_t max_TCP_conns;
uint64_t cumulative_TCP_conns;
struct Stats {
size_t num_TCP_conns;
size_t max_TCP_conns;
uint64_t cumulative_TCP_conns;
size_t num_UDP_conns;
size_t max_UDP_conns;
uint64_t cumulative_UDP_conns;
size_t num_UDP_conns;
size_t max_UDP_conns;
uint64_t cumulative_UDP_conns;
size_t num_ICMP_conns;
size_t max_ICMP_conns;
uint64_t cumulative_ICMP_conns;
size_t num_ICMP_conns;
size_t max_ICMP_conns;
uint64_t cumulative_ICMP_conns;
size_t num_fragments;
size_t max_fragments;
uint64_t num_packets;
};
size_t num_fragments;
size_t max_fragments;
uint64_t num_packets;
};
class Manager final
{
class Manager final {
public:
Manager();
~Manager();
Manager();
~Manager();
void Done(); // call to drain events before destructing
void Done(); // call to drain events before destructing
// Looks up the connection referred to by the given Val,
// which should be a conn_id record. Returns nil if there's
// no such connection or the Val is ill-formed.
Connection* FindConnection(Val* v);
// Looks up the connection referred to by the given Val,
// which should be a conn_id record. Returns nil if there's
// no such connection or the Val is ill-formed.
Connection* FindConnection(Val* v);
/**
* Looks up the connection referred to by a given key.
*
* @param conn_key The key for the connection to search for.
* @return The connection, or nullptr if one doesn't exist.
*/
Connection* FindConnection(const zeek::detail::ConnKey& conn_key);
/**
* Looks up the connection referred to by a given key.
*
* @param conn_key The key for the connection to search for.
* @return The connection, or nullptr if one doesn't exist.
*/
Connection* FindConnection(const zeek::detail::ConnKey& conn_key);
void Remove(Session* s);
void Insert(Session* c, bool remove_existing = true);
void Remove(Session* s);
void Insert(Session* c, bool remove_existing = true);
// Generating connection_pending events for all connections
// that are still active.
void Drain();
// Generating connection_pending events for all connections
// that are still active.
void Drain();
// Clears the session maps.
void Clear();
// Clears the session maps.
void Clear();
void GetStats(Stats& s);
void GetStats(Stats& s);
void Weird(const char* name, const Packet* pkt, const char* addl = "", const char* source = "");
void Weird(const char* name, const IP_Hdr* ip, const char* addl = "");
void Weird(const char* name, const Packet* pkt, const char* addl = "", const char* source = "");
void Weird(const char* name, const IP_Hdr* ip, const char* addl = "");
unsigned int CurrentSessions() { return session_map.size(); }
unsigned int CurrentSessions() { return session_map.size(); }
private:
using SessionMap = std::unordered_map<detail::Key, Session*, detail::KeyHash>;
using SessionMap = std::unordered_map<detail::Key, Session*, detail::KeyHash>;
// Inserts a new connection into the sessions map. If a connection with
// the same key already exists in the map, it will be overwritten by
// the new one. Connection count stats get updated either way (so most
// cases should likely check that the key is not already in the map to
// avoid unnecessary incrementing of connecting counts).
void InsertSession(detail::Key key, Session* session);
// Inserts a new connection into the sessions map. If a connection with
// the same key already exists in the map, it will be overwritten by
// the new one. Connection count stats get updated either way (so most
// cases should likely check that the key is not already in the map to
// avoid unnecessary incrementing of connecting counts).
void InsertSession(detail::Key key, Session* session);
SessionMap session_map;
detail::ProtocolStats* stats;
};
SessionMap session_map;
detail::ProtocolStats* stats;
};
} // namespace session
} // namespace session
// Manager for the currently active sessions.
extern session::Manager* session_mgr;
} // namespace zeek
} // namespace zeek