use differentiated record field accessors

This commit is contained in:
Vern Paxson 2021-02-25 14:47:44 -08:00
parent e363bab55f
commit 931cec4e06
10 changed files with 21 additions and 15 deletions

View file

@ -631,7 +631,7 @@ void Connection::CheckFlowLabel(bool is_orig, uint32_t flow_label)
{
if ( conn_val )
{
RecordVal* endp = conn_val->GetField(is_orig ? 1 : 2)->AsRecordVal();
RecordVal* endp = conn_val->GetFieldAs<RecordVal>(is_orig ? 1 : 2);
endp->Assign(4, val_mgr->Count(flow_label));
}

View file

@ -111,7 +111,7 @@ Substring::Vec* Substring::VecFromPolicy(VectorVal* vec)
const String* str = v->GetFieldAs<StringVal>(0);
auto* substr = new Substring(*str);
const VectorVal* aligns = v->GetField(1)->AsVectorVal();
const VectorVal* aligns = v->GetFieldAs<VectorVal>(1);
for ( unsigned int j = 1; j <= aligns->Size(); ++j )
{
const RecordVal* align = aligns->AsVectorVal()->RecordValAt(j);

View file

@ -1310,6 +1310,9 @@ protected:
static RecordTypeValMap parse_time_records;
private:
// Just for template inferencing.
RecordVal* Get() { return this; }
// Keep this handy for quick access during low-level operations.
RecordTypePtr rt;
@ -1479,6 +1482,10 @@ protected:
ValPtr DoClone(CloneState* state) override;
private:
// Just for template inferencing.
friend class RecordVal;
VectorVal* Get() { return this; }
// Check the type of the given element against our current
// yield type and adjust as necessary. Returns whether the
// element type-checked.

View file

@ -171,8 +171,8 @@ void ConnSize_Analyzer::SetDurationThreshold(double duration)
void ConnSize_Analyzer::UpdateConnVal(RecordVal *conn_val)
{
// RecordType *connection_type is decleared in NetVar.h
RecordVal* orig_endp = conn_val->GetField("orig")->AsRecordVal();
RecordVal* resp_endp = conn_val->GetField("resp")->AsRecordVal();
RecordVal* orig_endp = conn_val->GetFieldAs<RecordVal>("orig");
RecordVal* resp_endp = conn_val->GetFieldAs<RecordVal>("resp");
// endpoint is the RecordType from NetVar.h
int pktidx = id::endpoint->FieldOffset("num_pkts");

View file

@ -126,8 +126,8 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu
return false;
RecordVal* rv = c->RequestVal()->AsRecordVal();
const auto& is_tcp = rv->GetField(2);
reply = val_mgr->Port(CheckPort(port), is_tcp->IsOne() ?
auto is_tcp = rv->GetFieldAs<BoolVal>(2);
reply = val_mgr->Port(CheckPort(port), is_tcp ?
TRANSPORT_TCP : TRANSPORT_UDP);
event = pm_request_getport;
}

View file

@ -1099,7 +1099,7 @@ void TCP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig,
{
SynWeirds(flags, endpoint, len);
RecordVal* SYN_vals = build_syn_packet_val(is_orig, ip, tp);
init_window(endpoint, peer, flags, SYN_vals->GetField(5)->CoerceToInt(),
init_window(endpoint, peer, flags, SYN_vals->GetFieldAs<IntVal>(5),
base_seq, ack_seq);
if ( connection_SYN_packet )
@ -1282,8 +1282,8 @@ void TCP_Analyzer::FlipRoles()
void TCP_Analyzer::UpdateConnVal(RecordVal *conn_val)
{
RecordVal* orig_endp_val = conn_val->GetField("orig")->AsRecordVal();
RecordVal* resp_endp_val = conn_val->GetField("resp")->AsRecordVal();
auto orig_endp_val = conn_val->GetFieldAs<RecordVal>("orig");
auto resp_endp_val = conn_val->GetFieldAs<RecordVal>("resp");
orig_endp_val->Assign(0, val_mgr->Count(orig->Size()));
orig_endp_val->Assign(1, val_mgr->Count(int(orig->state)));

View file

@ -220,8 +220,8 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig,
void UDP_Analyzer::UpdateConnVal(RecordVal* conn_val)
{
RecordVal* orig_endp = conn_val->GetField("orig")->AsRecordVal();
RecordVal* resp_endp = conn_val->GetField("resp")->AsRecordVal();
auto orig_endp = conn_val->GetFieldAs<RecordVal>("orig");
auto resp_endp = conn_val->GetFieldAs<RecordVal>("resp");
UpdateEndpointVal(orig_endp, true);
UpdateEndpointVal(resp_endp, false);

View file

@ -437,7 +437,7 @@ bool Manager::PublishEvent(string topic, RecordVal* args)
return false;
auto event_name = args->GetFieldAs<StringVal>(0)->CheckString();
auto vv = args->GetField(1)->AsVectorVal();
auto vv = args->GetFieldAs<VectorVal>(1);
broker::vector xs;
xs.reserve(vv->Size());

View file

@ -67,7 +67,7 @@ broker::backend_options to_backend_options(broker::backend backend,
switch ( backend ) {
case broker::backend::sqlite:
{
auto path = options->GetField(0)->AsRecordVal()
auto path = options->GetFieldAs<RecordVal>(0)
->GetFieldAs<StringVal>(0)->CheckString();
return {{"path", path}};
}

View file

@ -3435,8 +3435,7 @@ function lookup_connection%(cid: conn_id%): connection
%%{
const char* conn_id_string(zeek::Val* c)
{
auto id = c->As<zeek::RecordVal*>()->GetField(0);
auto id_r = id->As<zeek::RecordVal*>();
auto id_r = c->As<zeek::RecordVal*>()->GetFieldAs<zeek::RecordVal>(0);
const zeek::IPAddr& orig_h = id_r->GetFieldAs<zeek::AddrVal>(0);
uint32_t orig_p = id_r->GetFieldAs<zeek::PortVal>(1)->Port();