mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Add methods to queue events without handler existence check
Added ConnectionEventFast() and QueueEventFast() methods to avoid redundant event handler existence checks. It's common practice for caller to already check for event handler existence before doing all the work of constructing the arguments, so it's desirable to not have to check for existence again. E.g. going through ConnectionEvent() means 3 existence checks: one you do yourself before calling it, one in ConnectionEvent(), and then another in QueueEvent(). The existence check itself can be more than a few operations sometimes as it needs to check a few flags that determine if it's enabled, has a local body, or has any remote receivers in the old comm. system or has been flagged as something to publish in the new comm. system.
This commit is contained in:
parent
8bc65f09ec
commit
b6862c5c59
72 changed files with 771 additions and 524 deletions
|
@ -637,7 +637,7 @@ void File::FileEvent(EventHandlerPtr h, val_list* vl)
|
|||
|
||||
void File::FileEvent(EventHandlerPtr h, val_list vl)
|
||||
{
|
||||
mgr.QueueEvent(h, std::move(vl));
|
||||
mgr.QueueEventFast(h, std::move(vl));
|
||||
|
||||
if ( h == file_new || h == file_over_new_connection ||
|
||||
h == file_sniff ||
|
||||
|
|
|
@ -443,7 +443,7 @@ string Manager::GetFileID(analyzer::Tag tag, Connection* c, bool is_orig)
|
|||
EnumVal* tagval = tag.AsEnumVal();
|
||||
Ref(tagval);
|
||||
|
||||
mgr.QueueEvent(get_file_handle, {
|
||||
mgr.QueueEventFast(get_file_handle, {
|
||||
tagval,
|
||||
c->BuildConnVal(),
|
||||
val_mgr->GetBool(is_orig),
|
||||
|
|
|
@ -41,7 +41,7 @@ bool DataEvent::DeliverChunk(const u_char* data, uint64 len, uint64 offset)
|
|||
{
|
||||
if ( ! chunk_event ) return true;
|
||||
|
||||
mgr.QueueEvent(chunk_event, {
|
||||
mgr.QueueEventFast(chunk_event, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
new StringVal(new BroString(data, len, 0)),
|
||||
val_mgr->GetCount(offset),
|
||||
|
@ -54,7 +54,7 @@ bool DataEvent::DeliverStream(const u_char* data, uint64 len)
|
|||
{
|
||||
if ( ! stream_event ) return true;
|
||||
|
||||
mgr.QueueEvent(stream_event, {
|
||||
mgr.QueueEventFast(stream_event, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
new StringVal(new BroString(data, len, 0)),
|
||||
});
|
||||
|
|
|
@ -53,6 +53,9 @@ void Entropy::Finalize()
|
|||
if ( ! fed )
|
||||
return;
|
||||
|
||||
if ( ! file_entropy )
|
||||
return;
|
||||
|
||||
double montepi, scc, ent, mean, chisq;
|
||||
montepi = scc = ent = mean = chisq = 0.0;
|
||||
entropy->Get(&ent, &chisq, &mean, &montepi, &scc);
|
||||
|
@ -64,7 +67,7 @@ void Entropy::Finalize()
|
|||
ent_result->Assign(3, new Val(montepi, TYPE_DOUBLE));
|
||||
ent_result->Assign(4, new Val(scc, TYPE_DOUBLE));
|
||||
|
||||
mgr.QueueEvent(file_entropy, {
|
||||
mgr.QueueEventFast(file_entropy, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
ent_result,
|
||||
});
|
||||
|
|
|
@ -48,7 +48,10 @@ void Hash::Finalize()
|
|||
if ( ! hash->IsValid() || ! fed )
|
||||
return;
|
||||
|
||||
mgr.QueueEvent(file_hash, {
|
||||
if ( ! file_hash )
|
||||
return;
|
||||
|
||||
mgr.QueueEventFast(file_hash, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
new StringVal(kind),
|
||||
hash->Get(),
|
||||
|
|
|
@ -81,7 +81,7 @@ refine flow Flow += {
|
|||
ids_event->Assign(11, to_port(${ev.dst_p}, ${ev.protocol}));
|
||||
ids_event->Assign(17, val_mgr->GetCount(${ev.packet_action}));
|
||||
|
||||
mgr.QueueEvent(::unified2_event, {
|
||||
mgr.QueueEventFast(::unified2_event, {
|
||||
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
|
||||
ids_event,
|
||||
},
|
||||
|
@ -113,7 +113,7 @@ refine flow Flow += {
|
|||
ids_event->Assign(15, val_mgr->GetCount(${ev.mpls_label}));
|
||||
ids_event->Assign(16, val_mgr->GetCount(${ev.vlan_id}));
|
||||
|
||||
mgr.QueueEvent(::unified2_event, {
|
||||
mgr.QueueEventFast(::unified2_event, {
|
||||
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
|
||||
ids_event,
|
||||
},
|
||||
|
@ -135,7 +135,7 @@ refine flow Flow += {
|
|||
packet->Assign(4, val_mgr->GetCount(${pkt.link_type}));
|
||||
packet->Assign(5, bytestring_to_val(${pkt.packet_data}));
|
||||
|
||||
mgr.QueueEvent(::unified2_packet, {
|
||||
mgr.QueueEventFast(::unified2_packet, {
|
||||
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
|
||||
packet,
|
||||
},
|
||||
|
|
|
@ -427,10 +427,11 @@ void file_analysis::OCSP::ParseRequest(OCSP_REQUEST* req)
|
|||
// TODO: try to parse out general name ?
|
||||
#endif
|
||||
|
||||
mgr.QueueEvent(ocsp_request, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
val_mgr->GetCount(version),
|
||||
});
|
||||
if ( ocsp_request )
|
||||
mgr.QueueEventFast(ocsp_request, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
val_mgr->GetCount(version),
|
||||
});
|
||||
|
||||
BIO *bio = BIO_new(BIO_s_mem());
|
||||
|
||||
|
@ -470,10 +471,11 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
const char *status_str = OCSP_response_status_str(OCSP_response_status(resp));
|
||||
StringVal* status_val = new StringVal(strlen(status_str), status_str);
|
||||
|
||||
mgr.QueueEvent(ocsp_response_status, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
status_val->Ref(),
|
||||
});
|
||||
if ( ocsp_response_status )
|
||||
mgr.QueueEventFast(ocsp_response_status, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
status_val->Ref(),
|
||||
});
|
||||
|
||||
//if (!resp_bytes)
|
||||
// {
|
||||
|
@ -491,12 +493,18 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
// get the basic response
|
||||
basic_resp = OCSP_response_get1_basic(resp);
|
||||
if ( !basic_resp )
|
||||
{
|
||||
Unref(status_val);
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
#if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER)
|
||||
resp_data = basic_resp->tbsResponseData;
|
||||
if ( !resp_data )
|
||||
{
|
||||
Unref(status_val);
|
||||
goto clean_up;
|
||||
}
|
||||
#endif
|
||||
|
||||
vl.append(GetFile()->GetVal()->Ref());
|
||||
|
|
|
@ -221,16 +221,20 @@ void file_analysis::X509::ParseBasicConstraints(X509_EXTENSION* ex)
|
|||
|
||||
if ( constr )
|
||||
{
|
||||
RecordVal* pBasicConstraint = new RecordVal(BifType::Record::X509::BasicConstraints);
|
||||
pBasicConstraint->Assign(0, val_mgr->GetBool(constr->ca ? 1 : 0));
|
||||
if ( x509_ext_basic_constraints )
|
||||
{
|
||||
RecordVal* pBasicConstraint = new RecordVal(BifType::Record::X509::BasicConstraints);
|
||||
pBasicConstraint->Assign(0, val_mgr->GetBool(constr->ca ? 1 : 0));
|
||||
|
||||
if ( constr->pathlen )
|
||||
pBasicConstraint->Assign(1, val_mgr->GetCount((int32_t) ASN1_INTEGER_get(constr->pathlen)));
|
||||
if ( constr->pathlen )
|
||||
pBasicConstraint->Assign(1, val_mgr->GetCount((int32_t) ASN1_INTEGER_get(constr->pathlen)));
|
||||
|
||||
mgr.QueueEventFast(x509_ext_basic_constraints, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
pBasicConstraint,
|
||||
});
|
||||
}
|
||||
|
||||
mgr.QueueEvent(x509_ext_basic_constraints, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
pBasicConstraint,
|
||||
});
|
||||
BASIC_CONSTRAINTS_free(constr);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,9 @@ refine connection MockConnection += {
|
|||
|
||||
function proc_signedcertificatetimestamp(rec: HandshakeRecord, version: uint8, logid: const_bytestring, timestamp: uint64, digitally_signed_algorithms: SignatureAndHashAlgorithm, digitally_signed_signature: const_bytestring) : bool
|
||||
%{
|
||||
if ( ! x509_ocsp_ext_signed_certificate_timestamp )
|
||||
return true;
|
||||
|
||||
BifEvent::generate_x509_ocsp_ext_signed_certificate_timestamp((analyzer::Analyzer *) bro_analyzer(),
|
||||
bro_analyzer()->GetFile()->GetVal()->Ref(),
|
||||
version,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue