Reformat the world

This commit is contained in:
Tim Wojtulewicz 2021-09-16 15:35:39 -07:00
parent 194cb24547
commit b2f171ec69
714 changed files with 35149 additions and 35203 deletions

View file

@ -3,19 +3,19 @@
#pragma once
#include <stdarg.h>
#include <list>
#include <utility>
#include <map>
#include <string>
#include <tuple>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "zeek/ZeekList.h"
#include "zeek/net_util.h"
namespace zeek {
namespace zeek
{
class Connection;
class EventHandlerPtr;
@ -28,34 +28,44 @@ template <class T> class IntrusivePtr;
using RecordValPtr = IntrusivePtr<RecordVal>;
using StringValPtr = IntrusivePtr<StringVal>;
namespace detail {
namespace detail
{
class Location;
class Expr;
} // namespace detail
} // namespace detail
namespace analyzer { class Analyzer; }
namespace file_analysis { class File; }
namespace analyzer
{
class Analyzer;
}
namespace file_analysis
{
class File;
}
// One cannot raise this exception directly, go through the
// Reporter's methods instead.
class ReporterException {
class ReporterException
{
protected:
friend class Reporter;
ReporterException() {}
};
ReporterException() { }
};
class InterpreterException : public ReporterException {
class InterpreterException : public ReporterException
{
protected:
friend class Reporter;
InterpreterException() {}
};
InterpreterException() { }
};
#define FMT_ATTR __attribute__((format(printf, 2, 3))) // sic! 1st is "this" I guess.
class Reporter {
class Reporter
{
public:
using IPPair = std::pair<IPAddr, IPAddr>;
using ConnTuple = std::tuple<IPAddr, IPAddr, uint32_t, uint32_t, TransportProto>;
@ -82,7 +92,7 @@ public:
void Error(const char* fmt, ...) FMT_ATTR;
// Returns the number of errors reported so far.
int Errors() { return errors; }
int Errors() { return errors; }
// Report a fatal error. Zeek will terminate after the message has been
// reported.
@ -94,11 +104,13 @@ public:
// Report a runtime error in evaluating a Zeek script expression. This
// function will not return but raise an InterpreterException.
[[noreturn]] void ExprRuntimeError(const detail::Expr* expr, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
[[noreturn]] void ExprRuntimeError(const detail::Expr* expr, const char* fmt, ...)
__attribute__((format(printf, 3, 4)));
// Report a runtime error in evaluating a Zeek script expression. This
// function will not return but raise an InterpreterException.
[[noreturn]] void RuntimeError(const detail::Location* location, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
[[noreturn]] void RuntimeError(const detail::Location* location, const char* fmt, ...)
__attribute__((format(printf, 3, 4)));
// Report a runtime error in executing a compiled script. This
// function will not return but raise an InterpreterException.
@ -106,15 +118,16 @@ public:
// Report a traffic weirdness, i.e., an unexpected protocol situation
// that may lead to incorrectly processing a connnection.
void Weird(const char* name, const char* addl = "", const char* source = ""); // Raises net_weird().
void Weird(file_analysis::File* f, const char* name,
const char* addl = "", const char* source = ""); // Raises file_weird().
void Weird(Connection* conn, const char* name,
const char* addl = "", const char* source = ""); // Raises conn_weird().
void Weird(RecordValPtr conn_id, StringValPtr uid,
const char* name, const char* addl = "", const char* source = ""); // Raises expired_conn_weird().
void Weird(const IPAddr& orig, const IPAddr& resp, const char* name,
const char* addl = "", const char* source = ""); // Raises flow_weird().
void Weird(const char* name, const char* addl = "",
const char* source = ""); // Raises net_weird().
void Weird(file_analysis::File* f, const char* name, const char* addl = "",
const char* source = ""); // Raises file_weird().
void Weird(Connection* conn, const char* name, const char* addl = "",
const char* source = ""); // Raises conn_weird().
void Weird(RecordValPtr conn_id, StringValPtr uid, const char* name, const char* addl = "",
const char* source = ""); // Raises expired_conn_weird().
void Weird(const IPAddr& orig, const IPAddr& resp, const char* name, const char* addl = "",
const char* source = ""); // Raises flow_weird().
// Syslog a message. This methods does nothing if we're running
// offline from a trace.
@ -130,32 +143,39 @@ public:
// Report an analyzer error. That analyzer will be set to not process
// any further input, but Zeek otherwise continues normally.
void AnalyzerError(analyzer::Analyzer* a, const char* fmt, ...) __attribute__((format(printf, 3, 4)));;
void AnalyzerError(analyzer::Analyzer* a, const char* fmt, ...)
__attribute__((format(printf, 3, 4)));
;
// Toggle whether non-fatal messages should be reported through the
// scripting layer rather on standard output. Fatal errors are always
// reported via stderr.
void ReportViaEvents(bool arg_via_events) { via_events = arg_via_events; }
void ReportViaEvents(bool arg_via_events) { via_events = arg_via_events; }
// Associates the given location with subsequent output. We create a
// stack of location so that the most recent is always the one that
// will be assumed to be the current one. The pointer must remain
// valid until the location is popped.
void PushLocation(const detail::Location* location)
{ locations.push_back(std::pair<const detail::Location*, const detail::Location*>(location, 0)); }
{
locations.push_back(
std::pair<const detail::Location*, const detail::Location*>(location, 0));
}
void PushLocation(const detail::Location* loc1, const detail::Location* loc2)
{ locations.push_back(std::pair<const detail::Location*, const detail::Location*>(loc1, loc2)); }
{
locations.push_back(
std::pair<const detail::Location*, const detail::Location*>(loc1, loc2));
}
// Removes the top-most location information from stack.
void PopLocation()
{ locations.pop_back(); }
void PopLocation() { locations.pop_back(); }
// Signals that we're entering processing an error handler event.
void BeginErrorHandler() { ++in_error_handler; }
void BeginErrorHandler() { ++in_error_handler; }
// Signals that we're done processing an error handler event.
void EndErrorHandler() { --in_error_handler; }
void EndErrorHandler() { --in_error_handler; }
/**
* Reset/cleanup state tracking for a "net" weird.
@ -176,23 +196,18 @@ public:
* Return the total number of weirds generated (counts weirds before
* any rate-limiting occurs).
*/
uint64_t GetWeirdCount() const
{ return weird_count; }
uint64_t GetWeirdCount() const { return weird_count; }
/**
* Return number of weirds generated per weird type/name (counts weirds
* before any rate-limiting occurs).
*/
const WeirdCountMap& GetWeirdsByType() const
{ return weird_count_by_type; }
const WeirdCountMap& GetWeirdsByType() const { return weird_count_by_type; }
/**
* Gets the weird sampling whitelist.
*/
const WeirdSet& GetWeirdSamplingWhitelist() const
{
return weird_sampling_whitelist;
}
const WeirdSet& GetWeirdSamplingWhitelist() const { return weird_sampling_whitelist; }
/**
* Sets the weird sampling whitelist.
@ -207,10 +222,7 @@ public:
/**
* Gets the weird sampling global list.
*/
const WeirdSet& GetWeirdSamplingGlobalList() const
{
return weird_sampling_global_list;
}
const WeirdSet& GetWeirdSamplingGlobalList() const { return weird_sampling_global_list; }
/**
* Sets the weird sampling global list.
@ -227,10 +239,7 @@ public:
*
* @return weird sampling threshold.
*/
uint64_t GetWeirdSamplingThreshold() const
{
return weird_sampling_threshold;
}
uint64_t GetWeirdSamplingThreshold() const { return weird_sampling_threshold; }
/**
* Sets the current weird sampling threshold.
@ -247,10 +256,7 @@ public:
*
* @return weird sampling rate.
*/
uint64_t GetWeirdSamplingRate() const
{
return weird_sampling_rate;
}
uint64_t GetWeirdSamplingRate() const { return weird_sampling_rate; }
/**
* Sets the weird sampling rate.
@ -267,10 +273,7 @@ public:
*
* @return weird sampling duration.
*/
double GetWeirdSamplingDuration() const
{
return weird_sampling_duration;
}
double GetWeirdSamplingDuration() const { return weird_sampling_duration; }
/**
* Sets the current weird sampling duration. Please note that
@ -284,23 +287,34 @@ public:
}
private:
void DoLog(const char* prefix, EventHandlerPtr event, FILE* out,
Connection* conn, ValPList* addl, bool location, bool time,
const char* postfix, const char* fmt, va_list ap) __attribute__((format(printf, 10, 0)));
void DoLog(const char* prefix, EventHandlerPtr event, FILE* out, Connection* conn,
ValPList* addl, bool location, bool time, const char* postfix, const char* fmt,
va_list ap) __attribute__((format(printf, 10, 0)));
// WeirdHelper doesn't really have to be variadic, but it calls DoLog
// and that takes va_list anyway.
void WeirdHelper(EventHandlerPtr event, ValPList vl, const char* fmt_name, ...) __attribute__((format(printf, 4, 5)));;
void WeirdHelper(EventHandlerPtr event, ValPList vl, const char* fmt_name, ...)
__attribute__((format(printf, 4, 5)));
;
void UpdateWeirdStats(const char* name);
inline bool WeirdOnSamplingWhiteList(const char* name)
{ return weird_sampling_whitelist.find(name) != weird_sampling_whitelist.end(); }
{
return weird_sampling_whitelist.find(name) != weird_sampling_whitelist.end();
}
inline bool WeirdOnGlobalList(const char* name)
{ return weird_sampling_global_list.find(name) != weird_sampling_global_list.end(); }
{
return weird_sampling_global_list.find(name) != weird_sampling_global_list.end();
}
bool PermitNetWeird(const char* name);
bool PermitFlowWeird(const char* name, const IPAddr& o, const IPAddr& r);
bool PermitExpiredConnWeird(const char* name, const RecordVal& conn_id);
enum class PermitWeird { Allow, Deny, Unknown };
enum class PermitWeird
{
Allow,
Deny,
Unknown
};
PermitWeird CheckGlobalWeirdLists(const char* name);
bool EmitToStderr(bool flag);
@ -313,7 +327,7 @@ private:
bool errors_to_stderr;
bool abort_on_scripting_errors = false;
std::list<std::pair<const detail::Location*, const detail::Location*> > locations;
std::list<std::pair<const detail::Location*, const detail::Location*>> locations;
uint64_t weird_count;
WeirdCountMap weird_count_by_type;
@ -326,9 +340,8 @@ private:
uint64_t weird_sampling_threshold;
uint64_t weird_sampling_rate;
double weird_sampling_duration;
};
};
extern Reporter* reporter;
} // namespace zeek
} // namespace zeek