mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
Merge branch 'topic/robin/event-dumper'
Changes: - Changing semantics of the new_event() meta event: it's raised only for events that have a handler defined. There are too many checks in Bro that prevent events wo/ handler from being even prepared to raise to do that differently. - Adding test case. * topic/robin/event-dumper: New script misc/dump-events.bro, along with core support, that dumps events Bro is raising in an easily readable form. Prettyfing Describe() for record types.
This commit is contained in:
commit
dadfcde70e
14 changed files with 420 additions and 8 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "Func.h"
|
||||
#include "Scope.h"
|
||||
#include "RemoteSerializer.h"
|
||||
#include "NetVar.h"
|
||||
|
||||
EventHandler::EventHandler(const char* arg_name)
|
||||
{
|
||||
|
@ -56,6 +57,9 @@ void EventHandler::Call(val_list* vl, bool no_remote)
|
|||
DEBUG_MSG("Event: %s\n", Name());
|
||||
#endif
|
||||
|
||||
if ( new_event )
|
||||
NewEvent(vl);
|
||||
|
||||
if ( ! no_remote )
|
||||
{
|
||||
loop_over_list(receivers, i)
|
||||
|
@ -75,6 +79,56 @@ void EventHandler::Call(val_list* vl, bool no_remote)
|
|||
}
|
||||
}
|
||||
|
||||
void EventHandler::NewEvent(val_list* vl)
|
||||
{
|
||||
if ( ! new_event )
|
||||
return;
|
||||
|
||||
if ( this == new_event.Ptr() )
|
||||
// new_event() is the one event we don't want to report.
|
||||
return;
|
||||
|
||||
RecordType* args = FType()->Args();
|
||||
VectorVal* vargs = new VectorVal(call_argument_vector);
|
||||
|
||||
for ( int i = 0; i < args->NumFields(); i++ )
|
||||
{
|
||||
const char* fname = args->FieldName(i);
|
||||
BroType* ftype = args->FieldType(i);
|
||||
Val* fdefault = args->FieldDefault(i);
|
||||
|
||||
RecordVal* rec = new RecordVal(call_argument);
|
||||
rec->Assign(0, new StringVal(fname));
|
||||
|
||||
ODesc d;
|
||||
d.SetShort();
|
||||
ftype->Describe(&d);
|
||||
rec->Assign(1, new StringVal(d.Description()));
|
||||
|
||||
if ( fdefault )
|
||||
{
|
||||
Ref(fdefault);
|
||||
rec->Assign(2, fdefault);
|
||||
}
|
||||
|
||||
if ( i < vl->length() && (*vl)[i] )
|
||||
{
|
||||
Val* val = (*vl)[i];
|
||||
Ref(val);
|
||||
rec->Assign(3, val);
|
||||
}
|
||||
|
||||
vargs->Assign(i, rec);
|
||||
}
|
||||
|
||||
val_list* mvl = new val_list(2);
|
||||
mvl->append(new StringVal(name));
|
||||
mvl->append(vargs);
|
||||
|
||||
Event* ev = new Event(new_event, mvl);
|
||||
mgr.Dispatch(ev);
|
||||
}
|
||||
|
||||
void EventHandler::AddRemoteHandler(SourceID peer)
|
||||
{
|
||||
receivers.append(peer);
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
static EventHandler* Unserialize(UnserialInfo* info);
|
||||
|
||||
private:
|
||||
void NewEvent(val_list* vl); // Raise new_event() meta event.
|
||||
|
||||
const char* name;
|
||||
Func* local;
|
||||
FuncType* type;
|
||||
|
|
|
@ -235,6 +235,8 @@ RecordType* script_id;
|
|||
TableType* id_table;
|
||||
RecordType* record_field;
|
||||
TableType* record_field_table;
|
||||
RecordType* call_argument;
|
||||
VectorType* call_argument_vector;
|
||||
|
||||
StringVal* cmd_line_bpf_filter;
|
||||
|
||||
|
@ -528,4 +530,6 @@ void init_net_var()
|
|||
id_table = internal_type("id_table")->AsTableType();
|
||||
record_field = internal_type("record_field")->AsRecordType();
|
||||
record_field_table = internal_type("record_field_table")->AsTableType();
|
||||
call_argument_vector = internal_type("call_argument_vector")->AsVectorType();
|
||||
call_argument = internal_type("call_argument")->AsRecordType();
|
||||
}
|
||||
|
|
|
@ -239,6 +239,8 @@ extern RecordType* script_id;
|
|||
extern TableType* id_table;
|
||||
extern RecordType* record_field;
|
||||
extern TableType* record_field_table;
|
||||
extern RecordType* call_argument;
|
||||
extern VectorType* call_argument_vector;
|
||||
|
||||
extern StringVal* cmd_line_bpf_filter;
|
||||
|
||||
|
|
14
src/Type.cc
14
src/Type.cc
|
@ -1035,10 +1035,16 @@ void RecordType::Describe(ODesc* d) const
|
|||
{
|
||||
if ( d->IsReadable() )
|
||||
{
|
||||
d->AddSP("record {");
|
||||
DescribeFields(d);
|
||||
d->SP();
|
||||
d->Add("}");
|
||||
if ( d->IsShort() && GetName().size() )
|
||||
d->Add(GetName());
|
||||
|
||||
else
|
||||
{
|
||||
d->AddSP("record {");
|
||||
DescribeFields(d);
|
||||
d->SP();
|
||||
d->Add("}");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
##! The protocol-independent events that the C/C++ core of Bro can generate.
|
||||
##!
|
||||
##!
|
||||
##! This is mostly events not related to a specific transport- or
|
||||
##! application-layer protocol, but also includes a few that may be generated
|
||||
##! by more than one protocols analyzer (like events generated by both UDP and
|
||||
##! TCP analysis.)
|
||||
##! TCP analysis.)
|
||||
|
||||
#
|
||||
# Documentation conventions:
|
||||
|
@ -1007,6 +1007,17 @@ event dns_mapping_lost_name%(dm: dns_mapping%);
|
|||
## dns_mapping_valid
|
||||
event dns_mapping_altered%(dm: dns_mapping, old_addrs: addr_set, new_addrs: addr_set%);
|
||||
|
||||
## A meta event generated for events that Bro raises. This will report all events
|
||||
## for which at least one handler is defined.
|
||||
##
|
||||
## Note that handling this meta event is expensive and should be limited to
|
||||
## debugging purposes.
|
||||
##
|
||||
## name: The name of the event.
|
||||
##
|
||||
## params: The event's parameters.
|
||||
event new_event%(name: string, params: call_argument_vector%);
|
||||
|
||||
## Deprecated. Will be removed.
|
||||
event root_backdoor_signature_found%(c: connection%);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue