mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Move Anon.h into zeek::detail namespace
This commit is contained in:
parent
7a5dae4354
commit
9992ec5c11
4 changed files with 19 additions and 14 deletions
12
src/Anon.cc
12
src/Anon.cc
|
@ -14,7 +14,9 @@
|
||||||
#include "ID.h"
|
#include "ID.h"
|
||||||
#include "IPAddr.h"
|
#include "IPAddr.h"
|
||||||
|
|
||||||
AnonymizeIPAddr* ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr};
|
using namespace zeek::detail;
|
||||||
|
|
||||||
|
AnonymizeIPAddr* zeek::detail::ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr};
|
||||||
|
|
||||||
static uint32_t rand32()
|
static uint32_t rand32()
|
||||||
{
|
{
|
||||||
|
@ -22,7 +24,7 @@ static uint32_t rand32()
|
||||||
}
|
}
|
||||||
|
|
||||||
// From tcpdpriv.
|
// From tcpdpriv.
|
||||||
int bi_ffs(uint32_t value)
|
static int bi_ffs(uint32_t value)
|
||||||
{
|
{
|
||||||
int add = 0;
|
int add = 0;
|
||||||
static uint8_t bvals[] = {
|
static uint8_t bvals[] = {
|
||||||
|
@ -360,7 +362,7 @@ static IntrusivePtr<TableVal> anon_preserve_orig_addr;
|
||||||
static IntrusivePtr<TableVal> anon_preserve_resp_addr;
|
static IntrusivePtr<TableVal> anon_preserve_resp_addr;
|
||||||
static IntrusivePtr<TableVal> anon_preserve_other_addr;
|
static IntrusivePtr<TableVal> anon_preserve_other_addr;
|
||||||
|
|
||||||
void init_ip_addr_anonymizers()
|
void zeek::detail::init_ip_addr_anonymizers()
|
||||||
{
|
{
|
||||||
ip_anonymizer[KEEP_ORIG_ADDR] = nullptr;
|
ip_anonymizer[KEEP_ORIG_ADDR] = nullptr;
|
||||||
ip_anonymizer[SEQUENTIALLY_NUMBERED] = new AnonymizeIPAddr_Seq();
|
ip_anonymizer[SEQUENTIALLY_NUMBERED] = new AnonymizeIPAddr_Seq();
|
||||||
|
@ -384,7 +386,7 @@ void init_ip_addr_anonymizers()
|
||||||
anon_preserve_other_addr = cast_intrusive<TableVal>(id->GetVal());
|
anon_preserve_other_addr = cast_intrusive<TableVal>(id->GetVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
|
ipaddr32_t zeek::detail::anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
|
||||||
{
|
{
|
||||||
TableVal* preserve_addr = nullptr;
|
TableVal* preserve_addr = nullptr;
|
||||||
auto addr = make_intrusive<AddrVal>(ip);
|
auto addr = make_intrusive<AddrVal>(ip);
|
||||||
|
@ -439,7 +441,7 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
|
||||||
#include "NetVar.h"
|
#include "NetVar.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output)
|
void zeek::detail::log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output)
|
||||||
{
|
{
|
||||||
if ( anonymization_mapping )
|
if ( anonymization_mapping )
|
||||||
mgr.Enqueue(anonymization_mapping,
|
mgr.Enqueue(anonymization_mapping,
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace zeek::detail {
|
||||||
|
|
||||||
// TODO: Anon.h may not be the right place to put these functions ...
|
// TODO: Anon.h may not be the right place to put these functions ...
|
||||||
|
|
||||||
enum ip_addr_anonymization_class_t {
|
enum ip_addr_anonymization_class_t {
|
||||||
|
@ -126,3 +128,5 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl);
|
||||||
|
|
||||||
#define LOG_ANONYMIZATION_MAPPING
|
#define LOG_ANONYMIZATION_MAPPING
|
||||||
void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output);
|
void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ void net_init(const std::optional<std::string>& interface,
|
||||||
reporter->Error("trace_output_file not defined in bro.init");
|
reporter->Error("trace_output_file not defined in bro.init");
|
||||||
}
|
}
|
||||||
|
|
||||||
init_ip_addr_anonymizers();
|
zeek::detail::init_ip_addr_anonymizers();
|
||||||
|
|
||||||
sessions = new NetSessions();
|
sessions = new NetSessions();
|
||||||
|
|
||||||
|
@ -409,8 +409,8 @@ void net_delete()
|
||||||
|
|
||||||
delete sessions;
|
delete sessions;
|
||||||
|
|
||||||
for ( int i = 0; i < NUM_ADDR_ANONYMIZATION_METHODS; ++i )
|
for ( int i = 0; i < zeek::detail::NUM_ADDR_ANONYMIZATION_METHODS; ++i )
|
||||||
delete ip_anonymizer[i];
|
delete zeek::detail::ip_anonymizer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
int _processing_suspended = 0;
|
int _processing_suspended = 0;
|
||||||
|
|
11
src/zeek.bif
11
src/zeek.bif
|
@ -5024,7 +5024,7 @@ function match_signatures%(c: connection, pattern_type: int, s: string,
|
||||||
## .. todo:: Currently dysfunctional.
|
## .. todo:: Currently dysfunctional.
|
||||||
function preserve_prefix%(a: addr, width: count%): any
|
function preserve_prefix%(a: addr, width: count%): any
|
||||||
%{
|
%{
|
||||||
AnonymizeIPAddr* ip_anon = ip_anonymizer[PREFIX_PRESERVING_A50];
|
zeek::detail::AnonymizeIPAddr* ip_anon = zeek::detail::ip_anonymizer[zeek::detail::PREFIX_PRESERVING_A50];
|
||||||
if ( ip_anon )
|
if ( ip_anon )
|
||||||
{
|
{
|
||||||
if ( a->AsAddr().GetFamily() == IPv6 )
|
if ( a->AsAddr().GetFamily() == IPv6 )
|
||||||
|
@ -5037,7 +5037,6 @@ function preserve_prefix%(a: addr, width: count%): any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -5051,7 +5050,7 @@ function preserve_prefix%(a: addr, width: count%): any
|
||||||
function preserve_subnet%(a: subnet%): any
|
function preserve_subnet%(a: subnet%): any
|
||||||
%{
|
%{
|
||||||
DEBUG_MSG("%s/%d\n", a->Prefix().AsString().c_str(), a->Width());
|
DEBUG_MSG("%s/%d\n", a->Prefix().AsString().c_str(), a->Width());
|
||||||
AnonymizeIPAddr* ip_anon = ip_anonymizer[PREFIX_PRESERVING_A50];
|
zeek::detail::AnonymizeIPAddr* ip_anon = zeek::detail::ip_anonymizer[zeek::detail::PREFIX_PRESERVING_A50];
|
||||||
if ( ip_anon )
|
if ( ip_anon )
|
||||||
{
|
{
|
||||||
if ( a->AsSubNet().Prefix().GetFamily() == IPv6 )
|
if ( a->AsSubNet().Prefix().GetFamily() == IPv6 )
|
||||||
|
@ -5087,7 +5086,7 @@ function preserve_subnet%(a: subnet%): any
|
||||||
function anonymize_addr%(a: addr, cl: IPAddrAnonymizationClass%): addr
|
function anonymize_addr%(a: addr, cl: IPAddrAnonymizationClass%): addr
|
||||||
%{
|
%{
|
||||||
int anon_class = cl->InternalInt();
|
int anon_class = cl->InternalInt();
|
||||||
if ( anon_class < 0 || anon_class >= NUM_ADDR_ANONYMIZATION_CLASSES )
|
if ( anon_class < 0 || anon_class >= zeek::detail::NUM_ADDR_ANONYMIZATION_CLASSES )
|
||||||
builtin_error("anonymize_addr(): invalid ip addr anonymization class");
|
builtin_error("anonymize_addr(): invalid ip addr anonymization class");
|
||||||
|
|
||||||
if ( a->AsAddr().GetFamily() == IPv6 )
|
if ( a->AsAddr().GetFamily() == IPv6 )
|
||||||
|
@ -5099,8 +5098,8 @@ function anonymize_addr%(a: addr, cl: IPAddrAnonymizationClass%): addr
|
||||||
{
|
{
|
||||||
const uint32_t* bytes;
|
const uint32_t* bytes;
|
||||||
a->AsAddr().GetBytes(&bytes);
|
a->AsAddr().GetBytes(&bytes);
|
||||||
return make_intrusive<AddrVal>(anonymize_ip(*bytes,
|
return make_intrusive<AddrVal>(zeek::detail::anonymize_ip(*bytes,
|
||||||
(enum ip_addr_anonymization_class_t) anon_class));
|
static_cast<zeek::detail::ip_addr_anonymization_class_t>(anon_class)));
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue